Jump to content

[1.7.10] [Solved?] Tile Entity is not saving nbt info (blockMetadata)


SackCastellon

Recommended Posts

I've created a TileEntity to store the metadata of a block, when i place my block averything goes well:

 

width=800 height=419https://dl.dropboxusercontent.com/u/184200482/img/ladder_ok.png[/img]

** The blocks' metadata are the following

| 2 | 6 | 10 | 14 | 18 | 22 |

**

 

But once I restart minecraft I see that the

blockMetadata

information has not been stored by the TileEntity:

 

width=800 height=419https://dl.dropboxusercontent.com/u/184200482/img/ladder_bad.png[/img]

** The blocks' metadata are the following

| 2 | 6 | 10 | 14 | 2 (18) | 6 (22) |

**

 

This is the error:

 

[20:26:41] [server thread/INFO]: Preparing start region for level 0
java.lang.InstantiationException: com.sackcastellon.betterwood.tileentities.TileEntityLadder
at java.lang.Class.newInstance(Unknown Source)
at net.minecraft.tileentity.TileEntity.createAndLoadEntity(TileEntity.java:127)
at net.minecraft.world.chunk.storage.AnvilChunkLoader.loadEntities(AnvilChunkLoader.java:525)
at net.minecraftforge.common.chunkio.ChunkIOProvider.callStage2(ChunkIOProvider.java:41)
at net.minecraftforge.common.chunkio.ChunkIOProvider.callStage2(ChunkIOProvider.java:12)
at net.minecraftforge.common.util.AsynchronousExecutor.skipQueue(AsynchronousExecutor.java:344)
at net.minecraftforge.common.util.AsynchronousExecutor.getSkipQueue(AsynchronousExecutor.java:302)
at net.minecraftforge.common.chunkio.ChunkIOExecutor.syncChunkLoad(ChunkIOExecutor.java:12)
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:146)
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:121)
at net.minecraft.server.MinecraftServer.initialWorldChunkLoad(MinecraftServer.java:315)
at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:79)
at net.minecraft.server.integrated.IntegratedServer.startServer(IntegratedServer.java:96)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:455)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:762)
Caused by: java.lang.NoSuchMethodException: com.sackcastellon.betterwood.tileentities.TileEntityLadder.<init>()
at java.lang.Class.getConstructor0(Unknown Source)
... 15 more
java.lang.InstantiationException: com.sackcastellon.betterwood.tileentities.TileEntityLadder
at java.lang.Class.newInstance(Unknown Source)
at net.minecraft.tileentity.TileEntity.createAndLoadEntity(TileEntity.java:127)
at net.minecraft.world.chunk.storage.AnvilChunkLoader.loadEntities(AnvilChunkLoader.java:525)
at net.minecraftforge.common.chunkio.ChunkIOProvider.callStage2(ChunkIOProvider.java:41)
at net.minecraftforge.common.chunkio.ChunkIOProvider.callStage2(ChunkIOProvider.java:12)
at net.minecraftforge.common.util.AsynchronousExecutor.skipQueue(AsynchronousExecutor.java:344)
at net.minecraftforge.common.util.AsynchronousExecutor.getSkipQueue(AsynchronousExecutor.java:302)
at net.minecraftforge.common.chunkio.ChunkIOExecutor.syncChunkLoad(ChunkIOExecutor.java:12)
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:146)
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:121)
at net.minecraft.server.MinecraftServer.initialWorldChunkLoad(MinecraftServer.java:315)
at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:79)
at net.minecraft.server.integrated.IntegratedServer.startServer(IntegratedServer.java:96)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:455)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:762)
Caused by: java.lang.NoSuchMethodException: com.sackcastellon.betterwood.tileentities.TileEntityLadder.<init>()
at java.lang.Class.getConstructor0(Unknown Source)
... 15 more
java.lang.InstantiationException: com.sackcastellon.betterwood.tileentities.TileEntityLadder
at java.lang.Class.newInstance(Unknown Source)
at net.minecraft.tileentity.TileEntity.createAndLoadEntity(TileEntity.java:127)
at net.minecraft.world.chunk.storage.AnvilChunkLoader.loadEntities(AnvilChunkLoader.java:525)
at net.minecraftforge.common.chunkio.ChunkIOProvider.callStage2(ChunkIOProvider.java:41)
at net.minecraftforge.common.chunkio.ChunkIOProvider.callStage2(ChunkIOProvider.java:12)
at net.minecraftforge.common.util.AsynchronousExecutor.skipQueue(AsynchronousExecutor.java:344)
at net.minecraftforge.common.util.AsynchronousExecutor.getSkipQueue(AsynchronousExecutor.java:302)
at net.minecraftforge.common.chunkio.ChunkIOExecutor.syncChunkLoad(ChunkIOExecutor.java:12)
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:146)
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:121)
at net.minecraft.server.MinecraftServer.initialWorldChunkLoad(MinecraftServer.java:315)
at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:79)
at net.minecraft.server.integrated.IntegratedServer.startServer(IntegratedServer.java:96)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:455)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:762)
Caused by: java.lang.NoSuchMethodException: com.sackcastellon.betterwood.tileentities.TileEntityLadder.<init>()
at java.lang.Class.getConstructor0(Unknown Source)
... 15 more
java.lang.InstantiationException: com.sackcastellon.betterwood.tileentities.TileEntityLadder
at java.lang.Class.newInstance(Unknown Source)
at net.minecraft.tileentity.TileEntity.createAndLoadEntity(TileEntity.java:127)
at net.minecraft.world.chunk.storage.AnvilChunkLoader.loadEntities(AnvilChunkLoader.java:525)
at net.minecraftforge.common.chunkio.ChunkIOProvider.callStage2(ChunkIOProvider.java:41)
at net.minecraftforge.common.chunkio.ChunkIOProvider.callStage2(ChunkIOProvider.java:12)
at net.minecraftforge.common.util.AsynchronousExecutor.skipQueue(AsynchronousExecutor.java:344)
at net.minecraftforge.common.util.AsynchronousExecutor.getSkipQueue(AsynchronousExecutor.java:302)
at net.minecraftforge.common.chunkio.ChunkIOExecutor.syncChunkLoad(ChunkIOExecutor.java:12)
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:146)
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:121)
at net.minecraft.server.MinecraftServer.initialWorldChunkLoad(MinecraftServer.java:315)
at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:79)
at net.minecraft.server.integrated.IntegratedServer.startServer(IntegratedServer.java:96)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:455)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:762)
Caused by: java.lang.NoSuchMethodException: com.sackcastellon.betterwood.tileentities.TileEntityLadder.<init>()
at java.lang.Class.getConstructor0(Unknown Source)
... 15 more
java.lang.InstantiationException: com.sackcastellon.betterwood.tileentities.TileEntityLadder
at java.lang.Class.newInstance(Unknown Source)
at net.minecraft.tileentity.TileEntity.createAndLoadEntity(TileEntity.java:127)
at net.minecraft.world.chunk.storage.AnvilChunkLoader.loadEntities(AnvilChunkLoader.java:525)
at net.minecraftforge.common.chunkio.ChunkIOProvider.callStage2(ChunkIOProvider.java:41)
at net.minecraftforge.common.chunkio.ChunkIOProvider.callStage2(ChunkIOProvider.java:12)
at net.minecraftforge.common.util.AsynchronousExecutor.skipQueue(AsynchronousExecutor.java:344)
at net.minecraftforge.common.util.AsynchronousExecutor.getSkipQueue(AsynchronousExecutor.java:302)
at net.minecraftforge.common.chunkio.ChunkIOExecutor.syncChunkLoad(ChunkIOExecutor.java:12)
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:146)
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:121)
at net.minecraft.server.MinecraftServer.initialWorldChunkLoad(MinecraftServer.java:315)
at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:79)
at net.minecraft.server.integrated.IntegratedServer.startServer(IntegratedServer.java:96)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:455)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:762)
Caused by: java.lang.NoSuchMethodException: com.sackcastellon.betterwood.tileentities.TileEntityLadder.<init>()
at java.lang.Class.getConstructor0(Unknown Source)
... 15 more
java.lang.InstantiationException: com.sackcastellon.betterwood.tileentities.TileEntityLadder
at java.lang.Class.newInstance(Unknown Source)
at net.minecraft.tileentity.TileEntity.createAndLoadEntity(TileEntity.java:127)
at net.minecraft.world.chunk.storage.AnvilChunkLoader.loadEntities(AnvilChunkLoader.java:525)
at net.minecraftforge.common.chunkio.ChunkIOProvider.callStage2(ChunkIOProvider.java:41)
at net.minecraftforge.common.chunkio.ChunkIOProvider.callStage2(ChunkIOProvider.java:12)
at net.minecraftforge.common.util.AsynchronousExecutor.skipQueue(AsynchronousExecutor.java:344)
at net.minecraftforge.common.util.AsynchronousExecutor.getSkipQueue(AsynchronousExecutor.java:302)
at net.minecraftforge.common.chunkio.ChunkIOExecutor.syncChunkLoad(ChunkIOExecutor.java:12)
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:146)
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:121)
at net.minecraft.server.MinecraftServer.initialWorldChunkLoad(MinecraftServer.java:315)
at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:79)
at net.minecraft.server.integrated.IntegratedServer.startServer(IntegratedServer.java:96)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:455)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:762)
Caused by: java.lang.NoSuchMethodException: com.sackcastellon.betterwood.tileentities.TileEntityLadder.<init>()
at java.lang.Class.getConstructor0(Unknown Source)
... 15 more
[20:26:42] [server thread/WARN]: Skipping BlockEntity with id Ladder
[20:26:42] [server thread/WARN]: Skipping BlockEntity with id Ladder
[20:26:42] [server thread/WARN]: Skipping BlockEntity with id Ladder
[20:26:42] [server thread/WARN]: Skipping BlockEntity with id Ladder
[20:26:42] [server thread/WARN]: Skipping BlockEntity with id Ladder
[20:26:42] [server thread/WARN]: Skipping BlockEntity with id Ladder
[20:26:42] [server thread/INFO]: Preparing spawn area: 81%

 

