Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

Posted

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

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.