From 4ce2971979d4841282c6edf0ec72da4a4f78594c Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Thu, 25 Jul 2024 18:47:04 +0200 Subject: [PATCH] I'm not like other IDs - Added support for TFC wood types on water wheels #6092 --- .../waterwheel/WaterWheelRenderer.java | 58 +++++++++++++------ 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/kinetics/waterwheel/WaterWheelRenderer.java b/src/main/java/com/simibubi/create/content/kinetics/waterwheel/WaterWheelRenderer.java index d51040ffb..cf5f547c7 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/waterwheel/WaterWheelRenderer.java +++ b/src/main/java/com/simibubi/create/content/kinetics/waterwheel/WaterWheelRenderer.java @@ -5,6 +5,8 @@ import java.util.Map; import java.util.Optional; import java.util.Random; +import javax.annotation.Nullable; + import com.jozufozu.flywheel.core.StitchedSprite; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.AllPartialModels; @@ -40,8 +42,6 @@ public class WaterWheelRenderer extends Kinetic 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")); - private static final String[] LOG_SUFFIXES = new String[] { "_log", "_stem" }; - protected final boolean large; public WaterWheelRenderer(Context context, boolean large) { @@ -92,30 +92,50 @@ public class WaterWheelRenderer extends Kinetic } public static BakedModel generateModel(BakedModel template, BlockState planksBlockState) { + Block planksBlock = planksBlockState.getBlock(); + ResourceLocation id = RegisteredObjects.getKeyOrThrow(planksBlock); + String wood = plankStateToWoodName(planksBlockState); + + if (wood == null) + return BakedModelHelper.generateModel(template, sprite -> null); + + String namespace = id.getNamespace(); + BlockState logBlockState = getLogBlockState(namespace, wood); + + Map map = new Reference2ReferenceOpenHashMap<>(); + map.put(OAK_PLANKS_TEMPLATE.get(), getSpriteOnSide(planksBlockState, Direction.UP)); + map.put(OAK_LOG_TEMPLATE.get(), getSpriteOnSide(logBlockState, Direction.SOUTH)); + map.put(OAK_LOG_TOP_TEMPLATE.get(), getSpriteOnSide(logBlockState, Direction.UP)); + + return BakedModelHelper.generateModel(template, map::get); + } + + @Nullable + private static String plankStateToWoodName(BlockState planksBlockState) { Block planksBlock = planksBlockState.getBlock(); ResourceLocation id = RegisteredObjects.getKeyOrThrow(planksBlock); String path = id.getPath(); - - if (path.endsWith("_planks")) { - String namespace = id.getNamespace(); - String wood = path.substring(0, path.length() - 7); - BlockState logBlockState = getLogBlockState(namespace, wood); - - Map map = new Reference2ReferenceOpenHashMap<>(); - map.put(OAK_PLANKS_TEMPLATE.get(), getSpriteOnSide(planksBlockState, Direction.UP)); - map.put(OAK_LOG_TEMPLATE.get(), getSpriteOnSide(logBlockState, Direction.SOUTH)); - map.put(OAK_LOG_TOP_TEMPLATE.get(), getSpriteOnSide(logBlockState, Direction.UP)); - - return BakedModelHelper.generateModel(template, map::get); - } - - return BakedModelHelper.generateModel(template, sprite -> null); + + 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) { - for (String suffix : LOG_SUFFIXES) { + for (String location : LOG_LOCATIONS) { Optional state = - ForgeRegistries.BLOCKS.getHolder(new ResourceLocation(namespace, wood + suffix)) + ForgeRegistries.BLOCKS.getHolder(new ResourceLocation(namespace, location.replace("x", wood))) .map(Holder::value) .map(Block::defaultBlockState); if (state.isPresent())