Skip to content

Commit

Permalink
Add Ender Nodes Helper (#629)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinthegreat1 authored Apr 12, 2024
1 parent fa97859 commit 8de8c71
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/de/hysky/skyblocker/SkyblockerMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import de.hysky.skyblocker.skyblock.dwarven.CrystalsLocationsManager;
import de.hysky.skyblocker.skyblock.dwarven.DwarvenHud;
import de.hysky.skyblocker.skyblock.end.BeaconHighlighter;
import de.hysky.skyblocker.skyblock.end.EnderNodes;
import de.hysky.skyblocker.skyblock.end.TheEnd;
import de.hysky.skyblocker.skyblock.garden.FarmingHud;
import de.hysky.skyblocker.skyblock.garden.LowerSensitivity;
Expand Down Expand Up @@ -110,6 +111,7 @@ public void onInitializeClient() {
FairySouls.init();
Relics.init();
MythologicalRitual.init();
EnderNodes.init();
OrderedWaypoints.init();
BackpackPreview.init();
QuickNav.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,8 @@ public static class Rift {
}

public static class TheEnd {
@SerialEntry
public boolean enableEnderNodeHelper = true;

@SerialEntry
public boolean hudEnabled = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
.group(OptionGroup.createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.locations.end"))
.collapsed(false)
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.locations.end.enableEnderNodeHelper"))
.binding(defaults.locations.end.enableEnderNodeHelper,
() -> config.locations.end.enableEnderNodeHelper,
newValue -> config.locations.end.enableEnderNodeHelper = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.locations.end.hudEnabled"))
.binding(defaults.locations.end.hudEnabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import de.hysky.skyblocker.skyblock.dungeon.DungeonScore;
import de.hysky.skyblocker.skyblock.dungeon.secrets.DungeonManager;
import de.hysky.skyblocker.skyblock.end.BeaconHighlighter;
import de.hysky.skyblocker.skyblock.end.EnderNodes;
import de.hysky.skyblocker.skyblock.end.TheEnd;
import de.hysky.skyblocker.skyblock.waypoint.MythologicalRitual;
import de.hysky.skyblocker.utils.SlayerUtils;
Expand Down Expand Up @@ -91,6 +92,7 @@ public abstract class ClientPlayNetworkHandlerMixin {
@Inject(method = "onParticle", at = @At("RETURN"))
private void skyblocker$onParticle(ParticleS2CPacket packet, CallbackInfo ci) {
MythologicalRitual.onParticle(packet);
EnderNodes.onParticle(packet);
}

@ModifyExpressionValue(method = "onEntityStatus", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/packet/s2c/play/EntityStatusS2CPacket;getEntity(Lnet/minecraft/world/World;)Lnet/minecraft/entity/Entity;"))
Expand Down
138 changes: 138 additions & 0 deletions src/main/java/de/hysky/skyblocker/skyblock/end/EnderNodes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package de.hysky.skyblocker.skyblock.end;

import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.utils.Utils;
import de.hysky.skyblocker.utils.scheduler.Scheduler;
import de.hysky.skyblocker.utils.waypoint.Waypoint;
import it.unimi.dsi.fastutil.ints.IntIntMutablePair;
import it.unimi.dsi.fastutil.ints.IntIntPair;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
import net.fabricmc.fabric.api.event.player.AttackBlockCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.network.packet.s2c.play.ParticleS2CPacket;
import net.minecraft.particle.ParticleType;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.util.ActionResult;
import net.minecraft.util.DyeColor;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.MathHelper;

import java.util.HashMap;
import java.util.Map;

public class EnderNodes {
private static final MinecraftClient client = MinecraftClient.getInstance();
private static final Map<BlockPos, EnderNode> enderNodes = new HashMap<>();

public static void init() {
Scheduler.INSTANCE.scheduleCyclic(EnderNodes::update, 20);
WorldRenderEvents.AFTER_TRANSLUCENT.register(EnderNodes::render);
AttackBlockCallback.EVENT.register((player, world, hand, pos, direction) -> {
enderNodes.remove(pos);
return ActionResult.PASS;
});
ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> reset());
}

public static void onParticle(ParticleS2CPacket packet) {
if (!shouldProcess()) return;
ParticleType<?> particleType = packet.getParameters().getType();
if (!ParticleTypes.PORTAL.getType().equals(particleType) && !ParticleTypes.WITCH.getType().equals(particleType))
return;

double x = packet.getX();
double y = packet.getY();
double z = packet.getZ();
double xFrac = MathHelper.floorMod(x, 1);
double yFrac = MathHelper.floorMod(y, 1);
double zFrac = MathHelper.floorMod(z, 1);
BlockPos pos;
Direction direction;
if (yFrac == 0.25) {
pos = BlockPos.ofFloored(x, y - 1, z);
direction = Direction.UP;
} else if (yFrac == 0.75) {
pos = BlockPos.ofFloored(x, y + 1, z);
direction = Direction.DOWN;
} else if (xFrac == 0.25) {
pos = BlockPos.ofFloored(x - 1, y, z);
direction = Direction.EAST;
} else if (xFrac == 0.75) {
pos = BlockPos.ofFloored(x + 1, y, z);
direction = Direction.WEST;
} else if (zFrac == 0.25) {
pos = BlockPos.ofFloored(x, y, z - 1);
direction = Direction.SOUTH;
} else if (zFrac == 0.75) {
pos = BlockPos.ofFloored(x, y, z + 1);
direction = Direction.NORTH;
} else {
return;
}

EnderNode enderNode = enderNodes.computeIfAbsent(pos, EnderNode::new);
IntIntPair particles = enderNode.particles.get(direction);
particles.left(particles.leftInt() + 1);
particles.right(particles.rightInt() + 1);
}

private static void update() {
if (shouldProcess()) {
for (EnderNode enderNode : enderNodes.values()) {
enderNode.updateParticles();
}
}
}

private static void render(WorldRenderContext context) {
if (shouldProcess()) {
for (EnderNode enderNode : enderNodes.values()) {
if (enderNode.shouldRender()) {
enderNode.render(context);
}
}
}
}

private static boolean shouldProcess() {
return SkyblockerConfigManager.get().locations.end.enableEnderNodeHelper && Utils.isInTheEnd();
}

private static void reset() {
enderNodes.clear();
}

public static class EnderNode extends Waypoint {
private final Map<Direction, IntIntPair> particles = Map.of(
Direction.UP, new IntIntMutablePair(0, 0),
Direction.DOWN, new IntIntMutablePair(0, 0),
Direction.EAST, new IntIntMutablePair(0, 0),
Direction.WEST, new IntIntMutablePair(0, 0),
Direction.SOUTH, new IntIntMutablePair(0, 0),
Direction.NORTH, new IntIntMutablePair(0, 0)
);
private long lastConfirmed;

private EnderNode(BlockPos pos) {
super(pos, () -> SkyblockerConfigManager.get().general.waypoints.waypointType, DyeColor.CYAN.getColorComponents(), false);
}

private void updateParticles() {
long currentTimeMillis = System.currentTimeMillis();
if (lastConfirmed + 2000 > currentTimeMillis || client.world == null || !particles.entrySet().stream().allMatch(entry -> entry.getValue().leftInt() >= 5 && entry.getValue().rightInt() >= 5 || !client.world.getBlockState(pos.offset(entry.getKey())).isAir())) return;
lastConfirmed = currentTimeMillis;
for (Map.Entry<Direction, IntIntPair> entry : particles.entrySet()) {
entry.getValue().left(0);
entry.getValue().right(0);
}
}

@Override
public boolean shouldRender() {
return super.shouldRender() && lastConfirmed + 5000 > System.currentTimeMillis();
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/assets/skyblocker/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@
"text.autoconfig.skyblocker.option.locations.rift.mcGrubberStacks.@Tooltip": "Used for calculating Motes sell prices.",

"text.autoconfig.skyblocker.option.locations.end": "The End",
"text.autoconfig.skyblocker.option.locations.end.enableEnderNodeHelper": "Enable Ender Node Helper",
"text.autoconfig.skyblocker.option.locations.end.hudEnabled": "HUD Enabled",
"text.autoconfig.skyblocker.option.locations.end.screen": "End HUD Config...",
"text.autoconfig.skyblocker.option.locations.end.waypoint": "End Protector Waypoint",
Expand Down

0 comments on commit 8de8c71

Please sign in to comment.