I'm not like other IDs

- Added support for TFC wood types on water wheels #6092
This commit is contained in:
simibubi 2024-07-25 18:47:04 +02:00
parent fc21d3abf6
commit 4ce2971979

View file

@ -5,6 +5,8 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Random; import java.util.Random;
import javax.annotation.Nullable;
import com.jozufozu.flywheel.core.StitchedSprite; import com.jozufozu.flywheel.core.StitchedSprite;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.simibubi.create.AllPartialModels; import com.simibubi.create.AllPartialModels;
@ -40,8 +42,6 @@ public class WaterWheelRenderer<T extends WaterWheelBlockEntity> extends Kinetic
public static final StitchedSprite OAK_LOG_TEMPLATE = new StitchedSprite(new ResourceLocation("block/oak_log")); public static final StitchedSprite OAK_LOG_TEMPLATE = new StitchedSprite(new ResourceLocation("block/oak_log"));
public static final StitchedSprite OAK_LOG_TOP_TEMPLATE = new StitchedSprite(new ResourceLocation("block/oak_log_top")); public static final StitchedSprite OAK_LOG_TOP_TEMPLATE = new StitchedSprite(new ResourceLocation("block/oak_log_top"));
private static final String[] LOG_SUFFIXES = new String[] { "_log", "_stem" };
protected final boolean large; protected final boolean large;
public WaterWheelRenderer(Context context, boolean large) { public WaterWheelRenderer(Context context, boolean large) {
@ -94,11 +94,12 @@ public class WaterWheelRenderer<T extends WaterWheelBlockEntity> extends Kinetic
public static BakedModel generateModel(BakedModel template, BlockState planksBlockState) { public static BakedModel generateModel(BakedModel template, BlockState planksBlockState) {
Block planksBlock = planksBlockState.getBlock(); Block planksBlock = planksBlockState.getBlock();
ResourceLocation id = RegisteredObjects.getKeyOrThrow(planksBlock); ResourceLocation id = RegisteredObjects.getKeyOrThrow(planksBlock);
String path = id.getPath(); String wood = plankStateToWoodName(planksBlockState);
if (wood == null)
return BakedModelHelper.generateModel(template, sprite -> null);
if (path.endsWith("_planks")) {
String namespace = id.getNamespace(); String namespace = id.getNamespace();
String wood = path.substring(0, path.length() - 7);
BlockState logBlockState = getLogBlockState(namespace, wood); BlockState logBlockState = getLogBlockState(namespace, wood);
Map<TextureAtlasSprite, TextureAtlasSprite> map = new Reference2ReferenceOpenHashMap<>(); Map<TextureAtlasSprite, TextureAtlasSprite> map = new Reference2ReferenceOpenHashMap<>();
@ -109,13 +110,32 @@ public class WaterWheelRenderer<T extends WaterWheelBlockEntity> extends Kinetic
return BakedModelHelper.generateModel(template, map::get); return BakedModelHelper.generateModel(template, map::get);
} }
return BakedModelHelper.generateModel(template, sprite -> null); @Nullable
private static String plankStateToWoodName(BlockState planksBlockState) {
Block planksBlock = planksBlockState.getBlock();
ResourceLocation id = RegisteredObjects.getKeyOrThrow(planksBlock);
String path = id.getPath();
if (path.endsWith("_planks")) // Covers most wood types
return path.substring(0, path.length() - 7);
if (path.contains("wood/planks/")) // TerraFirmaCraft
return path.substring(12);
return null;
} }
private static final String[] LOG_LOCATIONS = new String[] {
"x_log", "x_stem", // Covers most wood types
"wood/log/x" // TerraFirmaCraft
};
private static BlockState getLogBlockState(String namespace, String wood) { private static BlockState getLogBlockState(String namespace, String wood) {
for (String suffix : LOG_SUFFIXES) { for (String location : LOG_LOCATIONS) {
Optional<BlockState> state = Optional<BlockState> state =
ForgeRegistries.BLOCKS.getHolder(new ResourceLocation(namespace, wood + suffix)) ForgeRegistries.BLOCKS.getHolder(new ResourceLocation(namespace, location.replace("x", wood)))
.map(Holder::value) .map(Holder::value)
.map(Block::defaultBlockState); .map(Block::defaultBlockState);
if (state.isPresent()) if (state.isPresent())