Jump to content

TRMelon

Members
  • Posts

    9
  • Joined

  • Last visited

TRMelon's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. I have a simple creative tab but I want it to have a changing icon like in the CoFH mods, how is this done?
  2. That worked! Thank you so much, I've been googling for too many hours.
  3. Done, but am I supposed to use the IBlockState parameter? Removed those checks (got them from YouTube videos, clearly not great ones) I dont know how I'm meant to set that in getActualState, because it has no placer parameter which is how I get the facing direction. This is what I have now, the blocks place in the right direction but go to south when I re-open the world: @Override public boolean hasTileEntity(IBlockState state) { return true; } @Override public TileEntity createTileEntity(World world, IBlockState state) { return new TileEntityMachine(); } @Override public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) { TileEntityMachine machine = (TileEntityMachine) worldIn.getTileEntity(pos); return state.withProperty(FACING, machine.getFacing()); } @Override public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { TileEntityMachine machine = (TileEntityMachine) worldIn.getTileEntity(pos);; machine.setFacing(placer.getHorizontalFacing().getOpposite()); }
  4. Using hasTileEntity and createTileEntity now, instead of ITileEntityProvider Added mod id to all unlocalized names Removed common proxy, now the code is just in the main class Don't know what to do about the rest. Is this what you mean? public void setFacing(EnumFacing facing) { this.facing = facing; setFacing(facing); markDirty(); } This is what I've added to my machine class: @Override public boolean hasTileEntity() { return true; } @Override public TileEntity createTileEntity(World world, IBlockState state) { return new TileEntityMachine(); } @Override public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) { if (worldIn.getTileEntity(pos) instanceof TileEntityMachine) { TileEntityMachine machine = (TileEntityMachine) worldIn.getTileEntity(pos); return state.withProperty(FACING, machine.getFacing()); } return state.withProperty(FACING, EnumFacing.NORTH); } And I still have this: @Override public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) { TileEntity tileEntity = world.getTileEntity(pos); if (tileEntity instanceof TileEntityMachine) { TileEntityMachine machine = (TileEntityMachine) tileEntity; machine.setFacing(placer.getHorizontalFacing().getOpposite()); } return getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()).withProperty(TYPE, MachineTypes.values()[meta]); } Not sure this is what you meant I had to do, but now the block always faces north when placed.
  5. I have a very basic 'machine' block with variants and facing properties in its blockstate, the variant is saved and loaded when you re-open the world using 'getMetaFromState' override, and 'getStateFromMeta' also overridden. The problem is I don't know how to save the facing property as eventually, after adding more variants, there won't be enough room in the meta to store both properties. I'd like to save the facing property in a tile entity but I'm not sure how to load it when the world is saved and re-opened, is this possible? I have shown what I have so far, and how I register the tile entity (main and CommonProxy classes). Machine block class: package theredmelon.enhancedmechanisms.objects.machines; import net.minecraft.block.Block; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.World; import theredmelon.enhancedmechanisms.EnhancedMechanisms; import theredmelon.enhancedmechanisms.init.BlockInit; import theredmelon.enhancedmechanisms.init.ItemInit; import theredmelon.enhancedmechanisms.objects.blocks.item.IMetaBlockName; import theredmelon.enhancedmechanisms.objects.blocks.item.ItemBlockBase; import theredmelon.enhancedmechanisms.tileentity.TileEntityMachine; import theredmelon.enhancedmechanisms.utils.IHasModel; import theredmelon.enhancedmechanisms.utils.handlers.EnumHandler.MachineTypes; public class Machine extends Block implements IMetaBlockName, IHasModel, ITileEntityProvider { public static final PropertyEnum TYPE = PropertyEnum.create("type", MachineTypes.class); public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL); public Machine (String name, Material material, CreativeTabs tab) { super(material); setCreativeTab(tab); setUnlocalizedName(name); setRegistryName(name); setDefaultState(blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(TYPE, MachineTypes.THREEFOLD_COMBINER)); BlockInit.BLOCKS.add(this); ItemInit.MACHINE_ITEM = new ItemBlockBase(this).setRegistryName(name); ItemInit.ITEMS.add(ItemInit.MACHINE_ITEM); } @Override public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) { TileEntity tileEntity = world.getTileEntity(pos); if (tileEntity instanceof TileEntityMachine) { TileEntityMachine machine = (TileEntityMachine) tileEntity; machine.setFacing(placer.getHorizontalFacing().getOpposite()); } return getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()).withProperty(TYPE, MachineTypes.values()[meta]); } @Override protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[] {FACING, TYPE}); } @Override public int getMetaFromState(IBlockState state) { MachineTypes type = (MachineTypes) state.getValue(TYPE); return type.getID(); } @Override public IBlockState getStateFromMeta(int meta) { return getDefaultState().withProperty(TYPE, MachineTypes.values()[meta]); } @Override public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items) { for (int i = 0; i < MachineTypes.values().length; i++) { items.add(new ItemStack(this, 1, i)); } } @Override public String getSpecialName(ItemStack stack) { return MachineTypes.values()[stack.getItemDamage()].getName(); } @Override public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) { return new ItemStack(Item.getItemFromBlock(this), 1, getMetaFromState(world.getBlockState(pos))); } @Override public int damageDropped(IBlockState state) { return getMetaFromState(state); } @Override public void registerModels() { for (int i = 0; i < MachineTypes.values().length; i++) { EnhancedMechanisms.proxy.registerItemVariantsRenderer(Item.getItemFromBlock(this), i, "inventory", MachineTypes.values()[i].getName()); } } @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new TileEntityMachine(); } } TileEntityMachine: package theredmelon.enhancedmechanisms.tileentity; import com.ibm.icu.impl.duration.impl.DataRecord.EUnitVariant; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; import net.minecraft.network.play.server.SPacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; public class TileEntityMachine extends TileEntity { private EnumFacing facing; public EnumFacing getFacing() { if (facing != null) { return facing; } return EnumFacing.NORTH; } public void setFacing(EnumFacing facing) { this.facing = facing; markDirty(); } @Override public void readFromNBT(NBTTagCompound compound) { facing = EnumFacing.getHorizontal(compound.getInteger("Facing")); super.readFromNBT(compound); } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); compound.setInteger("Facing", facing.getHorizontalIndex()); return compound; } } EnhancedMechanisms (Main): package theredmelon.enhancedmechanisms; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.Mod.Instance; import net.minecraftforge.fml.common.SidedProxy; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import theredmelon.enhancedmechanisms.init.BlockInit; import theredmelon.enhancedmechanisms.init.CraftingInit; import theredmelon.enhancedmechanisms.proxy.CommonProxy; import theredmelon.enhancedmechanisms.utils.Reference; @Mod(modid = Reference.MOD_ID, name = Reference.NAME, version = Reference.VERSION) public class EnhancedMechanisms { @Instance public static EnhancedMechanisms instance; @SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.COMMON_PROXY_CLASS) public static CommonProxy proxy; @EventHandler public static void PreInit(FMLPreInitializationEvent event) { } @EventHandler public static void init(FMLInitializationEvent event) { CraftingInit.registerRecepies(); proxy.registerTileEntities(); } @EventHandler public static void PostInit(FMLPostInitializationEvent event) { } } CommonProxy: package theredmelon.enhancedmechanisms.proxy; import net.minecraft.item.Item; import net.minecraftforge.fml.common.registry.GameRegistry; import theredmelon.enhancedmechanisms.tileentity.TileEntityMachine; import theredmelon.enhancedmechanisms.utils.Reference; public class CommonProxy { public void registerItemRenderer(Item item, int meta, String id) { } public void registerItemVariantsRenderer(Item item, int meta, String id, String varientName) { } public void registerTileEntities() { GameRegistry.registerTileEntity(TileEntityMachine.class, Reference.MOD_ID + "TileEntityMachine"); } }
  6. k nvm, looked at how the anvil converted between state and meta data and used that instead of the crap i was trying to use here, ill have it fixed soon, that was the issue
  7. , Don't really know what you wanted me to with this line and since they all have different particle textures I don't think setting a default would help, so I tried putting it like this: "facing=north,type=threefold_combiner": { "model": "enhancedmechanisms:machine_threefold_combiner", "y": 180, "textures": { "particle": "blocks/planks_oak" } }, Tried both, neither worked. Was looking at what was going on, added some console prints: @Override public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) { System.out.println(state.getValue(TYPE)); System.out.println(state.getValue(FACING)); return super.getActualState(state, worldIn, pos); } the blockstate changed as I break the block, don't know why.
  8. When I break a machine block the particles are from the wrong model. I have three machines using the same block class and different variants, they also have a facing property. (I have only textured one, the others use cobblestone and dirt for now) EDIT (accidentally removed line, need to read before I post) - The first machine's particles work when it is facing north and south, but have cobblestone (2nd machine) particles for east and west. The second machine does the same but the broken particle texture is dirt, from the third model file And the same with the third and the particles are from the first machine The blockstates file is: (sorry I like to spread it out) { "variants": { "facing=north,type=threefold_combiner": { "model": "enhancedmechanisms:machine_threefold_combiner", "y": 180 }, "facing=south,type=threefold_combiner": { "model": "enhancedmechanisms:machine_threefold_combiner" }, "facing=east,type=threefold_combiner": { "model": "enhancedmechanisms:machine_threefold_combiner", "y": 270 }, "facing=west,type=threefold_combiner": { "model": "enhancedmechanisms:machine_threefold_combiner", "y": 90 }, "facing=north,type=alloy_smeltery": { "model": "cobblestone" }, "facing=south,type=alloy_smeltery": { "model": "cobblestone" }, "facing=east,type=alloy_smeltery": { "model": "cobblestone" }, "facing=west,type=alloy_smeltery": { "model": "cobblestone" }, "facing=north,type=machine_builder_crude": { "model": "dirt" }, "facing=south,type=machine_builder_crude": { "model": "dirt" }, "facing=east,type=machine_builder_crude": { "model": "dirt" }, "facing=west,type=machine_builder_crude": { "model": "dirt" } } } The first machine "threefold_combiner" model: { "parent": "block/block", "elements": [ { "from": [ 0, 0, 0 ], "to": [ 16, 16, 16 ], "faces": { "down": {"texture": "#down", "cullface": "down"}, "up": {"texture": "#up", "cullface": "up" }, "north": {"uv": [16, 0, 0, 16], "texture": "#north", "cullface": "north" }, "south": {"texture": "#south", "cullface": "south" }, "west": {"texture": "#west", "cullface": "west" }, "east": {"texture": "#east", "cullface": "east" } } } ], "textures": { "particle": "enhancedmechanisms:blocks/machine_threefold_combiner_front", "up": "enhancedmechanisms:blocks/machine_threefold_combiner_up", "down": "enhancedmechanisms:blocks/machine_threefold_combiner_front", "north": "enhancedmechanisms:blocks/machine_threefold_combiner_front", "east": "enhancedmechanisms:blocks/machine_threefold_combiner_east", "south": "enhancedmechanisms:blocks/machine_threefold_combiner_front", "west": "enhancedmechanisms:blocks/machine_threefold_combiner_west" } } The machine block class: package theredmelon.enhancedmechanisms.objects.machines; import net.minecraft.block.Block; import net.minecraft.block.BlockPistonBase; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.client.particle.ParticleManager; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.scoreboard.IScoreCriteria.EnumRenderType; import net.minecraft.util.EnumBlockRenderType; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.World; import theredmelon.enhancedmechanisms.EnhancedMechanisms; import theredmelon.enhancedmechanisms.init.BlockInit; import theredmelon.enhancedmechanisms.init.ItemInit; import theredmelon.enhancedmechanisms.objects.blocks.item.IMetaBlockName; import theredmelon.enhancedmechanisms.objects.blocks.item.ItemBlockBase; import theredmelon.enhancedmechanisms.utils.IHasModel; import theredmelon.enhancedmechanisms.utils.handlers.EnumHandler.MachineTypes; public class Machine extends Block implements IMetaBlockName, IHasModel { public static final PropertyEnum TYPE = PropertyEnum.create("type", MachineTypes.class); public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL); public Machine (String name, Material material, CreativeTabs tab) { super(material); setCreativeTab(tab); setUnlocalizedName(name); setRegistryName(name); setDefaultState(blockState.getBaseState().withProperty(TYPE, MachineTypes.THREEFOLD_COMBINER).withProperty(FACING, EnumFacing.NORTH)); BlockInit.BLOCKS.add(this); ItemInit.MACHINE_ITEM = new ItemBlockBase(this).setRegistryName(name); ItemInit.ITEMS.add(ItemInit.MACHINE_ITEM); } @Override public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) { return getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()).withProperty(TYPE, getStateFromMeta(meta * EnumFacing.HORIZONTALS.length).getValue(TYPE)); } @Override protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[] {TYPE, FACING}); } @Override public int getMetaFromState(IBlockState state) { MachineTypes type = (MachineTypes) state.getValue(TYPE); EnumFacing facing = (EnumFacing) state.getValue(FACING); int meta = type.getID() * EnumFacing.HORIZONTALS.length + facing.getIndex(); return meta; } @Override public IBlockState getStateFromMeta(int meta) { MachineTypes type = MachineTypes.values()[(int) (meta / EnumFacing.HORIZONTALS.length) % MachineTypes.values().length]; EnumFacing facing = EnumFacing.HORIZONTALS[meta % EnumFacing.HORIZONTALS.length]; return getDefaultState().withProperty(TYPE, type).withProperty(FACING, facing); } @Override public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items) { for (int i = 0; i < MachineTypes.values().length; i++) { items.add(new ItemStack(this, 1, i)); } } @Override public String getSpecialName(ItemStack stack) { return MachineTypes.values()[stack.getItemDamage() % MachineTypes.values().length].getName(); } @Override public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) { return new ItemStack(Item.getItemFromBlock(this), 1, ((MachineTypes) state.getValue(TYPE)).getID()); } @Override public int damageDropped(IBlockState state) { return (int) getMetaFromState(state) / EnumFacing.HORIZONTALS.length; } @Override public void registerModels() { for (int i = 0; i < MachineTypes.values().length; i++) { EnhancedMechanisms.proxy.registerItemVariantsRenderer(Item.getItemFromBlock(this), i, "inventory", MachineTypes.values()[i].getName()); } } } I don't know what else you'd want to see, but these are the ones I think you'd want to see, and there are no errors in console related to this issue. Thanks for the help.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.