mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 15:45:10 +00:00
Added handler support to NPC API.
This commit is contained in:
1 parent
69f96519dc
commit
d50f51e208
40 files changed
+1471
-56
No files matched your search
@@ -13,6 +13,7 @@ import java.util.Map;
|
||||
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -20,11 +21,17 @@ import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.controllers.LinkedNpcController.LinkedData;
|
||||
import noppes.npcs.scripted.CustomNPCsException;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.handler.ICloneHandler;
|
||||
import noppes.npcs.scripted.interfaces.IEntity;
|
||||
import noppes.npcs.scripted.interfaces.IWorld;
|
||||
import noppes.npcs.util.JsonException;
|
||||
import noppes.npcs.util.NBTJsonUtil;
|
||||
|
||||
public class ServerCloneController {
|
||||
public class ServerCloneController implements ICloneHandler {
|
||||
public static ServerCloneController Instance;
|
||||
|
||||
public ServerCloneController(){
|
||||
@@ -193,4 +200,39 @@ public class ServerCloneController {
|
||||
nbttagcompound.setTag("TransformAI", adv);
|
||||
}
|
||||
}
|
||||
|
||||
public IEntity spawn(double x, double y, double z, int tab, String name, IWorld world) {
|
||||
NBTTagCompound compound = this.getCloneData((ICommandSender)null, name, tab);
|
||||
if (compound == null) {
|
||||
throw new CustomNPCsException("Unknown clone tab:" + tab + " name:" + name, new Object[0]);
|
||||
} else {
|
||||
Entity entity = NoppesUtilServer.spawnClone(compound, (int)x, (int)y, (int)z, world.getMCWorld());
|
||||
return entity == null ? null : NpcAPI.Instance().getIEntity(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public IEntity get(int tab, String name, IWorld world) {
|
||||
NBTTagCompound compound = this.getCloneData((ICommandSender)null, name, tab);
|
||||
if (compound == null) {
|
||||
throw new CustomNPCsException("Unknown clone tab:" + tab + " name:" + name, new Object[0]);
|
||||
} else {
|
||||
Instance.cleanTags(compound);
|
||||
Entity entity = EntityList.createEntityFromNBT(compound, world.getMCWorld());
|
||||
return entity == null ? null : NpcAPI.Instance().getIEntity(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public void set(int tab, String name, IEntity entity) {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
if (!entity.getMCEntity().isEntityAlive()) {
|
||||
throw new CustomNPCsException("Cannot save dead entities", new Object[0]);
|
||||
} else {
|
||||
this.cleanTags(compound);
|
||||
this.saveClone(tab, name, compound);
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(int tab, String name) {
|
||||
this.removeClone(name, tab);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user