And this is my code:

 

BlockLadder.class

package com.sackcastellon.betterwood.block;

import static net.minecraftforge.common.util.ForgeDirection.EAST;
import static net.minecraftforge.common.util.ForgeDirection.NORTH;
import static net.minecraftforge.common.util.ForgeDirection.SOUTH;
import static net.minecraftforge.common.util.ForgeDirection.WEST;

import java.util.ArrayList;
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.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

import com.sackcastellon.betterwood.api.Tabs;
import com.sackcastellon.betterwood.handler.LadderHandler;
import com.sackcastellon.betterwood.lib.Reference;
import com.sackcastellon.betterwood.loader.ItemLoader;
import com.sackcastellon.betterwood.tileentities.TileEntityLadder;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class BlockLadder extends BlockContainer
{
@SideOnly(Side.CLIENT)
private final IIcon[] iconArray;

private final String path = Reference.TexturePath + "ladder/";

public BlockLadder()
{
	super(Material.wood);

	this.setCreativeTab(Tabs.tabBW);

	this.iconArray = new IIcon[itemLoader.woodTypes.length];
}

@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z)
{
	int meta = world.getTileEntity(x, y, z).getBlockMetadata() & 28; //Some tests to save up space

	System.out.println(world.getTileEntity(x, y, z).getBlockMetadata() + "=>" + meta);

        return new ItemStack(Item.getItemFromBlock(this), 1, meta);
}

