New fancy machine icon renderer - rotates top and bottom icon based on facing, also adds support for resource pack-based side textures

This commit is contained in:
Aidan C. Brady 2015-03-25 01:19:37 -04:00
parent 69624715ec
commit 19e0530253
10 changed files with 73 additions and 53 deletions

View file

@ -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
{

View file

@ -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;

View file

@ -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];
}

View file

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB