Skip to content

Commit

Permalink
Fixed Summons
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwinMindcraft committed Feb 6, 2018
1 parent b1aaf81 commit 49ee4b9
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion src/main/java/am2/common/extensions/EntityExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/am2/common/handler/EntityHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/am2/common/spell/SpellCaster.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/am2/common/spell/component/Dispel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Entity> 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;
}

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/am2/common/utils/EntityUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 49ee4b9

Please sign in to comment.