From 146b2589e2468adcb75d794bcd55433c776b0508 Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 12 Feb 2021 14:54:10 -0500 Subject: [PATCH] Fixed rare network error --- .../world/blocks/units/UnitBlock.java | 2 +- gradle.properties | 2 +- .../mindustry/tools/BindingsGenerator.java | 80 ++++++++++--------- 3 files changed, 43 insertions(+), 41 deletions(-) diff --git a/core/src/mindustry/world/blocks/units/UnitBlock.java b/core/src/mindustry/world/blocks/units/UnitBlock.java index ac38d3452f..872745c334 100644 --- a/core/src/mindustry/world/blocks/units/UnitBlock.java +++ b/core/src/mindustry/world/blocks/units/UnitBlock.java @@ -27,7 +27,7 @@ public class UnitBlock extends PayloadAcceptor{ @Remote(called = Loc.server) public static void unitBlockSpawn(Tile tile){ - if(!(tile.build instanceof UnitBuild build)) return; + if(tile == null || !(tile.build instanceof UnitBuild build)) return; build.spawned(); } diff --git a/gradle.properties b/gradle.properties index 7c0f949677..75d98185c9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ org.gradle.daemon=true org.gradle.jvmargs=-Xms256m -Xmx1024m -archash=afbb1f5080df42d0629d5997a3f1b14dafc467bf +archash=eac865a8a0f4fde121fdcd8850d9f039f725b546 diff --git a/tools/src/mindustry/tools/BindingsGenerator.java b/tools/src/mindustry/tools/BindingsGenerator.java index 83d3dd7975..8363e4a857 100644 --- a/tools/src/mindustry/tools/BindingsGenerator.java +++ b/tools/src/mindustry/tools/BindingsGenerator.java @@ -31,64 +31,66 @@ public class BindingsGenerator{ for(Class type : classes){ String name = type.getCanonicalName(); - result.append("jclass ").append(name).append("* of ") - .append(type.getSuperclass() == null ? "JVMObject" : type.getSuperclass().getSimpleName()).append(":\n"); - - for(Field field : type.getFields()){ - if(Modifier.isPublic(field.getModifiers())){ - result.append(" proc `").append(field.getName()).append("`*"); - result.append(": ").append(str(field.getType())); - result.append(" {.prop"); - if(Modifier.isStatic(field.getModifiers())) result.append(", `static`"); - if(Modifier.isStatic(field.getModifiers())) result.append(", `final`"); - result.append(".}\n"); - } - } Seq exec = new Seq<>(); exec.addAll(type.getDeclaredMethods()); exec.addAll(type.getDeclaredConstructors()); + exec.removeAll(e -> !Modifier.isPublic(e.getModifiers())); + + Seq fields = Seq.select(type.getDeclaredFields(), f -> Modifier.isPublic(f.getModifiers())); + + result.append("jclass ").append(name).append(" of `") + .append(type.getSuperclass() == null ? "JVMObject" : type.getSuperclass().getSimpleName()).append("`").append(exec.size + fields.size > 0 ? ":" : "").append("\n"); + + for(Field field : fields){ + result.append(" proc `").append(field.getName()).append("`*"); + result.append(": ").append(str(field.getType())); + result.append(" {.prop"); + if(Modifier.isStatic(field.getModifiers())) result.append(", `static`"); + if(Modifier.isStatic(field.getModifiers())) result.append(", `final`"); + result.append(".}\n"); + } + for(Executable method : exec){ - if(Modifier.isPublic(method.getModifiers())){ - String mname = method.getName().equals("") || method.getName().equals(type.getCanonicalName()) ? "new" : method.getName(); - result.append(" proc `").append(mname).append("`*"); + String mname = method.getName().equals("") || method.getName().equals(type.getCanonicalName()) ? "new" : method.getName(); + result.append(" proc `").append(mname).append("`"); - if(method.getParameterCount() > 0){ - result.append("("); + if(method.getParameterCount() > 0){ + result.append("("); - for(int i = 0; i < method.getParameterCount(); i++){ - Class p = method.getParameterTypes()[i]; + for(int i = 0; i < method.getParameterCount(); i++){ + Class p = method.getParameterTypes()[i]; - result.append(method.getParameters()[i].getName()).append(": ").append(str(p)); + result.append(method.getParameters()[i].getName()).append(": ").append(str(p)); - if(i != method.getParameterCount() - 1){ - result.append(", "); - } - } - - result.append(")"); - } - - if(method instanceof Method){ - Method m = (Method)method; - if(!m.getReturnType().equals(void.class)){ - result.append(": ").append(str(m.getReturnType())); + if(i != method.getParameterCount() - 1){ + result.append(", "); } } - //result.append(" {."); - //if(Modifier.isStatic(field.getModifiers())) result.append(", `static`"); - //if(Modifier.isStatic(field.getModifiers())) result.append(", `final`"); - //result.append(".}\n"); - result.append("\n"); + result.append(")"); } + + if(method instanceof Method){ + Method m = (Method)method; + if(!m.getReturnType().equals(void.class)){ + result.append(": ").append(str(m.getReturnType())); + } + } + + //result.append(" {."); + //if(Modifier.isStatic(field.getModifiers())) result.append(", `static`"); + //if(Modifier.isStatic(field.getModifiers())) result.append(", `final`"); + //result.append(".}\n"); + result.append("\n"); } result.append("\n"); } - Fi.get(OS.userhome).child("mindustry.nim").writeString(result.toString()); + Fi.get("/home/anuke/Projects/Nimdustry-java/mindustry_bindings.nim").writeString(result.toString()); + //Fi.get(OS.userhome).child("mindustry.nim").writeString(result.toString()); Log.info(result); }