1.12.2 Click droit sur un block avec un hammer que a une chance sur 2 de drop



  • je voudrais que quand je click droit sur un iron_ore il y est 1chance sur 2 d'avoir un iron_ingot. voici mon code

    package com.jerem5.mod.object.Items.tool;
    
    import java.util.Random;
    
    import com.jerem5.mod.Main;
    import com.jerem5.mod.init.ItemInit;
    import com.jerem5.mod.object.Items.ItemBase;
    
    import net.minecraft.block.Block;
    import net.minecraft.creativetab.CreativeTabs;
    import net.minecraft.entity.item.EntityItem;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.init.Blocks;
    import net.minecraft.init.Items;
    import net.minecraft.init.SoundEvents;
    import net.minecraft.item.ItemStack;
    import net.minecraft.util.EnumActionResult;
    import net.minecraft.util.EnumFacing;
    import net.minecraft.util.EnumHand;
    import net.minecraft.util.SoundCategory;
    import net.minecraft.util.math.BlockPos;
    import net.minecraft.world.World;
    
    public class ItemHammerMod extends ItemBase
    {
        public ItemHammerMod(String name, String material)
        {
            super(material);
            setUnlocalizedName(name);
            setRegistryName(name);
            setCreativeTab(CreativeTabs.TOOLS);
            ItemInit.ITEMS.add(this);
            
        }
    
        @Override
        public void registerModel()
        {
            Main.proxy.registerItemRenderer(this, 0);
        }
    
    
    
        
        
        public ItemHammerMod(String name)
        {
            super(name);
            this.setMaxStackSize(1);
            this.setMaxDamage(64);
        }
    
        @Override
        public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
        {
            
            if(!worldIn.isRemote) 
            {
                
                Block block = worldIn.getBlockState(pos).getBlock();
                
                if(block == Blocks.IRON_ORE) 
                {
                    
                    worldIn.destroyBlock(pos,false);
                    
                    EntityItem loot = new EntityItem(worldIn);
                    loot.setPosition(pos.getX(),pos.getY()+0.6d,pos.getZ());
                    loot.setItem(new ItemStack(Items.IRON_INGOT, 1));
                    
                    worldIn.spawnEntity(loot);
                    
                }
               
                
            }else
    


  • @jerem5 cadeau 😁

    @Override
        public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
        {
            IBlockState iblockstate = worldIn.getBlockState(pos);
            Block block = iblockstate.getBlock();
            
            Random random = new Random();
            
            if(block.equals(Blocks.IRON_ORE) && !worldIn.isRemote)
            {
                worldIn.spawnEntity(new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.IRON_INGOT, random.nextInt(2))));
                worldIn.setBlockToAir(pos);
                return EnumActionResult.SUCCESS;
            }
            else
            {
                return EnumActionResult.PASS;
            }
        }
    

Log in to reply