mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-25 09:54:25 +00:00
OVERHAULED IGuiData FRAMEWORK SO ALL UPDATES WIRE THROUGH SyncController (deprecated legacy setGuiData)
This commit is contained in:
1 parent
7f63b64a66
commit
1a77728bcd
3 files changed
+110
-15
No files matched your search
@@ -22,6 +22,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.client.ClientCacheHandler;
|
||||
import noppes.npcs.client.gui.util.IGuiData;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -291,6 +292,9 @@ public class SyncController {
|
||||
}
|
||||
|
||||
ClientCacheHandler.updateClientRevision(syncType, revision);
|
||||
|
||||
// New GUI data handling approach
|
||||
IGuiData.notifyUpdate(compound, key, id);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@@ -305,6 +309,9 @@ public class SyncController {
|
||||
}
|
||||
|
||||
ClientCacheHandler.updateClientRevision(syncType, revision);
|
||||
|
||||
// New GUI data handling approach
|
||||
IGuiData.notifyRemove(key, id);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════
|
||||
|
||||
@@ -9,13 +9,9 @@ import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumDataPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.client.gui.util.GuiContainerNPCInterface;
|
||||
import noppes.npcs.client.gui.util.GuiNPCInterface;
|
||||
import noppes.npcs.client.gui.util.IGuiData;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -59,15 +55,6 @@ public final class GuiDataPacket extends LargeAbstractPacket {
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
protected void handleCompleteData(ByteBuf data, EntityPlayer player) throws IOException {
|
||||
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
|
||||
if (gui instanceof GuiNPCInterface && ((GuiNPCInterface) gui).hasSubGui()) {
|
||||
gui = ((GuiNPCInterface) gui).getSubGui();
|
||||
} else if (gui instanceof GuiContainerNPCInterface && ((GuiContainerNPCInterface) gui).hasSubGui()) {
|
||||
gui = ((GuiContainerNPCInterface) gui).getSubGui();
|
||||
}
|
||||
if (gui instanceof IGuiData) {
|
||||
NBTTagCompound nbt = ByteBufUtils.readBigNBT(data);
|
||||
((IGuiData) gui).setGuiData(nbt);
|
||||
}
|
||||
IGuiData.legacySetGuiData(ByteBufUtils.readBigNBT(data));
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,108 @@
|
||||
package noppes.npcs.client.gui.util;
|
||||
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.controllers.sync.SyncHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* OVERHAULED IGuiData FRAMEWORK!
|
||||
* Based on the new {@link SyncController} and {@link SyncHandler} infrastructure
|
||||
*/
|
||||
public interface IGuiData {
|
||||
public void setGuiData(NBTTagCompound compound);
|
||||
|
||||
/**
|
||||
* Legacy data setter
|
||||
* @Deprecated Use {@link #onDataUpdated(NBTTagCompound)} or {@link #onDataRemoved(String)} instead
|
||||
*/
|
||||
default void setGuiData(NBTTagCompound compound) {
|
||||
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════
|
||||
// USE THESE !!!
|
||||
// ═══════════════════════════════════════════════════════════════════════
|
||||
|
||||
/** NOTE:
|
||||
* No need for full object dataset onDataReload on GUI open, as these datasets are
|
||||
* always freshly synced to their client's controllers thanks to {@link SyncController}
|
||||
*/
|
||||
|
||||
/**
|
||||
* When a controller's object gets saved on server side, the updated object is synced to the client
|
||||
* @param compound the compound of the updated object
|
||||
*/
|
||||
default void onDataUpdated(NBTTagCompound compound) {
|
||||
}
|
||||
|
||||
/**
|
||||
* When a controller's object gets saved on server side, the updated object is synced to the client
|
||||
* @param key key of updated object
|
||||
* @param compound compound of updated object
|
||||
*/
|
||||
default void onDataUpdated(NBTTagCompound compound, String key) {
|
||||
}
|
||||
|
||||
/**
|
||||
* When a controller's object gets saved on server side, the updated object is synced to the client
|
||||
* @param id id of updated object
|
||||
* @param compound compound of updated object
|
||||
*/
|
||||
default void onDataUpdated(NBTTagCompound compound, int id) {
|
||||
}
|
||||
|
||||
/**
|
||||
* When a controller's object gets deleted on server side, the deleted object is removed from the client
|
||||
* @param key key of removed object
|
||||
*/
|
||||
default void onDataRemoved(String key) {
|
||||
}
|
||||
|
||||
/**
|
||||
* When a controller's object gets deleted on server side, the deleted object is removed from the client
|
||||
* @param id id of removed object
|
||||
*/
|
||||
default void onDataRemoved(int id) {
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════
|
||||
// Static dispatchers
|
||||
// ═══════════════════════════════════════════════════════════════════════
|
||||
|
||||
static void legacySetGuiData(NBTTagCompound nbt) {
|
||||
GuiScreen gui = activeGui();
|
||||
if (gui instanceof IGuiData)
|
||||
((IGuiData) gui).setGuiData(nbt);
|
||||
}
|
||||
|
||||
static void notifyUpdate(NBTTagCompound nbt, String key, int id) {
|
||||
GuiScreen gui = activeGui();
|
||||
if (gui instanceof IGuiData) {
|
||||
((IGuiData) gui).onDataUpdated(nbt);
|
||||
((IGuiData) gui).onDataUpdated(nbt, key);
|
||||
((IGuiData) gui).onDataUpdated(nbt, id);
|
||||
}
|
||||
}
|
||||
|
||||
static void notifyRemove(String key, int id) {
|
||||
GuiScreen gui = activeGui();
|
||||
if (gui instanceof IGuiData) {
|
||||
((IGuiData) gui).onDataRemoved(key);
|
||||
((IGuiData) gui).onDataRemoved(id);
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════
|
||||
// Active Gui fetcher
|
||||
// ═══════════════════════════════════════════════════════════════════════
|
||||
|
||||
static GuiScreen activeGui() {
|
||||
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
|
||||
if (gui instanceof GuiNPCInterface && ((GuiNPCInterface) gui).hasSubGui())
|
||||
return ((GuiNPCInterface) gui).getSubGui();
|
||||
if (gui instanceof GuiContainerNPCInterface && ((GuiContainerNPCInterface) gui).hasSubGui())
|
||||
return ((GuiContainerNPCInterface) gui).getSubGui();
|
||||
return gui;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user