@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune)
{
	ArrayList<ItemStack> ret = new ArrayList<ItemStack>();

	int meta = 0;

        switch(world.getTileEntity(x, y, z).getBlockMetadata())
        {
        case 0: case 1: case 2: case 3:
        	meta = 0;
        	break;
        case 4: case 5: case 6: case 7:
        	meta = 4;
        	break;
        case 8: case 9: case 10: case 11:
        	meta = 8;
        	break;
        case 12: case 13: case 14: case 15:
        	meta = 12;
        	break;
        case 16: case 17: case 18: case 19:
        	meta = 16;
        	break;
        case 20: case 21: case 22: case 23:
        	meta = 20;
        	break;
        }

        ret.add(new ItemStack(Item.getItemFromBlock(this), 1, meta));
        
        return ret;
}

@Override
public TileEntity createNewTileEntity(World world, int meta)
{
	return new TileEntityLadder(meta);
}

@Override
public boolean isOpaqueCube()
{
	return false;
}

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void getSubBlocks(Item item, CreativeTabs tab, List list)
{
	for(int i = 0; i < ItemLoader.woodTypes.length; ++i)
	{
		list.add(new ItemStack(this, 1, i * 4));
	}
}

@Override
public void registerBlockIcons(IIconRegister iconRegister)
{
	for(int i = 0; i < ItemLoader.woodTypes.length; ++i)
	{
		this.iconArray[i] = iconRegister.registerIcon(path + (String) ItemLoader.woodTypes[i][1]);
	}
}

