From e308cd161bfae34f7843ff578b7e8845322d16f1 Mon Sep 17 00:00:00 2001 From: aidancbrady Date: Tue, 17 May 2016 01:11:39 -0400 Subject: [PATCH] More rendering work. I can't figure out the deal with these generator resources, it's freaking me out --- .../mekanism/common/block/BlockBasic.java | 8 +-- .../mekanism/common/block/BlockMachine.java | 18 ++--- .../client/GeneratorsClientProxy.java | 38 ++++++++++ .../generators/common/GeneratorsBlocks.java | 11 +++ .../common/block/BlockGenerator.java | 42 +++++++---- .../generators/common/block/BlockReactor.java | 28 +++++++- .../block/states/BlockStateGenerator.java | 69 +++++++++++++++++-- .../block/states/BlockStateReactor.java | 28 +++++++- .../blockstates/bio_generator.json | 20 ++++++ .../blockstates/gas_generator.json | 20 ++++++ .../blockstates/heat_generator.json | 20 ++++++ .../blockstates/solar_generator.json | 20 ++++++ .../blockstates/turbine_rotor.json | 2 +- .../blockstates/wind_generator.json | 20 ++++++ 14 files changed, 308 insertions(+), 36 deletions(-) create mode 100644 src/main/resources/assets/mekanismgenerators/blockstates/bio_generator.json create mode 100644 src/main/resources/assets/mekanismgenerators/blockstates/gas_generator.json create mode 100644 src/main/resources/assets/mekanismgenerators/blockstates/heat_generator.json create mode 100644 src/main/resources/assets/mekanismgenerators/blockstates/solar_generator.json create mode 100644 src/main/resources/assets/mekanismgenerators/blockstates/wind_generator.json diff --git a/src/main/java/mekanism/common/block/BlockBasic.java b/src/main/java/mekanism/common/block/BlockBasic.java index 7c030b020..25297b9c6 100644 --- a/src/main/java/mekanism/common/block/BlockBasic.java +++ b/src/main/java/mekanism/common/block/BlockBasic.java @@ -241,7 +241,8 @@ public abstract class BlockBasic extends Block implements ICTMBlock//TODO? imple @Override public float getExplosionResistance(World world, BlockPos pos, Entity exploder, Explosion explosion) { - BasicBlockType type = BasicBlockType.get(getBasicBlock(), getMetaFromState(world.getBlockState(pos))); + IBlockState state = world.getBlockState(pos); + BasicBlockType type = BasicBlockType.get(getBasicBlock(), state.getBlock().getMetaFromState(state)); if(type == BasicBlockType.REFINED_OBSIDIAN) { @@ -288,7 +289,7 @@ public abstract class BlockBasic extends Block implements ICTMBlock//TODO? imple @Override public int damageDropped(IBlockState state) { - return getMetaFromState(state); + return state.getBlock().getMetaFromState(state); } @Override @@ -906,7 +907,6 @@ public abstract class BlockBasic extends Block implements ICTMBlock//TODO? imple { if(!player.capabilities.isCreativeMode && !world.isRemote && willHarvest) { - float motion = 0.7F; double motionX = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D; double motionY = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D; @@ -1000,7 +1000,7 @@ public abstract class BlockBasic extends Block implements ICTMBlock//TODO? imple @Override public CTMData getCTMData(IBlockState state) { - return ctmData[getMetaFromState(state)][0]; + return ctmData[state.getBlock().getMetaFromState(state)][0]; } @Override diff --git a/src/main/java/mekanism/common/block/BlockMachine.java b/src/main/java/mekanism/common/block/BlockMachine.java index 8cc479877..b8d8674c2 100644 --- a/src/main/java/mekanism/common/block/BlockMachine.java +++ b/src/main/java/mekanism/common/block/BlockMachine.java @@ -387,7 +387,7 @@ public abstract class BlockMachine extends BlockContainer implements ICTMBlock @Override public int damageDropped(IBlockState state) { - return getMetaFromState(state); + return state.getBlock().getMetaFromState(state); } @Override @@ -451,7 +451,7 @@ public abstract class BlockMachine extends BlockContainer implements ICTMBlock } TileEntityBasicBlock tileEntity = (TileEntityBasicBlock)world.getTileEntity(pos); - int metadata = getMetaFromState(state); + int metadata = state.getBlock().getMetaFromState(state); if(entityplayer.getCurrentEquippedItem() != null) { @@ -608,7 +608,7 @@ public abstract class BlockMachine extends BlockContainer implements ICTMBlock @Override public TileEntity createTileEntity(World world, IBlockState state) { - int metadata = getMetaFromState(state); + int metadata = state.getBlock().getMetaFromState(state); if(MachineType.get(getMachineBlock(), metadata) == null) { @@ -661,7 +661,7 @@ public abstract class BlockMachine extends BlockContainer implements ICTMBlock public float getExplosionResistance(World world, BlockPos pos, Entity exploder, Explosion explosion) { IBlockState state = world.getBlockState(pos); - if(MachineType.get(getMachineBlock(), getMetaFromState(state)) != MachineType.PERSONAL_CHEST) + if(MachineType.get(getMachineBlock(), state.getBlock().getMetaFromState(state)) != MachineType.PERSONAL_CHEST) { return blockResistance; } @@ -838,7 +838,7 @@ public abstract class BlockMachine extends BlockContainer implements ICTMBlock { TileEntityBasicBlock tileEntity = (TileEntityBasicBlock)world.getTileEntity(pos); IBlockState state = world.getBlockState(pos); - ItemStack itemStack = new ItemStack(this, 1, getMetaFromState(state)); + ItemStack itemStack = new ItemStack(this, 1, state.getBlock().getMetaFromState(state)); if(itemStack.getTagCompound() == null) { @@ -940,7 +940,7 @@ public abstract class BlockMachine extends BlockContainer implements ICTMBlock public boolean canConnectRedstone(IBlockAccess world, BlockPos pos, EnumFacing side) { IBlockState state = world.getBlockState(pos); - MachineType type = MachineType.get(getMachineBlock(), getMetaFromState(state)); + MachineType type = MachineType.get(getMachineBlock(), state.getBlock().getMetaFromState(state)); switch(type) { @@ -976,7 +976,7 @@ public abstract class BlockMachine extends BlockContainer implements ICTMBlock public void setBlockBoundsBasedOnState(IBlockAccess world, BlockPos pos) { IBlockState state = world.getBlockState(pos); - MachineType type = MachineType.get(getMachineBlock(), getMetaFromState(state)); + MachineType type = MachineType.get(getMachineBlock(), state.getBlock().getMetaFromState(state)); switch(type) { @@ -1015,7 +1015,7 @@ public abstract class BlockMachine extends BlockContainer implements ICTMBlock public boolean isSideSolid(IBlockAccess world, BlockPos pos, EnumFacing side) { IBlockState state = world.getBlockState(pos); - MachineType type = MachineType.get(getMachineBlock(), getMetaFromState(state)); + MachineType type = MachineType.get(getMachineBlock(), state.getBlock().getMetaFromState(state)); switch(type) { @@ -1032,7 +1032,7 @@ public abstract class BlockMachine extends BlockContainer implements ICTMBlock @Override public CTMData getCTMData(IBlockState state) { - return ctmData[getMetaFromState(state)]; + return ctmData[state.getBlock().getMetaFromState(state)]; } @Override diff --git a/src/main/java/mekanism/generators/client/GeneratorsClientProxy.java b/src/main/java/mekanism/generators/client/GeneratorsClientProxy.java index 567d196fa..8914bc984 100644 --- a/src/main/java/mekanism/generators/client/GeneratorsClientProxy.java +++ b/src/main/java/mekanism/generators/client/GeneratorsClientProxy.java @@ -1,5 +1,7 @@ package mekanism.generators.client; +import java.io.IOException; + import mekanism.client.render.MekanismRenderer; import mekanism.client.render.ctm.CTMRegistry; import mekanism.generators.client.gui.GuiBioGenerator; @@ -24,8 +26,11 @@ import mekanism.generators.client.render.RenderReactor; import mekanism.generators.client.render.RenderSolarGenerator; import mekanism.generators.client.render.RenderTurbineRotor; import mekanism.generators.client.render.RenderWindGenerator; +import mekanism.generators.client.render.item.GeneratorItemModelFactory; import mekanism.generators.common.GeneratorsCommonProxy; import mekanism.generators.common.GeneratorsItems; +import mekanism.generators.common.block.states.BlockStateGenerator.GeneratorType; +import mekanism.generators.common.block.states.BlockStateReactor.ReactorBlockType; import mekanism.generators.common.tile.TileEntityAdvancedSolarGenerator; import mekanism.generators.common.tile.TileEntityBioGenerator; import mekanism.generators.common.tile.TileEntityGasGenerator; @@ -40,12 +45,16 @@ import mekanism.generators.common.tile.turbine.TileEntityTurbineRotor; import mekanism.generators.common.tile.turbine.TileEntityTurbineValve; import mekanism.generators.common.tile.turbine.TileEntityTurbineVent; import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.resources.model.IBakedModel; +import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; import net.minecraft.world.World; +import net.minecraftforge.client.event.ModelBakeEvent; import net.minecraftforge.client.event.TextureStitchEvent; +import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.fml.client.registry.ClientRegistry; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.relauncher.Side; @@ -54,6 +63,9 @@ import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class GeneratorsClientProxy extends GeneratorsCommonProxy { + public static final String[] CUSTOM_RENDERS = new String[] {"heat_generator", "solar_generator", "bio_generator", "wind_generator", + "gas_generator", "advanced_solar_generator"}; + @Override public void registerSpecialTileEntities() { @@ -81,7 +93,18 @@ public class GeneratorsClientProxy extends GeneratorsCommonProxy @Override public void registerBlockRenders() { + for(GeneratorType type : GeneratorType.values()) + { + ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(type.blockType.getBlock()), type.meta, new ModelResourceLocation("mekanismgenerators:" + type.getName(), "inventory")); + } + for(ReactorBlockType type : ReactorBlockType.values()) + { + if(type.isValidReactorBlock()) + { + ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(type.blockType.getBlock()), type.meta, new ModelResourceLocation("mekanismgenerators:" + type.getName(), "inventory")); + } + } } public void registerItemRender(Item item) @@ -89,6 +112,21 @@ public class GeneratorsClientProxy extends GeneratorsCommonProxy MekanismRenderer.registerItemRender("mekanismgenerators", item); } + @SubscribeEvent + public void onModelBake(ModelBakeEvent event) throws IOException + { + for(String s : CUSTOM_RENDERS) + { + ModelResourceLocation model = new ModelResourceLocation("mekanismgenerators:" + s, "inventory"); + Object obj = event.modelRegistry.getObject(model); + + if(obj instanceof IBakedModel) + { + event.modelRegistry.putObject(model, new GeneratorItemModelFactory((IBakedModel)obj)); + } + } + } + @Override public void preInit() { diff --git a/src/main/java/mekanism/generators/common/GeneratorsBlocks.java b/src/main/java/mekanism/generators/common/GeneratorsBlocks.java index 961b37e98..e20749242 100644 --- a/src/main/java/mekanism/generators/common/GeneratorsBlocks.java +++ b/src/main/java/mekanism/generators/common/GeneratorsBlocks.java @@ -5,9 +5,13 @@ import static mekanism.generators.common.block.states.BlockStateReactor.ReactorB import static mekanism.generators.common.block.states.BlockStateReactor.ReactorBlock.REACTOR_GLASS; import mekanism.generators.common.block.BlockGenerator; import mekanism.generators.common.block.BlockReactor; +import mekanism.generators.common.block.states.BlockStateGenerator.GeneratorBlockStateMapper; +import mekanism.generators.common.block.states.BlockStateReactor.ReactorBlockStateMapper; import mekanism.generators.common.item.ItemBlockGenerator; import mekanism.generators.common.item.ItemBlockReactor; import net.minecraft.block.Block; +import net.minecraft.client.renderer.block.statemap.IStateMapper; +import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.common.registry.GameRegistry.ObjectHolder; @@ -18,12 +22,19 @@ public class GeneratorsBlocks public static final Block Reactor = BlockReactor.getReactorBlock(REACTOR_BLOCK).setUnlocalizedName("Reactor"); public static final Block ReactorGlass = BlockReactor.getReactorBlock(REACTOR_GLASS).setUnlocalizedName("ReactorGlass"); + private static final IStateMapper generatorMapper = new GeneratorBlockStateMapper(); + private static final IStateMapper reactorMapper = new ReactorBlockStateMapper(); + public static void register() { GameRegistry.registerBlock(Generator, ItemBlockGenerator.class, "Generator"); GameRegistry.registerBlock(Reactor, ItemBlockReactor.class, "Reactor"); GameRegistry.registerBlock(ReactorGlass, ItemBlockReactor.class, "ReactorGlass"); + ModelLoader.setCustomStateMapper(Generator, generatorMapper); + ModelLoader.setCustomStateMapper(Reactor, reactorMapper); + ModelLoader.setCustomStateMapper(ReactorGlass, reactorMapper); + MekanismGenerators.proxy.registerBlockRenders(); } } diff --git a/src/main/java/mekanism/generators/common/block/BlockGenerator.java b/src/main/java/mekanism/generators/common/block/BlockGenerator.java index 4bd1d856c..f55b4c58e 100644 --- a/src/main/java/mekanism/generators/common/block/BlockGenerator.java +++ b/src/main/java/mekanism/generators/common/block/BlockGenerator.java @@ -1,6 +1,5 @@ package mekanism.generators.common.block; -import java.util.Arrays; import java.util.List; import java.util.Random; @@ -17,16 +16,12 @@ import mekanism.common.base.ISustainedInventory; import mekanism.common.base.ISustainedTank; import mekanism.common.block.states.BlockStateBasic; import mekanism.common.block.states.BlockStateFacing; -import mekanism.common.block.states.BlockStateMachine; -import mekanism.common.block.states.BlockStateBasic.BasicBlockType; import mekanism.common.multiblock.IMultiblock; import mekanism.common.security.ISecurityItem; import mekanism.common.security.ISecurityTile; import mekanism.common.tile.TileEntityBasicBlock; import mekanism.common.tile.TileEntityContainerBlock; import mekanism.common.tile.TileEntityElectricBlock; -import mekanism.common.tile.TileEntityFactory; -import mekanism.common.tile.TileEntityFluidTank; import mekanism.common.util.MekanismUtils; import mekanism.common.util.SecurityUtils; import mekanism.generators.common.GeneratorsBlocks; @@ -63,7 +58,6 @@ import net.minecraftforge.common.property.IExtendedBlockState; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import buildcraft.api.tools.IToolWrench; -import codechicken.lib.render.TextureUtils.IIconRegister; /** * Block class for handling multiple generator block IDs. @@ -162,6 +156,24 @@ public abstract class BlockGenerator extends BlockContainer implements ICTMBlock return type.meta; } + @Override + public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) + { + TileEntity tile = worldIn.getTileEntity(pos); + + if(tile instanceof TileEntityBasicBlock && ((TileEntityBasicBlock)tile).facing != null) + { + state = state.withProperty(BlockStateFacing.facingProperty, ((TileEntityBasicBlock)tile).facing); + } + + if(tile instanceof IActiveState) + { + state = state.withProperty(BlockStateGenerator.activeProperty, ((IActiveState)tile).getActive()); + } + + return state; + } + @Override public AxisAlignedBB getCollisionBoundingBox(World world, BlockPos pos, IBlockState state) { @@ -258,7 +270,7 @@ public abstract class BlockGenerator extends BlockContainer implements ICTMBlock @Override public int damageDropped(IBlockState state) { - return getMetaFromState(state); + return state.getBlock().getMetaFromState(state); } @Override @@ -396,7 +408,7 @@ public abstract class BlockGenerator extends BlockContainer implements ICTMBlock } TileEntityBasicBlock tileEntity = (TileEntityBasicBlock)world.getTileEntity(pos); - int metadata = getMetaFromState(state); + int metadata = state.getBlock().getMetaFromState(state); if(entityplayer.getCurrentEquippedItem() != null) { @@ -526,7 +538,7 @@ public abstract class BlockGenerator extends BlockContainer implements ICTMBlock @Override public TileEntity createTileEntity(World world, IBlockState state) { - int metadata = getMetaFromState(state); + int metadata = state.getBlock().getMetaFromState(state); if(GeneratorType.get(getGeneratorBlock(), metadata) == null) { @@ -541,6 +553,12 @@ public abstract class BlockGenerator extends BlockContainer implements ICTMBlock { return null; } + + @Override + public int getRenderType() + { + return 3; + } @Override public boolean isOpaqueCube() @@ -603,7 +621,7 @@ public abstract class BlockGenerator extends BlockContainer implements ICTMBlock { TileEntityBasicBlock tileEntity = (TileEntityBasicBlock)world.getTileEntity(pos); IBlockState state = world.getBlockState(pos); - ItemStack itemStack = new ItemStack(GeneratorsBlocks.Generator, 1, getMetaFromState(state)); + ItemStack itemStack = new ItemStack(GeneratorsBlocks.Generator, 1, state.getBlock().getMetaFromState(state)); if(itemStack.getTagCompound() == null) { @@ -682,7 +700,7 @@ public abstract class BlockGenerator extends BlockContainer implements ICTMBlock public boolean isSideSolid(IBlockAccess world, BlockPos pos, EnumFacing side) { IBlockState state = world.getBlockState(pos); - GeneratorType type = GeneratorType.get(getGeneratorBlock(), getMetaFromState(state)); + GeneratorType type = GeneratorType.get(getGeneratorBlock(), state.getBlock().getMetaFromState(state)); if(type != GeneratorType.SOLAR_GENERATOR && type != GeneratorType.ADVANCED_SOLAR_GENERATOR && @@ -739,7 +757,7 @@ public abstract class BlockGenerator extends BlockContainer implements ICTMBlock @Override public CTMData getCTMData(IBlockState state) { - return ctmData[getMetaFromState(state)]; + return ctmData[state.getBlock().getMetaFromState(state)]; } @Override diff --git a/src/main/java/mekanism/generators/common/block/BlockReactor.java b/src/main/java/mekanism/generators/common/block/BlockReactor.java index 0d1bf7ee3..30931c380 100644 --- a/src/main/java/mekanism/generators/common/block/BlockReactor.java +++ b/src/main/java/mekanism/generators/common/block/BlockReactor.java @@ -22,6 +22,7 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.block.properties.PropertyEnum; +import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.item.EntityItem; @@ -114,11 +115,32 @@ public abstract class BlockReactor extends BlockContainer implements ICTMBlock return state.withProperty(BlockStateBasic.ctmProperty, ctx); } + + @Override + public BlockState createBlockState() + { + return new BlockStateReactor(this, getTypeProperty()); + } + + @Override + public IBlockState getStateFromMeta(int meta) + { + ReactorBlockType type = ReactorBlockType.get(getReactorBlock(), meta & 0xF); + + return getDefaultState().withProperty(getTypeProperty(), type); + } + + @Override + public int getMetaFromState(IBlockState state) + { + ReactorBlockType type = state.getValue(getTypeProperty()); + return type.meta; + } @Override public int damageDropped(IBlockState state) { - return getMetaFromState(state); + return state.getBlock().getMetaFromState(state); } @Override @@ -199,7 +221,7 @@ public abstract class BlockReactor extends BlockContainer implements ICTMBlock @Override public TileEntity createTileEntity(World world, IBlockState state) { - int metadata = getMetaFromState(state); + int metadata = state.getBlock().getMetaFromState(state); if(ReactorBlockType.get(getReactorBlock(), metadata) == null) { @@ -335,7 +357,7 @@ public abstract class BlockReactor extends BlockContainer implements ICTMBlock @Override public CTMData getCTMData(IBlockState state) { - return ctmData[getMetaFromState(state)]; + return ctmData[state.getBlock().getMetaFromState(state)]; } @Override diff --git a/src/main/java/mekanism/generators/common/block/states/BlockStateGenerator.java b/src/main/java/mekanism/generators/common/block/states/BlockStateGenerator.java index bb467087e..6ae46fa69 100644 --- a/src/main/java/mekanism/generators/common/block/states/BlockStateGenerator.java +++ b/src/main/java/mekanism/generators/common/block/states/BlockStateGenerator.java @@ -24,11 +24,14 @@ import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.IBlockState; +import net.minecraft.client.renderer.block.statemap.StateMapperBase; +import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing.Plane; import net.minecraft.util.IStringSerializable; +import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.property.ExtendedBlockState; import net.minecraftforge.common.property.IUnlistedProperty; @@ -135,7 +138,6 @@ public class BlockStateGenerator extends ExtendedBlockState return null; } - public static GeneratorType get(Block block, int meta) { @@ -191,11 +193,68 @@ public class BlockStateGenerator extends ExtendedBlockState { return new ItemStack(GeneratorsBlocks.Generator, 1, meta); } - - @Override - public String toString() + + public boolean canRotateTo(EnumFacing side) { - return Integer.toString(meta); + return facingPredicate.apply(side); + } + + public boolean hasRotations() + { + return !facingPredicate.equals(Predicates.alwaysFalse()); + } + + public boolean hasActiveTexture() + { + return activable; + } + } + + public static class GeneratorBlockStateMapper extends StateMapperBase + { + @Override + protected ModelResourceLocation getModelResourceLocation(IBlockState state) + { + BlockGenerator block = (BlockGenerator)state.getBlock(); + GeneratorType type = state.getValue(block.getTypeProperty()); + StringBuilder builder = new StringBuilder(); + String nameOverride = null; + + if(type.hasActiveTexture()) + { + builder.append(activeProperty.getName()); + builder.append("="); + builder.append(state.getValue(activeProperty)); + } + + if(type.hasRotations()) + { + EnumFacing facing = state.getValue(BlockStateFacing.facingProperty); + + if(type.canRotateTo(facing)) + { + if(builder.length() > 0) + { + builder.append(","); + } + + builder.append(BlockStateFacing.facingProperty.getName()); + builder.append("="); + builder.append(facing.getName()); + } + else { + return new ModelResourceLocation("builtin/missing", "missing"); + } + } + + if(builder.length() == 0) + { + builder.append("normal"); + } + + ResourceLocation baseLocation = new ResourceLocation("mekanismgenerators", nameOverride != null ? nameOverride : type.getName()); + + return new ModelResourceLocation(baseLocation, builder.toString()); } } } diff --git a/src/main/java/mekanism/generators/common/block/states/BlockStateReactor.java b/src/main/java/mekanism/generators/common/block/states/BlockStateReactor.java index 18f7f8274..5c5cf2375 100644 --- a/src/main/java/mekanism/generators/common/block/states/BlockStateReactor.java +++ b/src/main/java/mekanism/generators/common/block/states/BlockStateReactor.java @@ -1,7 +1,6 @@ package mekanism.generators.common.block.states; import mekanism.common.Mekanism; -import mekanism.common.block.BlockBasic; import mekanism.common.block.states.BlockStateBasic; import mekanism.common.tile.TileEntityElectricBlock; import mekanism.common.util.LangUtils; @@ -18,9 +17,13 @@ import net.minecraft.block.Block; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.properties.PropertyEnum; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.renderer.block.statemap.StateMapperBase; +import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IStringSerializable; +import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.property.ExtendedBlockState; import net.minecraftforge.common.property.IUnlistedProperty; @@ -30,7 +33,7 @@ public class BlockStateReactor extends ExtendedBlockState { public static final PropertyBool activeProperty = PropertyBool.create("active"); - public BlockStateReactor(BlockBasic block, PropertyEnum typeProperty) + public BlockStateReactor(BlockReactor block, PropertyEnum typeProperty) { super(block, new IProperty[] {typeProperty, activeProperty}, new IUnlistedProperty[] {BlockStateBasic.ctmProperty}); } @@ -169,4 +172,25 @@ public class BlockStateReactor extends ExtendedBlockState return new ItemStack(blockType.getBlock(), 1, meta); } } + + public static class ReactorBlockStateMapper extends StateMapperBase + { + @Override + protected ModelResourceLocation getModelResourceLocation(IBlockState state) + { + BlockReactor block = (BlockReactor)state.getBlock(); + ReactorBlockType type = state.getValue(block.getTypeProperty()); + StringBuilder builder = new StringBuilder(); + String nameOverride = null; + + if(builder.length() == 0) + { + builder.append("normal"); + } + + ResourceLocation baseLocation = new ResourceLocation("mekanismgenerators", nameOverride != null ? nameOverride : type.getName()); + + return new ModelResourceLocation(baseLocation, builder.toString()); + } + } } diff --git a/src/main/resources/assets/mekanismgenerators/blockstates/bio_generator.json b/src/main/resources/assets/mekanismgenerators/blockstates/bio_generator.json new file mode 100644 index 000000000..591d119c5 --- /dev/null +++ b/src/main/resources/assets/mekanismgenerators/blockstates/bio_generator.json @@ -0,0 +1,20 @@ +{ + "forge_marker": 1, + "defaults": { + "model": "mekanism:nothing" + }, + "variants": { + "facing": { + "north": {}, + "south": {"y": 180}, + "east": {"y": 90}, + "west": {"y": -90} + }, + "active": { + "true": {}, + "false": {} + }, + "inventory": [{}] + } +} + diff --git a/src/main/resources/assets/mekanismgenerators/blockstates/gas_generator.json b/src/main/resources/assets/mekanismgenerators/blockstates/gas_generator.json new file mode 100644 index 000000000..591d119c5 --- /dev/null +++ b/src/main/resources/assets/mekanismgenerators/blockstates/gas_generator.json @@ -0,0 +1,20 @@ +{ + "forge_marker": 1, + "defaults": { + "model": "mekanism:nothing" + }, + "variants": { + "facing": { + "north": {}, + "south": {"y": 180}, + "east": {"y": 90}, + "west": {"y": -90} + }, + "active": { + "true": {}, + "false": {} + }, + "inventory": [{}] + } +} + diff --git a/src/main/resources/assets/mekanismgenerators/blockstates/heat_generator.json b/src/main/resources/assets/mekanismgenerators/blockstates/heat_generator.json new file mode 100644 index 000000000..591d119c5 --- /dev/null +++ b/src/main/resources/assets/mekanismgenerators/blockstates/heat_generator.json @@ -0,0 +1,20 @@ +{ + "forge_marker": 1, + "defaults": { + "model": "mekanism:nothing" + }, + "variants": { + "facing": { + "north": {}, + "south": {"y": 180}, + "east": {"y": 90}, + "west": {"y": -90} + }, + "active": { + "true": {}, + "false": {} + }, + "inventory": [{}] + } +} + diff --git a/src/main/resources/assets/mekanismgenerators/blockstates/solar_generator.json b/src/main/resources/assets/mekanismgenerators/blockstates/solar_generator.json new file mode 100644 index 000000000..591d119c5 --- /dev/null +++ b/src/main/resources/assets/mekanismgenerators/blockstates/solar_generator.json @@ -0,0 +1,20 @@ +{ + "forge_marker": 1, + "defaults": { + "model": "mekanism:nothing" + }, + "variants": { + "facing": { + "north": {}, + "south": {"y": 180}, + "east": {"y": 90}, + "west": {"y": -90} + }, + "active": { + "true": {}, + "false": {} + }, + "inventory": [{}] + } +} + diff --git a/src/main/resources/assets/mekanismgenerators/blockstates/turbine_rotor.json b/src/main/resources/assets/mekanismgenerators/blockstates/turbine_rotor.json index 61e2f3e61..15cc2af95 100644 --- a/src/main/resources/assets/mekanismgenerators/blockstates/turbine_rotor.json +++ b/src/main/resources/assets/mekanismgenerators/blockstates/turbine_rotor.json @@ -3,7 +3,7 @@ "defaults": { "model": "mekanism:fence_post", "textures": { - "all": "mekanismgenerators:blocks/TurbineRotor" + "texture": "mekanismgenerators:blocks/TurbineRotor" } }, "variants": { diff --git a/src/main/resources/assets/mekanismgenerators/blockstates/wind_generator.json b/src/main/resources/assets/mekanismgenerators/blockstates/wind_generator.json new file mode 100644 index 000000000..591d119c5 --- /dev/null +++ b/src/main/resources/assets/mekanismgenerators/blockstates/wind_generator.json @@ -0,0 +1,20 @@ +{ + "forge_marker": 1, + "defaults": { + "model": "mekanism:nothing" + }, + "variants": { + "facing": { + "north": {}, + "south": {"y": 180}, + "east": {"y": 90}, + "west": {"y": -90} + }, + "active": { + "true": {}, + "false": {} + }, + "inventory": [{}] + } +} +