jh62 Posted August 14, 2013 Share Posted August 14, 2013 Hi. My problem is that when I create a block, it's metadata matches the one from the material it's been made, but when I reset the game, that information is gone. I followed the metadaba based subblocks tutorial and the block and item i followed another tutorial: Block: package pablisMod.blocks; import java.util.List; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLiving; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import pablisMod.entities.TableOneEntity; import pablisMod.items.TableOneItem; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.LanguageRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class TableOneBlock extends BlockContainer { public static int id; public TableOneBlock(int id) { super(id, Material.wood); this.id = id; this.setBlockName("Table"); this.setCreativeTab(CreativeTabs.tabDecorations); this.setStepSound(Block.soundWoodFootstep); this.setHardness(0.5F); this.setTextureFile("/pablisMod/textures/TableOneIcon.png"); this.setRequiresSelfNotify(); // absolutely needed } public int quantityDropped(Random par1Random) { return 1; } @Override public int getRenderType() { return -1; } @Override public int getBlockTextureFromSideAndMetadata (int side, int metadata) { return 16 + metadata; } @Override public TileEntity createNewTileEntity(World var1) { return null; } @Override public TileEntity createTileEntity(World world, int metadata) { return new TableOneEntity(); } @Override public boolean renderAsNormalBlock() { return false; } @Override public boolean isBlockSolid(IBlockAccess par1iBlockAccess, int par2, int par3, int par4, int par5) { return super.isBlockSolid(par1iBlockAccess, par2, par3, par4, par5); } @Override public boolean isOpaqueCube() { return false; } @Override public boolean canPlaceTorchOnTop(World world, int x, int y, int z) { return super.canPlaceTorchOnTop(world, x, y, z); } @Override public boolean shouldSideBeRendered(IBlockAccess iblockaccess, int i, int j, int k, int l) { return false; } @SideOnly(Side.CLIENT) public void getSubBlocks(int par1, CreativeTabs tab, List subItems) { for (int ix = 0; ix < 4; ix++) { subItems.add(new ItemStack(this, 1, ix)); } } @Override public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving) { int var6 = MathHelper .floor_double((double) (par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; switch (var6) { case 0: par1World.setBlockMetadataWithNotify(par2, par3, par4, 2); break; case 1: par1World.setBlockMetadataWithNotify(par2, par3, par4, 5); break; case 2: par1World.setBlockMetadataWithNotify(par2, par3, par4, 4); break; case 3: par1World.setBlockMetadataWithNotify(par2, par3, par4, 3); break; } } public static Block registerBlock(int id) { Block m_fieldName = new TableOneBlock(id); GameRegistry.registerBlock(m_fieldName, TableOneItem.class, "TableOneItem"); GameRegistry.registerTileEntity(TableOneEntity.class, "TableOneEntity"); ItemStack stack = new ItemStack(m_fieldName, 1, 0); LanguageRegistry.addName(stack, "Oak Table"); GameRegistry.addRecipe(stack, "yyy", "x x", "x x", 'x', new ItemStack( Item.stick, 1, 0), 'y', new ItemStack(Block.woodSingleSlab, 1, 0)); stack = new ItemStack(m_fieldName, 1, 1); LanguageRegistry.addName(stack, "Spruce Table"); GameRegistry.addRecipe(stack, "yyy", "x x", "x x", 'x', new ItemStack( Item.stick, 1, 0), 'y', new ItemStack(Block.woodSingleSlab, 1, 1)); stack = new ItemStack(m_fieldName, 1, 2); LanguageRegistry.addName(stack, "Birch Table"); GameRegistry.addRecipe(stack, "yyy", "x x", "x x", 'x', new ItemStack( Item.stick, 1, 0), 'y', new ItemStack(Block.woodSingleSlab, 1, 2)); stack = new ItemStack(m_fieldName, 1, 3); LanguageRegistry.addName(stack, "Jungle Table"); GameRegistry.addRecipe(stack, "yyy", "x x", "x x", 'x', new ItemStack( Item.stick, 1, 0), 'y', new ItemStack(Block.woodSingleSlab, 1, 3)); return m_fieldName; } } Item: package pablisMod.items; import java.util.List; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; public class TableOneItem extends ItemBlock { private static final String[] subTypes = {"Oak ", "Spruce ", "Birch ", "Jungle "}; public TableOneItem(int id) { super(id); maxStackSize = 16; setCreativeTab(CreativeTabs.tabDecorations); setItemName("Table"); setHasSubtypes(true); } public static String[] getSubtypes() { return subTypes; } @Override public int getMetadata (int damageValue) { return damageValue; } @Override public String getItemNameIS(ItemStack par1ItemStack) { return subTypes[par1ItemStack.getItemDamage()] + getItemName(); } } Renderer (The renderer doesn't use the metadata yet because is always changing): package pablisMod.renderers; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.tileentity.TileEntity; import org.lwjgl.opengl.GL11; import pablisMod.models.TableOneModel; public class TableOneRenderer extends TileEntitySpecialRenderer { private TableOneModel model; private String texture; public TableOneRenderer() { model = new TableOneModel(); texture = "/pablisMod/textures/SpruceTableOne.png"; } int ang = 0; public void renderTileEntityAt(TileEntity entity, double d, double d1, double d2, float f) { int metadata = entity.getBlockMetadata(); int rotationAngle = 0; switch(metadata % 4){ case 0: rotationAngle = 0; break; case 1: rotationAngle = 90; break; case 2: rotationAngle = 180; break; case 3: rotationAngle = 270; break; } int i = 0; if (entity.worldObj != null) { i = (entity.worldObj.getBlockMetadata(entity.xCoord, entity.yCoord, entity.zCoord)); } GL11.glPushMatrix(); GL11.glTranslatef((float) d + 0.5F, (float) d1 + 1.5F, (float) d2 + 0.5F); GL11.glRotatef(rotationAngle, 0.0F, 1.0F, 0.0F); GL11.glScalef(1.0F, -1F, -1F); bindTextureByName(texture); model.renderModel(0.0625F); GL11.glPopMatrix(); } } How can I save the metadata of the block and mantain the same number on every world load. Quote Link to comment Share on other sites More sharing options...
hydroflame Posted August 14, 2013 Share Posted August 14, 2013 ok 1, if you're not doing any animation and only renderign based on metadata, use ISBRH not TESR 2, dont use this, "@SideOnly(Side.CLIENT)" ever, it only causes confusion nothing good ever came out of that 3, dont override this method: "public TileEntity createNewTileEntity(World var1) " 3, to read/write from TE you need to implement readFromNBT and writeToNBT Quote how to debug 101:http://www.minecraftforge.net/wiki/Debug_101 -hydroflame, author of the forge revolution- Link to comment Share on other sites More sharing options...
jh62 Posted August 14, 2013 Author Share Posted August 14, 2013 ok 1, if you're not doing any animation and only renderign based on metadata, use ISBRH not TESR 2, dont use this, "@SideOnly(Side.CLIENT)" ever, it only causes confusion nothing good ever came out of that 3, dont override this method: "public TileEntity createNewTileEntity(World var1) " 3, to read/write from TE you need to implement readFromNBT and writeToNBT I forgot to mention that I'm using minecraft 1.4.7 because of some mods that are incompatible (or don't exists) for 1.6.x and I have a big world and I don't want to lose it. I cant find those interfaces you mentioned (readFromNBT, writeFromNBT) and what does ISBRH stand for? I'm a noob at Minecraft code yet... Quote Link to comment Share on other sites More sharing options...
GotoLink Posted August 14, 2013 Share Posted August 14, 2013 He meant override readFromNBT and writeToNBT. (thus, those are methods) ISBRH is hydroflame way of calling ISimpleBlockRenderingHandler. Quote Link to comment Share on other sites More sharing options...
hydroflame Posted August 14, 2013 Share Posted August 14, 2013 ISBRH is hydroflame way of calling ISimpleBlockRenderingHandler. ISimpleBlockRenderingHandler ISBRH ... i wouldnt say its my way but i probably should be more clear whenever someone might not know about it Quote how to debug 101:http://www.minecraftforge.net/wiki/Debug_101 -hydroflame, author of the forge revolution- Link to comment Share on other sites More sharing options...
jh62 Posted August 14, 2013 Author Share Posted August 14, 2013 Yeah, I imagined that and found it already. Thanks! Quote Link to comment Share on other sites More sharing options...
jh62 Posted August 14, 2013 Author Share Posted August 14, 2013 Now, here's another thing I don't understand and it's the final thing i need to grasp: I've found the Basic Tile Entity tutorial on the forge tutorials page and it says to do the following: @Override public TileEntity createTileEntity(World world, int metadata) { try { TableOneEntity entity = new TableOneEntity(); entity.setTextureID(metadata); //System.out.println("metadata " + metadata); return entity; } catch (Exception e) { throw new RuntimeException(e); } } That's fine. I can save the block's TileEntity with the metadata from the block, but whenever the world restarts, the entity get's overwritten by a new one and the metadata changes to some other thing and I can't get the old TileEntity from the block instead of creating a new one with the params provided by this method. How do you do it usually? Quote Link to comment Share on other sites More sharing options...
jh62 Posted August 15, 2013 Author Share Posted August 15, 2013 Anybody? Can't figure this out. Whenever i reload my world, the tile entity of the block gets overwritten by the new block metadata wich equals (apparently) to the direction that the block was placed. Nevermind this. It was because I followed some tutorial and at some point it was changing the block's metadata. I'm able now to render the texture based on metadata. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.