15 juin 2015, 15:03
package fr.minecraftforgefrance.novamine.common;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class ItemPorte extends Item
{

public ItemPorte()
{
this.maxStackSize = 1;
this.setCreativeTab(CreativeTabs.tabBlock);
}

public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
{
if(side != 1)
{
return false;
}
else
{
++y;
Block block = ModNovamine.porte;

if(player.canPlayerEdit(x, y, z, side, itemStack) && player.canPlayerEdit(x, y + 1, z, side, itemStack))
{
if(!block.canPlaceBlockAt(world, x, y, z))
{
return false;
}
else
{
int i1 = MathHelper.floor_double((double)((player.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3;
placeDoorBlock(world, x, y, z, i1, block);
–itemStack.stackSize;
return true;
}
}
else
{
return false;
}
}
}

public static void placeDoorBlock(World world, int x, int y, int z, int side, Block block)
{
byte b0 = 0;
byte b1 = 0;

if(side == 0)
{
b1 = 1;
}

if(side == 1)
{
b0 = -1;
}

if(side == 2)
{
b1 = -1;
}

if(side == 3)
{
b0 = 1;
}

int i1 = (world.getBlock(x - b0, y, z - b1).isNormalCube() ? 1 : 0) + (world.getBlock(x - b0, y + 1, z - b1).isNormalCube() ? 1 : 0);
int j1 = (world.getBlock(x + b0, y, z + b1).isNormalCube() ? 1 : 0) + (world.getBlock(x + b0, y + 1, z + b1).isNormalCube() ? 1 : 0);
boolean flag = world.getBlock(x - b0, y, z - b1) == block || world.getBlock(x - b0, y + 1, z - b1) == block;
boolean flag1 = world.getBlock(x + b0, y, z + b1) == block || world.getBlock(x + b0, y + 1, z + b1) == block;
boolean flag2 = false;

if(flag && !flag1)
{
flag2 = true;
}
else if(j1 > i1)
{
flag2 = true;
}

world.setBlock(x, y, z, block, side, 2);
world.setBlock(x, y + 1, z, block, 8 | (flag2 ? 1 : 0), 2);
world.notifyBlocksOfNeighborChange(x, y, z, block);
world.notifyBlocksOfNeighborChange(x, y + 1, z, block);
}
}

et


package fr.minecraftforgefrance.novamine.common;

import java.util.Random;

import net.minecraft.block.BlockDoor;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class Porte extends BlockDoor
{

public Porte()
{
super(Material.wood);
this.setHardness(3.0F);
this.setResistance(5.0F);
this.disableStats();
}

@Override
public Item getItemDropped(int par1, Random rand, int par3)
{
return ModNovamine.porteItem;
}

@Override
@SideOnly(Side.CLIENT)
public Item getItem(World world, int x, int y, int z)
{
return ModNovamine.porteItem;
}

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
{
int i1 = this.func_150012_g(world, x, y, z);
int j1 = i1 & 7;
j1 ^= 4;
//ouvre la porte
if ((i1 & 8) == 0)
{
world.setBlockMetadataWithNotify(x, y, z, j1, 2);
world.markBlockRangeForRenderUpdate(x, y, z, x, y, z);
}
else
{
world.setBlockMetadataWithNotify(x, y - 1, z, j1, 2);
world.markBlockRangeForRenderUpdate(x, y - 1, z, x, y, z);
}
//jouer le son
world.playAuxSFXAtEntity(player, 1003, x, y, z, 0);

return true;
}
}

Je ne vois pas pourquoi il drop 2 item