diff options
| author | Roman / Linnea Gräf <roman.graef@gmail.com> | 2022-11-03 11:34:09 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-03 11:34:09 +0100 |
| commit | 2a6dbf5407b5772db3ac0d203da3cdfac13d69d5 (patch) | |
| tree | ac8cf5047e200423c8cdbb3aee57787e1d5f6f50 /src/main/java/io/github/moulberry/notenoughupdates/miscfeatures | |
| parent | 5f0291595204c06be9c6462dce6b166b03c19f68 (diff) | |
| download | notenoughupdates-2a6dbf5407b5772db3ac0d203da3cdfac13d69d5.tar.gz notenoughupdates-2a6dbf5407b5772db3ac0d203da3cdfac13d69d5.tar.bz2 notenoughupdates-2a6dbf5407b5772db3ac0d203da3cdfac13d69d5.zip | |
Add fully Hypixel-Rule compliant glowing mush highlighter (#266)
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscfeatures')
4 files changed, 197 insertions, 28 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalWishingCompassSolver.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalWishingCompassSolver.java index f378fdca..50975af9 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalWishingCompassSolver.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CrystalWishingCompassSolver.java @@ -22,6 +22,7 @@ package io.github.moulberry.notenoughupdates.miscfeatures; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.util.Line; import io.github.moulberry.notenoughupdates.core.util.Vec3Comparable; +import io.github.moulberry.notenoughupdates.events.SpawnParticleEvent; import io.github.moulberry.notenoughupdates.options.NEUConfig; import io.github.moulberry.notenoughupdates.options.customtypes.NEUDebugFlag; import io.github.moulberry.notenoughupdates.util.NEUDebugLogger; @@ -346,15 +347,15 @@ public class CrystalWishingCompassSolver { * per-area structure missing, or because Hypixel. * Always within 1 block of X=513 Y=106 Z=551. */ - public void onSpawnParticle( - EnumParticleTypes particleType, - double x, - double y, - double z - ) { + @SubscribeEvent + public void onSpawnParticle(SpawnParticleEvent event) { + EnumParticleTypes particleType = event.getParticleTypes(); + double x = event.getXCoord(); + double y = event.getYCoord(); + double z = event.getZCoord(); if (!NotEnoughUpdates.INSTANCE.config.mining.wishingCompassSolver || particleType != EnumParticleTypes.VILLAGER_HAPPY || - !SBInfo.getInstance().getLocation().equals("crystal_hollows")) { + !"crystal_hollows".equals(SBInfo.getInstance().getLocation())) { return; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FishingHelper.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FishingHelper.java index fff8d269..e3afc73d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FishingHelper.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FishingHelper.java @@ -21,6 +21,7 @@ package io.github.moulberry.notenoughupdates.miscfeatures; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.ChromaColour; +import io.github.moulberry.notenoughupdates.events.SpawnParticleEvent; import io.github.moulberry.notenoughupdates.util.SpecialColour; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.block.state.IBlockState; @@ -380,24 +381,24 @@ public class FishingHelper { return 1 / (d + (1 / (ZERO_PITCH - MAX_PITCH))) * (1 - d / MAX_DISTANCE) + MAX_PITCH; } - public boolean onSpawnParticle( - EnumParticleTypes particleType, - double x, - double y, - double z, - double xOffset, - double yOffset, - double zOffset - ) { + @SubscribeEvent + public void onSpawnParticle(SpawnParticleEvent event) { + EnumParticleTypes particleType = event.getParticleTypes(); + double x = event.getXCoord(); + double y = event.getYCoord(); + double z = event.getZCoord(); + double xOffset = event.getXOffset(); + double yOffset = event.getYOffset(); + double zOffset = event.getZOffset(); if (!NotEnoughUpdates.INSTANCE.config.fishing.hideOtherPlayerAll && !NotEnoughUpdates.INSTANCE.config.fishing.enableCustomParticles && !NotEnoughUpdates.INSTANCE.config.fishing.incomingFishWarning && !NotEnoughUpdates.INSTANCE.config.fishing.incomingFishWarningR) { - return false; + return; } if (hookEntities.isEmpty()) { - return false; + return; } if ((particleType == EnumParticleTypes.WATER_WAKE || particleType == EnumParticleTypes.SMOKE_NORMAL || particleType == EnumParticleTypes.FLAME) && Math.abs( @@ -610,22 +611,24 @@ public class FishingHelper { particleTypeI = NotEnoughUpdates.INSTANCE.config.fishing.yourParticleType; particleCustomColour = NotEnoughUpdates.INSTANCE.config.fishing.yourParticleColour; } else if (NotEnoughUpdates.INSTANCE.config.fishing.hideOtherPlayerAll) { - return true; + event.cancel(); + return; } else { particleTypeI = NotEnoughUpdates.INSTANCE.config.fishing.otherParticleType; particleCustomColour = NotEnoughUpdates.INSTANCE.config.fishing.otherParticleColour; } if (!NotEnoughUpdates.INSTANCE.config.fishing.enableCustomParticles) { - return false; + return; } int argb = SpecialColour.specialToChromaRGB(particleCustomColour); if (particleTypeI == 0) { - return false; + return; } else if (particleTypeI == 1) { - return true; + event.cancel(); + return; } if (Minecraft.getMinecraft() != null && Minecraft.getMinecraft().getRenderViewEntity() != null && @@ -633,11 +636,13 @@ public class FishingHelper { int i = Minecraft.getMinecraft().gameSettings.particleSetting; if (i == 1 && Minecraft.getMinecraft().theWorld.rand.nextInt(3) == 0) { - return true; + event.cancel(); + return; } if (i >= 2) { - return true; + event.cancel(); + return; } double xDist = Minecraft.getMinecraft().getRenderViewEntity().posX - x; @@ -678,7 +683,8 @@ public class FishingHelper { } if (customColour && (((argb >> 24) & 0xFF) < 10)) { - return true; + event.cancel(); + return; } EntityFX fx = Minecraft.getMinecraft().effectRenderer.spawnEffectParticle( @@ -706,10 +712,9 @@ public class FishingHelper { } } - return true; + event.cancel(); + return; } } - - return false; } } 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 new file mode 100644 index 00000000..0e71c7a9 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/world/GenericBlockHighlighter.java @@ -0,0 +1,89 @@ +/* + * 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.core.util.render.RenderUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.util.BlockPos; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; +import net.minecraftforge.client.event.RenderWorldLastEvent; +import net.minecraftforge.event.world.WorldEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; + +import java.util.HashSet; +import java.util.Set; + +public abstract class GenericBlockHighlighter { + protected abstract boolean isEnabled(); + + protected abstract boolean isValidHighlightSpot(BlockPos key); + + protected abstract int getColor(BlockPos blockPos); + + public final Set<BlockPos> highlightedBlocks = new HashSet<>(); + + @SubscribeEvent + public void onWorldRenderLast(RenderWorldLastEvent event) { + if (!isEnabled()) return; + World w = Minecraft.getMinecraft().theWorld; + if (w == null) return; + for (BlockPos blockPos : highlightedBlocks) { + RenderUtils.renderBoundingBox(blockPos, getColor(blockPos), event.partialTicks); + } + } + + @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())); + } + + 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); + return hitResult == null + || hitResult.typeOfHit != MovingObjectPosition.MovingObjectType.BLOCK + || bp.equals(hitResult.getBlockPos()); + } + + @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); + } + } +} 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 new file mode 100644 index 00000000..9857f84b --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/world/GlowingMushroomHighlighter.java @@ -0,0 +1,74 @@ +/* + * 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.isDecimalPartApproximately; + +public class GlowingMushroomHighlighter extends GenericBlockHighlighter { + + @SubscribeEvent + 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); + } + } + } + + + @Override + protected boolean isEnabled() { + return "farming_1".equals(SBInfo.getInstance().getLocation()) + && NotEnoughUpdates.INSTANCE.config.world.highlightGlowingMushrooms; + } + + @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.brown_mushroom || b == Blocks.red_mushroom; + } + + @Override + protected int getColor(BlockPos blockPos) { + return SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.config.world.glowingMushroomColor); + } + +} |
