Jump to content

Hubmac

Members
  • Posts

    2
  • Joined

  • Last visited

Posts posted by Hubmac

  1. Hi there i have problem with my mod. I create this mod for learning forge. Mod adds new item to minecraft and in the overided method "OnBlockDestroyed" i give to player 2 diamonds but when i click on this item in inventory dissapear or when i drop this item.

     

    Code: 

    package com.example.examplemod;
    
    import net.minecraft.block.BlockState;
    import net.minecraft.client.Minecraft;
    import net.minecraft.client.entity.player.ClientPlayerEntity;
    import net.minecraft.entity.LivingEntity;
    import net.minecraft.entity.player.PlayerEntity;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemGroup;
    import net.minecraft.item.ItemStack;
    import net.minecraft.item.Items;
    import net.minecraft.util.datafix.fixes.ItemStackUUID;
    import net.minecraft.util.math.BlockPos;
    import net.minecraft.world.World;
    import net.minecraftforge.common.MinecraftForge;
    import net.minecraftforge.common.ToolType;
    import net.minecraftforge.fml.common.registry.GameRegistry;
    
    public class Hammer extends Item {
    
        public Hammer() {
            super(new Item.Properties().group(ItemGroup.TOOLS).maxStackSize(4).addToolType(ToolType.AXE, 3).defaultMaxDamage(100).maxDamage(200));
        }
    
        @Override
        public boolean onBlockDestroyed(ItemStack itemStack, World world, BlockState blockState, BlockPos blockPos, LivingEntity livingEntity) {
            ClientPlayerEntity clientPlayerEntity = Minecraft.getInstance().player;
    
    
            clientPlayerEntity.sendChatMessage("You destroy: "+ blockState.getBlock().getRegistryName());
            clientPlayerEntity.inventory.addItemStackToInventory(new ItemStack(Items.DIAMOND, 2));
    
            return super.onBlockDestroyed(itemStack, world, blockState, blockPos, livingEntity);
        }
    }
×
×
  • Create New...

Important Information

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