mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-20 04:09:57 +00:00
-Overlays for players and NPCs are now grouped in an "overlay handler" object, similar to how you retrieve timers.
-Fixed client NPC overlay updates.
This commit is contained in:
1 parent
6fa5d0d8de
commit
6220a8ce14
20 files changed
+203
-164
No files matched your search
@@ -0,0 +1,82 @@
|
||||
package noppes.npcs.entity.data;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.controllers.PlayerData;
|
||||
import noppes.npcs.controllers.data.SkinOverlayData;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.scripted.interfaces.ISkinOverlay;
|
||||
import noppes.npcs.scripted.interfaces.handler.IOverlayHandler;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class DataSkinOverlays implements IOverlayHandler {
|
||||
public final Object parent;
|
||||
public HashMap<Integer, ISkinOverlay> overlayList = new HashMap<>();
|
||||
|
||||
public DataSkinOverlays(Object parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound nbtTagCompound) {
|
||||
HashMap<Integer,ISkinOverlay> skinOverlays = new HashMap<>();
|
||||
NBTTagList skinOverlayList = nbtTagCompound.getTagList("SkinOverlayData",10);
|
||||
for (int i = 0; i < skinOverlayList.tagCount(); i++) {
|
||||
int tagID = skinOverlayList.getCompoundTagAt(i).getInteger("SkinOverlayID");
|
||||
SkinOverlayData skinOverlay = (SkinOverlayData) SkinOverlayData.overlayFromNBT(skinOverlayList.getCompoundTagAt(i));
|
||||
skinOverlays.put(tagID, skinOverlay);
|
||||
}
|
||||
|
||||
this.overlayList = skinOverlays;
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
NBTTagList overlayList = new NBTTagList();
|
||||
if (!this.overlayList.isEmpty()) {
|
||||
for (Map.Entry<Integer,ISkinOverlay> overlayData : this.overlayList.entrySet()) {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setInteger("SkinOverlayID", overlayData.getKey());
|
||||
compound = ((SkinOverlayData) overlayData.getValue()).writeToNBT(compound);
|
||||
overlayList.appendTag(compound);
|
||||
}
|
||||
}
|
||||
nbttagcompound.setTag("SkinOverlayData",overlayList);
|
||||
return nbttagcompound;
|
||||
}
|
||||
|
||||
public void updateClient() {
|
||||
if (parent instanceof PlayerData) {
|
||||
NBTTagCompound compound = this.writeToNBT(new NBTTagCompound());
|
||||
((PlayerData) parent).player.getEntityData().setTag("SkinOverlayData", compound.getTagList("SkinOverlayData",10));
|
||||
} else if (parent instanceof EntityNPCInterface) {
|
||||
((EntityNPCInterface) parent).updateClient = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void add(int id, ISkinOverlay data) {
|
||||
((SkinOverlayData) data).parent = this;
|
||||
this.overlayList.put(id, data);
|
||||
updateClient();
|
||||
}
|
||||
|
||||
public ISkinOverlay get(int id) {
|
||||
return this.overlayList.get(id);
|
||||
}
|
||||
|
||||
public boolean has(int id) {
|
||||
return this.overlayList.containsKey(id);
|
||||
}
|
||||
|
||||
public boolean remove(int id) {
|
||||
boolean removed = this.overlayList.remove(id) != null;
|
||||
updateClient();
|
||||
return removed;
|
||||
}
|
||||
|
||||
public int size() { return this.overlayList.size(); }
|
||||
|
||||
public void clear() {
|
||||
this.overlayList.clear();
|
||||
updateClient();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user