Skip to content

Commit

Permalink
Merge pull request #747 from olim88/Dojo-helper
Browse files Browse the repository at this point in the history
Dojo helper
  • Loading branch information
kevinthegreat1 authored Jul 5, 2024
2 parents 1a74c70 + 4f2c569 commit fbf7f62
Show file tree
Hide file tree
Showing 18 changed files with 1,144 additions and 1 deletion.
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 @@ -11,6 +11,7 @@
import de.hysky.skyblocker.skyblock.chat.ChatRulesHandler;
import de.hysky.skyblocker.skyblock.chocolatefactory.EggFinder;
import de.hysky.skyblocker.skyblock.chocolatefactory.TimeTowerReminder;
import de.hysky.skyblocker.skyblock.crimson.dojo.DojoManager;
import de.hysky.skyblocker.skyblock.crimson.kuudra.Kuudra;
import de.hysky.skyblocker.skyblock.dungeon.*;
import de.hysky.skyblocker.skyblock.dungeon.partyfinder.PartyFinderScreen;
Expand Down Expand Up @@ -181,6 +182,7 @@ public void onInitializeClient() {
ApiUtils.init();
Debug.init();
Kuudra.init();
DojoManager.init();
RenderHelper.init();
FancyStatusBars.init();
EventNotifications.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,68 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
.controller(IntegerFieldControllerBuilder::create)
.build())
.build())
.build();
//dojo
.group(OptionGroup.createBuilder()
.name(Text.translatable("skyblocker.crimson.dojo"))
.collapsed(false)
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.crimson.dojo.forceHelper"))
.description(OptionDescription.of(Text.translatable("skyblocker.crimson.dojo.forceHelper.@Tooltip")))
.binding(config.crimsonIsle.dojo.enableForceHelper,
() -> config.crimsonIsle.dojo.enableForceHelper,
newValue -> config.crimsonIsle.dojo.enableForceHelper = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.crimson.dojo.staminaHelper"))
.description(OptionDescription.of(Text.translatable("skyblocker.crimson.dojo.staminaHelper.@Tooltip")))
.binding(config.crimsonIsle.dojo.enableStaminaHelper,
() -> config.crimsonIsle.dojo.enableStaminaHelper,
newValue -> config.crimsonIsle.dojo.enableStaminaHelper = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.crimson.dojo.masteryHelper"))
.description(OptionDescription.of(Text.translatable("skyblocker.crimson.dojo.masteryHelper.@Tooltip")))
.binding(config.crimsonIsle.dojo.enableMasteryHelper,
() -> config.crimsonIsle.dojo.enableMasteryHelper,
newValue -> config.crimsonIsle.dojo.enableMasteryHelper = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.crimson.dojo.disciplineHelper"))
.description(OptionDescription.of(Text.translatable("skyblocker.crimson.dojo.disciplineHelper.@Tooltip")))
.binding(config.crimsonIsle.dojo.enableDisciplineHelper,
() -> config.crimsonIsle.dojo.enableDisciplineHelper,
newValue -> config.crimsonIsle.dojo.enableDisciplineHelper = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.crimson.dojo.swiftnessHelper"))
.description(OptionDescription.of(Text.translatable("skyblocker.crimson.dojo.swiftnessHelper.@Tooltip")))
.binding(config.crimsonIsle.dojo.enableSwiftnessHelper,
() -> config.crimsonIsle.dojo.enableSwiftnessHelper,
newValue -> config.crimsonIsle.dojo.enableSwiftnessHelper = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.crimson.dojo.controlHelper"))
.description(OptionDescription.of(Text.translatable("skyblocker.crimson.dojo.controlHelper.@Tooltip")))
.binding(config.crimsonIsle.dojo.enableControlHelper,
() -> config.crimsonIsle.dojo.enableControlHelper,
newValue -> config.crimsonIsle.dojo.enableControlHelper = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.crimson.dojo.tenacityHelper"))
.description(OptionDescription.of(Text.translatable("skyblocker.crimson.dojo.tenacityHelper.@Tooltip")))
.binding(config.crimsonIsle.dojo.enableTenacityHelper,
() -> config.crimsonIsle.dojo.enableTenacityHelper,
newValue -> config.crimsonIsle.dojo.enableTenacityHelper = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.build())

.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ public class CrimsonIsleConfig {
@SerialEntry
public Kuudra kuudra = new Kuudra();

@SerialEntry
public Dojo dojo = new Dojo();


public static class Kuudra {
@SerialEntry
public boolean supplyWaypoints = true;
Expand All @@ -32,4 +36,27 @@ public static class Kuudra {
@SerialEntry
public int arrowPoisonThreshold = 32;
}

public static class Dojo {
@SerialEntry
public boolean enableForceHelper = true;

@SerialEntry
public boolean enableStaminaHelper = true;

@SerialEntry
public boolean enableMasteryHelper = true;

@SerialEntry
public boolean enableDisciplineHelper = true;

@SerialEntry
public boolean enableSwiftnessHelper = true;

@SerialEntry
public boolean enableControlHelper = true;

@SerialEntry
public boolean enableTenacityHelper = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import de.hysky.skyblocker.skyblock.CompactDamage;
import de.hysky.skyblocker.skyblock.FishingHelper;
import de.hysky.skyblocker.skyblock.chocolatefactory.EggFinder;
import de.hysky.skyblocker.skyblock.crimson.dojo.DojoManager;
import de.hysky.skyblocker.skyblock.dungeon.DungeonScore;
import de.hysky.skyblocker.skyblock.dungeon.secrets.DungeonManager;
import de.hysky.skyblocker.skyblock.end.BeaconHighlighter;
Expand Down Expand Up @@ -97,6 +98,7 @@ public abstract class ClientPlayNetworkHandlerMixin {
@Inject(method = "onParticle", at = @At("RETURN"))
private void skyblocker$onParticle(ParticleS2CPacket packet, CallbackInfo ci) {
MythologicalRitual.onParticle(packet);
DojoManager.onParticle(packet);
EnderNodes.onParticle(packet);
}

Expand Down
23 changes: 23 additions & 0 deletions src/main/java/de/hysky/skyblocker/mixins/ClientWorldMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package de.hysky.skyblocker.mixins;


import de.hysky.skyblocker.skyblock.crimson.dojo.DojoManager;
import de.hysky.skyblocker.utils.Utils;
import net.minecraft.block.BlockState;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.math.BlockPos;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ClientWorld.class)
public class ClientWorldMixin {

@Inject(method = "handleBlockUpdate", at = @At("RETURN"))
private void skyblocker$handleBlockUpdate(BlockPos pos, BlockState state, int flags, CallbackInfo ci) {
if (Utils.isInCrimson()) {
DojoManager.onBlockUpdate(pos.toImmutable(), state);
}
}
}
22 changes: 22 additions & 0 deletions src/main/java/de/hysky/skyblocker/mixins/PingMeasurerMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package de.hysky.skyblocker.mixins;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import de.hysky.skyblocker.skyblock.crimson.dojo.DojoManager;
import de.hysky.skyblocker.utils.Utils;
import net.minecraft.client.network.PingMeasurer;
import net.minecraft.util.profiler.MultiValueDebugSampleLogImpl;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(PingMeasurer.class)
public class PingMeasurerMixin {

@WrapOperation(method = "onPingResult", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/profiler/MultiValueDebugSampleLogImpl;push(J)V"))
private void skyblocker$onPingResult(MultiValueDebugSampleLogImpl log, long ping, Operation<Void> operation) {
if (Utils.isInCrimson()) {
DojoManager.onPingResult(ping);
}
operation.call(log, ping);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
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.WitherSkeletonEntity;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;

import java.awt.*;

public class ControlTestHelper {
private static final MinecraftClient CLIENT = MinecraftClient.getInstance();

private static WitherSkeletonEntity correctWitherSkeleton;
private static Vec3d lastPos;
private static long lastUpdate;
private static Vec3d pingOffset;
private static Vec3d lastPingOffset;

protected static void reset() {
correctWitherSkeleton = null;
lastPos = null;
lastUpdate = -1;
pingOffset = null;
lastPingOffset = null;
}

/**
* Find the correct WitherSkeleton entity when it spawns to start tracking it
*
* @param entity spawned entity
*/
protected static void onEntitySpawn(Entity entity) {
if (entity instanceof WitherSkeletonEntity witherSkeleton && correctWitherSkeleton == null) {
correctWitherSkeleton = witherSkeleton;
}
}

/**
* Finds where to look in 3 ticks effected by ping
*/
protected static void update() {
if (correctWitherSkeleton != null) {
//smoothly adjust the ping throughout the test
if (lastPos != null) {
lastPingOffset = pingOffset;
double ping = DojoManager.ping / 1000d;
//find distance between last position and current position of skeleton
Vec3d movementVector = correctWitherSkeleton.getPos().subtract(lastPos).multiply(1, 0.1, 1);
//adjust the vector to current ping (multiply by 1 + time in second until the next update offset by the players ping)
pingOffset = movementVector.multiply(1 + 3 / 20d + ping);
}
lastPos = correctWitherSkeleton.getPos();
lastUpdate = System.currentTimeMillis();
}
}

/**
* Renders an outline around where the player should aim (assumes values are updated every 3 ticks)
*
* @param context render context
*/
protected static void render(WorldRenderContext context) {
if (CLIENT.player != null && correctWitherSkeleton != null && pingOffset != null && lastPingOffset != null) {
float tickDelta = context.tickCounter().getTickDelta(false);
//how long until net update
double updatePercent = (double) (System.currentTimeMillis() - lastUpdate) / 150;
Vec3d aimPos = correctWitherSkeleton.getEyePos().add(pingOffset.multiply(updatePercent)).add(lastPingOffset.multiply(1 - updatePercent));
Box targetBox = new Box(aimPos.add(-0.5, -0.5, -0.5), aimPos.add(0.5, 0.5, 0.5));
boolean playerLookingAtBox = targetBox.raycast(CLIENT.player.getCameraPosVec(tickDelta), CLIENT.player.getCameraPosVec(tickDelta).add(CLIENT.player.getRotationVec(tickDelta).multiply(30))).isPresent();
float[] boxColor = playerLookingAtBox ? Color.GREEN.getColorComponents(new float[]{0, 0, 0}) : Color.LIGHT_GRAY.getColorComponents(new float[]{0, 0, 0});
RenderHelper.renderOutline(context, targetBox, boxColor, 3, true);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package de.hysky.skyblocker.skyblock.crimson.dojo;

import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntMaps;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import net.minecraft.client.MinecraftClient;

import java.util.Map;
import java.util.Objects;

public class DisciplineTestHelper {
private static final MinecraftClient CLIENT = MinecraftClient.getInstance();

/**
* Stores what sword is needed for the name of a zombie
*/
private static final Map<String, String> SWORD_TO_NAME_LOOKUP = Map.of(
"WOOD_SWORD", "Wood",
"IRON_SWORD", "Iron",
"GOLD_SWORD", "Gold",
"DIAMOND_SWORD", "Diamond"
);

/**
* Stores a color related to the color of the sword: wood = brown, iron = silver, gold = gold, diamond = cyan
*/
private static final Object2IntMap<String> SWORD_TO_COLOR_LOOKUP = Object2IntMaps.unmodifiable(new Object2IntOpenHashMap<>(Map.of(
"WOOD_SWORD", 0xa52a2a,
"IRON_SWORD", 0xc0c0c0,
"GOLD_SWORD", 0xffd700,
"DIAMOND_SWORD", 0x00ffff
)));

/**
* Works out if a zombie should glow based on its name and the currently held item by the player
*
* @param name name of the zombie to see if it should glow
* @return if the zombie should glow
*/
protected static boolean shouldGlow(String name) {
if (CLIENT == null || CLIENT.player == null) {
return false;
}
String heldId = CLIENT.player.getMainHandStack().getSkyblockId();
if (heldId == null) {
return false;
}
return Objects.equals(SWORD_TO_NAME_LOOKUP.get(heldId), name);
}

/**
* gets the color linked to the currently held sword for zombies to glow
*
* @return color linked to sword
*/
protected static int getColor() {
if (DojoManager.currentChallenge != DojoManager.DojoChallenges.DISCIPLINE || CLIENT == null || CLIENT.player == null) {
return 0;
}
String heldId = CLIENT.player.getMainHandStack().getSkyblockId();
if (heldId == null) {
return 0;
}
return SWORD_TO_COLOR_LOOKUP.getOrDefault(heldId, 0);
}
}
Loading

0 comments on commit fbf7f62

Please sign in to comment.