Skip to content

Commit

Permalink
Chisel compat for textures that are block location dependent (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cardinalstars authored Dec 7, 2024
1 parent 352d500 commit 5aec83a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -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')
}
23 changes: 23 additions & 0 deletions src/main/java/com/carpentersblocks/api/compat/Mods.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*/
Expand All @@ -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);
}

Expand Down

0 comments on commit 5aec83a

Please sign in to comment.