From 58e43eee5c02efbe6144bfd6e4b1a95101d24576 Mon Sep 17 00:00:00 2001 From: Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> Date: Thu, 28 Sep 2023 15:40:22 -0400 Subject: Add next burrow direction detection --- .../skyblock/diana/MythologicalRitual.java | 89 ++++++++++++++++------ 1 file changed, 66 insertions(+), 23 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/diana/MythologicalRitual.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/diana/MythologicalRitual.java index c74d5e77..ba27845a 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/diana/MythologicalRitual.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/diana/MythologicalRitual.java @@ -1,9 +1,6 @@ package me.xmrvizzy.skyblocker.skyblock.diana; import com.mojang.brigadier.Command; -import it.unimi.dsi.fastutil.booleans.BooleanBooleanMutablePair; -import it.unimi.dsi.fastutil.objects.Object2LongMap; -import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap; import me.xmrvizzy.skyblocker.SkyblockerMod; import me.xmrvizzy.skyblocker.config.SkyblockerConfig; import me.xmrvizzy.skyblocker.utils.Utils; @@ -14,6 +11,7 @@ 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.fabricmc.fabric.api.event.player.UseBlockCallback; +import net.fabricmc.fabric.api.util.TriState; import net.minecraft.block.Blocks; import net.minecraft.client.MinecraftClient; import net.minecraft.command.argument.BlockPosArgumentType; @@ -27,7 +25,9 @@ import net.minecraft.util.Hand; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; +import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; +import org.apache.commons.math3.stat.regression.SimpleRegression; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -40,10 +40,11 @@ import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.lit public class MythologicalRitual { private static final Pattern GRIFFIN_BURROW_DUG = Pattern.compile("(?You dug out a Griffin Burrow!|You finished the Griffin burrow chain!) \\((?\\d)/4\\)"); - private static final Map particlesMap = new HashMap<>(); - private static final Object2LongMap griffinBurrows = new Object2LongOpenHashMap<>(); + private static final float[] WHITE_COLOR_COMPONENTS = {1.0f, 1.0f, 1.0f}; + private static final Map griffinBurrows = new HashMap<>(); @Nullable private static BlockPos lastDugBurrowPos; + private static GriffinBurrow previousBurrow; public static void init() { WorldRenderEvents.AFTER_TRANSLUCENT.register(MythologicalRitual::render); @@ -55,32 +56,57 @@ public class MythologicalRitual { griffinBurrows.clear(); return Command.SINGLE_SUCCESS; })) - .then(literal("clearGriffinBurrow").then(argument("pos", BlockPosArgumentType.blockPos()).executes(context -> { - griffinBurrows.removeLong(context.getArgument("pos", BlockPos.class)); - return Command.SINGLE_SUCCESS; - })))))); + .then(literal("clearGriffinBurrow") + .then(argument("pos", BlockPosArgumentType.blockPos()).executes(context -> { + griffinBurrows.remove(context.getArgument("pos", BlockPos.class)); + return Command.SINGLE_SUCCESS; + })) + ) + ))); } public static void onParticle(ParticleS2CPacket packet) { - if (isActive() && ParticleTypes.CRIT.equals(packet.getParameters().getType()) || ParticleTypes.ENCHANT.equals(packet.getParameters().getType())) { - BlockPos pos = BlockPos.ofFloored(packet.getX(), packet.getY(), packet.getZ()).down(); - if (MinecraftClient.getInstance().world == null || !MinecraftClient.getInstance().world.getBlockState(pos).isOf(Blocks.GRASS_BLOCK)) { - return; - } - BooleanBooleanMutablePair particlesAtPos = particlesMap.computeIfAbsent(pos, pos1 -> BooleanBooleanMutablePair.of(false, false)); - particlesAtPos.left(particlesAtPos.leftBoolean() || ParticleTypes.CRIT.equals(packet.getParameters().getType())); - particlesAtPos.right(particlesAtPos.rightBoolean() || ParticleTypes.ENCHANT.equals(packet.getParameters().getType())); - if (particlesAtPos.leftBoolean() && particlesAtPos.rightBoolean() && griffinBurrows.getLong(pos) + 1000 < System.currentTimeMillis()) { - griffinBurrows.put(pos, 0); + if (isActive()) { + if (ParticleTypes.CRIT.equals(packet.getParameters().getType()) || ParticleTypes.ENCHANT.equals(packet.getParameters().getType())) { + BlockPos pos = BlockPos.ofFloored(packet.getX(), packet.getY(), packet.getZ()).down(); + if (MinecraftClient.getInstance().world == null || !MinecraftClient.getInstance().world.getBlockState(pos).isOf(Blocks.GRASS_BLOCK)) { + return; + } + GriffinBurrow burrow = griffinBurrows.computeIfAbsent(pos, pos1 -> new GriffinBurrow()); + if (ParticleTypes.CRIT.equals(packet.getParameters().getType())) burrow.critParticle++; + if (ParticleTypes.ENCHANT.equals(packet.getParameters().getType())) burrow.enchantParticle++; + if (burrow.critParticle >= 5 && burrow.enchantParticle >= 5 && burrow.confirmed == TriState.FALSE) { + griffinBurrows.get(pos).init(); + } + } else if (ParticleTypes.DUST.equals(packet.getParameters().getType())) { + BlockPos pos = BlockPos.ofFloored(packet.getX(), packet.getY(), packet.getZ()).down(2); + GriffinBurrow burrow = griffinBurrows.get(pos); + if (burrow == null) { + return; + } + burrow.regression.addData(packet.getX(), packet.getZ()); + double slope = burrow.regression.getSlope(); + if (Double.isNaN(slope)) { + return; + } + Vec3d nextBurrowDirection = new Vec3d(100, 2, slope * 100).normalize().multiply(500); + burrow.nextBurrowPlane = new Vec3d[]{ + Vec3d.of(pos).add(nextBurrowDirection), + Vec3d.of(pos).subtract(nextBurrowDirection) + }; } } } public static void render(WorldRenderContext context) { if (isActive()) { - for (Object2LongMap.Entry griffinBorrow : griffinBurrows.object2LongEntrySet()) { - if (griffinBorrow.getLongValue() <= 0) { - RenderHelper.renderFilledThroughWallsWithBeaconBeam(context, griffinBorrow.getKey(), DyeColor.GREEN.getColorComponents(), 0.5F); + for (Map.Entry burrowEntry : griffinBurrows.entrySet()) { + GriffinBurrow burrow = burrowEntry.getValue(); + if (burrow.confirmed == TriState.TRUE) { + RenderHelper.renderFilledThroughWallsWithBeaconBeam(context, burrowEntry.getKey(), DyeColor.GREEN.getColorComponents(), 0.5F); + } + if (burrow.confirmed != TriState.FALSE && burrow.nextBurrowPlane != null) { // TODO try before debug render? + RenderHelper.renderLinesFromPoints(context, burrow.nextBurrowPlane, WHITE_COLOR_COMPONENTS, 1, 5); } } } @@ -104,11 +130,28 @@ public class MythologicalRitual { public static void onChatMessage(Text message, boolean overlay) { if (isActive() && GRIFFIN_BURROW_DUG.matcher(message.getString()).matches()) { - griffinBurrows.put(lastDugBurrowPos, System.currentTimeMillis()); + if (previousBurrow != null) { + previousBurrow.confirmed = TriState.FALSE; + } + previousBurrow = griffinBurrows.get(lastDugBurrowPos); + previousBurrow.confirmed = TriState.DEFAULT; } } private static boolean isActive() { return SkyblockerConfig.get().general.fairySouls.enableFairySoulsHelper && Utils.getLocationRaw().equals("hub"); // TODO Change to actual config option } + + private static class GriffinBurrow { + private int critParticle; + private int enchantParticle; + private TriState confirmed = TriState.FALSE; + private final SimpleRegression regression = new SimpleRegression(); + private Vec3d[] nextBurrowPlane; + + private void init() { + confirmed = TriState.TRUE; + regression.clear(); + } + } } -- cgit