mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-18 05:45:03 +00:00
IWorld:
-Implemented spawnClone() with a boolean parameter to check entity protection from mods & plugins correctly (for real this time). ICloneHandler: -Implemented ignoreProtection boolean value for the spawn() function.
This commit is contained in:
1 parent
a4585fdf4d
commit
a3b5f5993e
5 files changed
+51
-8
No files matched your search
@@ -636,9 +636,29 @@ public class NoppesUtilServer {
|
||||
Server.sendData(player, EnumPacketClient.GUI_CLOSE, i, comp);
|
||||
}
|
||||
|
||||
public static Entity spawnClone(NBTTagCompound compound, int x, int y,
|
||||
public static Entity spawnCloneWithProtection(NBTTagCompound compound, int x, int y,
|
||||
int z, World worldObj) {
|
||||
ServerCloneController.Instance.cleanTags(compound);
|
||||
compound.setTag("Pos", NBTTags.nbtDoubleList(x + 0.5, y, z + 0.5));
|
||||
Entity entity = EntityList.createEntityFromNBT(compound, worldObj);
|
||||
if(entity == null){
|
||||
return null;
|
||||
}
|
||||
entity.setPosition((double) x + 0.5, (double) y, (double) z + 0.5);
|
||||
if(entity instanceof EntityNPCInterface){
|
||||
EntityNPCInterface npc = (EntityNPCInterface) entity;
|
||||
npc.ai.startPos = new int[]{MathHelper.floor_double(npc.posX),MathHelper.floor_double(npc.posY),MathHelper.floor_double(npc.posZ)};
|
||||
npc.ticksExisted = 0;
|
||||
npc.totalTicksAlive = 0;
|
||||
}
|
||||
worldObj.spawnEntityInWorld(entity);
|
||||
entity.prevPosY = entity.lastTickPosY = entity.posY = y + 1;
|
||||
return entity;
|
||||
}
|
||||
|
||||
public static Entity spawnClone(NBTTagCompound compound, int x, int y,
|
||||
int z, World worldObj) {
|
||||
ServerCloneController.Instance.cleanTags(compound);
|
||||
compound.setTag("Pos", NBTTags.nbtDoubleList(x + 0.5, y + 1, z + 0.5));
|
||||
Entity entity = EntityList.createEntityFromNBT(compound, worldObj);
|
||||
if(entity == null){
|
||||
@@ -653,6 +673,7 @@ public class NoppesUtilServer {
|
||||
worldObj.spawnEntityInWorld(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
public static boolean isOp(EntityPlayer player) {
|
||||
return MinecraftServer.getServer().getConfigurationManager().func_152596_g(player.getGameProfile());
|
||||
}
|
||||
|
||||
@@ -194,16 +194,25 @@ public class ServerCloneController implements ICloneHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public IEntity spawn(double x, double y, double z, int tab, String name, IWorld world) {
|
||||
public IEntity spawn(double x, double y, double z, int tab, String name, IWorld world, boolean ignoreProtection) {
|
||||
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());
|
||||
Entity entity;
|
||||
if (!ignoreProtection) {
|
||||
entity = NoppesUtilServer.spawnCloneWithProtection(compound, (int) x, (int) y, (int) z, world.getMCWorld());
|
||||
} else {
|
||||
entity = NoppesUtilServer.spawnClone(compound, (int) x, (int) y, (int) z, world.getMCWorld());
|
||||
}
|
||||
return entity == null ? null : NpcAPI.Instance().getIEntity(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public IEntity spawn(double x, double y, double z, int tab, String name, IWorld world) {
|
||||
return spawn(x, y, z, tab, name, world, true);
|
||||
}
|
||||
|
||||
public IEntity[] getTab(int tab, IWorld world) {
|
||||
File dir = new File(getDir(), tab + "");
|
||||
if (!dir.exists() || !dir.isDirectory() || dir.listFiles() == null) {
|
||||
|
||||
@@ -588,14 +588,21 @@ public class ScriptWorld implements IWorld {
|
||||
* @param name Name of the cloned entity
|
||||
* @return Returns the entity which was spawned
|
||||
*/
|
||||
public IEntity spawnClone(int x, int y, int z, int tab, String name){
|
||||
public IEntity spawnClone(int x, int y, int z, int tab, String name, boolean ignoreProtection){
|
||||
NBTTagCompound compound = ServerCloneController.Instance.getCloneData(null, name, tab);
|
||||
if(compound == null)
|
||||
return null;
|
||||
Entity entity = NoppesUtilServer.spawnClone(compound, x, y, z, world);
|
||||
if(entity == null)
|
||||
return null;
|
||||
return NpcAPI.Instance().getIEntity(entity);
|
||||
Entity entity;
|
||||
if (!ignoreProtection) {
|
||||
entity = NoppesUtilServer.spawnCloneWithProtection(compound, x, y, z, world);
|
||||
} else {
|
||||
entity = NoppesUtilServer.spawnClone(compound, x, y, z, world);
|
||||
}
|
||||
return entity == null ? null : NpcAPI.Instance().getIEntity(entity);
|
||||
}
|
||||
|
||||
public IEntity spawnClone(int x, int y, int z, int tab, String name) {
|
||||
return this.spawnClone(x,y,z,tab,name,true);
|
||||
}
|
||||
|
||||
public ScriptScoreboard getScoreboard(){
|
||||
|
||||
@@ -346,8 +346,11 @@ public interface IWorld {
|
||||
* @param z The z position the clone will be spawned at
|
||||
* @param tab The tab in which the clone is
|
||||
* @param name Name of the cloned entity
|
||||
* @param ignoreProtection Whether the spawning of this clone skips protection checks.
|
||||
* @return Returns the entity which was spawned
|
||||
*/
|
||||
IEntity spawnClone(int x, int y, int z, int tab, String name, boolean ignoreProtection);
|
||||
|
||||
IEntity spawnClone(int x, int y, int z, int tab, String name);
|
||||
|
||||
ScriptScoreboard getScoreboard();
|
||||
|
||||
@@ -9,6 +9,9 @@ import noppes.npcs.scripted.interfaces.IWorld;
|
||||
import noppes.npcs.scripted.interfaces.entity.IEntity;
|
||||
|
||||
public interface ICloneHandler {
|
||||
|
||||
IEntity spawn(double x, double y, double z, int tab, String name, IWorld world, boolean ignoreProtection);
|
||||
|
||||
IEntity spawn(double x, double y, double z, int tab, String name, IWorld world);
|
||||
|
||||
IEntity[] getTab(int tab, IWorld world);
|
||||
|
||||
Reference in new issue
Block a user