Added scripted block data synchronisation

This commit is contained in:
Goodbird committed 2024-01-21 22:17:24 +03:00
1 parent 7562d9a545
commit 32abb0f0ea
2 files changed
+27

No files matched your search

@@ -22,11 +22,13 @@ import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.math.BlockPos;
import net.minecraft.village.MerchantRecipeList;
import net.minecraft.world.WorldProvider;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.DimensionManager;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.blocks.tiles.TileScripted;
import noppes.npcs.config.ConfigDebug;
import noppes.npcs.config.ConfigMain;
import noppes.npcs.config.ConfigScript;
@@ -175,6 +177,8 @@ public class PacketHandlerServer{
forgeScriptPackets(type, buffer, player);
else if (type == EnumPacketServer.ScriptItemDataGet || type == EnumPacketServer.ScriptItemDataSave)
itemScriptPackets(type, buffer, player);
else if (type == EnumPacketServer.ScriptBlockDataGet || type == EnumPacketServer.ScriptBlockDataSave)
blockScriptPackets(type, buffer, player);
else if (type == EnumPacketServer.ScriptGlobalGuiDataGet || type == EnumPacketServer.ScriptGlobalGuiDataSave)
getScriptsEnabled(type, buffer, player);
else if (item.getItem() == CustomItems.scripter)
@@ -339,6 +343,27 @@ public class PacketHandlerServer{
}
}
private void blockScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws Exception {
if (type == EnumPacketServer.ScriptBlockDataGet) {
TileEntity tile = player.worldObj.getTileEntity(buffer.readInt(), buffer.readInt(), buffer.readInt());
if(!(tile instanceof TileScripted))
return;
NBTTagCompound compound = ((TileScripted) tile).getNBT(new NBTTagCompound());
compound.setTag("Languages", ScriptController.Instance.nbtLanguages());
Server.sendData(player, EnumPacketClient.GUI_DATA, compound);
} else if (type == EnumPacketServer.ScriptBlockDataSave) {
if (!player.capabilities.isCreativeMode) {
return;
}
TileEntity tile = player.worldObj.getTileEntity(buffer.readInt(), buffer.readInt(), buffer.readInt());
if(!(tile instanceof TileScripted))
return;
TileScripted script = (TileScripted) tile;
script.setNBT(Server.readNBT(buffer));
script.lastInited = -1;
}
}
private void featherPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws IOException {
if(type == EnumPacketServer.DimensionTeleport){
int dimension = buffer.readInt();
@@ -49,6 +49,8 @@ public enum EnumPacketServer {
ScriptItemDataSave(CustomNpcsPermissions.TOOL_SCRIPTER, false),
ScriptItemDataGet(false),
ScriptBlockDataSave(CustomNpcsPermissions.TOOL_SCRIPTER, false),
ScriptBlockDataGet(false),
LinkedGetAll, LinkedRemove(CustomNpcsPermissions.GLOBAL_LINKED), LinkedAdd(CustomNpcsPermissions.GLOBAL_LINKED),
ScriptDataSave(CustomNpcsPermissions.TOOL_SCRIPTER, true), ScriptDataGet(true),