MinecraftScripterAI
Discord ↗
Link Copied to Clipboard
×
"create a zombie egg ready to put on the builder"
/* First, create a custom item class for the Zombie Egg */ public class ZombieEggItem extends Item { public ZombieEggItem(Properties properties) { super(properties); } /* Override onItemUse to spawn a zombie when the item is used on a block */ @Override public ActionResultType useOn(ItemUseContext context) { World world = context.getLevel(); BlockPos pos = context.getClickedPos(); PlayerEntity player = context.getPlayer(); if (!world.isClientSide && player != null) { ZombieEntity zombie = EntityType.ZOMBIE.create(world); zombie.moveTo(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5, 0.0F, 0.0F); world.addFreshEntity(zombie); /* Consume the item */ context.getItemInHand().shrink(1); } return ActionResultType.SUCCESS; } } /* Then, register the item in the item registry */ public static final RegistryObject<Item> ZOMBIE_EGG = ITEMS.register("zombie_egg", () -> new ZombieEggItem(new Item.Properties().tab(ItemGroup.TAB_MISC)));