Skip to content

Commit

Permalink
Bootstrap for entity data
Browse files Browse the repository at this point in the history
  • Loading branch information
sakura-ryoko committed Jun 27, 2024
1 parent f7a7fb0 commit 339f6e7
Show file tree
Hide file tree
Showing 16 changed files with 1,155 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ author = masa
mod_file_name = litematica-fabric

# Current mod version
mod_version = 0.18.999-sakura.11
mod_version = 0.18.999-sakura.11-entity_data.1

# Required malilib version
malilib_version = 0.19.999-sakura.4
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/fi/dy/masa/litematica/InitHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@

import fi.dy.masa.litematica.config.Configs;
import fi.dy.masa.litematica.data.DataManager;
import fi.dy.masa.litematica.event.InputHandler;
import fi.dy.masa.litematica.event.KeyCallbacks;
import fi.dy.masa.litematica.event.RenderHandler;
import fi.dy.masa.litematica.event.WorldLoadListener;
import fi.dy.masa.litematica.data.EntitiesDataStorage;
import fi.dy.masa.litematica.event.*;
import fi.dy.masa.litematica.render.infohud.StatusInfoRenderer;
import fi.dy.masa.litematica.scheduler.ClientTickHandler;
import fi.dy.masa.malilib.config.ConfigManager;
import fi.dy.masa.malilib.event.InputEventHandler;
import fi.dy.masa.malilib.event.RenderEventHandler;
import fi.dy.masa.malilib.event.TickHandler;
import fi.dy.masa.malilib.event.WorldLoadHandler;
import fi.dy.masa.malilib.event.*;
import fi.dy.masa.malilib.interfaces.IInitializationHandler;
import fi.dy.masa.malilib.interfaces.IRenderer;

Expand All @@ -24,6 +19,7 @@ public class InitHandler implements IInitializationHandler
public void registerModHandlers()
{
ConfigManager.getInstance().registerConfigHandler(Reference.MOD_ID, new Configs());
EntitiesDataStorage.getInstance().onGameInit();

InputEventHandler.getKeybindManager().registerKeybindProvider(InputHandler.getInstance());
InputEventHandler.getInputManager().registerKeyboardInputHandler(InputHandler.getInstance());
Expand All @@ -33,7 +29,11 @@ public void registerModHandlers()
RenderEventHandler.getInstance().registerGameOverlayRenderer(renderer);
RenderEventHandler.getInstance().registerWorldLastRenderer(renderer);

ServerListener serverListener = new ServerListener();
ServerHandler.getInstance().registerServerHandler(serverListener);

TickHandler.getInstance().registerClientTickHandler(new ClientTickHandler());
TickHandler.getInstance().registerClientTickHandler(EntitiesDataStorage.getInstance());

WorldLoadListener listener = new WorldLoadListener();
WorldLoadHandler.getInstance().registerWorldLoadPreHandler(listener);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/fi/dy/masa/litematica/Reference.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package fi.dy.masa.litematica;

import net.minecraft.MinecraftVersion;
import fi.dy.masa.malilib.util.StringUtils;

public class Reference
{
public static final String MOD_ID = "litematica";
public static final String MOD_NAME = "Litematica";
public static final String MOD_VERSION = StringUtils.getModVersionString(MOD_ID);
public static final String MC_VERSION = MinecraftVersion.CURRENT.getName();
public static final String MOD_TYPE = "fabric";
public static final String MOD_STRING = MOD_ID+"-"+MOD_TYPE+"-"+MC_VERSION+"-"+MOD_VERSION;
}
2 changes: 2 additions & 0 deletions src/main/java/fi/dy/masa/litematica/config/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public static class Generic
public static final ConfigBoolean PLACEMENT_RESTRICTION = new ConfigBoolean("placementRestriction", false, "When enabled, the use key can only be used\nwhen holding the correct item for the targeted position,\nand the targeted position must have a missing block in the schematic", "Placement Restriction");
public static final ConfigBoolean RENDER_MATERIALS_IN_GUI = new ConfigBoolean("renderMaterialListInGuis", true, "Whether or not the material list should\nbe rendered inside GUIs");
public static final ConfigBoolean RENDER_THREAD_NO_TIMEOUT = new ConfigBoolean("renderThreadNoTimeout", true, "Removes the timeout from the rendering worker threads.\nIf you get very stuttery rendering when moving around\nor dealing with large schematics, try disabling this. It will however make\nthe schematic rendering a lot slower in some cases.");
public static final ConfigInteger SERVER_NBT_REQUEST_RATE = new ConfigInteger("serverNbtRequestRate", 2, "Limit request rate for server entity data syncer");
public static final ConfigBoolean SIGN_TEXT_PASTE = new ConfigBoolean("signTextPaste", true, "Automatically set the text in the sign GUIs from the schematic");
public static final ConfigString TOOL_ITEM = new ConfigString( "toolItem", "minecraft:stick", "The item to use as the \"tool\" for selections etc.");
public static final ConfigBoolean TOOL_ITEM_ENABLED = new ConfigBoolean("toolItemEnabled", true, "If true, then the \"tool\" item can be used to control selections etc.", "Tool Item Enabled");
Expand Down Expand Up @@ -131,6 +132,7 @@ public static class Generic
PLACEMENT_RESTRICTION_WARN,
RENDER_MATERIALS_IN_GUI,
RENDER_THREAD_NO_TIMEOUT,
SERVER_NBT_REQUEST_RATE,
SIGN_TEXT_PASTE,
TOOL_ITEM_ENABLED,
UNHIDE_SCHEMATIC_PROJECTS,
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/fi/dy/masa/litematica/data/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class DataManager implements IDirectoryCache
private static boolean canSave;
private static boolean isCarpetServer;
private static long clientTickStart;
private boolean hasIntegratedServer = false;

public static Identifier CARPET_HELLO = Identifier.of("carpet", "hello");
private final SelectionManager selectionManager = new SelectionManager();
Expand All @@ -66,6 +67,19 @@ public static DataManager getInstance()
return INSTANCE;
}

public void reset(boolean isLogout)
{
if (isLogout)
{
Litematica.debugLog("DataManager#reset() - log-out");
this.hasIntegratedServer = false;
}
else
{
Litematica.debugLog("DataManager#reset() - dimension change or log-in");
}
}

public static IDirectoryCache getDirectoryCache()
{
return INSTANCE;
Expand Down Expand Up @@ -96,6 +110,13 @@ public static boolean isCarpetServer()
return isCarpetServer;
}

public boolean hasIntegratedServer() { return this.hasIntegratedServer; }

public void setHasIntegratedServer(boolean toggle)
{
this.hasIntegratedServer = toggle;
}

public static void addChatListener(ToBooleanFunction<Text> listener)
{
synchronized (CHAT_LISTENERS)
Expand Down Expand Up @@ -334,6 +355,8 @@ private void savePerDimensionData()
this.schematicProjectsManager.saveCurrentProject();
JsonObject root = this.toJson();

root.add("block_entities", EntitiesDataStorage.getInstance().toJson());

File file = getCurrentStorageFile(false);
JsonUtils.writeJsonToFile(root, file);
}
Expand All @@ -352,6 +375,11 @@ private void loadPerDimensionData()
{
JsonObject root = element.getAsJsonObject();
this.fromJson(root);

if (JsonUtils.hasObject(root, "block_entities"))
{
EntitiesDataStorage.getInstance().fromJson(JsonUtils.getNestedObject(root, "block_entities", false));
}
}
}

Expand Down
Loading

0 comments on commit 339f6e7

Please sign in to comment.