From 5aec83aaa95e9400c2f07aa82380c63e83ab12c8 Mon Sep 17 00:00:00 2001 From: Ryan Nasers <42074409+Cardinalstars@users.noreply.github.com> Date: Sat, 7 Dec 2024 14:01:27 +0100 Subject: [PATCH] Chisel compat for textures that are block location dependent (#12) --- dependencies.gradle | 1 + .../com/carpentersblocks/api/compat/Mods.java | 23 +++++++++++++++ .../renderer/BlockHandlerBase.java | 28 ++++++++++++++++++- 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/carpentersblocks/api/compat/Mods.java diff --git a/dependencies.gradle b/dependencies.gradle index 5f7adec..53e246c 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -1,3 +1,4 @@ dependencies { compileOnly('com.github.GTNewHorizons:Angelica:1.0.0-alpha52:api') + compileOnly('com.github.GTNewHorizons:Chisel:2.15.3-GTNH:dev') } diff --git a/src/main/java/com/carpentersblocks/api/compat/Mods.java b/src/main/java/com/carpentersblocks/api/compat/Mods.java new file mode 100644 index 0000000..d72b1e1 --- /dev/null +++ b/src/main/java/com/carpentersblocks/api/compat/Mods.java @@ -0,0 +1,23 @@ +package com.carpentersblocks.api.compat; + +import cpw.mods.fml.common.Loader; + +public enum Mods { + + CHISEL("chisel"); + + public final String ID; + + private Boolean modLoaded; + + Mods(String ID) { + this.ID = ID; + } + + public boolean isModLoaded() { + if (this.modLoaded == null) { + this.modLoaded = Loader.isModLoaded(ID); + } + return this.modLoaded; + } +} diff --git a/src/main/java/com/carpentersblocks/renderer/BlockHandlerBase.java b/src/main/java/com/carpentersblocks/renderer/BlockHandlerBase.java index 1861c06..4cd5188 100644 --- a/src/main/java/com/carpentersblocks/renderer/BlockHandlerBase.java +++ b/src/main/java/com/carpentersblocks/renderer/BlockHandlerBase.java @@ -1,5 +1,7 @@ package com.carpentersblocks.renderer; +import static com.carpentersblocks.api.compat.Mods.CHISEL; + import net.minecraft.block.Block; import net.minecraft.block.BlockGrass; import net.minecraft.block.BlockRailBase; @@ -31,6 +33,7 @@ import com.carpentersblocks.util.handler.OverlayHandler.Overlay; import com.carpentersblocks.util.registry.FeatureRegistry; import com.carpentersblocks.util.registry.IconRegistry; +import com.cricketcraft.chisel.api.ICarvable; import com.gtnewhorizons.angelica.api.ThreadSafeISBRHFactory; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; @@ -538,6 +541,18 @@ protected IIcon getIcon(ItemStack itemStack, int side) { return icon; } + protected IIcon getIcon(ItemStack itemStack, int side, IBlockAccess world, int x, int y, int z) { + BlockProperties.prepareItemStackForRendering(itemStack); + IIcon icon = renderBlocks.getIconSafe( + getUniqueIcon(itemStack, side, BlockProperties.toBlock(itemStack).getIcon(world, x, y, z, side))); + + if (hasIconOverride[side]) { + icon = renderBlocks.getIconSafe(iconOverride[side]); + } + + return icon; + } + /** * Renders multiple textures to side. */ @@ -564,7 +579,18 @@ protected void renderMultiTexturedSide(ItemStack itemStack, int x, int y, int z, if (BlockProperties.blockRotates(itemStack)) { setTextureRotationForDirectionalBlock(side); } - setColorAndRender(itemStack, x, y, z, side, getIcon(itemStack, side)); + if (CHISEL.isModLoaded() && Block.getBlockFromItem(itemStack.getItem()) instanceof ICarvable) { + setColorAndRender( + itemStack, + x, + y, + z, + side, + getIcon(itemStack, side, renderBlocks.blockAccess, x, y, z)); + } else { + setColorAndRender(itemStack, x, y, z, side, getIcon(itemStack, side)); + } + setTextureRotation(side, tempRotation); }