Skip to content

Commit

Permalink
fix crashing bug
Browse files Browse the repository at this point in the history
  • Loading branch information
MeexReay committed May 30, 2023
1 parent 4dfd0f8 commit 887bcd2
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 132 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
129 changes: 115 additions & 14 deletions src/main/java/themixray/repeating/mod/RepeatingMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,82 @@ public void recordTick(RecordEvent e) {
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();
Expand Down Expand Up @@ -323,6 +399,18 @@ public RecordInputEvent(Boolean sneaking,
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 &&
Expand All @@ -340,19 +428,32 @@ public void callback() {
}

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() {
Expand All @@ -366,7 +467,7 @@ public String toText() {
((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";
Expand Down
127 changes: 64 additions & 63 deletions src/main/java/themixray/repeating/mod/RepeatingScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected void build(FlowLayout rootComponent) {
rootComponent
.surface(Surface.VANILLA_TRANSLUCENT)
.horizontalAlignment(HorizontalAlignment.CENTER)
.verticalAlignment(VerticalAlignment.TOP);
.verticalAlignment(VerticalAlignment.CENTER);

replay_btn = (ButtonComponent) Components.button(Text.of("replay"),
(ButtonComponent btn) -> {
Expand Down Expand Up @@ -75,69 +75,70 @@ protected void build(FlowLayout rootComponent) {
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 += ";";
}
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";
}

File p = new File(FabricLoader.getInstance().getGameDir().toFile(),"repeating");
if (!p.exists()) p.mkdir();
File file = new File(p,"export.txt");
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();
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");
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;
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();
}
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)))
}).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())
Expand All @@ -153,8 +154,8 @@ protected void build(FlowLayout rootComponent) {
.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)))
Expand Down Expand Up @@ -190,8 +191,8 @@ protected void build(FlowLayout rootComponent) {
.surface(Surface.DARK_PANEL)
.verticalAlignment(VerticalAlignment.CENTER)
.horizontalAlignment(HorizontalAlignment.CENTER)
.margins(Insets.of(1)))*/
);
.margins(Insets.of(1)))
)*/));
update_btns();
}
}
Loading

0 comments on commit 887bcd2

Please sign in to comment.