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
# Mod Properties
mod_version = 1.0.1
mod_version = 1.0.2
maven_group = themixray.repeating.mod
archives_base_name = repeating-mod

View File

@ -122,6 +122,82 @@ public class RepeatingMod implements ClientModInitializer {
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() {
is_recording = false;
menu.update_btns();
@ -323,6 +399,18 @@ public class RepeatingMod implements ClientModInitializer {
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() {
return sneaking == null &&
jumping == null &&
@ -340,19 +428,32 @@ public class RepeatingMod implements ClientModInitializer {
}
public void inputCallback() {
if (sneaking != null) if (client.player.input.sneaking != sneaking) client.player.input.sneaking = sneaking;
if (jumping != null) if (client.player.input.jumping != jumping) client.player.input.jumping = jumping;
if (movementSideways != null) if (client.player.input.movementSideways != movementSideways) client.player.input.movementSideways = movementSideways;
if (movementForward != null) if (client.player.input.movementForward != movementForward) client.player.input.movementForward = movementForward;
if (pressingForward != null) if (client.player.input.pressingForward != pressingForward) client.player.input.pressingForward = pressingForward;
if (pressingBack != null) if (client.player.input.pressingBack != pressingBack) client.player.input.pressingBack = pressingBack;
if (pressingLeft != null) if (client.player.input.pressingLeft != pressingLeft) client.player.input.pressingLeft = pressingLeft;
if (pressingRight != null) if (client.player.input.pressingRight != pressingRight) client.player.input.pressingRight = pressingRight;
if (sprinting != null) if (client.player.isSprinting() != sprinting) client.player.setSprinting(sprinting);
if (client.player.getYaw() != yaw) client.player.setYaw(yaw);
if (client.player.getHeadYaw() != head_yaw) client.player.setHeadYaw(head_yaw);
if (client.player.getBodyYaw() != body_yaw) client.player.setBodyYaw(body_yaw);
if (client.player.getPitch() != pitch) client.player.setPitch(pitch);
if (sprinting != null && client.player.isSprinting() != sprinting)
client.player.setSprinting(sprinting);
if (client.player.getYaw() != yaw)
client.player.setYaw(yaw);
if (client.player.getHeadYaw() != head_yaw)
client.player.setHeadYaw(head_yaw);
if (client.player.getBodyYaw() != body_yaw)
client.player.setBodyYaw(body_yaw);
if (client.player.getPitch() != pitch)
client.player.setPitch(pitch);
if (sneaking != null && client.player.input.sneaking != sneaking)
client.player.input.sneaking = sneaking;
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() {
@ -366,7 +467,7 @@ public class RepeatingMod implements ClientModInitializer {
((pressingLeft==null)?"n":(pressingLeft?"1":"0"))+"&"+
((pressingRight==null)?"n":(pressingRight?"1":"0"))+"&"+
head_yaw+"&"+body_yaw+"&"+ pitch +"&"+
((sprinting==null)?"n":(sprinting?"1":"0"));
((sprinting==null)?"n":(sprinting?"1":"0")+"&"+ yaw);
}
public String getType() {
return "input";

View File

@ -43,7 +43,7 @@ public class RepeatingScreen extends BaseOwoScreen<FlowLayout> {
rootComponent
.surface(Surface.VANILLA_TRANSLUCENT)
.horizontalAlignment(HorizontalAlignment.CENTER)
.verticalAlignment(VerticalAlignment.TOP);
.verticalAlignment(VerticalAlignment.CENTER);
replay_btn = (ButtonComponent) Components.button(Text.of("replay"),
(ButtonComponent btn) -> {
@ -75,69 +75,70 @@ public class RepeatingScreen extends BaseOwoScreen<FlowLayout> {
Sizing.fixed(120),Sizing.fixed(20));
rootComponent.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)))
.padding(Insets.of(5))
.surface(Surface.DARK_PANEL)
.verticalAlignment(VerticalAlignment.CENTER)
.horizontalAlignment(HorizontalAlignment.CENTER)
.margins(Insets.of(1)))
.child(Containers.verticalFlow(Sizing.content(), Sizing.content())
.child(Containers.horizontalFlow(Sizing.content(), Sizing.content())
.child(replay_btn).child(loop_btn))
.child(record_btn)
.child(Components.button(Text.translatable(
"text.repeating-mod.export"),
(ButtonComponent btn) -> {
String t = "";
for (int i = 0; i < mod.record.size(); i++) {
t += mod.record.get(i).toText();
if (i != mod.record.size()-1)
t += ";";
}
File p = new File(FabricLoader.getInstance().getGameDir().toFile(),"repeating");
if (!p.exists()) p.mkdir();
File file = new File(p,"export.txt");
try {
if (!file.exists()) file.createNewFile();
Files.write(file.toPath(), t.getBytes());
Runtime.getRuntime().exec("explorer /select,\""+file.getAbsolutePath()+"\"");
} catch (Exception e) {
e.printStackTrace();
}
}).margins(Insets.of(10,1,1,1)).sizing(
Sizing.fixed(120),Sizing.fixed(20)))
.child(Components.button(Text.translatable(
"text.repeating-mod.import"),
(ButtonComponent btn) -> {
mod.record.clear();
File p = new File(FabricLoader.getInstance().getGameDir().toFile(),"repeating");
if (!p.exists()) p.mkdir();
File file = new File(p,"import.txt");
try {
if (!file.exists()) {
file.createNewFile();
Runtime.getRuntime().exec("explorer /select,\""+file.getAbsolutePath()+"\"");
return;
Containers.horizontalFlow(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)))
.padding(Insets.of(5))
.surface(Surface.DARK_PANEL)
.verticalAlignment(VerticalAlignment.CENTER)
.horizontalAlignment(HorizontalAlignment.CENTER)
.margins(Insets.of(1)))
.child(Containers.verticalFlow(Sizing.content(), Sizing.content())
.child(Containers.horizontalFlow(Sizing.content(), Sizing.content())
.child(replay_btn).child(loop_btn))
.child(record_btn)
.child(Components.button(Text.translatable(
"text.repeating-mod.export"),
(ButtonComponent btn) -> {
String t = "";
for (int i = 0; i < mod.record.size(); i++) {
t += mod.record.get(i).toText();
if (i != mod.record.size()-1)
t += "\n";
}
String t = Files.readString(file.toPath());
for (String s:t.split(";"))
mod.record.add(RepeatingMod.RecordEvent.fromText(s));
} catch (Exception e) {
e.printStackTrace();
}
}).margins(Insets.of(1)).sizing(
Sizing.fixed(120),Sizing.fixed(20)))
.padding(Insets.of(10))
.surface(Surface.DARK_PANEL)
.verticalAlignment(VerticalAlignment.CENTER)
.horizontalAlignment(HorizontalAlignment.CENTER)
.margins(Insets.of(1)))
File p = new File(FabricLoader.getInstance().getGameDir().toFile(),"repeating");
if (!p.exists()) p.mkdir();
File file = new File(p,"export.txt");
try {
if (!file.exists()) file.createNewFile();
Files.write(file.toPath(), t.getBytes());
Runtime.getRuntime().exec("explorer /select,\""+file.getAbsolutePath()+"\"");
} catch (Exception e) {
e.printStackTrace();
}
}).margins(Insets.of(10,1,1,1)).sizing(
Sizing.fixed(120),Sizing.fixed(20)))
.child(Components.button(Text.translatable(
"text.repeating-mod.import"),
(ButtonComponent btn) -> {
mod.record.clear();
File p = new File(FabricLoader.getInstance().getGameDir().toFile(),"repeating");
if (!p.exists()) p.mkdir();
File file = new File(p,"import.txt");
try {
if (!file.exists()) {
file.createNewFile();
Runtime.getRuntime().exec("explorer /select,\""+file.getAbsolutePath()+"\"");
return;
}
String t = Files.readString(file.toPath());
for (String s:t.split("\n"))
mod.record.add(RepeatingMod.RecordEvent.fromText(s));
} catch (Exception e) {
e.printStackTrace();
}
}).margins(Insets.of(1)).sizing(
Sizing.fixed(120),Sizing.fixed(20)))
.padding(Insets.of(10))
.surface(Surface.DARK_PANEL)
.verticalAlignment(VerticalAlignment.CENTER)
.horizontalAlignment(HorizontalAlignment.CENTER)
.margins(Insets.of(1)))
/*).child(
Containers.verticalFlow(Sizing.content(), Sizing.content())
.child(Containers.verticalFlow(Sizing.content(), Sizing.content())
@ -153,8 +154,8 @@ public class RepeatingScreen extends BaseOwoScreen<FlowLayout> {
.surface(Surface.DARK_PANEL)
.verticalAlignment(VerticalAlignment.CENTER)
.horizontalAlignment(HorizontalAlignment.CENTER)
.margins(Insets.of(1)))
).child(
.margins(Insets.of(1)))*/
/*).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)))
@ -190,8 +191,8 @@ public class RepeatingScreen extends BaseOwoScreen<FlowLayout> {
.surface(Surface.DARK_PANEL)
.verticalAlignment(VerticalAlignment.CENTER)
.horizontalAlignment(HorizontalAlignment.CENTER)
.margins(Insets.of(1)))*/
);
.margins(Insets.of(1)))
)*/));
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.UseBlockCallback;
import net.minecraft.client.MinecraftClient;
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.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.Shadow;
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;
import java.util.Date;
@Mixin(ClientPlayerEntity.class)
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")
private void init(CallbackInfo ci) {
@ -46,45 +32,7 @@ public abstract class MovementMixin {
@Inject(at = @At(value = "HEAD"), method = "tickMovement")
private void onMove(CallbackInfo ci) {
if (RepeatingMod.me.is_recording) {
RepeatingMod.RecordInputEvent l = ((RepeatingMod.RecordInputEvent)RepeatingMod.me.getLastRecord("input"));
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);
}
}
RepeatingMod.me.recordAllInput();
}
}
@ -95,6 +43,7 @@ public abstract class MovementMixin {
RepeatingMod.input_replay.sprinting != null &&
RepeatingMod.input_replay.sprinting != sprinting) {
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}",
"name": "Repeating Mod",
"description": "Mod that repeats your actions. ",
"description": "Mod that repeats your recorded actions. ",
"authors": [
"TheMixRay"
],