Skip to content

Commit 44799f1

Browse files
committed
Update BaseScript for MC 1.7.10
1 parent d7bc0e0 commit 44799f1

File tree

3 files changed

+43
-32
lines changed

3 files changed

+43
-32
lines changed

build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ repositories {
1414
}
1515

1616
dependencies {
17-
implementation("com.github.tth05:jindex:0.0.43")
17+
implementation("com.github.tth05:jindex:0.0.45")
1818
implementation("com.github.tth05:SCNet:d683b47")
1919

2020
implementation('com.formdev:flatlaf:2.6')
@@ -47,6 +47,7 @@ runtime {
4747
'java.net.http',
4848
'java.xml',
4949
'jdk.unsupported',
50+
'jdk.zipfs',
5051
'java.datatransfer'
5152
]
5253
}

src/main/java/com/github/minecraft_ta/totalDebugCompanion/jdt/BaseScript.java

+36-31
Original file line numberDiff line numberDiff line change
@@ -15,51 +15,53 @@ public class BaseScript {
1515
private static final Pattern IMPORT_PATTERN = Pattern.compile("import\\s(.*?);");
1616

1717
private static final String BASE_SCRIPT_IMPORTS = """
18-
import java.io.StringWriter;
19-
import java.util.Arrays;
20-
import java.util.List;
21-
import java.lang.reflect.*;
18+
import cpw.mods.fml.common.FMLCommonHandler;
2219
import net.minecraft.entity.player.EntityPlayerMP;
2320
import net.minecraft.server.MinecraftServer;
24-
import net.minecraft.util.text.TextComponentString;
21+
import net.minecraft.util.ChatComponentText;
2522
import net.minecraft.world.World;
2623
import net.minecraft.world.WorldServer;
27-
import net.minecraftforge.fml.common.FMLCommonHandler;
28-
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
24+
import net.minecraftforge.common.DimensionManager;
25+
26+
import java.io.StringWriter;
27+
import java.lang.reflect.Constructor;
28+
import java.lang.reflect.Field;
29+
import java.lang.reflect.Method;
30+
import java.util.Arrays;
31+
import java.util.List;
2932
""";
3033

3134
//language=Java
3235
private static final String BASE_SCRIPT_TEXT = """
3336
abstract class BaseScript {
34-
3537
/*
3638
---- MC stuff
3739
*/
38-
40+
3941
public MinecraftServer getServer() {
4042
return FMLCommonHandler.instance().getMinecraftServerInstance();
4143
}
4244
4345
public void sendToAllPlayers(String message) {
44-
getServerPlayers().forEach(p -> p.sendMessage(new TextComponentString(message)));
46+
getServerPlayers().forEach(p -> p.addChatMessage(new ChatComponentText(message)));
4547
}
4648
4749
public World getServerOverworld() {
48-
return getServer().getWorld(0);
50+
return DimensionManager.getWorld(0);
4951
}
5052
5153
public List<WorldServer> getServerWorlds() {
52-
return Arrays.asList(getServer().worlds);
54+
return Arrays.asList(getServer().worldServers);
5355
}
5456
55-
public List<EntityPlayerMP> getServerPlayers() {
56-
return getServer().getPlayerList().getPlayers();
57-
}
58-
57+
public List<EntityPlayerMP> getServerPlayers() {
58+
return getServer().getConfigurationManager().playerEntityList;
59+
}
60+
\s
5961
/*
6062
---- Reflection
6163
*/
62-
64+
6365
public static <T> T createInstance(Class<T> clazz, Object... args) {
6466
try {
6567
Constructor<T> ctor = clazz.getDeclaredConstructor(Arrays.stream(args).map(Object::getClass).toArray(Class[]::new));
@@ -69,7 +71,7 @@ public static <T> T createInstance(Class<T> clazz, Object... args) {
6971
throw new RuntimeException(e);
7072
}
7173
}
72-
74+
7375
public static <T> T createInstance(Class<T> clazz, Class<?>[] argClasses, Object... args) {
7476
try {
7577
Constructor<T> ctor = clazz.getDeclaredConstructor(argClasses);
@@ -79,11 +81,11 @@ public static <T> T createInstance(Class<T> clazz, Class<?>[] argClasses, Object
7981
throw new RuntimeException(e);
8082
}
8183
}
82-
84+
8385
public static <T> T invokeMethod(Object o, String methodName, Object... args) {
8486
return invokeMethod(o, methodName, Arrays.stream(args).map(Object::getClass).toArray(Class[]::new), args);
8587
}
86-
88+
8789
public static <T> T invokeMethod(Object o, String methodName, Class<?>[] argClasses, Object... args) {
8890
try {
8991
Method method = o.getClass().getDeclaredMethod(methodName, argClasses);
@@ -93,11 +95,11 @@ public static <T> T invokeMethod(Object o, String methodName, Class<?>[] argClas
9395
throw new RuntimeException(e);
9496
}
9597
}
96-
98+
9799
public static <T> T invokeStaticMethod(Class<?> c, String methodName, Object... args) {
98100
return invokeStaticMethod(c, methodName, Arrays.stream(args).map(Object::getClass).toArray(Class[]::new), args);
99101
}
100-
102+
101103
public static <T> T invokeStaticMethod(Class<?> c, String methodName, Class<?>[] argClasses, Object... args) {
102104
try {
103105
Method method = c.getDeclaredMethod(methodName, argClasses);
@@ -107,7 +109,7 @@ public static <T> T invokeStaticMethod(Class<?> c, String methodName, Class<?>[]
107109
throw new RuntimeException(e);
108110
}
109111
}
110-
112+
111113
public static <T> T getFieldValue(Object o, String fieldName) {
112114
Field f = findField(o.getClass(), fieldName);
113115
f.setAccessible(true);
@@ -117,11 +119,11 @@ public static <T> T getFieldValue(Object o, String fieldName) {
117119
throw new RuntimeException(e);
118120
}
119121
}
120-
122+
121123
public static void setField(Object o, String fieldName, Object value) {
122124
setField(o.getClass(), o, fieldName, value);
123125
}
124-
126+
125127
public static void setField(Class<?> clazz, Object o, String fieldName, Object value) {
126128
try {
127129
Field field = findField(clazz, fieldName);
@@ -131,7 +133,11 @@ public static void setField(Class<?> clazz, Object o, String fieldName, Object v
131133
throw new RuntimeException(e);
132134
}
133135
}
134-
136+
137+
public static Field findField(Object o, String fieldName) {
138+
return findField(o.getClass(), fieldName);
139+
}
140+
135141
public static Field findField(Class<?> clazz, String fieldName) {
136142
Class<?> current = clazz;
137143
while (current != null) {
@@ -141,10 +147,10 @@ public static Field findField(Class<?> clazz, String fieldName) {
141147
current = current.getSuperclass();
142148
}
143149
}
144-
150+
145151
throw new RuntimeException("Field not found: " + fieldName);
146152
}
147-
153+
148154
public static void setStaticField(Class<?> c, String fieldName, Object value) {
149155
try {
150156
Field field = c.getDeclaredField(fieldName);
@@ -154,7 +160,7 @@ public static void setStaticField(Class<?> c, String fieldName, Object value) {
154160
throw new RuntimeException(e);
155161
}
156162
}
157-
163+
\s
158164
/*
159165
---- Logging
160166
*/
@@ -170,8 +176,7 @@ public void log(Object s) {
170176
}
171177
172178
public abstract void run() throws Throwable;
173-
}
174-
""".replace(" ", "\t");
179+
}""".replace(" ", "\t");
175180

176181
private static final String BASE_SCRIPT = BASE_SCRIPT_IMPORTS + BASE_SCRIPT_TEXT;
177182
private static final Path PATH = CompanionApp.getRootPath().resolve("scripts").resolve("BaseScript.java");

src/main/java/com/github/minecraft_ta/totalDebugCompanion/jdt/impls/CompilationUnitImpl.java

+5
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,9 @@ private static String extractPackageName(String contents) {
9595

9696
return "";
9797
}
98+
99+
@Override
100+
public boolean ignoreOptionalProblems() {
101+
return true;
102+
}
98103
}

0 commit comments

Comments
 (0)