From a47af08d0f2a9273077f1cc0fc88f78e92102411 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Sun, 18 Dec 2022 02:58:12 -0600 Subject: [PATCH] Fixed spawning clones without checking for region protection. --- .../java/noppes/npcs/NoppesUtilServer.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index 7e082ca90..a17d80b64 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -19,6 +19,7 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.passive.EntityBat; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.projectile.EntityArrow; @@ -36,6 +37,8 @@ import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.DamageSource; import net.minecraft.util.MathHelper; import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.EntityJoinWorldEvent; import noppes.npcs.constants.EnumGuiType; import noppes.npcs.constants.EnumPacketClient; import noppes.npcs.constants.EnumPlayerData; @@ -672,7 +675,7 @@ public class NoppesUtilServer { } Server.sendData(player, EnumPacketClient.GUI_CLOSE, i, comp); } - + public static Entity spawnCloneWithProtection(NBTTagCompound compound, int x, int y, int z, World worldObj) { ServerCloneController.Instance.cleanTags(compound); @@ -716,8 +719,19 @@ public class NoppesUtilServer { if(entity == null){ return null; } - worldObj.spawnEntityInWorld(entity); - return entity; + int i = MathHelper.floor_double(entity.posX / 16.0D); + int j = MathHelper.floor_double(entity.posZ / 16.0D); + if (!entity.forceSpawn && !worldObj.checkChunksExist( + (int)entity.posX,(int)entity.posY,(int)entity.posZ,(int)entity.posX,(int)entity.posY,(int)entity.posZ + )) + { + return null; + } else { + worldObj.getChunkFromChunkCoords(i, j).addEntity(entity); + worldObj.loadedEntityList.add(entity); + worldObj.onEntityAdded(entity); + return entity; + } } public static boolean isOp(EntityPlayer player) {