@Override
public IIcon getIcon(int side, int meta)
{
	return this.iconArray[meta / 4];
}


/**
     * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
     * cleared to be reused)
     */
@Override
    public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z)
    {
        this.setBlockBoundsBasedOnState(world, x, y, z);
        return super.getCollisionBoundingBoxFromPool(world, x, y, z);
    }

    /**
     * Updates the blocks bounds based on its current state. Args: world, x, y, z
     */
@Override
    public void setBlockBoundsBasedOnState(IBlockAccess block, int x, int y, int z)
    {
        this.setBlockBounds(block.getBlockMetadata(x, y, z));
    }

    /**
     * Returns the bounding box of the wired rectangular prism to render.
     */
@Override
    @SideOnly(Side.CLIENT)
    public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z)
    {
        this.setBlockBoundsBasedOnState(world, x, y, z);
        return super.getSelectedBoundingBoxFromPool(world, x, y, z);
    }

    public void setBlockBounds(int metadata)
    {
        float f = 0.125F;
        
        int meta = metadata & 3;
        
        if(meta == 0)
        {
            this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
        }
        
        else if(meta == 1)
        {
            this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
        }
        
        else if(meta == 2)
        {
            this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
        }
        
        else if(meta == 3)
        {
            this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
        }
    }

    /**
     * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
     */
    @Override
    public boolean renderAsNormalBlock()
    {
        return false;
    }

    /**
     * The type of render function that is called for this block
     */
    @Override
    public int getRenderType()
    {
        return LadderHandler.renderId;
    }

    /**
     * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
     */
    @Override
    public boolean canPlaceBlockAt(World world, int x, int y, int z)
    {
        return world.isSideSolid(x - 1, y, z, EAST ) ||
               world.isSideSolid(x + 1, y, z, WEST ) ||
               world.isSideSolid(x, y, z - 1, SOUTH) ||
               world.isSideSolid(x, y, z + 1, NORTH);
    }

    /**
     * Called when a block is placed using its ItemBlock. Args: World, X, Y, Z, side, hitX, hitY, hitZ, block metadata
     */
    @Override
    public int onBlockPlaced(World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int meta)
    {
        int j1 = meta;

        switch(meta)
        {
        case 0:
        	if ((meta == 0 || side == 2) && world.isSideSolid(x, y, z + 1, NORTH))
            {
                j1 = 0;
            }

            if ((j1 == 0 || side == 3) && world.isSideSolid(x, y, z - 1, SOUTH))
            {
                j1 = 1;
            }

            if ((j1 == 0 || side == 4) && world.isSideSolid(x + 1, y, z, WEST))
            {
                j1 = 2;
            }

            if ((j1 == 0 || side == 5) && world.isSideSolid(x - 1, y, z, EAST))
            {
                j1 = 3;
            }
            break;

        case 4:
        	if ((meta == 4 || side == 2) && world.isSideSolid(x, y, z + 1, NORTH))
            {
                j1 = 4;
            }

            if ((j1 == 4 || side == 3) && world.isSideSolid(x, y, z - 1, SOUTH))
            {
                j1 = 5;
            }

            if ((j1 == 4 || side == 4) && world.isSideSolid(x + 1, y, z, WEST))
            {
                j1 = 6;
            }

            if ((j1 == 4 || side == 5) && world.isSideSolid(x - 1, y, z, EAST))
            {
                j1 = 7;
            }
            break;

        case 8:
        	if ((meta == 8 || side == 2) && world.isSideSolid(x, y, z + 1, NORTH))
            {
                j1 = 8;
            }

            if ((j1 == 8 || side == 3) && world.isSideSolid(x, y, z - 1, SOUTH))
            {
                j1 = 9;
            }

            if ((j1 == 8 || side == 4) && world.isSideSolid(x + 1, y, z, WEST))
            {
                j1 = 10;
            }

            if ((j1 == 8 || side == 5) && world.isSideSolid(x - 1, y, z, EAST))
            {
                j1 = 11;
            }
            break;

        case 12:
        	if ((meta == 12 || side == 2) && world.isSideSolid(x, y, z + 1, NORTH))
            {
                j1 = 12;
            }

            if ((j1 == 12 || side == 3) && world.isSideSolid(x, y, z - 1, SOUTH))
            {
                j1 = 13;
            }

            if ((j1 == 12 || side == 4) && world.isSideSolid(x + 1, y, z, WEST))
            {
                j1 = 14;
            }

            if ((j1 == 12 || side == 5) && world.isSideSolid(x - 1, y, z, EAST))
            {
                j1 = 15;
            }
            break;

        case 16:
        	if ((meta == 16 || side == 2) && world.isSideSolid(x, y, z + 1, NORTH))
            {
                j1 = 16;
            }

            if ((j1 == 16 || side == 3) && world.isSideSolid(x, y, z - 1, SOUTH))
            {
                j1 = 17;
            }

            if ((j1 == 16 || side == 4) && world.isSideSolid(x + 1, y, z, WEST))
            {
                j1 = 18;
            }

            if ((j1 == 16 || side == 5) && world.isSideSolid(x - 1, y, z, EAST))
            {
                j1 = 19;
            }
            break;

        case 20:
        	if ((meta == 20 || side == 2) && world.isSideSolid(x, y, z + 1, NORTH))
            {
                j1 = 20;
            }

            if ((j1 == 20 || side == 3) && world.isSideSolid(x, y, z - 1, SOUTH))
            {
                j1 = 21;
            }

            if ((j1 == 20 || side == 4) && world.isSideSolid(x + 1, y, z, WEST))
            {
                j1 = 22;
            }

            if ((j1 == 20 || side == 5) && world.isSideSolid(x - 1, y, z, EAST))
            {
                j1 = 23;
            }
            break;
        }

        return j1;
    }

    /**
     * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
     * their own) Args: x, y, z, neighbor Block
     */
    @Override
    public void onNeighborBlockChange(World world, int x, int y, int z, Block block)
    {
        int l = world.getBlockMetadata(x, y, z);
        boolean flag = false;

        if ((l == 0 || l == 4 || l == 8 || l == 12 || l == 16 || l == 20) && world.isSideSolid(x, y, z + 1, NORTH))
        {
            flag = true;
        }

        if ((l == 1 || l == 5 || l == 9 || l == 13 || l == 17 || l == 21) && world.isSideSolid(x, y, z - 1, SOUTH))
        {
            flag = true;
        }

        if ((l == 2 || l == 6 || l == 10 || l == 14 || l == 18 || l == 22) && world.isSideSolid(x + 1, y, z, WEST))
        {
            flag = true;
        }

        if ((l == 3 || l == 7 || l == 11 || l == 15 || l == 19 || l == 23) && world.isSideSolid(x - 1, y, z, EAST))
        {
            flag = true;
        }

        if (!flag)
        {
            this.dropBlockAsItem(world, x, y, z, l, 0);
            world.setBlockToAir(x, y, z);
        }

        super.onNeighborBlockChange(world, x, y, z, block);
    }

    /**
     * Returns the quantity of items to drop on block destruction.
     */
    @Override
    public int quantityDropped(Random random)
    {
        return 1;
    }

    @Override
    public boolean isLadder(IBlockAccess world, int x, int y, int z, EntityLivingBase entity)
    {
        return true;
    }
}

 

