From 19e05302534da194ab9b4b8b7e318ac9887feba6 Mon Sep 17 00:00:00 2001 From: "Aidan C. Brady" Date: Wed, 25 Mar 2015 01:19:37 -0400 Subject: [PATCH] New fancy machine icon renderer - rotates top and bottom icon based on facing, also adds support for resource pack-based side textures --- .../client/render/MekanismRenderer.java | 45 ++++++++++++ .../render/block/MachineRenderingHandler.java | 13 ++++ .../mekanism/common/block/BlockMachine.java | 68 ++++-------------- ....png => ChemicalInjectionChamberFront.png} | Bin ...CombinerFrontOff.png => CombinerFront.png} | Bin ...FrontOff.png => EnergizedSmelterFront.png} | Bin ...rontOff.png => EnrichmentChamberFront.png} | Bin ...FrontOff.png => OsmiumCompressorFront.png} | Bin ...FrontOff.png => PrecisionSawmillFront.png} | Bin ...ntOff.png => PurificationChamberFront.png} | Bin 10 files changed, 73 insertions(+), 53 deletions(-) rename src/main/resources/assets/mekanism/textures/blocks/{ChemicalInjectionChamberFrontOff.png => ChemicalInjectionChamberFront.png} (100%) rename src/main/resources/assets/mekanism/textures/blocks/{CombinerFrontOff.png => CombinerFront.png} (100%) rename src/main/resources/assets/mekanism/textures/blocks/{EnergizedSmelterFrontOff.png => EnergizedSmelterFront.png} (100%) rename src/main/resources/assets/mekanism/textures/blocks/{EnrichmentChamberFrontOff.png => EnrichmentChamberFront.png} (100%) rename src/main/resources/assets/mekanism/textures/blocks/{OsmiumCompressorFrontOff.png => OsmiumCompressorFront.png} (100%) rename src/main/resources/assets/mekanism/textures/blocks/{PrecisionSawmillFrontOff.png => PrecisionSawmillFront.png} (100%) rename src/main/resources/assets/mekanism/textures/blocks/{PurificationChamberFrontOff.png => PurificationChamberFront.png} (100%) diff --git a/src/main/java/mekanism/client/render/MekanismRenderer.java b/src/main/java/mekanism/client/render/MekanismRenderer.java index dbf71adab..56bdc9644 100644 --- a/src/main/java/mekanism/client/render/MekanismRenderer.java +++ b/src/main/java/mekanism/client/render/MekanismRenderer.java @@ -16,6 +16,7 @@ import mekanism.client.render.tileentity.RenderPortableTank; import mekanism.client.render.tileentity.RenderSalinationController; import mekanism.common.ObfuscatedNames; import mekanism.common.base.ISpecialBounds; +import mekanism.common.block.BlockMachine.MachineType; import mekanism.common.util.MekanismUtils; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; @@ -25,6 +26,7 @@ import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.init.Blocks; @@ -61,8 +63,12 @@ public class MekanismRenderer private static float lightmapLastY; private static boolean optifineBreak = false; + public static int[] directionMap = new int[] {3, 0, 1, 2}; + public static RenderConfigurableMachine machineRenderer = new RenderConfigurableMachine(); + private static String[] simpleSides = new String[] {"Down", "Up", "Front", "Back", "Left", "Right"}; + public static void init() { MinecraftForge.EVENT_BUS.register(new MekanismRenderer()); @@ -132,6 +138,45 @@ public class MekanismRenderer RenderPortableTank.resetDisplayInts(); } } + + public static boolean blockIconExists(String texture) //Credit to CoFHCore + { + String[] split = texture.split(":"); + texture = split[0] + ":textures/blocks/" + split[1] + ".png"; + + try { + Minecraft.getMinecraft().getResourceManager().getAllResources(new ResourceLocation(texture)); + return true; + } catch(Throwable t) { + return false; + } + } + + public static void loadDynamicTextures(IIconRegister register, MachineType type, IIcon def, IIcon[] textures) + { + for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) + { + String tex = "mekanism:" + type.name + simpleSides[side.ordinal()]; + String texOn = tex + "On"; + + if(blockIconExists(tex)) + { + textures[side.ordinal()] = register.registerIcon(tex); + + if(blockIconExists(texOn)) + { + textures[side.ordinal()+6] = register.registerIcon(texOn); + } + else { + textures[side.ordinal()+6] = register.registerIcon(tex); + } + } + else { + textures[side.ordinal()] = def; + textures[side.ordinal()+6] = def; + } + } + } public static class Model3D { diff --git a/src/main/java/mekanism/client/render/block/MachineRenderingHandler.java b/src/main/java/mekanism/client/render/block/MachineRenderingHandler.java index d0e3a8025..4a8e7d639 100644 --- a/src/main/java/mekanism/client/render/block/MachineRenderingHandler.java +++ b/src/main/java/mekanism/client/render/block/MachineRenderingHandler.java @@ -20,11 +20,13 @@ import mekanism.client.model.ModelRotaryCondensentrator; import mekanism.client.model.ModelSeismicVibrator; import mekanism.client.render.MekanismRenderer; import mekanism.common.block.BlockMachine.MachineType; +import mekanism.common.tile.TileEntityBasicBlock; import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils.ResourceType; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; import net.minecraft.world.IBlockAccess; import net.minecraftforge.client.model.AdvancedModelLoader; @@ -240,6 +242,17 @@ public class MachineRenderingHandler implements ISimpleBlockRenderingHandler { if(!MachineType.get(block, metadata).hasModel) { + TileEntity tile = world.getTileEntity(x, y, z); + + if(tile instanceof TileEntityBasicBlock) + { + if(((TileEntityBasicBlock)tile).getFacing() >= 2) + { + renderer.uvRotateTop = MekanismRenderer.directionMap[((TileEntityBasicBlock)tile).getFacing()-2]; + renderer.uvRotateBottom = MekanismRenderer.directionMap[((TileEntityBasicBlock)tile).getFacing()-2]; + } + } + renderer.renderStandardBlock(block, x, y, z); renderer.setRenderBoundsFromBlock(block); return true; diff --git a/src/main/java/mekanism/common/block/BlockMachine.java b/src/main/java/mekanism/common/block/BlockMachine.java index 89ef32be1..b0d81d841 100644 --- a/src/main/java/mekanism/common/block/BlockMachine.java +++ b/src/main/java/mekanism/common/block/BlockMachine.java @@ -14,6 +14,7 @@ import mekanism.api.MekanismConfig.machines; import mekanism.api.MekanismConfig.usage; import mekanism.api.energy.IEnergizedItem; import mekanism.api.energy.IStrictEnergyStorage; +import mekanism.client.render.MekanismRenderer; import mekanism.common.ItemAttacher; import mekanism.common.Mekanism; import mekanism.common.MekanismBlocks; @@ -102,7 +103,6 @@ import net.minecraftforge.fluids.FluidContainerRegistry; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; import buildcraft.api.tools.IToolWrench; -import cpw.mods.fml.common.ModAPIManager; import cpw.mods.fml.common.Optional.Interface; import cpw.mods.fml.common.Optional.Method; import cpw.mods.fml.relauncher.Side; @@ -179,18 +179,10 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds, IPer switch(blockType) { case MACHINE_BLOCK_1: - icons[0][0] = register.registerIcon("mekanism:EnrichmentChamberFrontOff"); - icons[0][1] = register.registerIcon("mekanism:EnrichmentChamberFrontOn"); - icons[0][2] = BASE_ICON; - icons[1][0] = register.registerIcon("mekanism:OsmiumCompressorFrontOff"); - icons[1][1] = register.registerIcon("mekanism:OsmiumCompressorFrontOn"); - icons[1][2] = BASE_ICON; - icons[2][0] = register.registerIcon("mekanism:CombinerFrontOff"); - icons[2][1] = register.registerIcon("mekanism:CombinerFrontOn"); - icons[2][2] = BASE_ICON; - icons[3][0] = register.registerIcon("mekanism:CrusherFrontOff"); - icons[3][1] = register.registerIcon("mekanism:CrusherFrontOn"); - icons[3][2] = BASE_ICON; + MekanismRenderer.loadDynamicTextures(register, MachineType.ENRICHMENT_CHAMBER, BASE_ICON, icons[0]); + MekanismRenderer.loadDynamicTextures(register, MachineType.OSMIUM_COMPRESSOR, BASE_ICON, icons[1]); + MekanismRenderer.loadDynamicTextures(register, MachineType.COMBINER, BASE_ICON, icons[2]); + MekanismRenderer.loadDynamicTextures(register, MachineType.CRUSHER, BASE_ICON, icons[3]); icons[5][0] = register.registerIcon("mekanism:BasicFactoryFront"); icons[5][1] = register.registerIcon("mekanism:BasicFactorySide"); icons[5][2] = register.registerIcon("mekanism:BasicFactoryTop"); @@ -200,21 +192,13 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds, IPer icons[7][0] = register.registerIcon("mekanism:EliteFactoryFront"); icons[7][1] = register.registerIcon("mekanism:EliteFactorySide"); icons[7][2] = register.registerIcon("mekanism:EliteFactoryTop"); - icons[9][0] = register.registerIcon("mekanism:PurificationChamberFrontOff"); - icons[9][1] = register.registerIcon("mekanism:PurificationChamberFrontOn"); - icons[9][2] = BASE_ICON; - icons[10][0] = register.registerIcon("mekanism:EnergizedSmelterFrontOff"); - icons[10][1] = register.registerIcon("mekanism:EnergizedSmelterFrontOn"); - icons[10][2] = register.registerIcon("mekanism:SteelCasing"); + MekanismRenderer.loadDynamicTextures(register, MachineType.PURIFICATION_CHAMBER, BASE_ICON, icons[9]); + MekanismRenderer.loadDynamicTextures(register, MachineType.ENERGIZED_SMELTER, BASE_ICON, icons[10]); icons[11][0] = register.registerIcon("mekanism:Teleporter"); break; case MACHINE_BLOCK_2: - icons[3][0] = register.registerIcon("mekanism:ChemicalInjectionChamberFrontOff"); - icons[3][1] = register.registerIcon("mekanism:ChemicalInjectionChamberFrontOn"); - icons[3][2] = BASE_ICON; - icons[5][0] = register.registerIcon("mekanism:PrecisionSawmillFrontOff"); - icons[5][1] = register.registerIcon("mekanism:PrecisionSawmillFrontOn"); - icons[5][2] = BASE_ICON; + MekanismRenderer.loadDynamicTextures(register, MachineType.CHEMICAL_INJECTION_CHAMBER, BASE_ICON, icons[3]); + MekanismRenderer.loadDynamicTextures(register, MachineType.PRECISION_SAWMILL, BASE_ICON, icons[5]); break; case MACHINE_BLOCK_3: icons[0][0] = register.registerIcon("mekanism:AmbientAccumulator"); @@ -387,13 +371,7 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds, IPer case 3: case 9: case 10: - if(side == 3) - { - return icons[meta][0]; - } - else { - return icons[meta][2]; - } + return icons[meta][side == 3 ? 2 : (side == 2 ? 3 : side)]; case 5: case 6: case 7: @@ -416,13 +394,7 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds, IPer { case 3: case 5: - if(side == 3) - { - return icons[meta][0]; - } - else { - return icons[meta][2]; - } + return icons[meta][side == 3 ? 2 : (side == 2 ? 3 : side)]; default: return icons[meta][0] != null ? icons[meta][0] : BASE_ICON; } @@ -471,13 +443,8 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds, IPer case 3: case 9: case 10: - if(side == tileEntity.facing) - { - return MekanismUtils.isActive(world, x, y, z) ? icons[meta][1] : icons[meta][0]; - } - else { - return icons[meta][2]; - } + boolean active = MekanismUtils.isActive(world, x, y, z); + return icons[meta][MekanismUtils.getBaseOrientation(side, tileEntity.facing)+(active ? 6 : 0)]; case 5: case 6: case 7: @@ -500,13 +467,8 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds, IPer { case 3: case 5: - if(side == tileEntity.facing) - { - return MekanismUtils.isActive(world, x, y, z) ? icons[meta][1] : icons[meta][0]; - } - else { - return icons[meta][2]; - } + boolean active = MekanismUtils.isActive(world, x, y, z); + return icons[meta][MekanismUtils.getBaseOrientation(side, tileEntity.facing)+(active ? 6 : 0)]; default: return icons[meta][0]; } diff --git a/src/main/resources/assets/mekanism/textures/blocks/ChemicalInjectionChamberFrontOff.png b/src/main/resources/assets/mekanism/textures/blocks/ChemicalInjectionChamberFront.png similarity index 100% rename from src/main/resources/assets/mekanism/textures/blocks/ChemicalInjectionChamberFrontOff.png rename to src/main/resources/assets/mekanism/textures/blocks/ChemicalInjectionChamberFront.png diff --git a/src/main/resources/assets/mekanism/textures/blocks/CombinerFrontOff.png b/src/main/resources/assets/mekanism/textures/blocks/CombinerFront.png similarity index 100% rename from src/main/resources/assets/mekanism/textures/blocks/CombinerFrontOff.png rename to src/main/resources/assets/mekanism/textures/blocks/CombinerFront.png diff --git a/src/main/resources/assets/mekanism/textures/blocks/EnergizedSmelterFrontOff.png b/src/main/resources/assets/mekanism/textures/blocks/EnergizedSmelterFront.png similarity index 100% rename from src/main/resources/assets/mekanism/textures/blocks/EnergizedSmelterFrontOff.png rename to src/main/resources/assets/mekanism/textures/blocks/EnergizedSmelterFront.png diff --git a/src/main/resources/assets/mekanism/textures/blocks/EnrichmentChamberFrontOff.png b/src/main/resources/assets/mekanism/textures/blocks/EnrichmentChamberFront.png similarity index 100% rename from src/main/resources/assets/mekanism/textures/blocks/EnrichmentChamberFrontOff.png rename to src/main/resources/assets/mekanism/textures/blocks/EnrichmentChamberFront.png diff --git a/src/main/resources/assets/mekanism/textures/blocks/OsmiumCompressorFrontOff.png b/src/main/resources/assets/mekanism/textures/blocks/OsmiumCompressorFront.png similarity index 100% rename from src/main/resources/assets/mekanism/textures/blocks/OsmiumCompressorFrontOff.png rename to src/main/resources/assets/mekanism/textures/blocks/OsmiumCompressorFront.png diff --git a/src/main/resources/assets/mekanism/textures/blocks/PrecisionSawmillFrontOff.png b/src/main/resources/assets/mekanism/textures/blocks/PrecisionSawmillFront.png similarity index 100% rename from src/main/resources/assets/mekanism/textures/blocks/PrecisionSawmillFrontOff.png rename to src/main/resources/assets/mekanism/textures/blocks/PrecisionSawmillFront.png diff --git a/src/main/resources/assets/mekanism/textures/blocks/PurificationChamberFrontOff.png b/src/main/resources/assets/mekanism/textures/blocks/PurificationChamberFront.png similarity index 100% rename from src/main/resources/assets/mekanism/textures/blocks/PurificationChamberFrontOff.png rename to src/main/resources/assets/mekanism/textures/blocks/PurificationChamberFront.png