fix crashing bug

This commit is contained in:
MeexReay 2023-05-30 21:31:13 +03:00
parent 4dfd0f8aba
commit 887bcd2221
6 changed files with 208 additions and 136 deletions

View File

@ -9,7 +9,7 @@ yarn_mappings=1.19.3+build.1
loader_version=0.14.17 loader_version=0.14.17
# Mod Properties # Mod Properties
mod_version = 1.0.1 mod_version = 1.0.2
maven_group = themixray.repeating.mod maven_group = themixray.repeating.mod
archives_base_name = repeating-mod archives_base_name = repeating-mod

View File

@ -122,6 +122,82 @@ public class RepeatingMod implements ClientModInitializer {
last_record = now; last_record = now;
} }
public void recordAllInput() {
RecordInputEvent l = ((RecordInputEvent)getLastRecord("input"));
if (l == null) {
RecordInputEvent e = new RecordInputEvent(
client.player.input.sneaking,
client.player.input.jumping,
client.player.input.movementSideways,
client.player.input.movementForward,
client.player.input.pressingForward,
client.player.input.pressingBack,
client.player.input.pressingLeft,
client.player.input.pressingRight,
client.player.getHeadYaw(),
client.player.getBodyYaw(),
client.player.getPitch(),
client.player.isSprinting(),
client.player.getYaw());
recordTick(e);
} else {
RecordInputEvent e = new RecordInputEvent(
((Boolean) client.player.input.sneaking == l.sneaking) ? null : client.player.input.sneaking,
((Boolean) client.player.input.jumping == l.jumping) ? null : client.player.input.jumping,
(((Float) client.player.input.movementSideways).equals(l.movementSideways)) ? null : client.player.input.movementSideways,
(((Float) client.player.input.movementForward).equals(l.movementForward)) ? null : client.player.input.movementForward,
((Boolean) client.player.input.pressingForward == l.pressingForward) ? null : client.player.input.pressingForward,
((Boolean) client.player.input.pressingBack == l.pressingBack) ? null : client.player.input.pressingBack,
((Boolean) client.player.input.pressingLeft == l.pressingLeft) ? null : client.player.input.pressingLeft,
((Boolean) client.player.input.pressingRight == l.pressingRight) ? null : client.player.input.pressingRight,
client.player.getHeadYaw(),RepeatingMod.client.player.getBodyYaw(),client.player.getPitch(),
((Boolean) client.player.isSprinting() == l.sprinting) ? null : client.player.isSprinting(),
client.player.getYaw());
if (!(e.isEmpty() &&
e.yaw == l.yaw &&
e.head_yaw == l.head_yaw &&
e.pitch == l.pitch &&
e.body_yaw == l.body_yaw)) {
e.fillEmpty(l);
recordTick(e);
}
}
}
public void recordCameraInput() {
RecordInputEvent l = ((RecordInputEvent)getLastRecord("input"));
if (l == null) {
RecordInputEvent e = new RecordInputEvent(
client.player.input.sneaking,
client.player.input.jumping,
client.player.input.movementSideways,
client.player.input.movementForward,
client.player.input.pressingForward,
client.player.input.pressingBack,
client.player.input.pressingLeft,
client.player.input.pressingRight,
client.player.getHeadYaw(),
client.player.getBodyYaw(),
client.player.getPitch(),
client.player.isSprinting(),
client.player.getYaw());
recordTick(e);
} else {
RecordInputEvent e = new RecordInputEvent(null,null,null,null,
null,null,null,null,client.player.getHeadYaw(),
RepeatingMod.client.player.getBodyYaw(),client.player.getPitch(),null,client.player.getYaw());
if (!(e.yaw == l.yaw &&
e.head_yaw == l.head_yaw &&
e.pitch == l.pitch &&
e.body_yaw == l.body_yaw)) {
e.fillEmpty(l);
recordTick(e);
}
}
}
public void stopRecording() { public void stopRecording() {
is_recording = false; is_recording = false;
menu.update_btns(); menu.update_btns();
@ -323,6 +399,18 @@ public class RepeatingMod implements ClientModInitializer {
this.yaw = yaw; this.yaw = yaw;
} }
public void fillEmpty(RecordInputEvent e) {
if (sneaking == null) sneaking = e.sneaking;
if (jumping == null) jumping = e.jumping;
if (movementSideways == null) movementSideways = e.movementSideways;
if (movementForward == null) movementForward = e.movementForward;
if (pressingForward == null) pressingForward = e.pressingForward;
if (pressingBack == null) pressingBack = e.pressingBack;
if (pressingLeft == null) pressingLeft = e.pressingLeft;
if (pressingRight == null) pressingRight = e.pressingRight;
if (sprinting == null) sprinting = e.sprinting;
}
public boolean isEmpty() { public boolean isEmpty() {
return sneaking == null && return sneaking == null &&
jumping == null && jumping == null &&
@ -340,19 +428,32 @@ public class RepeatingMod implements ClientModInitializer {
} }
public void inputCallback() { public void inputCallback() {
if (sneaking != null) if (client.player.input.sneaking != sneaking) client.player.input.sneaking = sneaking; if (sprinting != null && client.player.isSprinting() != sprinting)
if (jumping != null) if (client.player.input.jumping != jumping) client.player.input.jumping = jumping; client.player.setSprinting(sprinting);
if (movementSideways != null) if (client.player.input.movementSideways != movementSideways) client.player.input.movementSideways = movementSideways; if (client.player.getYaw() != yaw)
if (movementForward != null) if (client.player.input.movementForward != movementForward) client.player.input.movementForward = movementForward; client.player.setYaw(yaw);
if (pressingForward != null) if (client.player.input.pressingForward != pressingForward) client.player.input.pressingForward = pressingForward; if (client.player.getHeadYaw() != head_yaw)
if (pressingBack != null) if (client.player.input.pressingBack != pressingBack) client.player.input.pressingBack = pressingBack; client.player.setHeadYaw(head_yaw);
if (pressingLeft != null) if (client.player.input.pressingLeft != pressingLeft) client.player.input.pressingLeft = pressingLeft; if (client.player.getBodyYaw() != body_yaw)
if (pressingRight != null) if (client.player.input.pressingRight != pressingRight) client.player.input.pressingRight = pressingRight; client.player.setBodyYaw(body_yaw);
if (sprinting != null) if (client.player.isSprinting() != sprinting) client.player.setSprinting(sprinting); if (client.player.getPitch() != pitch)
if (client.player.getYaw() != yaw) client.player.setYaw(yaw); client.player.setPitch(pitch);
if (client.player.getHeadYaw() != head_yaw) client.player.setHeadYaw(head_yaw); if (sneaking != null && client.player.input.sneaking != sneaking)
if (client.player.getBodyYaw() != body_yaw) client.player.setBodyYaw(body_yaw); client.player.input.sneaking = sneaking;
if (client.player.getPitch() != pitch) client.player.setPitch(pitch); if (jumping != null && client.player.input.jumping != jumping)
client.player.input.jumping = jumping;
if (movementSideways != null && client.player.input.movementSideways != movementSideways)
client.player.input.movementSideways = movementSideways;
if (movementForward != null && client.player.input.movementForward != movementForward)
client.player.input.movementForward = movementForward;
if (pressingForward != null && client.player.input.pressingForward != pressingForward)
client.player.input.pressingForward = pressingForward;
if (pressingBack != null && client.player.input.pressingBack != pressingBack)
client.player.input.pressingBack = pressingBack;
if (pressingLeft != null && client.player.input.pressingLeft != pressingLeft)
client.player.input.pressingLeft = pressingLeft;
if (pressingRight != null && client.player.input.pressingRight != pressingRight)
client.player.input.pressingRight = pressingRight;
} }
public String toText() { public String toText() {
@ -366,7 +467,7 @@ public class RepeatingMod implements ClientModInitializer {
((pressingLeft==null)?"n":(pressingLeft?"1":"0"))+"&"+ ((pressingLeft==null)?"n":(pressingLeft?"1":"0"))+"&"+
((pressingRight==null)?"n":(pressingRight?"1":"0"))+"&"+ ((pressingRight==null)?"n":(pressingRight?"1":"0"))+"&"+
head_yaw+"&"+body_yaw+"&"+ pitch +"&"+ head_yaw+"&"+body_yaw+"&"+ pitch +"&"+
((sprinting==null)?"n":(sprinting?"1":"0")); ((sprinting==null)?"n":(sprinting?"1":"0")+"&"+ yaw);
} }
public String getType() { public String getType() {
return "input"; return "input";

View File

@ -43,7 +43,7 @@ public class RepeatingScreen extends BaseOwoScreen<FlowLayout> {
rootComponent rootComponent
.surface(Surface.VANILLA_TRANSLUCENT) .surface(Surface.VANILLA_TRANSLUCENT)
.horizontalAlignment(HorizontalAlignment.CENTER) .horizontalAlignment(HorizontalAlignment.CENTER)
.verticalAlignment(VerticalAlignment.TOP); .verticalAlignment(VerticalAlignment.CENTER);
replay_btn = (ButtonComponent) Components.button(Text.of("replay"), replay_btn = (ButtonComponent) Components.button(Text.of("replay"),
(ButtonComponent btn) -> { (ButtonComponent btn) -> {
@ -75,6 +75,7 @@ public class RepeatingScreen extends BaseOwoScreen<FlowLayout> {
Sizing.fixed(120),Sizing.fixed(20)); Sizing.fixed(120),Sizing.fixed(20));
rootComponent.child( rootComponent.child(
Containers.horizontalFlow(Sizing.content(), Sizing.content()).child(
Containers.verticalFlow(Sizing.content(), Sizing.content()) Containers.verticalFlow(Sizing.content(), Sizing.content())
.child(Containers.verticalFlow(Sizing.content(), Sizing.content()) .child(Containers.verticalFlow(Sizing.content(), Sizing.content())
.child(Components.label(Text.translatable("text.repeating-mod.basic")).margins(Insets.of(1))) .child(Components.label(Text.translatable("text.repeating-mod.basic")).margins(Insets.of(1)))
@ -94,7 +95,7 @@ public class RepeatingScreen extends BaseOwoScreen<FlowLayout> {
for (int i = 0; i < mod.record.size(); i++) { for (int i = 0; i < mod.record.size(); i++) {
t += mod.record.get(i).toText(); t += mod.record.get(i).toText();
if (i != mod.record.size()-1) if (i != mod.record.size()-1)
t += ";"; t += "\n";
} }
File p = new File(FabricLoader.getInstance().getGameDir().toFile(),"repeating"); File p = new File(FabricLoader.getInstance().getGameDir().toFile(),"repeating");
@ -126,7 +127,7 @@ public class RepeatingScreen extends BaseOwoScreen<FlowLayout> {
return; return;
} }
String t = Files.readString(file.toPath()); String t = Files.readString(file.toPath());
for (String s:t.split(";")) for (String s:t.split("\n"))
mod.record.add(RepeatingMod.RecordEvent.fromText(s)); mod.record.add(RepeatingMod.RecordEvent.fromText(s));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -153,8 +154,8 @@ public class RepeatingScreen extends BaseOwoScreen<FlowLayout> {
.surface(Surface.DARK_PANEL) .surface(Surface.DARK_PANEL)
.verticalAlignment(VerticalAlignment.CENTER) .verticalAlignment(VerticalAlignment.CENTER)
.horizontalAlignment(HorizontalAlignment.CENTER) .horizontalAlignment(HorizontalAlignment.CENTER)
.margins(Insets.of(1))) .margins(Insets.of(1)))*/
).child( /*).child(
Containers.verticalFlow(Sizing.content(), Sizing.content()) Containers.verticalFlow(Sizing.content(), Sizing.content())
.child(Containers.verticalFlow(Sizing.content(), Sizing.content()) .child(Containers.verticalFlow(Sizing.content(), Sizing.content())
.child(Components.label(Text.translatable("text.repeating-mod.settings")).margins(Insets.of(1))) .child(Components.label(Text.translatable("text.repeating-mod.settings")).margins(Insets.of(1)))
@ -190,8 +191,8 @@ public class RepeatingScreen extends BaseOwoScreen<FlowLayout> {
.surface(Surface.DARK_PANEL) .surface(Surface.DARK_PANEL)
.verticalAlignment(VerticalAlignment.CENTER) .verticalAlignment(VerticalAlignment.CENTER)
.horizontalAlignment(HorizontalAlignment.CENTER) .horizontalAlignment(HorizontalAlignment.CENTER)
.margins(Insets.of(1)))*/ .margins(Insets.of(1)))
); )*/));
update_btns(); update_btns();
} }
} }

View File

@ -2,31 +2,17 @@ package themixray.repeating.mod.mixin;
import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents; import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents;
import net.fabricmc.fabric.api.event.player.UseBlockCallback; import net.fabricmc.fabric.api.event.player.UseBlockCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.entity.MovementType;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.hit.HitResult; import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.Vec3d;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import themixray.repeating.mod.RepeatingMod; import themixray.repeating.mod.RepeatingMod;
import java.util.Date;
@Mixin(ClientPlayerEntity.class) @Mixin(ClientPlayerEntity.class)
public abstract class MovementMixin { public abstract class MovementMixin {
public Vec3d lastVec = null;
@Shadow public abstract void sendMessage(Text message);
@Shadow @Final protected MinecraftClient client;
@Shadow public abstract float getYaw(float tickDelta);
@Shadow private float lastYaw;
@Shadow private float lastPitch;
@Inject(at = @At(value = "HEAD"), method = "init") @Inject(at = @At(value = "HEAD"), method = "init")
private void init(CallbackInfo ci) { private void init(CallbackInfo ci) {
@ -46,45 +32,7 @@ public abstract class MovementMixin {
@Inject(at = @At(value = "HEAD"), method = "tickMovement") @Inject(at = @At(value = "HEAD"), method = "tickMovement")
private void onMove(CallbackInfo ci) { private void onMove(CallbackInfo ci) {
if (RepeatingMod.me.is_recording) { if (RepeatingMod.me.is_recording) {
RepeatingMod.RecordInputEvent l = ((RepeatingMod.RecordInputEvent)RepeatingMod.me.getLastRecord("input")); RepeatingMod.me.recordAllInput();
if (l == null) {
RepeatingMod.RecordInputEvent e = new RepeatingMod.RecordInputEvent(
RepeatingMod.client.player.input.sneaking,
RepeatingMod.client.player.input.jumping,
RepeatingMod.client.player.input.movementSideways,
RepeatingMod.client.player.input.movementForward,
RepeatingMod.client.player.input.pressingForward,
RepeatingMod.client.player.input.pressingBack,
RepeatingMod.client.player.input.pressingLeft,
RepeatingMod.client.player.input.pressingRight,
RepeatingMod.client.player.getHeadYaw(),
RepeatingMod.client.player.getBodyYaw(),
RepeatingMod.client.player.getPitch(),
RepeatingMod.client.player.isSprinting(),
RepeatingMod.client.player.getYaw());
RepeatingMod.me.recordTick(e);
} else {
RepeatingMod.RecordInputEvent e = new RepeatingMod.RecordInputEvent(
((Boolean) RepeatingMod.client.player.input.sneaking == l.sneaking) ? null : RepeatingMod.client.player.input.sneaking,
((Boolean) RepeatingMod.client.player.input.jumping == l.jumping) ? null : RepeatingMod.client.player.input.jumping,
(((Float) RepeatingMod.client.player.input.movementSideways).equals(l.movementSideways)) ? null : RepeatingMod.client.player.input.movementSideways,
(((Float) RepeatingMod.client.player.input.movementForward).equals(l.movementForward)) ? null : RepeatingMod.client.player.input.movementForward,
((Boolean) RepeatingMod.client.player.input.pressingForward == l.pressingForward) ? null : RepeatingMod.client.player.input.pressingForward,
((Boolean) RepeatingMod.client.player.input.pressingBack == l.pressingBack) ? null : RepeatingMod.client.player.input.pressingBack,
((Boolean) RepeatingMod.client.player.input.pressingLeft == l.pressingLeft) ? null : RepeatingMod.client.player.input.pressingLeft,
((Boolean) RepeatingMod.client.player.input.pressingRight == l.pressingRight) ? null : RepeatingMod.client.player.input.pressingRight,
RepeatingMod.client.player.getHeadYaw(),RepeatingMod.client.player.getBodyYaw(),RepeatingMod.client.player.getPitch(),
((Boolean) RepeatingMod.client.player.isSprinting() == l.sprinting) ? null : RepeatingMod.client.player.isSprinting(),
RepeatingMod.client.player.getYaw());
if (!(e.isEmpty() &&
e.yaw == l.yaw &&
e.head_yaw == l.head_yaw &&
e.pitch == l.pitch &&
e.body_yaw == l.body_yaw)) {
RepeatingMod.me.recordTick(e);
}
}
} }
} }
@ -95,6 +43,7 @@ public abstract class MovementMixin {
RepeatingMod.input_replay.sprinting != null && RepeatingMod.input_replay.sprinting != null &&
RepeatingMod.input_replay.sprinting != sprinting) { RepeatingMod.input_replay.sprinting != sprinting) {
ci.cancel(); ci.cancel();
return;
} }
} }
} }

View File

@ -0,0 +1,21 @@
package themixray.repeating.mod.mixin;
import net.minecraft.client.input.KeyboardInput;
import net.minecraft.client.render.GameRenderer;
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;
import themixray.repeating.mod.RepeatingMod;
@Mixin(GameRenderer.class)
public abstract class RendererMixin {
@Inject(at = @At(value = "TAIL"), method = "tick")
private void onTickTail(CallbackInfo ci) {
if (RepeatingMod.me.is_replaying) {
if (RepeatingMod.input_replay != null) {
RepeatingMod.me.recordCameraInput();
}
}
}
}

View File

@ -4,7 +4,7 @@
"version": "${version}", "version": "${version}",
"name": "Repeating Mod", "name": "Repeating Mod",
"description": "Mod that repeats your actions. ", "description": "Mod that repeats your recorded actions. ",
"authors": [ "authors": [
"TheMixRay" "TheMixRay"
], ],