From ea52fa0d5587276626406fd0cee98618e05d2fbb Mon Sep 17 00:00:00 2001 From: boubou19 Date: Thu, 17 Jul 2025 20:49:32 +0200 Subject: [PATCH] Speed up forge event registration (#98) --- .../forestry/core/items/ItemForestryTool.java | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/main/java/forestry/core/items/ItemForestryTool.java b/src/main/java/forestry/core/items/ItemForestryTool.java index 759b48e00..698f352cc 100755 --- a/src/main/java/forestry/core/items/ItemForestryTool.java +++ b/src/main/java/forestry/core/items/ItemForestryTool.java @@ -31,7 +31,7 @@ public class ItemForestryTool extends ItemForestry { setMaxDamage(200); this.remnants = remnants; if (remnants != null) { - MinecraftForge.EVENT_BUS.register(this); + MinecraftForge.EVENT_BUS.register(new EventHandler()); } } @@ -53,20 +53,6 @@ public class ItemForestryTool extends ItemForestry { return ForgeHooks.canToolHarvestBlock(block, 0, stack); } - @SubscribeEvent - public void onDestroyCurrentItem(PlayerDestroyItemEvent event) { - if (event.original == null || event.original.getItem() != this) { - return; - } - - EntityPlayer player = event.entityPlayer; - World world = player.worldObj; - - if (!world.isRemote && remnants != null) { - ItemStackUtil.dropItemStackAsEntity(remnants.copy(), world, player.posX, player.posY, player.posZ); - } - } - @Override public boolean onBlockDestroyed(ItemStack itemstack, World world, Block block, int x, int y, int z, EntityLivingBase entityliving) { @@ -80,4 +66,21 @@ public class ItemForestryTool extends ItemForestry { public boolean isFull3D() { return true; } + + public class EventHandler { + + @SubscribeEvent + public void onDestroyCurrentItem(PlayerDestroyItemEvent event) { + if (event.original == null || event.original.getItem() != ItemForestryTool.this) { + return; + } + + EntityPlayer player = event.entityPlayer; + World world = player.worldObj; + + if (!world.isRemote && remnants != null) { + ItemStackUtil.dropItemStackAsEntity(remnants.copy(), world, player.posX, player.posY, player.posZ); + } + } + } }