Skip to content

Commit

Permalink
Add noSave feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Nickid2018 committed Jun 21, 2024
1 parent d4d29b7 commit ecf69ae
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 12 deletions.
28 changes: 28 additions & 0 deletions src/main/java/io/github/nickid2018/genwiki/RemapSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,34 @@ public static void remapSettings(GenWikiMode mode, RemapProgram remapProgram) {
}
)
);
remapProgram.addPostTransform(
"net.minecraft.server.MinecraftServer",
new MethodTransform(
"tickServer",
"(Ljava/util/function/BooleanSupplier;)V",
methodNode -> {
FieldInsnNode findAutoSaveIntervalPoint = null;
for (AbstractInsnNode node : methodNode.instructions) {
if (node instanceof FieldInsnNode fieldInsnNode) {
if (fieldInsnNode.getOpcode() == Opcodes.PUTFIELD &&
fieldInsnNode.name.equals("ticksUntilAutosave")) {
findAutoSaveIntervalPoint = fieldInsnNode;
break;
}
}
}
if (findAutoSaveIntervalPoint != null) {
methodNode.instructions.insertBefore(findAutoSaveIntervalPoint, new MethodInsnNode(
Opcodes.INVOKESTATIC,
"io/github/nickid2018/genwiki/iso/ISOInjectionEntryPoints",
"handleAutoSaveInterval",
"(I)I",
false
));
}
}
)
);
remapProgram.addInjectEntries(new IncludeJarPackages("io.github.nickid2018.genwiki.iso"));
remapProgram.addInjectEntries(new SingleFile(
"transparency.fsh",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public static void clampColorInjection(Vector3f vector3f) {

private static boolean ortho = false;
private static int invokeCount = 0;
private static boolean noSave = false;
private static Matrix4f orthoMatrix = new Matrix4f().ortho(-2, 2, -2, 2, -0.1f, 1000);

public static Matrix4f getProjectionMatrixInjection(Matrix4f source) {
Expand All @@ -41,6 +42,12 @@ public static Matrix4f getProjectionMatrixInjection(Matrix4f source) {
return source;
}

public static int handleAutoSaveInterval(int source) {
if (noSave)
return 1;
return source;
}

public static void handleChat(String chat) {
chat = chat.trim();
if (chat.toLowerCase().startsWith("run"))
Expand All @@ -63,6 +70,8 @@ public static void doCommand(String chat) {
switch (chat.toLowerCase()) {
case "persp" -> ortho = false;
case "ortho" -> ortho = true;
case "nosave" -> noSave = true;
case "save" -> noSave = false;
default -> {
String[] commands = chat.split(" ", 2);
String commandHead = commands[0];
Expand Down
27 changes: 15 additions & 12 deletions src/main/java/io/github/nickid2018/genwiki/remap/SingleFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@ public record SingleFile(String file, String path) implements InjectEntries {
@Override
@SneakyThrows
public Map<String, byte[]> getInjectEntries() {
JarFile thisJar = new JarFile(
IncludeJarPackages.class
.getProtectionDomain()
.getCodeSource()
.getLocation()
.getPath()
);
Optional<JarEntry> fileFind = thisJar.stream().filter(e -> e.getName().equals(file)).findFirst();
if (fileFind.isEmpty())
return Map.of();
byte[] bytes = thisJar.getInputStream(fileFind.get()).readAllBytes();
return Map.of(path, bytes);
try (
JarFile thisJar = new JarFile(
IncludeJarPackages.class
.getProtectionDomain()
.getCodeSource()
.getLocation()
.getPath()
)
) {
Optional<JarEntry> fileFind = thisJar.stream().filter(e -> e.getName().equals(file)).findFirst();
if (fileFind.isEmpty())
return Map.of();
byte[] bytes = thisJar.getInputStream(fileFind.get()).readAllBytes();
return Map.of(path, bytes);
}
}
}

0 comments on commit ecf69ae

Please sign in to comment.