diff options
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CustomItemEffects.java')
| -rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CustomItemEffects.java | 457 |
1 files changed, 224 insertions, 233 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CustomItemEffects.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CustomItemEffects.java index d7d27f99..e592a503 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CustomItemEffects.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CustomItemEffects.java @@ -5,12 +5,9 @@ import io.github.moulberry.notenoughupdates.util.SBInfo; import io.github.moulberry.notenoughupdates.util.SpecialColour; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.block.Block; -import net.minecraft.block.BlockCrops; -import net.minecraft.block.BlockPackedIce; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; -import net.minecraft.client.audio.PositionedSoundRecord; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.multiplayer.WorldClient; @@ -19,9 +16,6 @@ import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.texture.TextureUtil; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.client.resources.model.IBakedModel; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.item.EntityArmorStand; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.init.Items; @@ -31,7 +25,6 @@ import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.util.*; -import net.minecraft.world.World; import net.minecraftforge.client.event.DrawBlockHighlightEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent; @@ -43,8 +36,8 @@ import org.lwjgl.util.vector.Vector3f; import java.awt.*; import java.io.ByteArrayInputStream; -import java.util.*; import java.util.List; +import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -54,7 +47,7 @@ public class CustomItemEffects { private static final int MAX_BUILDERS_BLOCKS = 241; - private HashSet<BlockPos> zapperBlocks = new HashSet<>(); + private final HashSet<BlockPos> zapperBlocks = new HashSet<>(); private boolean zapperDirty = false; public long aoteUseMillis = 0; @@ -73,48 +66,48 @@ public class CustomItemEffects { public long lastMillis = 0; public Vector3f getCurrentPosition() { - if(aoteTeleportationMillis <= 0) return null; + if (aoteTeleportationMillis <= 0) return null; return aoteTeleportationCurr; } @SubscribeEvent public void onTick(TickEvent.RenderTickEvent event) { - if(Minecraft.getMinecraft().thePlayer == null) return; + if (Minecraft.getMinecraft().thePlayer == null) return; zapperDirty = true; long currentTime = System.currentTimeMillis(); - int delta = (int)(currentTime - lastMillis); + int delta = (int) (currentTime - lastMillis); lastMillis = currentTime; - if(delta <= 0) return; + if (delta <= 0) return; - if(aoteTeleportationMillis > tpTime*2) { - aoteTeleportationMillis = tpTime*2; + if (aoteTeleportationMillis > tpTime * 2) { + aoteTeleportationMillis = tpTime * 2; } - if(aoteTeleportationMillis < 0) aoteTeleportationMillis = 0; + if (aoteTeleportationMillis < 0) aoteTeleportationMillis = 0; - if(currentTime - aoteUseMillis > 1000 && aoteTeleportationMillis <= 0) { + if (currentTime - aoteUseMillis > 1000 && aoteTeleportationMillis <= 0) { aoteTeleportationCurr = null; } - if(aoteTeleportationCurr != null) { - if(aoteTeleportationMillis > 0) { + if (aoteTeleportationCurr != null) { + if (aoteTeleportationMillis > 0) { int deltaMin = Math.min(delta, aoteTeleportationMillis); - float factor = deltaMin/(float)aoteTeleportationMillis; + float factor = deltaMin / (float) aoteTeleportationMillis; - float dX = aoteTeleportationCurr.x - (float)Minecraft.getMinecraft().thePlayer.posX; - float dY = aoteTeleportationCurr.y - (float)Minecraft.getMinecraft().thePlayer.posY; - float dZ = aoteTeleportationCurr.z - (float)Minecraft.getMinecraft().thePlayer.posZ; + float dX = aoteTeleportationCurr.x - (float) Minecraft.getMinecraft().thePlayer.posX; + float dY = aoteTeleportationCurr.y - (float) Minecraft.getMinecraft().thePlayer.posY; + float dZ = aoteTeleportationCurr.z - (float) Minecraft.getMinecraft().thePlayer.posZ; - aoteTeleportationCurr.x -= dX*factor; - aoteTeleportationCurr.y -= dY*factor; - aoteTeleportationCurr.z -= dZ*factor; + aoteTeleportationCurr.x -= dX * factor; + aoteTeleportationCurr.y -= dY * factor; + aoteTeleportationCurr.z -= dZ * factor; - if(Minecraft.getMinecraft().theWorld.getBlockState(new BlockPos(aoteTeleportationCurr.x, + if (Minecraft.getMinecraft().theWorld.getBlockState(new BlockPos(aoteTeleportationCurr.x, aoteTeleportationCurr.y, aoteTeleportationCurr.z)).getBlock().getMaterial() != Material.air) { - aoteTeleportationCurr.y = (float)Math.ceil(aoteTeleportationCurr.y); + aoteTeleportationCurr.y = (float) Math.ceil(aoteTeleportationCurr.y); } aoteTeleportationMillis -= deltaMin; @@ -131,21 +124,21 @@ public class CustomItemEffects { @SubscribeEvent public void onPlayerInteract(PlayerInteractEvent event) { - if(event.action == PlayerInteractEvent.Action.RIGHT_CLICK_AIR || event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) { + if (event.action == PlayerInteractEvent.Action.RIGHT_CLICK_AIR || event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) { ItemStack held = Minecraft.getMinecraft().thePlayer.getHeldItem(); String internal = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(held); - if(internal != null) { + if (internal != null) { boolean shadowWarp = false; - if(internal.equals("HYPERION") || internal.equals("VALKYRIE") || internal.equals("SCYLLA") || internal.equals("ASTRAEA")) { + if (internal.equals("HYPERION") || internal.equals("VALKYRIE") || internal.equals("SCYLLA") || internal.equals("ASTRAEA")) { NBTTagCompound tag = held.getTagCompound(); - if(tag != null && tag.hasKey("ExtraAttributes", 10)) { + if (tag != null && tag.hasKey("ExtraAttributes", 10)) { NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); - if(ea != null && ea.hasKey("ability_scroll", 9)) { + if (ea != null && ea.hasKey("ability_scroll", 9)) { NBTTagList list = ea.getTagList("ability_scroll", 8); - for(int i=0; i<list.tagCount(); i++) { - if(list.getStringTagAt(i).equals("IMPLOSION_SCROLL")) { + for (int i = 0; i < list.tagCount(); i++) { + if (list.getStringTagAt(i).equals("IMPLOSION_SCROLL")) { lastUsedHyperion = System.currentTimeMillis(); - } else if(list.getStringTagAt(i).equals("SHADOW_WARP_SCROLL")) { + } else if (list.getStringTagAt(i).equals("SHADOW_WARP_SCROLL")) { shadowWarp = true; } } @@ -153,23 +146,23 @@ public class CustomItemEffects { } } - if(usingEtherwarp) { + if (usingEtherwarp) { lastEtherwarpUse = tick; } - if(tpTime <= 0 || Minecraft.getMinecraft().gameSettings.thirdPersonView != 0) return; + if (tpTime <= 0 || Minecraft.getMinecraft().gameSettings.thirdPersonView != 0) return; boolean aote = NotEnoughUpdates.INSTANCE.config.itemOverlays.enableSmoothAOTE && (internal.equals("ASPECT_OF_THE_END") || internal.equals("ASPECT_OF_THE_VOID")); boolean hyp = NotEnoughUpdates.INSTANCE.config.itemOverlays.enableSmoothHyperion && shadowWarp; - if(usingEtherwarp) { + if (usingEtherwarp) { tpTime = NotEnoughUpdates.INSTANCE.config.itemOverlays.smoothTpMillisEtherwarp; } else { tpTime = NotEnoughUpdates.INSTANCE.config.itemOverlays.smoothTpMillis; } - if(usingEtherwarp || aote || hyp) { + if (usingEtherwarp || aote || hyp) { aoteUseMillis = System.currentTimeMillis(); - if(aoteTeleportationCurr == null) { + if (aoteTeleportationCurr == null) { aoteTeleportationCurr = new Vector3f(); aoteTeleportationCurr.x = (float) Minecraft.getMinecraft().thePlayer.posX; aoteTeleportationCurr.y = (float) Minecraft.getMinecraft().thePlayer.posY; @@ -182,10 +175,10 @@ public class CustomItemEffects { @SubscribeEvent public void onGameTick(TickEvent.ClientTickEvent event) { - if(event.phase != TickEvent.Phase.END) return; + if (event.phase != TickEvent.Phase.END) return; - if(!usingEtherwarp && wasUsingEtherwarp) { - if(Minecraft.getMinecraft().thePlayer.rotationYaw > 0) { + if (!usingEtherwarp && wasUsingEtherwarp) { + if (Minecraft.getMinecraft().thePlayer.rotationYaw > 0) { Minecraft.getMinecraft().thePlayer.rotationYaw -= 0.000001; } else { Minecraft.getMinecraft().thePlayer.rotationYaw += 0.000001; @@ -194,8 +187,7 @@ public class CustomItemEffects { wasUsingEtherwarp = usingEtherwarp; tick++; - if(tick > Integer.MAX_VALUE/2) tick = 0; - + if (tick > Integer.MAX_VALUE / 2) tick = 0; } @@ -209,32 +201,32 @@ public class CustomItemEffects { private float targetSensMult = 1; public float getSensMultiplier() { - if(targetSensMult < 0) { + if (targetSensMult < 0) { currentSensMult = 1; } else { float deltaSens = targetSensMult - currentSensMult; - currentSensMult += deltaSens*lastPartialDelta*0.1;// (0.05 * ); - if(currentSensMult < 0.25f) currentSensMult = 0.25f; - if(currentSensMult > 1) currentSensMult = 1; + currentSensMult += deltaSens * lastPartialDelta * 0.1;// (0.05 * ); + if (currentSensMult < 0.25f) currentSensMult = 0.25f; + if (currentSensMult > 1) currentSensMult = 1; } return currentSensMult; } public float getFovMultiplier(float partialTicks) { - float partialDelta = partialTicks+tick - lastPartialTicks; - if(partialDelta < 0) partialDelta++; + float partialDelta = partialTicks + tick - lastPartialTicks; + if (partialDelta < 0) partialDelta++; - if(partialDelta > 0) lastPartialDelta = partialDelta; + if (partialDelta > 0) lastPartialDelta = partialDelta; - if(targetFOVMult < 0) { + if (targetFOVMult < 0) { currentFOVMult = 1; } else { float deltaFOV = targetFOVMult - currentFOVMult; - currentFOVMult += deltaFOV*lastPartialDelta*0.2; - if(currentFOVMult < 0.15f) currentFOVMult = 0.15f; - if(currentFOVMult > 1) currentFOVMult = 1; + currentFOVMult += deltaFOV * lastPartialDelta * 0.2; + if (currentFOVMult < 0.15f) currentFOVMult = 0.15f; + if (currentFOVMult > 1) currentFOVMult = 1; } lastPartialTicks = partialTicks + tick; return currentFOVMult; @@ -247,25 +239,25 @@ public class CustomItemEffects { @SubscribeEvent public void onOverlayDrawn(RenderGameOverlayEvent.Post event) { - if(((event.type == null && Loader.isModLoaded("labymod")) || + if (((event.type == null && Loader.isModLoaded("labymod")) || event.type == RenderGameOverlayEvent.ElementType.CROSSHAIRS)) { ItemStack held = Minecraft.getMinecraft().thePlayer.getHeldItem(); String heldInternal = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(held); - if(usingEtherwarp && NotEnoughUpdates.INSTANCE.config.itemOverlays.enableEtherwarpHelperOverlay) { + if (usingEtherwarp && NotEnoughUpdates.INSTANCE.config.itemOverlays.enableEtherwarpHelperOverlay) { String denyTpReason = null; - if(etherwarpRaycast == null) { + if (etherwarpRaycast == null) { denyTpReason = "Too far!"; } else { BlockPos pos = etherwarpRaycast.pos; - if(!etherwarpRaycast.state.getBlock().isCollidable() || + if (!etherwarpRaycast.state.getBlock().isCollidable() || etherwarpRaycast.state.getBlock().getCollisionBoundingBox(Minecraft.getMinecraft().theWorld, etherwarpRaycast.pos, etherwarpRaycast.state) == null) { denyTpReason = "Not solid!"; } else { WorldClient world = Minecraft.getMinecraft().theWorld; Block above = world.getBlockState(pos.add(0, 1, 0)).getBlock(); - if(above != Blocks.air && above.isCollidable() && + if (above != Blocks.air && above.isCollidable() && above.getCollisionBoundingBox(Minecraft.getMinecraft().theWorld, pos.add(0, 1, 0), world.getBlockState(pos.add(0, 1, 0))) != null || world.getBlockState(pos.add(0, 2, 0)).getBlock() != Blocks.air) { @@ -274,28 +266,27 @@ public class CustomItemEffects { } } - if(denyTpReason != null) { + if (denyTpReason != null) { ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - Utils.drawStringCentered(EnumChatFormatting.RED+"Can't TP: " + denyTpReason, + Utils.drawStringCentered(EnumChatFormatting.RED + "Can't TP: " + denyTpReason, Minecraft.getMinecraft().fontRendererObj, - scaledResolution.getScaledWidth()/2f, scaledResolution.getScaledHeight()/2f+10, true, 0); + scaledResolution.getScaledWidth() / 2f, scaledResolution.getScaledHeight() / 2f + 10, true, 0); GlStateManager.color(1, 1, 1, 1); } } boolean onPrivateIsland = SBInfo.getInstance().getLocation() == null || SBInfo.getInstance().getLocation().equals("dynamic"); - - if(NotEnoughUpdates.INSTANCE.config.itemOverlays.enableWandOverlay && + if (NotEnoughUpdates.INSTANCE.config.itemOverlays.enableWandOverlay && Minecraft.getMinecraft().objectMouseOver != null && Minecraft.getMinecraft().objectMouseOver.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK && onPrivateIsland) { IBlockState hover = Minecraft.getMinecraft().theWorld.getBlockState( Minecraft.getMinecraft().objectMouseOver.getBlockPos().offset( Minecraft.getMinecraft().objectMouseOver.sideHit, 1)); - if(hover.getBlock() == Blocks.air) { + if (hover.getBlock() == Blocks.air) { - if(heldInternal != null && heldInternal.equals("BUILDERS_WAND")) { + if (heldInternal != null && heldInternal.equals("BUILDERS_WAND")) { ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); HashSet<BlockPos> candidatesOld = new HashSet<>(); @@ -303,53 +294,53 @@ public class CustomItemEffects { IBlockState match = Minecraft.getMinecraft().theWorld.getBlockState(Minecraft.getMinecraft().objectMouseOver.getBlockPos()); Item matchItem = Item.getItemFromBlock(match.getBlock()); - if(matchItem != null) { - ItemStack matchStack = new ItemStack(matchItem, 1, + if (matchItem != null) { + ItemStack matchStack = new ItemStack(matchItem, 1, match.getBlock().getDamageValue(Minecraft.getMinecraft().theWorld, Minecraft.getMinecraft().objectMouseOver.getBlockPos())); getBuildersWandCandidates(Minecraft.getMinecraft().thePlayer, Minecraft.getMinecraft().objectMouseOver, event.partialTicks, - candidatesOld, candidatesOldSorted, 999-MAX_BUILDERS_BLOCKS); + candidatesOld, candidatesOldSorted, 999 - MAX_BUILDERS_BLOCKS); boolean usingDirtWand = false; int itemCount; - if(match.getBlock() == Blocks.dirt && matchStack.getItemDamage() == 0 && hasDirtWand()) { + if (match.getBlock() == Blocks.dirt && matchStack.getItemDamage() == 0 && hasDirtWand()) { itemCount = candidatesOld.size(); usingDirtWand = true; } else { itemCount = countItemsInInventoryAndStorage(matchStack); } - if(candidatesOld.size() > MAX_BUILDERS_BLOCKS) { - Utils.drawStringCentered(EnumChatFormatting.RED.toString()+candidatesOld.size()+"/"+MAX_BUILDERS_BLOCKS, + if (candidatesOld.size() > MAX_BUILDERS_BLOCKS) { + Utils.drawStringCentered(EnumChatFormatting.RED.toString() + candidatesOld.size() + "/" + MAX_BUILDERS_BLOCKS, Minecraft.getMinecraft().fontRendererObj, - scaledResolution.getScaledWidth()/2f, scaledResolution.getScaledHeight()/2f+10, true, 0); + scaledResolution.getScaledWidth() / 2f, scaledResolution.getScaledHeight() / 2f + 10, true, 0); } else { String pre = EnumChatFormatting.GREEN.toString(); - if(itemCount < candidatesOld.size()) { + if (itemCount < candidatesOld.size()) { pre = EnumChatFormatting.RED.toString(); } - Utils.drawStringCentered(pre+Math.min(candidatesOld.size(), itemCount)+"/"+ + Utils.drawStringCentered(pre + Math.min(candidatesOld.size(), itemCount) + "/" + Math.min(candidatesOld.size(), MAX_BUILDERS_BLOCKS), Minecraft.getMinecraft().fontRendererObj, - scaledResolution.getScaledWidth()/2f, scaledResolution.getScaledHeight()/2f+10, true, 0); + scaledResolution.getScaledWidth() / 2f, scaledResolution.getScaledHeight() / 2f + 10, true, 0); } - String itemCountS = EnumChatFormatting.DARK_GRAY+"x"+EnumChatFormatting.RESET+itemCount; + String itemCountS = EnumChatFormatting.DARK_GRAY + "x" + EnumChatFormatting.RESET + itemCount; int itemCountLen = Minecraft.getMinecraft().fontRendererObj.getStringWidth(itemCountS); - if(NotEnoughUpdates.INSTANCE.config.itemOverlays.wandBlockCount) { - if(usingDirtWand) { - Utils.drawItemStack(new ItemStack(Items.gold_nugget), scaledResolution.getScaledWidth()/2 - (itemCountLen+16)/2, - scaledResolution.getScaledHeight()/2+10+4); + if (NotEnoughUpdates.INSTANCE.config.itemOverlays.wandBlockCount) { + if (usingDirtWand) { + Utils.drawItemStack(new ItemStack(Items.gold_nugget), scaledResolution.getScaledWidth() / 2 - (itemCountLen + 16) / 2, + scaledResolution.getScaledHeight() / 2 + 10 + 4); Minecraft.getMinecraft().fontRendererObj.drawString(itemCountS, - scaledResolution.getScaledWidth()/2f - (itemCountLen+16)/2f+11, scaledResolution.getScaledHeight()/2f+10+8, + scaledResolution.getScaledWidth() / 2f - (itemCountLen + 16) / 2f + 11, scaledResolution.getScaledHeight() / 2f + 10 + 8, -1, true); } else { - Utils.drawItemStack(matchStack, scaledResolution.getScaledWidth()/2 - (itemCountLen+16)/2, - scaledResolution.getScaledHeight()/2+10+4); + Utils.drawItemStack(matchStack, scaledResolution.getScaledWidth() / 2 - (itemCountLen + 16) / 2, + scaledResolution.getScaledHeight() / 2 + 10 + 4); Minecraft.getMinecraft().fontRendererObj.drawString(itemCountS, - scaledResolution.getScaledWidth()/2f - (itemCountLen+16)/2f+16, scaledResolution.getScaledHeight()/2f+10+8, + scaledResolution.getScaledWidth() / 2f - (itemCountLen + 16) / 2f + 16, scaledResolution.getScaledHeight() / 2f + 10 + 8, -1, true); } @@ -366,7 +357,7 @@ public class CustomItemEffects { } //ethermerge - private class RaycastResult { + private static class RaycastResult { IBlockState state; BlockPos pos; @@ -377,34 +368,34 @@ public class CustomItemEffects { } private RaycastResult raycast(EntityPlayerSP player, float partialTicks, float dist, float step) { - Vector3f pos = new Vector3f((float)player.posX, (float)player.posY+player.getEyeHeight(), (float)player.posZ); + Vector3f pos = new Vector3f((float) player.posX, (float) player.posY + player.getEyeHeight(), (float) player.posZ); Vec3 lookVec3 = player.getLook(partialTicks); - Vector3f look = new Vector3f((float)lookVec3.xCoord, (float)lookVec3.yCoord, (float)lookVec3.zCoord); + Vector3f look = new Vector3f((float) lookVec3.xCoord, (float) lookVec3.yCoord, (float) lookVec3.zCoord); look.scale(step / look.length()); - int stepCount = (int)Math.ceil(dist/step); + int stepCount = (int) Math.ceil(dist / step); - for(int i=0; i<stepCount; i++) { + for (int i = 0; i < stepCount; i++) { Vector3f.add(pos, look, pos); WorldClient world = Minecraft.getMinecraft().theWorld; BlockPos position = new BlockPos(pos.x, pos.y, pos.z); IBlockState state = world.getBlockState(position); - if(state.getBlock() != Blocks.air) { + if (state.getBlock() != Blocks.air) { //Back-step Vector3f.sub(pos, look, pos); look.scale(0.1f); - for(int j=0; j<10; j++) { + for (int j = 0; j < 10; j++) { Vector3f.add(pos, look, pos); BlockPos position2 = new BlockPos(pos.x, pos.y, pos.z); IBlockState state2 = world.getBlockState(position2); - if(state2.getBlock() != Blocks.air) { + if (state2.getBlock() != Blocks.air) { return new RaycastResult(state2, position2); } } @@ -419,8 +410,8 @@ public class CustomItemEffects { public int countItemsInInventoryAndStorage(ItemStack match) { int count = 0; - for(ItemStack stack : Minecraft.getMinecraft().thePlayer.inventory.mainInventory) { - if(match.isItemEqual(stack)) { + for (ItemStack stack : Minecraft.getMinecraft().thePlayer.inventory.mainInventory) { + if (match.isItemEqual(stack)) { count += stack.stackSize; } } @@ -428,23 +419,23 @@ public class CustomItemEffects { ItemStack held = Minecraft.getMinecraft().thePlayer.getHeldItem(); String heldInternal = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(held); - if(heldInternal != null && heldInternal.equals("BUILDERS_WAND")) { - if(held.hasTagCompound() && held.getTagCompound().hasKey("ExtraAttributes", 10) && + if (heldInternal != null && heldInternal.equals("BUILDERS_WAND")) { + if (held.hasTagCompound() && held.getTagCompound().hasKey("ExtraAttributes", 10) && held.getTagCompound().getCompoundTag("ExtraAttributes").hasKey("builder's_wand_data", 7)) { byte[] bytes = held.getTagCompound().getCompoundTag("ExtraAttributes").getByteArray("builder's_wand_data"); try { NBTTagCompound contents_nbt = CompressedStreamTools.readCompressed(new ByteArrayInputStream(bytes)); NBTTagList items = contents_nbt.getTagList("i", 10); - for(int j=0; j<items.tagCount(); j++) { + for (int j = 0; j < items.tagCount(); j++) { NBTTagCompound buildersItem = items.getCompoundTagAt(j); - if(buildersItem.getKeySet().size() > 0) { - if(buildersItem.getInteger("id") == Item.getIdFromItem(match.getItem()) && + if (buildersItem.getKeySet().size() > 0) { + if (buildersItem.getInteger("id") == Item.getIdFromItem(match.getItem()) && buildersItem.getInteger("Damage") == match.getItemDamage()) { count += items.getCompoundTagAt(j).getByte("Count"); } } } - } catch(Exception e) { + } catch (Exception e) { return count; } } @@ -454,9 +445,9 @@ public class CustomItemEffects { } public boolean hasDirtWand() { - for(ItemStack stack : Minecraft.getMinecraft().thePlayer.inventory.mainInventory) { + for (ItemStack stack : Minecraft.getMinecraft().thePlayer.inventory.mainInventory) { String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack); - if(internalname != null && internalname.equals("INFINIDIRT_WAND")) { + if (internalname != null && internalname.equals("INFINIDIRT_WAND")) { return true; } } @@ -464,24 +455,23 @@ public class CustomItemEffects { ItemStack held = Minecraft.getMinecraft().thePlayer.getHeldItem(); String heldInternal = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(held); - if(heldInternal != null && heldInternal.equals("BUILDERS_WAND")) { - if(held.hasTagCompound() && held.getTagCompound().hasKey("ExtraAttributes", 10) && + if (heldInternal != null && heldInternal.equals("BUILDERS_WAND")) { + if (held.hasTagCompound() && held.getTagCompound().hasKey("ExtraAttributes", 10) && held.getTagCompound().getCompoundTag("ExtraAttributes").hasKey("builder's_wand_data", 7)) { byte[] bytes = held.getTagCompound().getCompoundTag("ExtraAttributes").getByteArray("builder's_wand_data"); try { NBTTagCompound contents_nbt = CompressedStreamTools.readCompressed(new ByteArrayInputStream(bytes)); NBTTagList items = contents_nbt.getTagList("i", 10); - for(int j=0; j<items.tagCount(); j++) { + for (int j = 0; j < items.tagCount(); j++) { NBTTagCompound buildersItem = items.getCompoundTagAt(j); - if(buildersItem.getKeySet().size() > 0) { + if (buildersItem.getKeySet().size() > 0) { String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalnameFromNBT(buildersItem.getCompoundTag("tag")); - if(internalname != null && internalname.equals("INFINIDIRT_WAND")) { + if (internalname != null && internalname.equals("INFINIDIRT_WAND")) { return true; } } } - } catch(Exception e) { - } + } catch (Exception ignored) {} } } @@ -489,6 +479,7 @@ public class CustomItemEffects { } private static final List<BlockPos> zapperOffsets = new ArrayList<>(); + static { zapperOffsets.add(new BlockPos(0, 0, -1)); zapperOffsets.add(new BlockPos(0, 0, 1)); @@ -497,8 +488,10 @@ public class CustomItemEffects { zapperOffsets.add(new BlockPos(0, 1, 0)); zapperOffsets.add(new BlockPos(0, -1, 0)); } + private static final HashSet<Block> cropBlocksZapper = new HashSet<>(); private static final HashSet<Block> otherBannedBlocksZapper = new HashSet<>(); + static { cropBlocksZapper.add(Blocks.wheat); cropBlocksZapper.add(Blocks.carrots); @@ -518,7 +511,7 @@ public class CustomItemEffects { @SubscribeEvent public void renderBlockOverlay(DrawBlockHighlightEvent event) { - if(aoteTeleportationCurr != null && aoteTeleportationMillis > 0) { + if (aoteTeleportationCurr != null && aoteTeleportationMillis > 0) { event.setCanceled(true); } usingEtherwarp = false; @@ -529,28 +522,28 @@ public class CustomItemEffects { ItemStack held = Minecraft.getMinecraft().thePlayer.getHeldItem(); String heldInternal = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(held); - if(heldInternal != null) { + if (heldInternal != null) { boolean onPrivateIsland = SBInfo.getInstance().getLocation() == null || SBInfo.getInstance().getLocation().equals("dynamic"); EntityPlayer player = event.player; - double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double)event.partialTicks; - double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double)event.partialTicks; - double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double)event.partialTicks; + double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double) event.partialTicks; + double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double) event.partialTicks; + double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double) event.partialTicks; - if(tick - lastEtherwarpUse > 10) { + if (tick - lastEtherwarpUse > 10) { boolean aotv = Minecraft.getMinecraft().thePlayer.isSneaking() && (heldInternal.equals("ASPECT_OF_THE_VOID") || heldInternal.equals("ASPECT_OF_THE_END")); - if(aotv || heldInternal.equals("ETHERWARP_CONDUIT")) { + if (aotv || heldInternal.equals("ETHERWARP_CONDUIT")) { usingEtherwarp = !aotv; - if(aotv) { + if (aotv) { NBTTagCompound tag = held.getTagCompound(); - if(tag != null && tag.hasKey("ExtraAttributes", 10)) { + if (tag != null && tag.hasKey("ExtraAttributes", 10)) { NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); usingEtherwarp = ea.hasKey("ethermerge"); } } - if(usingEtherwarp) { + if (usingEtherwarp) { int dist = 0; for (String line : NotEnoughUpdates.INSTANCE.manager.getLoreFromNBT(held.getTagCompound())) { String cleaned = Utils.cleanColour(line); @@ -594,14 +587,14 @@ public class CustomItemEffects { } } - if(heldInternal.equals("BLOCK_ZAPPER")) { + if (heldInternal.equals("BLOCK_ZAPPER")) { if (!onPrivateIsland || !NotEnoughUpdates.INSTANCE.config.itemOverlays.enableZapperOverlay || event.target.typeOfHit != MovingObjectPosition.MovingObjectType.BLOCK) { zapperBlocks.clear(); return; } - if(zapperDirty) { + if (zapperDirty) { zapperDirty = false; zapperBlocks.clear(); @@ -615,36 +608,36 @@ public class CustomItemEffects { BlockPos above = pos.add(0, 1, 0); Block aboveBlock = Minecraft.getMinecraft().theWorld.getBlockState(above).getBlock(); - if(!cropBlocksZapper.contains(aboveBlock) && !cropBlocksZapper.contains(block) && + if (!cropBlocksZapper.contains(aboveBlock) && !cropBlocksZapper.contains(block) && !otherBannedBlocksZapper.contains(block) && !block.hasTileEntity(firstBlockState) && block.getBlockHardness(Minecraft.getMinecraft().theWorld, pos) >= 0) { - for(int i=0; i<164; i++) { + for (int i = 0; i < 164; i++) { zapperBlocks.add(pos); returnablePositions.remove(pos); List<BlockPos> availableNeighbors = new ArrayList<>(); - for(BlockPos offset : zapperOffsets) { + for (BlockPos offset : zapperOffsets) { BlockPos newPos = pos.add(offset); - if(zapperBlocks.contains(newPos)) continue; + if (zapperBlocks.contains(newPos)) continue; IBlockState state = Minecraft.getMinecraft().theWorld.getBlockState(newPos); - if(state != null && state.getBlock() == block) { + if (state != null && state.getBlock() == block) { above = newPos.add(0, 1, 0); aboveBlock = Minecraft.getMinecraft().theWorld.getBlockState(above).getBlock(); - if(!cropBlocksZapper.contains(aboveBlock)) { + if (!cropBlocksZapper.contains(aboveBlock)) { availableNeighbors.add(newPos); } } } - if(availableNeighbors.size() >= 2) { + if (availableNeighbors.size() >= 2) { returnablePositions.add(pos); pos = availableNeighbors.get(0); - } else if(availableNeighbors.size() == 1) { + } else if (availableNeighbors.size() == 1) { pos = availableNeighbors.get(0); - } else if(returnablePositions.isEmpty()) { + } else if (returnablePositions.isEmpty()) { break; } else { i--; @@ -653,7 +646,7 @@ public class CustomItemEffects { } } } - for(BlockPos pos : zapperBlocks) { + for (BlockPos pos : zapperBlocks) { Block block = Minecraft.getMinecraft().theWorld.getBlockState(pos).getBlock(); drawFilledBoundingBox(block.getSelectedBoundingBox(Minecraft.getMinecraft().theWorld, pos) .expand(0.001D, 0.001D, 0.001D).offset(-d0, -d1, -d2), @@ -662,10 +655,10 @@ public class CustomItemEffects { GlStateManager.depthMask(true); GlStateManager.enableTexture2D(); GlStateManager.disableBlend(); - } else if(NotEnoughUpdates.INSTANCE.config.itemOverlays.enableTreecapOverlay && + } else if (NotEnoughUpdates.INSTANCE.config.itemOverlays.enableTreecapOverlay && (heldInternal.equals("JUNGLE_AXE") || heldInternal.equals("TREECAPITATOR_AXE"))) { int maxWood = 10; - if(heldInternal.equals("TREECAPITATOR_AXE")) maxWood = 35; + if (heldInternal.equals("TREECAPITATOR_AXE")) maxWood = 35; if (event.target.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { GlStateManager.enableBlend(); @@ -674,7 +667,7 @@ public class CustomItemEffects { GlStateManager.disableTexture2D(); GlStateManager.depthMask(false); - if(Minecraft.getMinecraft().theWorld.getBlockState(event.target.getBlockPos()).getBlock() == Blocks.log || + if (Minecraft.getMinecraft().theWorld.getBlockState(event.target.getBlockPos()).getBlock() == Blocks.log || Minecraft.getMinecraft().theWorld.getBlockState(event.target.getBlockPos()).getBlock() == Blocks.log2) { int woods = 0; @@ -685,8 +678,8 @@ public class CustomItemEffects { candidatesNew.add(event.target.getBlockPos()); - while(woods < maxWood) { - if(candidatesNew.isEmpty()) { + while (woods < maxWood) { + if (candidatesNew.isEmpty()) { break; } @@ -696,20 +689,20 @@ public class CustomItemEffects { woods += candidates.size(); boolean random = woods > maxWood; - while(!candidates.isEmpty()) { + while (!candidates.isEmpty()) { BlockPos candidate = candidates.pop(); Block block = Minecraft.getMinecraft().theWorld.getBlockState(candidate).getBlock(); candidatesOld.add(candidate); - for(int x = -1; x <= 1; x++) { - for(int y = -1; y <= 1; y++) { - for(int z = -1; z <= 1; z++) { - if(x != 0 || y != 0 || z != 0) { + for (int x = -1; x <= 1; x++) { + for (int y = -1; y <= 1; y++) { + for (int z = -1; z <= 1; z++) { + if (x != 0 || y != 0 || z != 0) { BlockPos posNew = candidate.add(x, y, z); - if(!candidatesOld.contains(posNew) && !candidates.contains(posNew) && !candidatesNew.contains(posNew)) { + if (!candidatesOld.contains(posNew) && !candidates.contains(posNew) && !candidatesNew.contains(posNew)) { Block blockNew = Minecraft.getMinecraft().theWorld.getBlockState(posNew).getBlock(); - if(blockNew == Blocks.log || blockNew == Blocks.log2) { + if (blockNew == Blocks.log || blockNew == Blocks.log2) { candidatesNew.add(posNew); } } @@ -721,7 +714,7 @@ |
