diff --git a/common/src/brentmaas/buildguide/common/AbstractRenderHandler.java b/common/src/brentmaas/buildguide/common/AbstractRenderHandler.java index c81ebc9..b697363 100644 --- a/common/src/brentmaas/buildguide/common/AbstractRenderHandler.java +++ b/common/src/brentmaas/buildguide/common/AbstractRenderHandler.java @@ -41,7 +41,7 @@ public abstract class AbstractRenderHandler { public void render() { pushProfiler(BuildGuide.modid); - if(BuildGuide.stateManager.isStatePresent() && BuildGuide.stateManager.getState().enabled && BuildGuide.stateManager.getState().isShapeAvailable() && BuildGuide.stateManager.getState().getCurrentShapeSet().origin != null) { // isStatePresent: quickfix for weird ClassNotFoundException when opening the GUI + if(BuildGuide.stateManager.getState().enabled && BuildGuide.stateManager.getState().isShapeAvailable() && BuildGuide.stateManager.getState().getCurrentShapeSet().origin != null) { for(ShapeSet s: BuildGuide.stateManager.getState().shapeSets) renderShapeSet(s); } diff --git a/common/src/brentmaas/buildguide/common/State.java b/common/src/brentmaas/buildguide/common/State.java index 399574e..8638cd1 100644 --- a/common/src/brentmaas/buildguide/common/State.java +++ b/common/src/brentmaas/buildguide/common/State.java @@ -27,6 +27,7 @@ public class State { private static final String PERSISTENCE_ISHAPENEW = "iShapeNew"; private boolean initialised = false; + private boolean fromPersistence = false; public ArrayList shapeSets = new ArrayList(); protected int iShapeSet = 0; public int iShapeNew = ShapeRegistry.getShapeId(ShapeCircle.class); @@ -82,20 +83,27 @@ public void pushNewShapeSet() { newShapeSet.colourOriginG = random.nextFloat(); newShapeSet.colourOriginB = random.nextFloat(); } - newShapeSet.updateAllShapes(); shapeSets.add(newShapeSet); } public void initCheck() { if(!initialised) { + if(fromPersistence) { + for(ShapeSet shapeSet: shapeSets) { + shapeSet.updateAllShapes(); + } + } + if(shapeSets.size() == 0) { pushNewShapeSet(); + shapeSets.get(0).updateAllShapes(); } for(ShapeSet s: shapeSets) { if(s.origin == null) { s.resetOrigin(); } } + initialised = true; } } @@ -222,6 +230,8 @@ public void loadPersistence(File persistenceFile) throws IOException { scanner.close(); iShapeSet = Math.max(0, Math.min(shapeSets.size() - 1, iShapeSet)); iShapeNew = Math.max(0, Math.min(ShapeRegistry.getNumberOfShapes() - 1, iShapeNew)); + + fromPersistence = true; } public void savePersistence(File persistenceFile) throws IOException { diff --git a/common/src/brentmaas/buildguide/common/screen/BaseScreen.java b/common/src/brentmaas/buildguide/common/screen/BaseScreen.java index 732a8fe..8dec9c6 100644 --- a/common/src/brentmaas/buildguide/common/screen/BaseScreen.java +++ b/common/src/brentmaas/buildguide/common/screen/BaseScreen.java @@ -42,6 +42,8 @@ public void init() { addWidget(buttonVisualisation); addWidget(buttonShapeList); addWidget(buttonConfiguration); + + BuildGuide.stateManager.getState().initCheck(); } public void render() { diff --git a/common/src/brentmaas/buildguide/common/screen/ShapeScreen.java b/common/src/brentmaas/buildguide/common/screen/ShapeScreen.java index 5a1f4db..0c72503 100644 --- a/common/src/brentmaas/buildguide/common/screen/ShapeScreen.java +++ b/common/src/brentmaas/buildguide/common/screen/ShapeScreen.java @@ -53,8 +53,6 @@ public class ShapeScreen extends BaseScreen{ public void init() { super.init(); - BuildGuide.stateManager.getState().initCheck(); - if(!BuildGuide.stateManager.getState().isShapeAvailable()) { buttonShapePrevious.setActive(false); buttonShapeNext.setActive(false); diff --git a/common/src/brentmaas/buildguide/common/screen/ShapelistScreen.java b/common/src/brentmaas/buildguide/common/screen/ShapelistScreen.java index 50581ea..5793f3e 100644 --- a/common/src/brentmaas/buildguide/common/screen/ShapelistScreen.java +++ b/common/src/brentmaas/buildguide/common/screen/ShapelistScreen.java @@ -21,6 +21,7 @@ public class ShapelistScreen extends BaseScreen { private IButton buttonNewShapeNext = BuildGuide.widgetHandler.createButton(145, 70, 20, 20, "->", () -> updateNewShape(1)); private IButton buttonAdd = BuildGuide.widgetHandler.createButton(5, 90, 160, 20, BuildGuide.screenHandler.translate("screen.buildguide.add"), () -> { BuildGuide.stateManager.getState().pushNewShapeSet(); + BuildGuide.stateManager.getState().getShapeSet(BuildGuide.stateManager.getState().getNumberOfShapeSets() - 1).updateAllShapes(); shapeList.addEntry(BuildGuide.stateManager.getState().getNumberOfShapeSets() - 1); checkActive(); diff --git a/common/src/brentmaas/buildguide/common/shape/Shape.java b/common/src/brentmaas/buildguide/common/shape/Shape.java index b32146a..dd4034b 100644 --- a/common/src/brentmaas/buildguide/common/shape/Shape.java +++ b/common/src/brentmaas/buildguide/common/shape/Shape.java @@ -184,7 +184,6 @@ public void restorePersistence(String persistenceData) { for(int i = 0;i < properties.size();++i) { success = success & properties.get(i).setValueFromString(splitData[i]); } - update(); error = !success; }else { error = true; diff --git a/common/src/brentmaas/buildguide/common/shape/ShapeSet.java b/common/src/brentmaas/buildguide/common/shape/ShapeSet.java index 15e186e..3423cef 100644 --- a/common/src/brentmaas/buildguide/common/shape/ShapeSet.java +++ b/common/src/brentmaas/buildguide/common/shape/ShapeSet.java @@ -36,7 +36,6 @@ public ShapeSet(int startIndex) { private Shape initialiseShape(String shapeId) { Shape newShape = ShapeRegistry.getNewInstance(shapeId); newShape.shapeSet = this; - newShape.update(); return newShape; } @@ -98,6 +97,7 @@ public boolean isShapeAvailable(int index) { public Shape getShape() { if(shapes[index] == null) { shapes[index] = initialiseShape(ShapeRegistry.getClassIdentifier(index)); + shapes[index].update(); } return shapes[index]; @@ -164,11 +164,7 @@ public void restorePersistence(String persistenceData) { int index = ShapeRegistry.getShapeId(key); if(index >= 0) { shapes[index] = initialiseShape(key); - // Lock wizardry due to classloading issues on Forge - shapes[index].cancelFuture(); - shapes[index].lock.lock(); shapes[index].restorePersistence(value); - shapes[index].lock.unlock(); } } }