TileEntityLadder.class

package com.sackcastellon.betterwood.tileentities;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;

public class TileEntityLadder extends TileEntity
{
public TileEntityLadder(int meta)
{
	this.blockMetadata = meta;
}

@Override
public void readFromNBT(NBTTagCompound nbt)
{
	super.readFromNBT(nbt);

	this.blockMetadata = nbt.getInteger("Metadata");
}

@Override
public void writeToNBT(NBTTagCompound nbt)
{
	super.writeToNBT(nbt);

	nbt.setInteger("Metadata", this.blockMetadata);
}

@Override
public int getBlockMetadata()
{
	return this.blockMetadata;
}

@Override
public Packet getDescriptionPacket()
{
	NBTTagCompound nbt = new NBTTagCompound();
	this.writeToNBT(nbt);
	return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 0, nbt);
}

@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt)
{
	this.readFromNBT(pkt.func_148857_g());
}
}

 

ItemBlockLadder.class

package com.sackcastellon.betterwood.itemblock;

import java.util.List;

import com.sackcastellon.betterwood.loader.ItemLoader;
import com.sackcastellon.betterwood.loader.LoreLoader;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;

public class ItemBlockLadder extends ItemBlock {

public ItemBlockLadder(Block block)
{
	super(block);

	this.setHasSubtypes(true);
	this.setMaxDamage(0);
}

