diff options
author | olim <bobq4582@gmail.com> | 2024-05-01 19:21:59 +0100 |
---|---|---|
committer | olim <bobq4582@gmail.com> | 2024-07-01 14:26:13 +0100 |
commit | d23f2f42e9fc57e06341a372c319fec54f510899 (patch) | |
tree | 9735f8f34112ef311a9b6e4cd1222e5b1b8ff5fa /src/main | |
parent | 654b66e62bdb63a2ef3dc9607c941027c6c07812 (diff) | |
download | Skyblocker-d23f2f42e9fc57e06341a372c319fec54f510899.tar.gz Skyblocker-d23f2f42e9fc57e06341a372c319fec54f510899.tar.bz2 Skyblocker-d23f2f42e9fc57e06341a372c319fec54f510899.zip |
clean up and fix force test
when mob is hit in force reset timer
Diffstat (limited to 'src/main')
3 files changed, 53 insertions, 13 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DojoManager.java b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DojoManager.java index 61a8d010..dd2df117 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DojoManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DojoManager.java @@ -7,11 +7,18 @@ import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents; 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.AttackEntityCallback; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket; import net.minecraft.network.packet.s2c.play.ParticleS2CPacket; import net.minecraft.text.Text; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.EntityHitResult; +import net.minecraft.world.World; import java.util.Arrays; import java.util.regex.Matcher; @@ -19,6 +26,7 @@ import java.util.regex.Pattern; public class DojoManager { + private static final MinecraftClient CLIENT = MinecraftClient.getInstance(); private static final String START_MESSAGE = "§e[NPC] §eMaster Tao§f: Ahhh, here we go! Let's get you into the Arena."; private static final Pattern TEST_OF_PATTERN = Pattern.compile("\\s+Test of (\\w+) OBJECTIVES"); private static final String CHALLENGE_FINISHED_REGEX = "\\s+CHALLENGE ((COMPLETED)|(FAILED))"; @@ -52,6 +60,7 @@ public class DojoManager { ClientPlayConnectionEvents.JOIN.register((_handler, _sender, _client) -> reset()); ClientEntityEvents.ENTITY_LOAD.register(DojoManager::onEntitySpawn); ClientEntityEvents.ENTITY_UNLOAD.register(DojoManager::onEntityDespawn); + AttackEntityCallback.EVENT.register(DojoManager::onEntityAttacked); } @@ -122,7 +131,11 @@ public class DojoManager { } } private static void onEntitySpawn(Entity entity, ClientWorld clientWorld) { - if (Utils.getLocation() != Location.CRIMSON_ISLE || !inArena) { + if (Utils.getLocation() != Location.CRIMSON_ISLE || !inArena || CLIENT == null || CLIENT.player == null) { + return; + } + //check close by + if (entity.distanceTo(CLIENT.player) > 50 || Math.abs(entity.getBlockY() - CLIENT.player.getBlockY()) > 5){ return; } switch (currentChallenge) { @@ -141,6 +154,16 @@ public class DojoManager { } } + private static ActionResult onEntityAttacked(PlayerEntity playerEntity, World world, Hand hand, Entity entity, EntityHitResult entityHitResult) { + if (Utils.getLocation() != Location.CRIMSON_ISLE || !inArena) { + return null; + } + switch (currentChallenge) { + case FORCE -> ForceTestHelper.onEntityAttacked(entity); + } + return ActionResult.PASS; + } + public static void onParticle(ParticleS2CPacket packet) { if (Utils.getLocation() != Location.CRIMSON_ISLE || !inArena) { return; diff --git a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/ForceTestHelper.java b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/ForceTestHelper.java index bf27ce1f..c709f64a 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/ForceTestHelper.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/ForceTestHelper.java @@ -2,9 +2,11 @@ package de.hysky.skyblocker.skyblock.crimson.dojo; import de.hysky.skyblocker.utils.render.RenderHelper; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; +import net.minecraft.client.MinecraftClient; import net.minecraft.entity.Entity; import net.minecraft.entity.mob.ZombieEntity; import net.minecraft.text.Text; +import net.minecraft.util.Formatting; import net.minecraft.util.math.Vec3d; import java.awt.*; @@ -36,9 +38,19 @@ public class ForceTestHelper { zombies.put(zombie, System.currentTimeMillis() + 10100); //they last for 10100 millis ish so this is the time they despawn } } + + protected static void onEntityAttacked(Entity entity) { + if (entity instanceof ZombieEntity zombie) { + if (zombies.containsKey(zombie)) { + zombies.put(zombie,System.currentTimeMillis() + 10100); //timer is reset when they are hit + } + } + } + protected static void onEntityDespawn(Entity entity) { if (entity instanceof ZombieEntity zombie) { zombies.remove(zombie); + } } @@ -46,9 +58,21 @@ public class ForceTestHelper { //render times long currentTime = System.currentTimeMillis(); for (Map.Entry<ZombieEntity, Long> zombie : zombies.entrySet()) { - float secondsTime = Math.max((zombie.getValue() - currentTime) / 1000f, 0); + float secondsTime = Math.max((zombie.getValue() - currentTime) / 1000f, 0); + + Text text; + if (secondsTime > 1) { + text = Text.literal(FORMATTER.format(secondsTime)).formatted(Formatting.GREEN); + } + else if (secondsTime > 0) { + text = Text.literal(FORMATTER.format(secondsTime)).formatted(Formatting.YELLOW); + } + else { + text = Text.literal("Soon").formatted(Formatting.RED); //todo translate + } + Vec3d lablePos = zombie.getKey().getEyePos(); - RenderHelper.renderText(context, Text.literal(FORMATTER.format(secondsTime)), lablePos, 1.5f, true); + RenderHelper.renderText(context, text, lablePos, 1.5f, true); } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/TenacityTestHelper.java b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/TenacityTestHelper.java index 3639c351..b2f99d2e 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/TenacityTestHelper.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/TenacityTestHelper.java @@ -17,7 +17,6 @@ import java.util.*; public class TenacityTestHelper { private static final MinecraftClient CLIENT = MinecraftClient.getInstance(); - private static final Map<ArmorStandEntity, Vec3d> fireBallsWithStartPos = new HashMap<>(); private static final Map<ArmorStandEntity, Vec3d> particleOffsets = new HashMap<>(); @@ -57,16 +56,10 @@ public class TenacityTestHelper { } public static void onEntitySpawn(Entity entity) { - if (CLIENT == null || CLIENT.player == null) { - return; - } if (entity instanceof ArmorStandEntity armorStand) { - Vec3d fireballPos = armorStand.getPos(); - Vec3d playerPos = armorStand.getPos(); - // they should be holding coal block but are not holding anything idk just check they are close enough to the player - if (fireballPos.distanceTo(playerPos) < 50 && Math.abs(fireballPos.y - playerPos.y) < 5){ - fireBallsWithStartPos.put(armorStand,armorStand.getPos()); - } + // they should be holding coal block but are not holding anything idk + fireBallsWithStartPos.put(armorStand,armorStand.getPos()); + } } |