Posted September 9, 201411 yr I want that u can change the texture of the block by doing right-click with another Block. public class VariableBlock extends BlockContainer implements ITileEntityProvider { @SideOnly(Side.CLIENT) private IIcon topIcon; public VariableBlock() { super(Material.ground); this.setCreativeTab(CreativeTabs.tabBlock); } @Override public boolean isOpaqueCube() { return false; } public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int meta, float f1, float f2, float f3) { ItemStack stack = player.getCurrentEquippedItem(); if(stack != null && Block.getBlockFromItem(stack.getItem()) != null) { Block block = Block.getBlockFromItem(stack.getItem()); topIcon = block.getIcon(1, 0); blockIcon = block.getIcon(3, 0); return true; } return false; } @Override public TileEntity createNewTileEntity(World var1, int var2) { return new TileEntityVariableBlock(); } @SideOnly(Side.CLIENT) public IIcon getIcon(int side, int meta) { return side == 1 ? this.topIcon : (side == 0 ? this.topIcon : this.blockIcon); } @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister ir) { this.blockIcon = ir.registerIcon("furnace_side"); this.topIcon = ir.registerIcon("furnace_top"); } } With this code i can change the texture, but all change the texutre, not only one. Second problem: The grass is gray.
September 9, 201411 yr Author With metadata i can only have 4 (?) different textures in one world. And one mistake by myself: I mean: You can click with a cobble on one of this blocks, at another with a sandstone , ... And then they look like the block. 3. Problem after reload they have the first texture
September 9, 201411 yr Author With a TileEntity I need them to save in the NBT-Tag right? But how i should save it in there? And how I should get the Texture from there in the getIcon Method?
September 9, 201411 yr Make your block implement ITileEntityProvider and return your tile entity in the new method. In getIcon (look in Block.class for the version that takes x, y, z as arguments) use ((YourTile) world.getTileEntity(x, y, z)).field .. For further help wiki Check out my blog! http://www.whov.altervista.org
September 10, 201411 yr Author I'm done so far, but 2 Problems: 1. Some Texture are wrong like gray grass and the different wood has always the oak texture 2. After a reload the textures are away public class VariableBlock extends BlockContainer implements ITileEntityProvider { public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int meta, float f1, float f2, float f3) { ItemStack stack = player.getCurrentEquippedItem(); TileEntityVariableBlock te = (TileEntityVariableBlock) world.getTileEntity(x, y, z); if(stack != null && Block.getBlockFromItem(stack.getItem()) != null) { te.setIconStack(stack); return true; } return false; } @Override public TileEntity createNewTileEntity(World var1, int var2) { return new TileEntityVariableBlock(); } @SideOnly(Side.CLIENT) public IIcon getIcon(IBlockAccess ba, int x, int y, int z, int side) { TileEntityVariableBlock te = (TileEntityVariableBlock) ba.getTileEntity(x, y, z); return (te != null && te.getIcon(side) != null) ? te.getIcon(side) : this.blockIcon; } public class TileEntityVariableBlock extends TileEntity { private ItemStack iconStack; public void setIconStack(ItemStack stack) { iconStack = stack; } public IIcon getIcon(int side) { return iconStack != null ? Block.getBlockFromItem(iconStack.getItem()).getIcon(side, 0) : null; } @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); iconStack = ItemStack.loadItemStackFromNBT(nbt); } @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); iconStack.writeToNBT(nbt); } } public static Block VariableBlock= new VariableBlock().setBlockName("VariableBlock"); @EventHandler private void FMLInit(FMLInitializationEvent event) { GameRegistry.registerBlock(VariableBlock, "VariableBlock"); GameRegistry.registerTileEntity(TileEntityVariableBlock.class, "TileEntityVariableBlock"); }
September 10, 201411 yr Hi Problem 1: oak You need to handle the wood metadata as well. Different metadata is used for different types of wood, or eg different colours of wool. http://greyminecraftcoder.blogspot.com.au/2013/07/blocks.html Problem 2: http://www.minecraftforge.net/forum/index.php/topic,23256.msg117993.html#msg117993 -TGG
September 10, 201411 yr Author I add this but: It doesn't work with the reload @Override public Packet getDescriptionPacket() { S35PacketUpdateTileEntity packet = (S35PacketUpdateTileEntity) super.getDescriptionPacket(); NBTTagCompound tag = packet != null ? packet.func_148857_g() : new NBTTagCompound(); addInfoToNBT(tag); return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag); } @Override public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { super.onDataPacket(net, pkt); NBTTagCompound tag = pkt.func_148857_g(); loadInfoFromNBT(tag); } private void addInfoToNBT(NBTTagCompound tag) { if(iconStack != null) iconStack.writeToNBT(tag); } private void loadInfoFromNBT(NBTTagCompound tag) { iconStack = ItemStack.loadItemStackFromNBT(tag); }
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.