diff options
| author | GodOfPro <59516901+GodOfProDev@users.noreply.github.com> | 2022-11-10 00:36:45 +0330 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-09 22:06:45 +0100 |
| commit | 3ffff3428b72371b35ea3067ae33588d89e7fc85 (patch) | |
| tree | fbd9ea997ee4d0d822290548ef76ae315b5fdf24 /src/main/java/io/github/moulberry/notenoughupdates/miscfeatures | |
| parent | 8f8ced3155c2c694dd7d5326e635b51c112cb79f (diff) | |
| download | notenoughupdates-3ffff3428b72371b35ea3067ae33588d89e7fc85.tar.gz notenoughupdates-3ffff3428b72371b35ea3067ae33588d89e7fc85.tar.bz2 notenoughupdates-3ffff3428b72371b35ea3067ae33588d89e7fc85.zip | |
Added Endernode Highlighter (#421)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscfeatures')
4 files changed, 147 insertions, 21 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/EnderNodes.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/EnderNodes.java index b0823a7d..874c0a93 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/EnderNodes.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/EnderNodes.java @@ -24,13 +24,9 @@ import io.github.moulberry.notenoughupdates.util.SBInfo; import io.github.moulberry.notenoughupdates.util.SpecialColour; import io.github.moulberry.notenoughupdates.util.TitleUtil; import net.minecraft.client.Minecraft; -import net.minecraft.util.ChatComponentText; public class EnderNodes { - // TODO Add ender node highliter - // TODO Add ender node counter ( maybe money estimation ) - - public static void dispalyEndermiteNotif() { + public static void displayEndermiteNotif() { if (NotEnoughUpdates.INSTANCE.config.notifications.endermiteAlert && SBInfo.getInstance().getLocation() != null && SBInfo.getInstance().getLocation().equals("combat_3")) { TitleUtil.getInstance().createTitle("Nested Endermite", diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/world/EnderNodeHighlighter.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/world/EnderNodeHighlighter.java new file mode 100644 index 00000000..ce0e6a25 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/world/EnderNodeHighlighter.java @@ -0,0 +1,97 @@ +/* + * 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.world; + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.events.SpawnParticleEvent; +import io.github.moulberry.notenoughupdates.util.SBInfo; +import io.github.moulberry.notenoughupdates.util.SpecialColour; +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.init.Blocks; +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumParticleTypes; +import net.minecraft.world.World; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +import static io.github.moulberry.notenoughupdates.util.MathUtil.basicallyEqual; + +public class EnderNodeHighlighter extends GenericBlockHighlighter { + + private static final EnderNodeHighlighter INSTANCE = new EnderNodeHighlighter(); + + public static EnderNodeHighlighter getInstance() + { + return INSTANCE; + } + + + @SubscribeEvent + public void onParticleSpawn(SpawnParticleEvent event) { + if (!isEnabled()) return; + if (event.getParticleTypes() == EnumParticleTypes.PORTAL) { + double x = event.getXCoord(); + double y = event.getYCoord(); + double z = event.getZCoord(); + + boolean xZero = basicallyEqual((x - 0.5) % 1, 0, 0.2); + boolean yZero = basicallyEqual((y - 0.5) % 1, 0, 0.2); + boolean zZero = basicallyEqual((z - 0.5) % 1, 0, 0.2); + + if (Math.abs(y % 1) == 0.25 && xZero && zZero) { + if (tryRegisterInterest(x, y - 1, z)) return; + } + if (Math.abs(y % 1) == 0.75 && xZero && zZero) { + if (tryRegisterInterest(x, y + 1, z)) return; + } + if (Math.abs(x % 1) == 0.25 && yZero && zZero) { + if (tryRegisterInterest(x + 1, y, z)) return; + } + if (Math.abs(x % 1) == 0.75 && yZero && zZero) { + if (tryRegisterInterest(x - 1, y, z)) return; + } + if (Math.abs(z % 1) == 0.25 && yZero && xZero) { + if (tryRegisterInterest(x, y, z + 1)) return; + } + if (Math.abs(z % 1) == 0.75 && yZero && xZero) { + tryRegisterInterest(x, y, z - 1); + } + } + } + + @Override + protected boolean isEnabled() { + return "combat_3".equals(SBInfo.getInstance().getLocation()) + && NotEnoughUpdates.INSTANCE.config.world.highlightEnderNodes; + } + + @Override + protected boolean isValidHighlightSpot(BlockPos key) { + World w = Minecraft.getMinecraft().theWorld; + if (w == null) return false; + Block b = w.getBlockState(key).getBlock(); + return b == Blocks.end_stone || b == Blocks.obsidian; + } + + @Override + protected int getColor(BlockPos blockPos) { + return SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.config.world.enderNodeColor); + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/world/GenericBlockHighlighter.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/world/GenericBlockHighlighter.java index 0e71c7a9..67d6f46e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/world/GenericBlockHighlighter.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/world/GenericBlockHighlighter.java @@ -56,34 +56,69 @@ public abstract class GenericBlockHighlighter { @SubscribeEvent public void onTick(TickEvent.ClientTickEvent ev) { if (ev.phase != TickEvent.Phase.END) return; - highlightedBlocks.removeIf(it -> !isValidHighlightSpot(it) || !canPlayerSeeBlock(it.getX(), it.getY(), it.getZ())); + highlightedBlocks.removeIf(it -> !isValidHighlightSpot(it) || + !canPlayerSeeNearBlocks(it.getX(), it.getY(), it.getZ())); } protected boolean canPlayerSeeBlock(double xCoord, double yCoord, double zCoord) { EntityPlayerSP p = Minecraft.getMinecraft().thePlayer; if (p == null) return false; - World w = p.worldObj; - MovingObjectPosition hitResult = w.rayTraceBlocks( - new Vec3(p.posX, p.posY + p.eyeHeight, p.posZ), - new Vec3(xCoord, yCoord, zCoord), - false, - true, - true - ); - BlockPos bp = new BlockPos(xCoord, yCoord, zCoord); + Vec3 playerPosition = new Vec3(p.posX, p.posY + p.eyeHeight, p.posZ); + MovingObjectPosition hitResult = rayTraceBlocks(p.worldObj, playerPosition, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5); + return canSee(hitResult, new BlockPos(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5)); + } + + protected boolean canPlayerSeeNearBlocks(double x, double y, double z) { + EntityPlayerSP p = Minecraft.getMinecraft().thePlayer; + if (p == null) return false; + World world = p.worldObj; + Vec3 playerPosition = new Vec3(p.posX, p.posY + p.eyeHeight, p.posZ); + BlockPos blockPos = new BlockPos(x, y, z); + MovingObjectPosition hitResult1 = rayTraceBlocks(world, playerPosition, x, y, z); + if (canSee(hitResult1, blockPos)) return true; + MovingObjectPosition hitResult2 = rayTraceBlocks(world, playerPosition, x + 1, y, z); + if (canSee(hitResult2, blockPos.add(1, 0, 1))) return true; + MovingObjectPosition hitResult3 = rayTraceBlocks(world, playerPosition, x + 1, y + 1, z); + if (canSee(hitResult3, blockPos.add(1, 1, 0))) return true; + MovingObjectPosition hitResult4 = rayTraceBlocks(world, playerPosition, x + 1, y + 1, z + 1); + if (canSee(hitResult4, blockPos.add(1, 1, 1))) return true; + + MovingObjectPosition hitResult5 = rayTraceBlocks(world, playerPosition, x, y + 1, z + 1); + if (canSee(hitResult5, blockPos.add(0, 1, 1))) return true; + MovingObjectPosition hitResult6 = rayTraceBlocks(world, playerPosition, x, y + 1, z); + if (canSee(hitResult6, blockPos.add(0, 1, 0))) return true; + MovingObjectPosition hitResult7 = rayTraceBlocks(world, playerPosition, x + 1, y, z + 1); + if (canSee(hitResult7, blockPos.add(1, 0, 1))) return true; + MovingObjectPosition hitResult8 = rayTraceBlocks(world, playerPosition, x, y + 1, z); + if (canSee(hitResult8, blockPos.add(0, 1, 0))) return true; + + return false; + } + + private static boolean canSee(MovingObjectPosition hitResult, BlockPos bp) { return hitResult == null || hitResult.typeOfHit != MovingObjectPosition.MovingObjectType.BLOCK || bp.equals(hitResult.getBlockPos()); } + private static MovingObjectPosition rayTraceBlocks(World world, Vec3 playerPosition, double x, double y, double z) { + return world.rayTraceBlocks(playerPosition, new Vec3(x, y, z), false, true, true); + } + @SubscribeEvent public void onWorldChange(WorldEvent.Load event) { highlightedBlocks.clear(); } - public void registerInterest(BlockPos pos) { - if (isValidHighlightSpot(pos) && canPlayerSeeBlock(pos.getX(), pos.getY(), pos.getZ())) { - highlightedBlocks.add(pos); + public boolean tryRegisterInterest(double x, double y, double z) { + BlockPos blockPos = new BlockPos(x, y, z); + boolean contains = highlightedBlocks.contains(blockPos); + if (!contains) { + boolean canSee = canPlayerSeeNearBlocks(blockPos.getX(), blockPos.getY(), blockPos.getZ()); + if (isValidHighlightSpot(blockPos) && canSee) { + highlightedBlocks.add(blockPos); + } } + return contains; } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/world/GlowingMushroomHighlighter.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/world/GlowingMushroomHighlighter.java index 9857f84b..fa5794ea 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/world/GlowingMushroomHighlighter.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/world/GlowingMushroomHighlighter.java @@ -39,14 +39,12 @@ public class GlowingMushroomHighlighter extends GenericBlockHighlighter { public void onParticleSpawn(SpawnParticleEvent event) { if (!isEnabled()) return; if (event.getParticleTypes() == EnumParticleTypes.SPELL_MOB) { - BlockPos blockPos = new BlockPos(event.getXCoord(), event.getYCoord(), event.getZCoord()); - if (highlightedBlocks.contains(blockPos)) return; if ( isDecimalPartApproximately(event.getXCoord(), 0.5) && isDecimalPartApproximately(event.getYCoord(), 0.1) && isDecimalPartApproximately(event.getZCoord(), 0.5) ) { - registerInterest(blockPos); + tryRegisterInterest(event.getXCoord(), event.getYCoord(), event.getZCoord()); } } } |
