Skip to content
This repository has been archived by the owner on Sep 24, 2024. It is now read-only.

Commit

Permalink
Full crash fix with ThunderHack Recode
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekiplay committed Feb 23, 2024
1 parent a71c1f0 commit 9056db8
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 14 deletions.
57 changes: 51 additions & 6 deletions src/main/java/nekiplay/meteorplus/features/modules/NoSlowPlus.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,53 @@ public NoSlowPlus() {
super(MeteorPlusAddon.CATEGORY, "no-slow+", "Remove or increase slowness.");
}


public SettingGroup usingItemGroup = settings.createGroup("Using item");
public SettingGroup sneakGroup = settings.createGroup("Sneak");
public SettingGroup defaultGroup = settings.getDefaultGroup();

private final Setting<Double> forward = defaultGroup.add(new DoubleSetting.Builder()
.name("Forward multiplier")
private final Setting<Double> usingForward = usingItemGroup.add(new DoubleSetting.Builder()
.name("forward-multiplier")
.defaultValue(1)
.min(0.2)
.sliderRange(0.2, 1)
.build()
);

private final Setting<Double> usingSideways = usingItemGroup.add(new DoubleSetting.Builder()
.name("sideways-multiplier")
.defaultValue(1)
.min(0.2)
.sliderRange(0.2, 1)
.build()
);

private final Setting<Double> sneakForward = sneakGroup.add(new DoubleSetting.Builder()
.name("forward-multiplier")
.defaultValue(1)
.min(0.2)
.sliderRange(0.2, 1)
.build()
);

private final Setting<Double> sneakSideways = sneakGroup.add(new DoubleSetting.Builder()
.name("sideways-multiplier")
.defaultValue(1)
.min(0.2)
.sliderRange(0.2, 1)
.build()
);

private final Setting<Double> otherForward = defaultGroup.add(new DoubleSetting.Builder()
.name("forward-multiplier")
.defaultValue(1)
.min(0.2)
.sliderRange(0.2, 1)
.build()
);

private final Setting<Double> sideways = defaultGroup.add(new DoubleSetting.Builder()
.name("Sideways multiplier")
private final Setting<Double> otherSideways = defaultGroup.add(new DoubleSetting.Builder()
.name("sideways-multiplier")
.defaultValue(1)
.min(0.2)
.sliderRange(0.2, 1)
Expand All @@ -33,7 +68,17 @@ public NoSlowPlus() {

@EventHandler
private void onUse(PlayerUseMultiplier event) {
event.setForward(forward.get().floatValue());
event.setSideways(sideways.get().floatValue());
if (mc.player.isUsingItem()) {
event.setForward(usingForward.get().floatValue());
event.setSideways(usingSideways.get().floatValue());
}
if (mc.player.isSneaking()) {
event.setForward(sneakForward.get().floatValue());
event.setSideways(sneakSideways.get().floatValue());
}
else {
event.setForward(otherForward.get().floatValue());
event.setSideways(otherSideways.get().floatValue());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,38 @@
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(value = ClientPlayerEntity.class, priority = 1001)
public class ClientPlayerEntityMixin {
@Shadow
public Input input;
@Inject(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isUsingItem()Z", ordinal = 0))
private void hookCustomMultiplier(CallbackInfo ci) {
final PlayerUseMultiplier playerUseMultiplier = new PlayerUseMultiplier(0.2f, 0.2f);
MeteorClient.EVENT_BUS.post(playerUseMultiplier);
if (playerUseMultiplier.getForward() == 0.2f && playerUseMultiplier.getSideways() == 0.2f) {
return;
}

final Input input = this.input;
// reverse
input.movementForward /= 0.2f;
input.movementSideways /= 0.2f;

// then
final PlayerUseMultiplier playerUseMultiplier = new PlayerUseMultiplier(0.2f, 0.2f);
MeteorClient.EVENT_BUS.post(playerUseMultiplier);
input.movementForward *= playerUseMultiplier.getForward();
input.movementSideways *= playerUseMultiplier.getSideways();
}

/**
* Hook sprint effect from NoSlow module
*/
@Redirect(method = "canStartSprinting", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isUsingItem()Z"))
private boolean hookSprintAffectStart(ClientPlayerEntity playerEntity) {
@Inject(method = "canStartSprinting", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isUsingItem()Z"), cancellable = true)
private void hookSprintAffectStart(CallbackInfoReturnable<Boolean> cir) {
if (Modules.get().get(NoSlowPlus.class).isActive()) {
return false;
cir.setReturnValue(true);
}

return playerEntity.isUsingItem();
}
}

0 comments on commit 9056db8

Please sign in to comment.