    public int getMetadata(int metadata)
    {
        return metadata;
    }

    @Override
@SideOnly(Side.CLIENT)
    public IIcon getIconFromDamage(int meta)
    {
        return this.field_150939_a.getIcon(2, meta);
    }

@Override
public String getUnlocalizedName(ItemStack stack)
{
	return "bw.block.ladder." + (String) ItemLoader.woodTypes[stack.getItemDamage() / 4][1];
}

@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean flag)
{
	list.add(LoreLoader.Block + ": " + LoreLoader.getMaterialLore((String) ItemLoader.woodTypes[stack.getItemDamage() / 4][1]));
}
}

 

ClientProxy.class

package com.sackcastellon.betterwood.proxy;

import com.sackcastellon.betterwood.handler.*;

import cpw.mods.fml.client.registry.RenderingRegistry;

public class ClientProxy extends CommonProxy
{
@Override
public void registerRenderers()
{
	RenderingRegistry.registerBlockHandler(new LadderHandler());
}
}

 

This code goes in the

preInit

method:

Blocks.Ladder = new BlockLadder();
GameRegistry.registerBlock(Blocks.Ladder, ItemBlockLadder.class, "Ladder");

 

And this in the

init

method:

GameRegistry.registerTileEntity(TileEntityLadder.class, "Ladder");

Link to comment
Share on other sites

First of all don't just re-use Minecraft's field in the TE. It is used for something else.

You need a default constructor on your TileEntity, otherwise MC cannot load it.

 

I've been looking for where the

blockMetadata

field were used and it's only used on the

TileEntity.class

, so I'm assuming there is no problem if I use it to store the block metadata.

 

And looks like it works by adding the default constructor:

public TileEntityLadder() {}

 

Thanks  :)

 

PS: Unless I get an error by "re-using" Minecraft's field in the TE, I won't change it.

Link to comment
Share on other sites

PS: Unless I get an error by "re-using" Minecraft's field in the TE, I won't change it.

Search for usages on the getter (getBlockMetadata). There are a lot of usages in the minecraft codebase. Do not do this.

 

Yes, I know there are a bunch of classes using the getter, but (in my opinion) the important is to know where is the value of the field set, so as there are no setter, the only way to set the value of the field is this:

 

    public void markDirty()
    {
        if (this.worldObj != null)
        {
            this.blockMetadata = this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord);
            this.worldObj.markTileEntityChunkModified(this.xCoord, this.yCoord, this.zCoord, this);

            if (this.getBlockType() != Blocks.air)
            {
                this.worldObj.func_147453_f(this.xCoord, this.yCoord, this.zCoord, this.getBlockType());
            }
        }
    }

 

More concretely this part:

this.blockMetadata = this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord);

 

Which I think is the same thing that I'm doing, isn't it?

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

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