Bonjour,
J’ai créer un block, je voudrais que le joueur quand il casse le block un item drop (très simple).
Mais je sais pas, j’ai du oublier quelques chose mais je vois pas ou… j’ai bien Override et tout je sais pas.
Class Block:
package com.CSC.net.block;
import java.util.Random;
import javax.annotation.Nullable;
import com.CSC.net.item.CSCItems;
import net.minecraft.block.Block;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.BlockPlanks;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class blockbois extends BlockHorizontal{
public blockbois(Material materialIn) {
super(materialIn);
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
this.setSoundType(SoundType.WOOD);
this.setHarvestLevel("Class", 0);
}
public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
}
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta));
}
public int getMetaFromState(IBlockState state)
{
return ((EnumFacing)state.getValue(FACING)).getHorizontalIndex();
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {FACING});
}
@Override
public int quantityDropped(Random random)
{
return 1;
}
@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return CSCItems.item_boisabime;
}
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
//(1 chance / 10)
if(worldIn.rand.nextInt(10) == 5)
{
System.out.println("");
EntityZombie zombie = new EntityZombie(worldIn);
zombie.setChild(true);
zombie.addPotionEffect(new PotionEffect(Potion.getPotionById(2), 9999999, 2));
zombie.addPotionEffect(new PotionEffect(Potion.getPotionById(4), 9999999, 2));
zombie.setPosition(pos.getX(), pos.getY() + 1, pos.getZ());
worldIn.spawnEntityInWorld(zombie);
}
worldIn.setBlockState(new BlockPos(pos.getX(), pos.getY(), pos.getZ()), CSCBlocks.block_invisible.getDefaultState());
}
}
Register Block:
public static final Block block_bois = new blockbois(Material.WOOD).setHardness(2.0F).setResistance(5.0F).setUnlocalizedName("block_bois").setCreativeTab(CreativeTabs.DECORATIONS);