aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorKevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>2023-09-27 00:58:08 -0400
committerKevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>2023-10-22 23:20:33 -0400
commit0314c406d18d49ac00998c4a33bfdeea4e10280f (patch)
treeb8209d2701d6f24c8afeb507bf05a77da2394a28 /src/main
parent3d59588b658c0c9e4cb90960b7390b27077ea516 (diff)
downloadSkyblocker-0314c406d18d49ac00998c4a33bfdeea4e10280f.tar.gz
Skyblocker-0314c406d18d49ac00998c4a33bfdeea4e10280f.tar.bz2
Skyblocker-0314c406d18d49ac00998c4a33bfdeea4e10280f.zip
Update burrow finish detection
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/diana/MythologicalRitual.java71
1 files changed, 55 insertions, 16 deletions
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 a70fa172..c74d5e77 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/diana/MythologicalRitual.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/diana/MythologicalRitual.java
@@ -2,74 +2,113 @@ 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;
import me.xmrvizzy.skyblocker.utils.render.RenderHelper;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
+import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents;
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.minecraft.block.Blocks;
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.command.argument.BlockPosArgumentType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.packet.s2c.play.ParticleS2CPacket;
import net.minecraft.particle.ParticleTypes;
+import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.DyeColor;
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.world.World;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
-import java.util.Set;
+import java.util.regex.Pattern;
+import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument;
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;
public class MythologicalRitual {
+ private static final Pattern GRIFFIN_BURROW_DUG = Pattern.compile("(?<message>You dug out a Griffin Burrow!|You finished the Griffin burrow chain!) \\((?<index>\\d)/4\\)");
private static final Map<BlockPos, BooleanBooleanMutablePair> particlesMap = new HashMap<>();
- private static final Set<BlockPos> griffinBurrows = new HashSet<>();
+ private static final Object2LongMap<BlockPos> griffinBurrows = new Object2LongOpenHashMap<>();
+ @Nullable
+ private static BlockPos lastDugBurrowPos;
public static void init() {
WorldRenderEvents.AFTER_TRANSLUCENT.register(MythologicalRitual::render);
AttackBlockCallback.EVENT.register(MythologicalRitual::onAttackBlock);
- ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(
- literal(SkyblockerMod.NAMESPACE).then(literal("diana").then(literal("clearGriffinBurrows").executes(context -> {
+ UseBlockCallback.EVENT.register(MythologicalRitual::onUseBlock);
+ ClientReceiveMessageEvents.GAME.register(MythologicalRitual::onChatMessage);
+ ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(literal(SkyblockerMod.NAMESPACE).then(literal("diana")
+ .then(literal("clearGriffinBurrows").executes(context -> {
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;
+ }))))));
}
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());
+ 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.add(pos);
+ if (particlesAtPos.leftBoolean() && particlesAtPos.rightBoolean() && griffinBurrows.getLong(pos) + 1000 < System.currentTimeMillis()) {
+ griffinBurrows.put(pos, 0);
}
}
}
public static void render(WorldRenderContext context) {
if (isActive()) {
- for (BlockPos griffinBorrow : griffinBurrows) {
- RenderHelper.renderFilledThroughWallsWithBeaconBeam(context, griffinBorrow, DyeColor.GREEN.getColorComponents(), 0.5F);
+ for (Object2LongMap.Entry<BlockPos> griffinBorrow : griffinBurrows.object2LongEntrySet()) {
+ if (griffinBorrow.getLongValue() <= 0) {
+ RenderHelper.renderFilledThroughWallsWithBeaconBeam(context, griffinBorrow.getKey(), DyeColor.GREEN.getColorComponents(), 0.5F);
+ }
}
}
}
public static ActionResult onAttackBlock(PlayerEntity player, World world, Hand hand, BlockPos pos, Direction direction) {
- if (isActive()) {
- griffinBurrows.remove(pos);
+ return onInteractBlock(pos);
+ }
+
+ public static ActionResult onUseBlock(PlayerEntity player, World world, Hand hand, BlockHitResult hitResult) {
+ return onInteractBlock(hitResult.getBlockPos());
+ }
+
+ @NotNull
+ private static ActionResult onInteractBlock(BlockPos pos) {
+ if (isActive() && griffinBurrows.containsKey(pos)) {
+ lastDugBurrowPos = pos;
}
return ActionResult.PASS;
}
+ public static void onChatMessage(Text message, boolean overlay) {
+ if (isActive() && GRIFFIN_BURROW_DUG.matcher(message.getString()).matches()) {
+ griffinBurrows.put(lastDugBurrowPos, System.currentTimeMillis());
+ }
+ }
+
private static boolean isActive() {
- return SkyblockerConfig.get().general.fairySouls.enableFairySoulsHelper && Utils.getLocationRaw().equals("hub") ; // TODO Change to actual config option
+ return SkyblockerConfig.get().general.fairySouls.enableFairySoulsHelper && Utils.getLocationRaw().equals("hub"); // TODO Change to actual config option
}
}