Skip to content

Commit

Permalink
Pre rewrite/fabric/1.21 block entities (#4)
Browse files Browse the repository at this point in the history
* Bootstrap for entity data

* Fix data channel for servux

* block entities servux paste (#3)

* feat: paste to servux

* feat: paste to servux

* feat: paste to servux

* fix

* Forgot to merge my fixes

* Forgot to merge my fixes

* Fix Accurate Placement for Crafter Orientations and a few other Block States

* Update accuratePlacement Protocol V3 for use with Servux

* Fix:  Item Frame floor / ceiling Yaw values.

* Add settings for Entity Data Syncer

* Add settings for Entity Data Syncer

* code cleanup / Litematic Entity NBT Save handling

* code cleanup / Litematic Entity NBT Save handling

---------

Co-authored-by: Liyan Zhao <[email protected]>
  • Loading branch information
sakura-ryoko and zly2006 authored Jul 3, 2024
1 parent d7651a6 commit 04f5158
Show file tree
Hide file tree
Showing 28 changed files with 1,471 additions and 51 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ author = masa
mod_file_name = litematica-fabric

# Current mod version
mod_version = 0.18.999-sakura.11
mod_version = 0.18.999-sakura.12

# Required malilib version
malilib_version = 0.19.999-sakura.4
malilib_id = 7af53f6c0a
malilib_version = 0.19.999-sakura.6
malilib_id = dc2525e2ee

# Minecraft, Fabric Loader and API and mappings versions
minecraft_version_out = 1.21
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;
}
10 changes: 9 additions & 1 deletion src/main/java/fi/dy/masa/litematica/config/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class Configs implements IConfigHandler

public static class Generic
{
public static final ConfigOptionList EASY_PLACE_PROTOCOL = new ConfigOptionList("easyPlaceProtocolVersion", EasyPlaceProtocol.AUTO, "The type of \"accurate placement protocol\" to use.\n- Auto: Uses v3 in single player, and by default Slabs-only in multiplayer,\n unless the server has Carpet mod that sends a 'carpet:hello'\n packet, in which case v2 is used on that server.\n- Version 3: Only supported by Litematica itself (in single player) for now.\n- Version 2: Compatible with servers with the Carpet mod\n (either QuickCarpet by skyrising and DeadlyMC,\n or CarpetExtra in addition to FabricCarpet.\n And in both cases the 'accurateBlockPlacement' Carpet rule needs\n to be enabled on the server).\n- Slabs only: Only fixes top slabs. Compatible with Paper servers.\n- None: Does not modify coordinates.");
public static final ConfigOptionList EASY_PLACE_PROTOCOL = new ConfigOptionList("easyPlaceProtocolVersion", EasyPlaceProtocol.AUTO, "The type of \"accurate placement protocol\" to use.\n- Auto: Uses v3 in single player, and by default Slabs-only in multiplayer,\n unless the server has Carpet mod that sends a 'carpet:hello'\n packet, in which case v2 is used on that server.\n- Version 3: Only supported by Litematica itself (in single player) or with Servux.\n- Version 2: Compatible with servers with the Carpet mod\n (either QuickCarpet by skyrising and DeadlyMC,\n or CarpetExtra in addition to FabricCarpet.\n And in both cases the 'accurateBlockPlacement' Carpet rule needs\n to be enabled on the server).\n- Slabs only: Only fixes top slabs. Compatible with Paper servers.\n- None: Does not modify coordinates.");
public static final ConfigOptionList PASTE_NBT_BEHAVIOR = new ConfigOptionList("pasteNbtRestoreBehavior", PasteNbtBehavior.NONE, "Whether or not the NBT data of blocks is attempted to be restored,\nand which method is used for that.\n- Place & Data Modify will try to place the \"NBT-picked\" block\n near the player, and then use the data modify\n command to transfer the NBT data to the setblock'ed block\n- Place & Clone will try to place the \"NBT-picked\" block\n near the player, and then clone it to the final location.\n- Teleport & Place will try to teleport the player nearby and then\n directly place the NBT-picked item in the correct position.\nNote that the teleport & place method doesn't currently work correctly/at all.\nThe recommended method is §ePlace & Data Modify§r, however for that to work\nyou will probably need to lower the pasteCommandLimit to 1 per tick and increase\nthe pasteCommandInterval to 1-4 ticks or something.\nThus you should only use this for pasting important blocks that need the data,\nfor example by making a schematic of just the inventories,\nand then paste that with replace behavior set to None.");
public static final ConfigOptionList PASTE_REPLACE_BEHAVIOR = new ConfigOptionList("pasteReplaceBehavior", ReplaceBehavior.NONE, "The behavior of replacing existing blocks\nin the Paste schematic tool mode");
public static final ConfigOptionList PLACEMENT_REPLACE_BEHAVIOR = new ConfigOptionList("placementReplaceBehavior", ReplaceBehavior.ALL, "The block replace behavior when adding blocks\nto the schematic world.\n\nThis allows using overlapped placements without the\nlater handled placement always overwriting earlier ones with air.\nOn the other hand some blocks like light blocks are considered\nto be air, so they would need the \"All\" replace behavior\nto get placed at all.");
Expand Down Expand Up @@ -55,6 +55,8 @@ public static class Generic
public static final ConfigBoolean EASY_PLACE_SP_HANDLING = new ConfigBoolean("easyPlaceSinglePlayerHandling", true, "If enabled, then Litematica handles the so called\n\"Carpet mod Accurate Block Placement Protocol\" itself in single player.\nThis is recommended to be kept enabled if you\nare going to use Easy Place in single player.");
public static final ConfigInteger EASY_PLACE_SWAP_INTERVAL = new ConfigInteger("easyPlaceSwapInterval", 0, 0, 10000, "The interval in milliseconds the Easy Place mode waits\nafter swapping inventory slots and placing a block.\nUseful to avoid placing wrong blocks when having high ping.");
public static final ConfigBoolean EASY_PLACE_VANILLA_REACH = new ConfigBoolean("easyPlaceVanillaReach", false, "If enabled, reduces reach distance from 6 to 4.5\nso servers don't reject placement of far blocks.");
public static final ConfigBoolean ENTITY_DATA_SYNC = new ConfigBoolean("entityDataSync", true, "Use the Entity Data Sync protocol from Servux\nto obtain Entity Data from the server");
public static final ConfigBoolean ENTITY_DATA_SYNC_BACKUP = new ConfigBoolean("entityDataSyncBackup", true, "Use the Vanilla NBT Query method when Servux\nis not available. This method requires Operator Privileges.");
public static final ConfigBoolean EXECUTE_REQUIRE_TOOL = new ConfigBoolean("executeRequireHoldingTool", true, "Require holding an enabled tool item\nfor the executeOperation hotkey to work");
public static final ConfigBoolean FIX_CHEST_MIRROR = new ConfigBoolean("fixChestMirror", true, "Enable a fix to the broken chest mirror code in vanilla");
public static final ConfigBoolean FIX_RAIL_ROTATION = new ConfigBoolean("fixRailRotation", true, "If true, then a fix is applied for the vanilla bug in rails,\nwhere the 180 degree rotations of straight north-south and\neast-west rails rotate 90 degrees counterclockwise instead >_>");
Expand All @@ -73,6 +75,7 @@ public static class Generic
public static final ConfigBoolean PASTE_TO_MCFUNCTION = new ConfigBoolean("pasteToMcFunctionFiles", false, "If enabled, then instead of actually pasting schematics to the world,\nthey are written as setblock commands into text files.");
public static final ConfigBoolean PASTE_USE_FILL_COMMAND = new ConfigBoolean("pasteUseFillCommand", true, "If enabled, then instead of only using individual /setblock commands,\nthe command-based Paste operation (which is used on servers)\nwill also try to use /fill commands for any continuous areas of the same block.\nThis has no effect in single player, since the mod sets the blocks directly\nin the integrated server's world in and doesn't use commands at all.");
public static final ConfigBoolean PASTE_USING_COMMANDS_IN_SP = new ConfigBoolean("pasteUsingCommandsInSp", false, "This is a temporary hack workaround to use the command-based pasting\nalso in single player, which allows using the render layer limited\npasting in single player, which currently doesn't work with\nthe direct world access pasting that single player normally uses.\n\nNote that this will have all the same NBT data restoration\nlimitations that multiplayer pasting has normally.");
public static final ConfigBoolean PASTE_USING_SERVUX = new ConfigBoolean("pasteUsingServux", true, "Use Servux to paste a schematic directly to the server.\nThis method is much faster than the traditional\ncommand-based method, and it supports restoring\nEntity NBT Data.");
public static final ConfigBoolean PICK_BLOCK_AVOID_DAMAGEABLE = new ConfigBoolean("pickBlockAvoidDamageable", true, "Avoids replacing any damageable items in the hotbar");
public static final ConfigBoolean PICK_BLOCK_AVOID_TOOLS = new ConfigBoolean("pickBlockAvoidTools", false, "Avoids replacing any tool items in the hotbar.\n\nThis means any items that extend the vanilla ToolItem class.");
public static final ConfigBoolean PICK_BLOCK_ENABLED = new ConfigBoolean("pickBlockEnabled", true, "Enables the schematic world pick block hotkeys.\nThere is also a hotkey for toggling this option to toggle those hotkeys... o.o", "Pick Block Hotkeys");
Expand All @@ -81,6 +84,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 All @@ -103,6 +107,8 @@ public static class Generic
EASY_PLACE_SP_HANDLING,
EASY_PLACE_PROTOCOL,
EASY_PLACE_VANILLA_REACH,
ENTITY_DATA_SYNC,
ENTITY_DATA_SYNC_BACKUP,
EXECUTE_REQUIRE_TOOL,
FIX_CHEST_MIRROR,
FIX_RAIL_ROTATION,
Expand All @@ -122,6 +128,7 @@ public static class Generic
PASTE_TO_MCFUNCTION,
PASTE_USE_FILL_COMMAND,
PASTE_USING_COMMANDS_IN_SP,
PASTE_USING_SERVUX,
PICK_BLOCK_AVOID_DAMAGEABLE,
PICK_BLOCK_AVOID_TOOLS,
PICK_BLOCK_ENABLED,
Expand All @@ -131,6 +138,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 04f5158

Please sign in to comment.