5 nov. 2014, 15:23

Bonjour,
J’ai suivi le tuto pour orienter son bloc avec metadata mais, après test, le bloc ne s’oriente pas.
Pouvez-vous m’aider ?

Block :


public class BlockCrusher extends BasicBlock

{
public static String[] subBlock = new String[] {"copper", "bronze", "steel"};
public IIcon[][] iconArray = new IIcon[subBlock.length][3];
private static boolean field_149934_M;

public void registerBlockIcons(IIconRegister iconRegister)
{
for(int i = 0; i < subBlock.length; i++)
{
this.iconArray*[0] = iconRegister.registerIcon("neworesbasic:" + subBlock* + "_crusher_top");
this.iconArray*[1] = iconRegister.registerIcon("neworesbasic:" + subBlock* + "_crusher_front");
this.iconArray*[2] = iconRegister.registerIcon("neworesbasic:" + subBlock* + "_crusher_side");
}
}

public void getSubBlocks(Item item, CreativeTabs tabs, List list)
{
for(int i = 0; i < subBlock.length; i++)
{
list.add(new ItemStack(item, 1, i));
}
}

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

@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int metadata)
{
if(side == 1) // UP
   {
    return this.iconArray[metadata][0];
   }
   else if(side == 3) // FRONT : 3
   {
    return this.iconArray[metadata][1];
   }
   else
   {
    return this.iconArray[metadata][2];
   }
}

public BlockCrusher()
{
this.setCreativeTab(Basic.BasicTab);
}

@Override
    public TileEntity createTileEntity(World world, int metadata)
    {
        return new TileEntityCrusher();
    }

    @Override
    public boolean hasTileEntity(int metadata)
    {
        return true;
    }

    public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9)
{
    FMLNetworkHandler.openGui(player, Basic.instance, 0, world, x, y, z);
return true;
}

    public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase living, ItemStack stack)
{
TileEntity te = world.getTileEntity(x, y, z);
if(te != null && te instanceof TileEntityCrusher && stack.hasDisplayName())
{
((TileEntityCrusher)te).setCustomGuiName(stack.getDisplayName());
}
if(te instanceof TileEntityCrusher)
{
int direction = MathHelper.floor_double((double)(living.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3;
            ((TileEntityCrusher)te).setDirection((byte)direction);
}
}

    public void breakBlock(World world, int x, int y, int z, Block block, int metadata)
    {
    dropContainerItem(world, x, y, z);
        super.breakBlock(world, x, y, z, block, metadata);
    }

    protected void dropContainerItem(World world, int x, int y, int z)
    {
    TileEntityCrusher tecrusher = (TileEntityCrusher)world.getTileEntity(x, y, z);

        if (tecrusher != null)
        {
            for (int slotId = 0; slotId < tecrusher.getSizeInventory(); slotId++)
            {
                ItemStack stack = tecrusher.getStackInSlot(slotId);

                if (stack != null)
                {
                    float f = world.rand.nextFloat() * 0.8F + 0.1F;
                    float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
                    EntityItem entityitem;

                    for (float f2 = world.rand.nextFloat() * 0.8F + 0.1F; stack.stackSize > 0; world.spawnEntityInWorld(entityitem))
                    {
                        int k1 = world.rand.nextInt(21) + 10;

                        if (k1 > stack.stackSize)
                        {
                            k1 = stack.stackSize;
                        }

                        stack.stackSize -= k1;
                        entityitem = new EntityItem(world, (double)((float)x + f), (double)((float)y + f1), (double)((float)z + f2), new ItemStack(stack.getItem(), k1, stack.getItemDamage()));
                        float f3 = 0.05F;
                        entityitem.motionX = (double)((float)world.rand.nextGaussian() * f3);
                        entityitem.motionY = (double)((float)world.rand.nextGaussian() * f3 + 0.2F);
                        entityitem.motionZ = (double)((float)world.rand.nextGaussian() * f3);

                        if (stack.hasTagCompound())
                        {
                            entityitem.getEntityItem().setTagCompound((NBTTagCompound)stack.getTagCompound().copy());
                        }
                    }
                }
            }
        }
    }

    public static void updateCrusherBlockState(boolean p_149931_0_, World p_149931_1_, int p_149931_2_, int p_149931_3_, int p_149931_4_)
    {
        int l = p_149931_1_.getBlockMetadata(p_149931_2_, p_149931_3_, p_149931_4_);
        TileEntity tileentity = p_149931_1_.getTileEntity(p_149931_2_, p_149931_3_, p_149931_4_);
        field_149934_M = true;

        /*if (p_149931_0_)
        {
            p_149931_1_.setBlock(p_149931_2_, p_149931_3_, p_149931_4_, Basic.crusher); // In-crushing block
        }
        else
        {
            p_149931_1_.setBlock(p_149931_2_, p_149931_3_, p_149931_4_, Basic.crusher);
        }*/

        field_149934_M = false;
        p_149931_1_.setBlockMetadataWithNotify(p_149931_2_, p_149931_3_, p_149931_4_, l, 2);

        if (tileentity != null)
        {
            tileentity.validate();
            p_149931_1_.setTileEntity(p_149931_2_, p_149931_3_, p_149931_4_, tileentity);
        }
    }

    public boolean hasComparatorInputOverride()
    {
        return true;
    }

    public int getComparatorInputOverride(World p_149736_1_, int p_149736_2_, int p_149736_3_, int p_149736_4_, int p_149736_5_)
    {
        return Container.calcRedstoneFromInventory((IInventory)p_149736_1_.getTileEntity(p_149736_2_, p_149736_3_, p_149736_4_));
    }
}

TileEntity :


private byte direction;

@Override
public void readFromNBT(NBTTagCompound nbttag)
{
super.readFromNBT(nbttag);
this.direction = nbttag.getByte("Direction");
// Code. Mystère… ;)
}

@Override
public void writeToNBT(NBTTagCompound nbttag)
{
super.writeToNBT(nbttag);
nbttag.setByte("Direction", this.direction);
// Code. Mystère... ;)
}

public byte getDirection()
{
return direction;
}

public void setDirection(byte direction)
{
this.direction = direction;
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}

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

public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt)
{
this.readFromNBT(pkt.func_148857_g());
this.worldObj.markBlockRangeForRenderUpdate(this.xCoord, this.yCoord, this.zCoord, this.xCoord, this.yCoord, this.zCoord);
}