From fc14d0d59351afdb9afeb24d938f956f0ed9334d Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+Alexdoru@users.noreply.github.com> Date: Sat, 17 Sep 2022 00:11:57 +0200 Subject: [PATCH] exit unnecessary calculation earlier (#27) --- .../common/items/tools/Magnet.java | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/brandon3055/draconicevolution/common/items/tools/Magnet.java b/src/main/java/com/brandon3055/draconicevolution/common/items/tools/Magnet.java index 714d6d0a..989fe0e5 100644 --- a/src/main/java/com/brandon3055/draconicevolution/common/items/tools/Magnet.java +++ b/src/main/java/com/brandon3055/draconicevolution/common/items/tools/Magnet.java @@ -90,7 +90,7 @@ public class Magnet extends ItemDE { List nearestItems = items.stream().limit(ConfigHandler.magnetStackLimit).collect(Collectors.toList()); - boolean flag = false; + boolean playSound = false; for (EntityItem item : nearestItems) { if (item.getEntityItem() == null) { @@ -105,32 +105,35 @@ public class Magnet extends ItemDE { == item.getEntityItem().getItemDamage())) { continue; } - flag = true; + playSound = true; - if (item.delayBeforeCanPickup > 0) item.delayBeforeCanPickup = 0; - item.motionX = item.motionY = item.motionZ = 0; + if (item.delayBeforeCanPickup > 0) { + item.delayBeforeCanPickup = 0; + } + item.motionX = 0; + item.motionY = 0; + item.motionZ = 0; item.setPosition( entity.posX - 0.2 + (world.rand.nextDouble() * 0.4), entity.posY - 0.6, entity.posZ - 0.2 + (world.rand.nextDouble() * 0.4)); } - if (flag) + if (playSound) { world.playSoundAtEntity( entity, "random.orb", 0.1F, 0.5F * ((world.rand.nextFloat() - world.rand.nextFloat()) * 0.7F + 2F)); + } - List xp = world.getEntitiesWithinAABB( - EntityXPOrb.class, - AxisAlignedBB.getBoundingBox( - entity.posX, entity.posY, entity.posZ, entity.posX, entity.posY, entity.posZ) - .expand(4, 4, 4)); - - EntityPlayer player = (EntityPlayer) entity; - - for (EntityXPOrb orb : xp) { - if (!world.isRemote) { + if (!world.isRemote) { + List xp = world.getEntitiesWithinAABB( + EntityXPOrb.class, + AxisAlignedBB.getBoundingBox( + entity.posX, entity.posY, entity.posZ, entity.posX, entity.posY, entity.posZ) + .expand(4, 4, 4)); + EntityPlayer player = (EntityPlayer) entity; + for (EntityXPOrb orb : xp) { if (orb.field_70532_c == 0 && orb.isEntityAlive()) { if (MinecraftForge.EVENT_BUS.post(new PlayerPickupXpEvent(player, orb))) continue; world.playSoundAtEntity(