fix easy config
This commit is contained in:
parent
629a44a27a
commit
51b68dd48f
@ -37,7 +37,6 @@ dependencies {
|
||||
// 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
|
||||
include "io.wispforest:owo-sentinel:${project.owo_version}"
|
||||
modImplementation 'org.yaml:snakeyaml:2.0'
|
||||
}
|
||||
|
||||
base {
|
||||
|
@ -9,7 +9,7 @@ yarn_mappings=1.19.3+build.1
|
||||
loader_version=0.14.17
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 1.0.3
|
||||
mod_version = 1.0.4
|
||||
maven_group = themixray.repeating.mod
|
||||
archives_base_name = repeating-mod
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
package themixray.repeating.mod;
|
||||
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@ -12,14 +10,12 @@ import java.io.File;
|
||||
public class EasyConfig {
|
||||
public final Path path;
|
||||
public final File file;
|
||||
public Map<String,Object> data;
|
||||
private Yaml yaml;
|
||||
public Map<String,String> data;
|
||||
|
||||
public EasyConfig(File f, Map<String,Object> def) {
|
||||
public EasyConfig(File f, Map<String,String> def) {
|
||||
this.path = f.toPath();
|
||||
this.file = f;
|
||||
this.data = new HashMap<>();
|
||||
this.yaml = new Yaml();
|
||||
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
@ -32,22 +28,22 @@ public class EasyConfig {
|
||||
|
||||
reload();
|
||||
|
||||
for (Map.Entry<String,Object> m:def.entrySet())
|
||||
for (Map.Entry<String,String> m:def.entrySet())
|
||||
if (!data.containsKey(m.getKey()))
|
||||
data.put(m.getKey(),m.getValue());
|
||||
|
||||
save();
|
||||
}
|
||||
public EasyConfig(Path f, Map<String,Object> def) {
|
||||
public EasyConfig(Path f, Map<String,String> 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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
@ -74,14 +70,22 @@ public class EasyConfig {
|
||||
write(data);
|
||||
}
|
||||
|
||||
private String toYaml(Map<String,Object> p) {
|
||||
return yaml.dump(p);
|
||||
private String toText(Map<String,String> 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) {
|
||||
return (Map<String, Object>) yaml.load(j);
|
||||
private Map<String,String> toMap(String 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 {
|
||||
return toMap(Files.readString(path));
|
||||
} catch (IOException e) {
|
||||
@ -89,9 +93,9 @@ public class EasyConfig {
|
||||
}
|
||||
return new HashMap<>();
|
||||
}
|
||||
private void write(Map<String,Object> p) {
|
||||
private void write(Map<String,String> p) {
|
||||
try {
|
||||
Files.write(path, toYaml(p).getBytes());
|
||||
Files.write(path, toText(p).getBytes());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -52,12 +52,12 @@ public class RepeatingMod implements ClientModInitializer {
|
||||
LOGGER.info("Repeating mod initialized");
|
||||
me = this;
|
||||
|
||||
Map<String,Object> def = new HashMap<>();
|
||||
def.put("record_pos_delay", (int) record_pos_delay);
|
||||
Map<String,String> def = new HashMap<>();
|
||||
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(
|
||||
"key.repeating-mod.menu",InputUtil.Type.KEYSYM,
|
||||
@ -71,9 +71,8 @@ public class RepeatingMod implements ClientModInitializer {
|
||||
|
||||
menu = new RepeatingScreen();
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||
if (menu_key.wasPressed()) {
|
||||
if (menu_key.wasPressed())
|
||||
client.setScreen(menu);
|
||||
}
|
||||
if (toggle_replay_key.wasPressed()) {
|
||||
if (!is_recording) {
|
||||
if (is_replaying)
|
||||
@ -108,16 +107,19 @@ public class RepeatingMod implements ClientModInitializer {
|
||||
menu.update_btns();
|
||||
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(() -> {
|
||||
while (is_recording) {
|
||||
record.add(new RecordMoveEvent(client.player.getPos(),
|
||||
client.player.getHeadYaw(), client.player.getPitch()));
|
||||
try {
|
||||
Thread.sleep(record_pos_delay);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
record.add(new RecordMoveEvent(client.player.getPos(),
|
||||
client.player.getHeadYaw(), client.player.getPitch()));
|
||||
}
|
||||
});
|
||||
move_tick.start();
|
||||
@ -152,7 +154,8 @@ public class RepeatingMod implements ClientModInitializer {
|
||||
client.player.getBodyYaw(),
|
||||
client.player.getPitch(),
|
||||
client.player.isSprinting(),
|
||||
client.player.getYaw());
|
||||
client.player.getYaw(),
|
||||
client.player.getMovementSpeed());
|
||||
recordTick(e);
|
||||
} else {
|
||||
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,
|
||||
client.player.getHeadYaw(),RepeatingMod.client.player.getBodyYaw(),client.player.getPitch(),
|
||||
((Boolean) client.player.isSprinting() == l.sprinting) ? null : client.player.isSprinting(),
|
||||
client.player.getYaw());
|
||||
client.player.getYaw(),client.player.getMovementSpeed());
|
||||
|
||||
if (!(e.isEmpty() &&
|
||||
e.yaw == l.yaw &&
|
||||
@ -195,12 +198,14 @@ public class RepeatingMod implements ClientModInitializer {
|
||||
client.player.getBodyYaw(),
|
||||
client.player.getPitch(),
|
||||
client.player.isSprinting(),
|
||||
client.player.getYaw());
|
||||
client.player.getYaw(),
|
||||
client.player.getMovementSpeed());
|
||||
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());
|
||||
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(),client.player.getMovementSpeed());
|
||||
|
||||
if (!(e.yaw == l.yaw &&
|
||||
e.head_yaw == l.head_yaw &&
|
||||
@ -270,47 +275,15 @@ public class RepeatingMod implements ClientModInitializer {
|
||||
String type = String.valueOf(t.charAt(0));
|
||||
String[] args = t.substring(2).split("&");
|
||||
if (type.equals("d")) {
|
||||
return new RecordDelayEvent(
|
||||
Long.parseLong(args[0]));
|
||||
return RecordDelayEvent.fromArgs(args);
|
||||
} else if (type.equals("m")) {
|
||||
return new RecordMoveEvent(new Vec3d(
|
||||
Double.parseDouble(args[0]),
|
||||
Double.parseDouble(args[1]),
|
||||
Double.parseDouble(args[2])),
|
||||
Float.parseFloat(args[3]),
|
||||
Float.parseFloat(args[4]));
|
||||
return RecordMoveEvent.fromArgs(args);
|
||||
} else if (type.equals("p")) {
|
||||
return new RecordInputEvent(
|
||||
(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]));
|
||||
return RecordInputEvent.fromArgs(args);
|
||||
} else if (type.equals("b")) {
|
||||
return new RecordBlockBreakEvent(new BlockPos(
|
||||
Integer.parseInt(args[0]),
|
||||
Integer.parseInt(args[1]),
|
||||
Integer.parseInt(args[2])));
|
||||
return RecordBlockBreakEvent.fromArgs(args);
|
||||
} else if (type.equals("i")) {
|
||||
return new RecordBlockInteractEvent(
|
||||
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")));
|
||||
return RecordBlockInteractEvent.fromArgs(args);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -322,6 +295,10 @@ public class RepeatingMod implements ClientModInitializer {
|
||||
public static class RecordDelayEvent extends RecordEvent {
|
||||
public long delay;
|
||||
|
||||
public static RecordDelayEvent fromArgs(String[] a) {
|
||||
return new RecordDelayEvent(Long.parseLong(a[0]));
|
||||
}
|
||||
|
||||
public RecordDelayEvent(long delay) {
|
||||
this.delay = delay;
|
||||
}
|
||||
@ -347,6 +324,15 @@ public class RepeatingMod implements ClientModInitializer {
|
||||
public float yaw;
|
||||
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) {
|
||||
this.vec = vec;
|
||||
this.yaw = yaw;
|
||||
@ -385,7 +371,24 @@ public class RepeatingMod implements ClientModInitializer {
|
||||
public float head_yaw;
|
||||
public float body_yaw;
|
||||
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,
|
||||
Boolean jumping,
|
||||
@ -399,7 +402,8 @@ public class RepeatingMod implements ClientModInitializer {
|
||||
float body_yaw,
|
||||
float head_pitch,
|
||||
Boolean sprinting,
|
||||
float yaw) {
|
||||
float yaw,
|
||||
float speed) {
|
||||
this.sneaking = sneaking;
|
||||
this.jumping = jumping;
|
||||
this.movementSideways = movementSideways;
|
||||
@ -413,6 +417,7 @@ public class RepeatingMod implements ClientModInitializer {
|
||||
this.pitch = head_pitch;
|
||||
this.sprinting = sprinting;
|
||||
this.yaw = yaw;
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
public void fillEmpty(RecordInputEvent e) {
|
||||
@ -454,6 +459,8 @@ public class RepeatingMod implements ClientModInitializer {
|
||||
client.player.setBodyYaw(body_yaw);
|
||||
if (client.player.getPitch() != pitch)
|
||||
client.player.setPitch(pitch);
|
||||
if (client.player.getMovementSpeed() != speed)
|
||||
client.player.setMovementSpeed(speed);
|
||||
if (sneaking != null && client.player.input.sneaking != sneaking)
|
||||
client.player.input.sneaking = sneaking;
|
||||
if (jumping != null && client.player.input.jumping != jumping)
|
||||
@ -483,8 +490,10 @@ 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")+"&"+ yaw);
|
||||
((sprinting==null)?"n":(sprinting?"1":"0")+
|
||||
"&"+yaw+"&"+speed);
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return "input";
|
||||
}
|
||||
@ -493,6 +502,13 @@ public class RepeatingMod implements ClientModInitializer {
|
||||
public static class RecordBlockBreakEvent extends RecordEvent {
|
||||
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(
|
||||
BlockPos pos) {
|
||||
this.pos = pos;
|
||||
@ -514,6 +530,21 @@ public class RepeatingMod implements ClientModInitializer {
|
||||
public Hand hand;
|
||||
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) {
|
||||
this.hand = hand;
|
||||
this.hitResult = hitResult;
|
||||
|
@ -18,6 +18,7 @@ public class RepeatingScreen extends BaseOwoScreen<FlowLayout> {
|
||||
public ButtonComponent replay_btn;
|
||||
public ButtonComponent record_btn;
|
||||
public ButtonComponent loop_btn;
|
||||
public boolean was_build = false;
|
||||
|
||||
public RepeatingScreen() {
|
||||
this.mod = RepeatingMod.me;
|
||||
@ -29,13 +30,15 @@ public class RepeatingScreen extends BaseOwoScreen<FlowLayout> {
|
||||
}
|
||||
|
||||
public void update_btns() {
|
||||
replay_btn.setMessage(Text.translatable("text.repeating-mod." +
|
||||
((mod.is_replaying) ? "stop" : "start")).append(" ")
|
||||
.append(Text.translatable("text.repeating-mod.replay")));
|
||||
record_btn.setMessage(Text.translatable("text.repeating-mod." +
|
||||
((mod.is_recording) ? "stop" : "start")).append(" ")
|
||||
.append(Text.translatable("text.repeating-mod.record")));
|
||||
loop_btn.setMessage(Text.of(((mod.loop_replay) ? "\uefff " : "\ueffe ")));
|
||||
if (was_build) {
|
||||
replay_btn.setMessage(Text.translatable("text.repeating-mod." +
|
||||
((mod.is_replaying) ? "stop" : "start")).append(" ")
|
||||
.append(Text.translatable("text.repeating-mod.replay")));
|
||||
record_btn.setMessage(Text.translatable("text.repeating-mod." +
|
||||
((mod.is_recording) ? "stop" : "start")).append(" ")
|
||||
.append(Text.translatable("text.repeating-mod.record")));
|
||||
loop_btn.setMessage(Text.of(((mod.loop_replay) ? "\uefff " : "\ueffe ")));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -73,6 +76,7 @@ public class RepeatingScreen extends BaseOwoScreen<FlowLayout> {
|
||||
}
|
||||
}).margins(Insets.of(1)).sizing(
|
||||
Sizing.fixed(120),Sizing.fixed(20));
|
||||
was_build = true;
|
||||
|
||||
rootComponent.child(
|
||||
Containers.horizontalFlow(Sizing.content(), Sizing.content()).child(
|
||||
@ -169,7 +173,7 @@ public class RepeatingScreen extends BaseOwoScreen<FlowLayout> {
|
||||
.setFromDiscreteValue(mod.record_pos_delay)
|
||||
.message((String 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();
|
||||
if (mod.record_pos_delay > -1)
|
||||
return Text.translatable("text.repeating-mod.pos_delay", s);
|
||||
|
@ -10,6 +10,7 @@ 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 themixray.repeating.mod.TickTask;
|
||||
|
||||
@Mixin(ClientPlayerEntity.class)
|
||||
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")
|
||||
private void onMove(CallbackInfo ci) {
|
||||
if (RepeatingMod.me.is_recording) {
|
||||
|
Loading…
Reference in New Issue
Block a user