-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #747 from olim88/Dojo-helper
Dojo helper
- Loading branch information
Showing
18 changed files
with
1,144 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/java/de/hysky/skyblocker/mixins/ClientWorldMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
22
src/main/java/de/hysky/skyblocker/mixins/PingMeasurerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/ControlTestHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DisciplineTestHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.