From 49ee4b9f01cd585cacec9f51365a84a79db8b039 Mon Sep 17 00:00:00 2001 From: EdwinMindcraft Date: Tue, 6 Feb 2018 21:04:57 +0100 Subject: [PATCH] Fixed Summons --- build.properties | 2 +- .../am2/common/extensions/EntityExtension.java | 4 +++- .../java/am2/common/handler/EntityHandler.java | 2 ++ src/main/java/am2/common/spell/SpellCaster.java | 6 ++++-- .../java/am2/common/spell/component/Dispel.java | 16 +++++++++------- src/main/java/am2/common/utils/EntityUtils.java | 11 +++++++++++ 6 files changed, 30 insertions(+), 11 deletions(-) diff --git a/build.properties b/build.properties index 6248767c7..5d929f3a9 100644 --- a/build.properties +++ b/build.properties @@ -2,7 +2,7 @@ #Sat Dec 24 21:55:56 PST 2016 mcmapping=snapshot_20161111 version=1.5.0C -build_number=3 +build_number=4 jei_version=3.7.8.+ mcversion=1.10.2 mod_name=ArsMagica2 diff --git a/src/main/java/am2/common/extensions/EntityExtension.java b/src/main/java/am2/common/extensions/EntityExtension.java index d7a70ee3b..2647ae363 100644 --- a/src/main/java/am2/common/extensions/EntityExtension.java +++ b/src/main/java/am2/common/extensions/EntityExtension.java @@ -25,6 +25,7 @@ import am2.common.packet.AMNetHandler; import am2.common.packet.AMPacketIDs; import am2.common.spell.ContingencyType; +import am2.common.utils.EntityUtils; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityCreature; import net.minecraft.entity.EntityLivingBase; @@ -458,10 +459,11 @@ public boolean getCanHaveMoreSummons() { } private void verifySummons(){ + this.setCurrentSummons(summon_ent_ids.size()); for (int i = 0; i < summon_ent_ids.size(); ++i){ int id = summon_ent_ids.get(i); Entity e = entity.worldObj.getEntityByID(id); - if (e == null || !(e instanceof EntityLivingBase)){ + if (e == null || !(e instanceof EntityLivingBase) || EntityUtils.getOwner((EntityLivingBase) e) != entity.getEntityId()){ summon_ent_ids.remove(i); i--; removeSummon(); diff --git a/src/main/java/am2/common/handler/EntityHandler.java b/src/main/java/am2/common/handler/EntityHandler.java index 54f982a65..df6457b5d 100644 --- a/src/main/java/am2/common/handler/EntityHandler.java +++ b/src/main/java/am2/common/handler/EntityHandler.java @@ -271,6 +271,8 @@ else if (event.getEntityLiving().getHealth() * 4 < event.getEntityLiving().getMa ext.setContingency(ContingencyType.NULL, null); } } + if (EntityUtils.isSummonExpired(event.getEntityLiving())) + event.getEntityLiving().setDead(); } private void sendUpdate(EntityLivingBase ent, byte id, byte[] data) { diff --git a/src/main/java/am2/common/spell/SpellCaster.java b/src/main/java/am2/common/spell/SpellCaster.java index 10f152bc5..dce3a46d6 100644 --- a/src/main/java/am2/common/spell/SpellCaster.java +++ b/src/main/java/am2/common/spell/SpellCaster.java @@ -105,7 +105,7 @@ public SpellData createSpellData(ItemStack source) { stages.add(stage); NBTTagCompound storedData = this.storedData.copy(); storedData.merge(this.getStoredData(getCurrentShapeGroup()).copy()); - return new SpellData(source, stages, uuid, new NBTTagCompound()); + return new SpellData(source, stages, uuid, storedData); } @Override @@ -380,7 +380,9 @@ public NBTTagCompound getStoredData(int shapeGroup) { @Override public NBTTagCompound getCommonStoredData() { - return this.storedData == null ? new NBTTagCompound() : storedData; + if (this.storedData == null) + this.storedData = new NBTTagCompound(); + return storedData; } @Override diff --git a/src/main/java/am2/common/spell/component/Dispel.java b/src/main/java/am2/common/spell/component/Dispel.java index ad4933892..ae4721311 100644 --- a/src/main/java/am2/common/spell/component/Dispel.java +++ b/src/main/java/am2/common/spell/component/Dispel.java @@ -73,19 +73,21 @@ public boolean applyEffectEntity(SpellData spell, World world, EntityLivingBase if (!world.isRemote) removePotionEffects((EntityLivingBase)target, effectsToRemove); - //TODO: - /*if (ExtendedProperties.For((EntityLivingBase)target).getNumSummons() > 0){ + + if (EntityExtension.For((EntityLivingBase)target).getCurrentSummons() > 0){ if (!world.isRemote){ - Iterator it = world.loadedEntityList.iterator(); + Iterator it = world.loadedEntityList.iterator(); + int i = EntityExtension.For((EntityLivingBase)target).getCurrentSummons(); while (it.hasNext()){ Entity ent = (Entity)it.next(); - if (ent instanceof EntitySummonedCreature && ((EntitySummonedCreature)ent).GetOwningEntity() == target){ - ent.attackEntityFrom(DamageSource.outOfWorld, 5000); - break; + if (ent instanceof EntityLivingBase && EntityUtils.isSummon((EntityLivingBase) ent) && EntityUtils.getOwner((EntityLivingBase) ent) == target.getEntityId()){ + ent.setDead(); + if (--i <= 0) + break; } } } - }*/ + } return true; } diff --git a/src/main/java/am2/common/utils/EntityUtils.java b/src/main/java/am2/common/utils/EntityUtils.java index 9dad1e96e..03be0fb38 100644 --- a/src/main/java/am2/common/utils/EntityUtils.java +++ b/src/main/java/am2/common/utils/EntityUtils.java @@ -199,6 +199,17 @@ public static void setSummonDuration(EntityLivingBase entity, int duration){ entity.getEntityData().setInteger(summonDurationKey, duration); } + public static boolean isSummonExpired(EntityLivingBase entity) { + if (entity.getEntityData() == null || !isSummon(entity)) + return false; + int duration = entity.getEntityData().getInteger(summonDurationKey); + if (duration <= 0) + return false; + if (entity.ticksExisted > duration) + return true; + return false; + } + public static int getOwner(EntityLivingBase entityliving){ if (!isSummon(entityliving)) return -1; Integer ownerID = entityliving.getEntityData().getInteger(summonOwnerKey);