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 | 147 |
1 files changed, 103 insertions, 44 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 e621cf78..452f8a9b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CustomItemEffects.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CustomItemEffects.java @@ -1,3 +1,22 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + package io.github.moulberry.notenoughupdates.miscfeatures; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; @@ -11,7 +30,11 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.multiplayer.WorldClient; -import net.minecraft.client.renderer.*; +import net.minecraft.client.renderer.BlockRendererDispatcher; +import net.minecraft.client.renderer.EntityRenderer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.texture.TextureUtil; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; @@ -24,7 +47,13 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import net.minecraft.util.*; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.Vec3; +import net.minecraft.util.Vec3i; import net.minecraftforge.client.event.DrawBlockHighlightEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent; @@ -36,8 +65,14 @@ import org.lwjgl.util.vector.Vector3f; import java.awt.*; import java.io.ByteArrayInputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; import java.util.List; -import java.util.*; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -178,12 +213,14 @@ public class CustomItemEffects { @SubscribeEvent public void onGameTick(TickEvent.ClientTickEvent event) { if (event.phase != TickEvent.Phase.END) return; + EntityPlayerSP player = Minecraft.getMinecraft().thePlayer; + if (player == null) return; if (!usingEtherwarp && wasUsingEtherwarp) { - if (Minecraft.getMinecraft().thePlayer.rotationYaw > 0) { - Minecraft.getMinecraft().thePlayer.rotationYaw -= 0.000001; + if (player.rotationYaw > 0) { + player.rotationYaw -= 0.000001; } else { - Minecraft.getMinecraft().thePlayer.rotationYaw += 0.000001; + player.rotationYaw += 0.000001; } } wasUsingEtherwarp = usingEtherwarp; @@ -238,6 +275,7 @@ public class CustomItemEffects { private boolean usingEtherwarp = false; private RaycastResult etherwarpRaycast = null; private int lastEtherwarpUse = 0; + private String denyTpReason = null; @SubscribeEvent public void onOverlayDrawn(RenderGameOverlayEvent.Post event) { @@ -246,40 +284,50 @@ public class CustomItemEffects { ItemStack held = Minecraft.getMinecraft().thePlayer.getHeldItem(); String heldInternal = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(held); - if (usingEtherwarp && NotEnoughUpdates.INSTANCE.config.itemOverlays.enableEtherwarpHelperOverlay) { - String denyTpReason = null; + WorldClient world = Minecraft.getMinecraft().theWorld; + if (usingEtherwarp) { + denyTpReason = null; if (etherwarpRaycast == null) { denyTpReason = "Too far!"; } else { BlockPos pos = etherwarpRaycast.pos; - if (!etherwarpRaycast.state.getBlock().isCollidable() || - etherwarpRaycast.state.getBlock().getCollisionBoundingBox( - Minecraft.getMinecraft().theWorld, - etherwarpRaycast.pos, - etherwarpRaycast.state - ) == null) { + Block block = etherwarpRaycast.state.getBlock(); + if (!block.isCollidable() || + //Don't allow teleport at this block + block == Blocks.carpet || block == Blocks.skull || + block.getCollisionBoundingBox(world, etherwarpRaycast.pos, etherwarpRaycast.state) == null && + //Allow teleport at this block + block != Blocks.wall_sign && block != Blocks.standing_sign) { 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() && - 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) { + BlockPos blockPosAbove = pos.add(0, 1, 0); + Block blockAbove = world.getBlockState(blockPosAbove).getBlock(); + + Block twoBlockAbove = world.getBlockState(pos.add(0, 2, 0)).getBlock(); + if (blockAbove != Blocks.air && + //Allow teleport to the block below this block + blockAbove != Blocks.carpet && blockAbove != Blocks.skull && blockAbove.isCollidable() && + blockAbove.getCollisionBoundingBox(world, blockPosAbove, world.getBlockState(blockPosAbove)) != null || + //Don't allow teleport to the block below this block + blockAbove == Blocks.wall_sign || block == Blocks.standing_sign || + //Allow teleport to the block 2 blocks below this block + twoBlockAbove != Blocks.air && twoBlockAbove != Blocks.double_plant && twoBlockAbove != Blocks.carpet && + blockAbove != Blocks.skull) { denyTpReason = "No air above!"; } } } - if (denyTpReason != null) { - ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - Utils.drawStringCentered(EnumChatFormatting.RED + "Can't TP: " + denyTpReason, - Minecraft.getMinecraft().fontRendererObj, - scaledResolution.getScaledWidth() / 2f, scaledResolution.getScaledHeight() / 2f + 10, true, 0 - ); - GlStateManager.color(1, 1, 1, 1); + if (NotEnoughUpdates.INSTANCE.config.itemOverlays.enableEtherwarpHelperOverlay) { + if (denyTpReason != null) { + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + Utils.drawStringCentered(EnumChatFormatting.RED + "Can't TP: " + denyTpReason, + Minecraft.getMinecraft().fontRendererObj, + scaledResolution.getScaledWidth() / 2f, scaledResolution.getScaledHeight() / 2f + 10, true, 0 + ); + GlStateManager.color(1, 1, 1, 1); + } } } @@ -291,7 +339,7 @@ public class CustomItemEffects { Minecraft.getMinecraft().objectMouseOver.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK && onPrivateIsland) { - IBlockState hover = Minecraft.getMinecraft().theWorld.getBlockState( + IBlockState hover = world.getBlockState( Minecraft.getMinecraft().objectMouseOver.getBlockPos().offset( Minecraft.getMinecraft().objectMouseOver.sideHit, 1)); if (hover.getBlock() == Blocks.air) { @@ -303,14 +351,14 @@ public class CustomItemEffects { TreeMap<Float, Set<BlockPos>> candidatesOldSorted = new TreeMap<>(); IBlockState match = - Minecraft.getMinecraft().theWorld.getBlockState(Minecraft.getMinecraft().objectMouseOver.getBlockPos()); + world.getBlockState(Minecraft.getMinecraft().objectMouseOver.getBlockPos()); Item matchItem = Item.getItemFromBlock(match.getBlock()); if (matchItem != null) { ItemStack matchStack = new ItemStack(matchItem, 1, match .getBlock() .getDamageValue( - Minecraft.getMinecraft().theWorld, + world, Minecraft.getMinecraft().objectMouseOver.getBlockPos() ) ); @@ -568,7 +616,8 @@ public class CustomItemEffects { 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) { + //Don't need to wait 10 ticks when zoom is disabled + if (tick - lastEtherwarpUse > 10 || !NotEnoughUpdates.INSTANCE.config.itemOverlays.etherwarpZoom) { boolean aotv = Minecraft.getMinecraft().thePlayer.isSneaking() && (heldInternal.equals("ASPECT_OF_THE_VOID") || heldInternal.equals("ASPECT_OF_THE_END")); if (aotv || heldInternal.equals("ETHERWARP_CONDUIT")) { @@ -597,20 +646,30 @@ public class CustomItemEffects { if (etherwarpRaycast != null && NotEnoughUpdates.INSTANCE.config.itemOverlays.enableEtherwarpBlockOverlay) { - AxisAlignedBB bb = etherwarpRaycast.state.getBlock().getSelectedBoundingBox( - Minecraft.getMinecraft().theWorld, - etherwarpRaycast.pos - ) - .expand(0.01D, 0.01D, 0.01D).offset(-d0, -d1, -d2); - drawFilledBoundingBox(bb, 1f, NotEnoughUpdates.INSTANCE.config.itemOverlays.etherwarpHighlightColour); + if (denyTpReason == null || !NotEnoughUpdates.INSTANCE.config.itemOverlays.disableOverlayWhenFailed) { + AxisAlignedBB box = etherwarpRaycast.state.getBlock().getSelectedBoundingBox( + Minecraft.getMinecraft().theWorld, + etherwarpRaycast.pos + ); + AxisAlignedBB bb = box.expand(0.01D, 0.01D, 0.01D).offset(-d0, -d1, -d2); + drawFilledBoundingBox( + bb, + 1f, + NotEnoughUpdates.INSTANCE.config.itemOverlays.etherwarpHighlightColour + ); - GlStateManager.disableDepth(); - drawOutlineBoundingBox(bb, 2f, NotEnoughUpdates.INSTANCE.config.itemOverlays.etherwarpHighlightColour); - GlStateManager.enableDepth(); + GlStateManager.disableDepth(); + drawOutlineBoundingBox( + bb, + 2f, + NotEnoughUpdates.INSTANCE.config.itemOverlays.etherwarpHighlightColour + ); + GlStateManager.enableDepth(); - GlStateManager.depthMask(true); - GlStateManager.enableTexture2D(); - GlStateManager.disableBlend(); + GlStateManager.depthMask(true); + GlStateManager.enableTexture2D(); + GlStateManager.disableBlend(); + } if (NotEnoughUpdates.INSTANCE.config.itemOverlays.etherwarpZoom) { float distFactor = 1 - |
