Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[SOLVED][1.14.3] onBlockActivated does not give player item


MrNoodles75
 Share

Recommended Posts

I am trying to make termite nests and when the nests are a certain age you can click them with a hoe to get termites.

so I tried doing this:

Spoiler
 
 
0
 Advanced issues found
 
 
Spoiler

public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
    ItemStack itemstack = player.getHeldItem(handIn);
    if (itemstack.isEmpty()) {
        return true;
    } else {
        int i = state.get(AGE);
        Item item = itemstack.getItem();
        if (item == Items.WOODEN_HOE || item == Items.STONE_HOE || item == Items.IRON_HOE || item == Items.GOLDEN_HOE || item == Items.DIAMOND_HOE) {
            if (i > 0 && !worldIn.isRemote) {
                if (!player.abilities.isCreativeMode) {
                    itemstack.shrink(1);
                    if (itemstack.isEmpty()) {
                        player.setHeldItem(handIn, new ItemStack(ModItems.TERMITE));
                    } else if (!player.inventory.addItemStackToInventory(new ItemStack(ModItems.TERMITE))) {
                        player.dropItem(new ItemStack(ModItems.TERMITE), false);
                    }
                }
                this.setAgeLevel(worldIn, pos, state, 0);
                worldIn.playSound((PlayerEntity)null, pos, SoundEvents.ITEM_AXE_STRIP, SoundCategory.BLOCKS, 1.0F, 1.0F);
            }

            return true;
        } else {
            return false;
        }
    }
}

but that didn't seem to work.

as you can see I am getting the termites from a ModItems class that looks like this

Spoiler
 
 
0
 Advanced issues found
 
 
Spoiler

@ObjectHolder("extrablocks:termite")
public static Termite TERMITE;

witch is from the Termite class:

Spoiler
 
 
0
 Advanced issues found
 
 
Spoiler

import net.minecraft.item.Item;

public class Termite extends Item {

    public Termite() {
        super(new Properties()
                .group(ExtraBlocks.setup.itemGroup2)
                .maxStackSize(16)
        );
        setRegistryName("termite");
     }
}

and then I create the item in my Main Mod Class here:

Spoiler
 
 
0
 Advanced issues found
 
 
Spoiler

event.getRegistry().register(new Termite());

but the block never drops the item.

Edited by MrNoodles75
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.