fix easy config

This commit is contained in:
MeexReay 2023-05-31 12:22:28 +03:00
parent 629a44a27a
commit 51b68dd48f
6 changed files with 135 additions and 82 deletions

View File

@ -37,7 +37,6 @@ dependencies {
// include this if you don't want force your users to install owo // include this if you don't want force your users to install owo
// sentinel will warn them and give the option to download it automatically // sentinel will warn them and give the option to download it automatically
include "io.wispforest:owo-sentinel:${project.owo_version}" include "io.wispforest:owo-sentinel:${project.owo_version}"
modImplementation 'org.yaml:snakeyaml:2.0'
} }
base { base {

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.3 mod_version = 1.0.4
maven_group = themixray.repeating.mod maven_group = themixray.repeating.mod
archives_base_name = repeating-mod archives_base_name = repeating-mod

View File

@ -1,7 +1,5 @@
package themixray.repeating.mod; package themixray.repeating.mod;
import org.yaml.snakeyaml.Yaml;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
@ -12,14 +10,12 @@ import java.io.File;
public class EasyConfig { public class EasyConfig {
public final Path path; public final Path path;
public final File file; public final File file;
public Map<String,Object> data; public Map<String,String> data;
private Yaml yaml;
public EasyConfig(File f, Map<String,Object> def) { public EasyConfig(File f, Map<String,String> def) {
this.path = f.toPath(); this.path = f.toPath();
this.file = f; this.file = f;
this.data = new HashMap<>(); this.data = new HashMap<>();
this.yaml = new Yaml();
if (!file.exists()) { if (!file.exists()) {
try { try {
@ -32,22 +28,22 @@ public class EasyConfig {
reload(); reload();
for (Map.Entry<String,Object> m:def.entrySet()) for (Map.Entry<String,String> m:def.entrySet())
if (!data.containsKey(m.getKey())) if (!data.containsKey(m.getKey()))
data.put(m.getKey(),m.getValue()); data.put(m.getKey(),m.getValue());
save(); save();
} }
public EasyConfig(Path f, Map<String,Object> def) { public EasyConfig(Path f, Map<String,String> def) {
this(f.toFile(),def); this(f.toFile(),def);
} }
public EasyConfig(String parent,String child,Map<String,Object> def) { public EasyConfig(String parent,String child,Map<String,String> def) {
this(new File(parent,child),def); this(new File(parent,child),def);
} }
public EasyConfig(File parent,String child,Map<String,Object> def) { public EasyConfig(File parent,String child,Map<String,String> def) {
this(new File(parent,child),def); this(new File(parent,child),def);
} }
public EasyConfig(Path parent,String child,Map<String,Object> def) { public EasyConfig(Path parent,String child,Map<String,String> def) {
this(new File(parent.toFile(),child),def); this(new File(parent.toFile(),child),def);
} }
@ -74,14 +70,22 @@ public class EasyConfig {
write(data); write(data);
} }
private String toYaml(Map<String,Object> p) { private String toText(Map<String,String> p) {
return yaml.dump(p); String t = "";
for (Map.Entry<String,String> e:p.entrySet())
t += e.getKey() + "=" + e.getValue() + "\n";
return t;
} }
private Map<String,Object> toMap(String j) { private Map<String,String> toMap(String j) {
return (Map<String, Object>) yaml.load(j); Map<String,String> m = new HashMap<>();
for (String l:j.split("\n")) {
String s[] = l.split("=");
m.put(s[0],s[1]);
}
return m;
} }
private Map<String,Object> read() { private Map<String,String> read() {
try { try {
return toMap(Files.readString(path)); return toMap(Files.readString(path));
} catch (IOException e) { } catch (IOException e) {
@ -89,9 +93,9 @@ public class EasyConfig {
} }
return new HashMap<>(); return new HashMap<>();
} }
private void write(Map<String,Object> p) { private void write(Map<String,String> p) {
try { try {
Files.write(path, toYaml(p).getBytes()); Files.write(path, toText(p).getBytes());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -52,12 +52,12 @@ public class RepeatingMod implements ClientModInitializer {
LOGGER.info("Repeating mod initialized"); LOGGER.info("Repeating mod initialized");
me = this; me = this;
Map<String,Object> def = new HashMap<>(); Map<String,String> def = new HashMap<>();
def.put("record_pos_delay", (int) record_pos_delay); def.put("record_pos_delay", String.valueOf(record_pos_delay));
conf = new EasyConfig(loader.getConfigDir(),"repeating-mod.yml",def); conf = new EasyConfig(loader.getConfigDir(),"repeating-mod",def);
record_pos_delay = (Integer) conf.data.get("record_pos_delay"); record_pos_delay = Long.parseLong(conf.data.get("record_pos_delay"));
menu_key = KeyBindingHelper.registerKeyBinding(new KeyBinding( menu_key = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.repeating-mod.menu",InputUtil.Type.KEYSYM, "key.repeating-mod.menu",InputUtil.Type.KEYSYM,
@ -71,9 +71,8 @@ public class RepeatingMod implements ClientModInitializer {
menu = new RepeatingScreen(); menu = new RepeatingScreen();
ClientTickEvents.END_CLIENT_TICK.register(client -> { ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (menu_key.wasPressed()) { if (menu_key.wasPressed())
client.setScreen(menu); client.setScreen(menu);
}
if (toggle_replay_key.wasPressed()) { if (toggle_replay_key.wasPressed()) {
if (!is_recording) { if (!is_recording) {
if (is_replaying) if (is_replaying)
@ -108,16 +107,19 @@ public class RepeatingMod implements ClientModInitializer {
menu.update_btns(); menu.update_btns();
record.clear(); record.clear();
if (record_pos_delay != -1) { record.add(new RecordMoveEvent(client.player.getPos(),
client.player.getHeadYaw(), client.player.getPitch()));
if (record_pos_delay > 0) {
move_tick = new Thread(() -> { move_tick = new Thread(() -> {
while (is_recording) { while (is_recording) {
record.add(new RecordMoveEvent(client.player.getPos(),
client.player.getHeadYaw(), client.player.getPitch()));
try { try {
Thread.sleep(record_pos_delay); Thread.sleep(record_pos_delay);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
record.add(new RecordMoveEvent(client.player.getPos(),
client.player.getHeadYaw(), client.player.getPitch()));
} }
}); });
move_tick.start(); move_tick.start();
@ -152,7 +154,8 @@ public class RepeatingMod implements ClientModInitializer {
client.player.getBodyYaw(), client.player.getBodyYaw(),
client.player.getPitch(), client.player.getPitch(),
client.player.isSprinting(), client.player.isSprinting(),
client.player.getYaw()); client.player.getYaw(),
client.player.getMovementSpeed());
recordTick(e); recordTick(e);
} else { } else {
RecordInputEvent e = new RecordInputEvent( RecordInputEvent e = new RecordInputEvent(
@ -166,7 +169,7 @@ public class RepeatingMod implements ClientModInitializer {
((Boolean) client.player.input.pressingRight == l.pressingRight) ? null : client.player.input.pressingRight, ((Boolean) client.player.input.pressingRight == l.pressingRight) ? null : client.player.input.pressingRight,
client.player.getHeadYaw(),RepeatingMod.client.player.getBodyYaw(),client.player.getPitch(), client.player.getHeadYaw(),RepeatingMod.client.player.getBodyYaw(),client.player.getPitch(),
((Boolean) client.player.isSprinting() == l.sprinting) ? null : client.player.isSprinting(), ((Boolean) client.player.isSprinting() == l.sprinting) ? null : client.player.isSprinting(),
client.player.getYaw()); client.player.getYaw(),client.player.getMovementSpeed());
if (!(e.isEmpty() && if (!(e.isEmpty() &&
e.yaw == l.yaw && e.yaw == l.yaw &&
@ -195,12 +198,14 @@ public class RepeatingMod implements ClientModInitializer {
client.player.getBodyYaw(), client.player.getBodyYaw(),
client.player.getPitch(), client.player.getPitch(),
client.player.isSprinting(), client.player.isSprinting(),
client.player.getYaw()); client.player.getYaw(),
client.player.getMovementSpeed());
recordTick(e); recordTick(e);
} else { } else {
RecordInputEvent e = new RecordInputEvent(null,null,null,null, RecordInputEvent e = new RecordInputEvent(null,null,null,
null,null,null,null,client.player.getHeadYaw(), null,null,null,null,null,
RepeatingMod.client.player.getBodyYaw(),client.player.getPitch(),null,client.player.getYaw()); client.player.getHeadYaw(),RepeatingMod.client.player.getBodyYaw(),client.player.getPitch(),
null,client.player.getYaw(),client.player.getMovementSpeed());
if (!(e.yaw == l.yaw && if (!(e.yaw == l.yaw &&
e.head_yaw == l.head_yaw && e.head_yaw == l.head_yaw &&
@ -270,47 +275,15 @@ public class RepeatingMod implements ClientModInitializer {
String type = String.valueOf(t.charAt(0)); String type = String.valueOf(t.charAt(0));
String[] args = t.substring(2).split("&"); String[] args = t.substring(2).split("&");
if (type.equals("d")) { if (type.equals("d")) {
return new RecordDelayEvent( return RecordDelayEvent.fromArgs(args);
Long.parseLong(args[0]));
} else if (type.equals("m")) { } else if (type.equals("m")) {
return new RecordMoveEvent(new Vec3d( return RecordMoveEvent.fromArgs(args);
Double.parseDouble(args[0]),
Double.parseDouble(args[1]),
Double.parseDouble(args[2])),
Float.parseFloat(args[3]),
Float.parseFloat(args[4]));
} else if (type.equals("p")) { } else if (type.equals("p")) {
return new RecordInputEvent( return RecordInputEvent.fromArgs(args);
(args[0].equals("n")?null:args[0].equals("1")),
(args[1].equals("n")?null:args[1].equals("1")),
(args[2].equals("n")?null:Float.parseFloat(args[2])),
(args[3].equals("n")?null:Float.parseFloat(args[3])),
(args[4].equals("n")?null:args[4].equals("1")),
(args[5].equals("n")?null:args[5].equals("1")),
(args[6].equals("n")?null:args[6].equals("1")),
(args[7].equals("n")?null:args[7].equals("1")),
Float.parseFloat(args[8]),Float.parseFloat(args[9]),
Float.parseFloat(args[10]),
(args[11].equals("n")?null:args[11].equals("1")),
Float.parseFloat(args[12]));
} else if (type.equals("b")) { } else if (type.equals("b")) {
return new RecordBlockBreakEvent(new BlockPos( return RecordBlockBreakEvent.fromArgs(args);
Integer.parseInt(args[0]),
Integer.parseInt(args[1]),
Integer.parseInt(args[2])));
} else if (type.equals("i")) { } else if (type.equals("i")) {
return new RecordBlockInteractEvent( return RecordBlockInteractEvent.fromArgs(args);
Hand.valueOf(args[5]),
new BlockHitResult(new Vec3d(
Double.parseDouble(args[0]),
Double.parseDouble(args[1]),
Double.parseDouble(args[2])),
Direction.byId(Integer.parseInt(args[4])),
new BlockPos(
Integer.parseInt(args[0]),
Integer.parseInt(args[1]),
Integer.parseInt(args[2])),
args[3].equals("1")));
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -322,6 +295,10 @@ public class RepeatingMod implements ClientModInitializer {
public static class RecordDelayEvent extends RecordEvent { public static class RecordDelayEvent extends RecordEvent {
public long delay; public long delay;
public static RecordDelayEvent fromArgs(String[] a) {
return new RecordDelayEvent(Long.parseLong(a[0]));
}
public RecordDelayEvent(long delay) { public RecordDelayEvent(long delay) {
this.delay = delay; this.delay = delay;
} }
@ -347,6 +324,15 @@ public class RepeatingMod implements ClientModInitializer {
public float yaw; public float yaw;
public float pitch; public float pitch;
public static RecordMoveEvent fromArgs(String[] a) {
return new RecordMoveEvent(new Vec3d(
Double.parseDouble(a[0]),
Double.parseDouble(a[1]),
Double.parseDouble(a[2])),
Float.parseFloat(a[3]),
Float.parseFloat(a[4]));
}
public RecordMoveEvent(Vec3d vec,float yaw,float pitch) { public RecordMoveEvent(Vec3d vec,float yaw,float pitch) {
this.vec = vec; this.vec = vec;
this.yaw = yaw; this.yaw = yaw;
@ -385,7 +371,24 @@ public class RepeatingMod implements ClientModInitializer {
public float head_yaw; public float head_yaw;
public float body_yaw; public float body_yaw;
public float pitch; public float pitch;
public float speed;
public static RecordInputEvent fromArgs(String[] a) {
return new RecordInputEvent(
(a[0].equals("n")?null:a[0].equals("1")),
(a[1].equals("n")?null:a[1].equals("1")),
(a[2].equals("n")?null:Float.parseFloat(a[2])),
(a[3].equals("n")?null:Float.parseFloat(a[3])),
(a[4].equals("n")?null:a[4].equals("1")),
(a[5].equals("n")?null:a[5].equals("1")),
(a[6].equals("n")?null:a[6].equals("1")),
(a[7].equals("n")?null:a[7].equals("1")),
Float.parseFloat(a[8]),Float.parseFloat(a[9]),
Float.parseFloat(a[10]),
(a[11].equals("n")?null:a[11].equals("1")),
Float.parseFloat(a[12]),
Float.parseFloat(a[13]));
}
public RecordInputEvent(Boolean sneaking, public RecordInputEvent(Boolean sneaking,
Boolean jumping, Boolean jumping,
@ -399,7 +402,8 @@ public class RepeatingMod implements ClientModInitializer {
float body_yaw, float body_yaw,
float head_pitch, float head_pitch,
Boolean sprinting, Boolean sprinting,
float yaw) { float yaw,
float speed) {
this.sneaking = sneaking; this.sneaking = sneaking;
this.jumping = jumping; this.jumping = jumping;
this.movementSideways = movementSideways; this.movementSideways = movementSideways;
@ -413,6 +417,7 @@ public class RepeatingMod implements ClientModInitializer {
this.pitch = head_pitch; this.pitch = head_pitch;
this.sprinting = sprinting; this.sprinting = sprinting;
this.yaw = yaw; this.yaw = yaw;
this.speed = speed;
} }
public void fillEmpty(RecordInputEvent e) { public void fillEmpty(RecordInputEvent e) {
@ -454,6 +459,8 @@ public class RepeatingMod implements ClientModInitializer {
client.player.setBodyYaw(body_yaw); client.player.setBodyYaw(body_yaw);
if (client.player.getPitch() != pitch) if (client.player.getPitch() != pitch)
client.player.setPitch(pitch); client.player.setPitch(pitch);
if (client.player.getMovementSpeed() != speed)
client.player.setMovementSpeed(speed);
if (sneaking != null && client.player.input.sneaking != sneaking) if (sneaking != null && client.player.input.sneaking != sneaking)
client.player.input.sneaking = sneaking; client.player.input.sneaking = sneaking;
if (jumping != null && client.player.input.jumping != jumping) if (jumping != null && client.player.input.jumping != jumping)
@ -483,8 +490,10 @@ 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")+"&"+ yaw); ((sprinting==null)?"n":(sprinting?"1":"0")+
"&"+yaw+"&"+speed);
} }
public String getType() { public String getType() {
return "input"; return "input";
} }
@ -493,6 +502,13 @@ public class RepeatingMod implements ClientModInitializer {
public static class RecordBlockBreakEvent extends RecordEvent { public static class RecordBlockBreakEvent extends RecordEvent {
public BlockPos pos; public BlockPos pos;
public static RecordBlockBreakEvent fromArgs(String[] a) {
return new RecordBlockBreakEvent(new BlockPos(
Integer.parseInt(a[0]),
Integer.parseInt(a[1]),
Integer.parseInt(a[2])));
}
public RecordBlockBreakEvent( public RecordBlockBreakEvent(
BlockPos pos) { BlockPos pos) {
this.pos = pos; this.pos = pos;
@ -514,6 +530,21 @@ public class RepeatingMod implements ClientModInitializer {
public Hand hand; public Hand hand;
public BlockHitResult hitResult; public BlockHitResult hitResult;
public static RecordBlockInteractEvent fromArgs(String[] a) {
return new RecordBlockInteractEvent(
Hand.valueOf(a[5]),
new BlockHitResult(new Vec3d(
Double.parseDouble(a[0]),
Double.parseDouble(a[1]),
Double.parseDouble(a[2])),
Direction.byId(Integer.parseInt(a[4])),
new BlockPos(
Integer.parseInt(a[0]),
Integer.parseInt(a[1]),
Integer.parseInt(a[2])),
a[3].equals("1")));
}
public RecordBlockInteractEvent(Hand hand, BlockHitResult hitResult) { public RecordBlockInteractEvent(Hand hand, BlockHitResult hitResult) {
this.hand = hand; this.hand = hand;
this.hitResult = hitResult; this.hitResult = hitResult;

View File

@ -18,6 +18,7 @@ public class RepeatingScreen extends BaseOwoScreen<FlowLayout> {
public ButtonComponent replay_btn; public ButtonComponent replay_btn;
public ButtonComponent record_btn; public ButtonComponent record_btn;
public ButtonComponent loop_btn; public ButtonComponent loop_btn;
public boolean was_build = false;
public RepeatingScreen() { public RepeatingScreen() {
this.mod = RepeatingMod.me; this.mod = RepeatingMod.me;
@ -29,13 +30,15 @@ public class RepeatingScreen extends BaseOwoScreen<FlowLayout> {
} }
public void update_btns() { public void update_btns() {
replay_btn.setMessage(Text.translatable("text.repeating-mod." + if (was_build) {
((mod.is_replaying) ? "stop" : "start")).append(" ") replay_btn.setMessage(Text.translatable("text.repeating-mod." +
.append(Text.translatable("text.repeating-mod.replay"))); ((mod.is_replaying) ? "stop" : "start")).append(" ")
record_btn.setMessage(Text.translatable("text.repeating-mod." + .append(Text.translatable("text.repeating-mod.replay")));
((mod.is_recording) ? "stop" : "start")).append(" ") record_btn.setMessage(Text.translatable("text.repeating-mod." +
.append(Text.translatable("text.repeating-mod.record"))); ((mod.is_recording) ? "stop" : "start")).append(" ")
loop_btn.setMessage(Text.of(((mod.loop_replay) ? "\uefff " : "\ueffe "))); .append(Text.translatable("text.repeating-mod.record")));
loop_btn.setMessage(Text.of(((mod.loop_replay) ? "\uefff " : "\ueffe ")));
}
} }
@Override @Override
@ -73,6 +76,7 @@ public class RepeatingScreen extends BaseOwoScreen<FlowLayout> {
} }
}).margins(Insets.of(1)).sizing( }).margins(Insets.of(1)).sizing(
Sizing.fixed(120),Sizing.fixed(20)); Sizing.fixed(120),Sizing.fixed(20));
was_build = true;
rootComponent.child( rootComponent.child(
Containers.horizontalFlow(Sizing.content(), Sizing.content()).child( Containers.horizontalFlow(Sizing.content(), Sizing.content()).child(
@ -169,7 +173,7 @@ public class RepeatingScreen extends BaseOwoScreen<FlowLayout> {
.setFromDiscreteValue(mod.record_pos_delay) .setFromDiscreteValue(mod.record_pos_delay)
.message((String s)->{ .message((String s)->{
mod.record_pos_delay = Long.parseLong(s); mod.record_pos_delay = Long.parseLong(s);
mod.conf.data.put("record_pos_delay",mod.record_pos_delay); mod.conf.data.put("record_pos_delay",String.valueOf(mod.record_pos_delay));
mod.conf.save(); mod.conf.save();
if (mod.record_pos_delay > -1) if (mod.record_pos_delay > -1)
return Text.translatable("text.repeating-mod.pos_delay", s); return Text.translatable("text.repeating-mod.pos_delay", s);

View File

@ -10,6 +10,7 @@ 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 themixray.repeating.mod.TickTask;
@Mixin(ClientPlayerEntity.class) @Mixin(ClientPlayerEntity.class)
public abstract class MovementMixin { public abstract class MovementMixin {
@ -29,6 +30,20 @@ public abstract class MovementMixin {
}); });
} }
@Inject(at = @At(value = "HEAD"), method = "tick")
private void onTickHead(CallbackInfo ci) {
for (TickTask t:TickTask.ticks)
if (t.getAt() == TickTask.TickAt.HEAD)
t.tick();
}
@Inject(at = @At(value = "TAIL"), method = "tick")
private void onTickTail(CallbackInfo ci) {
for (TickTask t:TickTask.ticks)
if (t.getAt() == TickTask.TickAt.TAIL)
t.tick();
}
@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) {