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 ?