Jump to content

[1.14.4] Can't spawn an ItemEntity


Ayfri

Recommended Posts

I just want to spawn an Item on my mod when I right click with empty hand on a log, I make this

package fr.ayfri.testmod.init;

import net.minecraft.entity.item.ItemEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.tags.BlockTags;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;

public class BlockEventHandler {

    public static final BlockEventHandler INSTANCE = new BlockEventHandler();

    @SubscribeEvent
    public void OnRightClickBlock(PlayerInteractEvent.RightClickBlock e) {

        if(e.getWorld().getBlockState(e.getPos()).getBlock().isIn(BlockTags.LOGS) && e.getEntityPlayer().getHeldItemMainhand().isEmpty()) {
            System.out.println("wood log touched");

            ItemEntity wood_piece = new ItemEntity(e.getWorld(), e.getPos().getX(), e.getPos().getY(), e.getPos().getZ(), new ItemStack(ModItems.wood_piece));
            e.getWorld().addEntity(wood_piece);

        }
        return;

    }

}

But when I right click on a log, it says "wood log touched" but it doesn't spawn any Item, can you help me to figure out why ?

Edited by Ayfri
println text in French
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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



×
×
  • Create New...

Important Information

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