Add in an event for zombie summoning. Allows for mods to control summoning behaviour, as well as custom summoned mob.

This commit is contained in:
Christian 2013-10-13 12:21:57 -04:00
parent 6c45b43eee
commit f9c283a2e5
3 changed files with 109 additions and 3 deletions

View file

@ -5,7 +5,9 @@ import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
@ -15,6 +17,7 @@ import net.minecraftforge.event.Event.Result;
import net.minecraftforge.event.entity.living.LivingPackSizeEvent;
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
import net.minecraftforge.event.entity.living.LivingSpawnEvent.AllowDespawn;
import net.minecraftforge.event.entity.living.ZombieEvent.SummonAidEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
@ -107,4 +110,11 @@ public class ForgeEventFactory
MinecraftForge.EVENT_BUS.post(event);
return event;
}
public static SummonAidEvent fireZombieSummonAid(EntityZombie zombie, World world, int x, int y, int z, EntityLivingBase attacker, double summonChance)
{
SummonAidEvent summonEvent = new SummonAidEvent(zombie, world, x, y, z, attacker, summonChance);
MinecraftForge.EVENT_BUS.post(summonEvent);
return summonEvent;
}
}

View file

@ -0,0 +1,48 @@
package net.minecraftforge.event.entity.living;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.world.World;
import net.minecraftforge.event.Cancelable;
import net.minecraftforge.event.entity.EntityEvent;
public class ZombieEvent extends EntityEvent {
public ZombieEvent(EntityZombie entity)
{
super(entity);
}
public EntityZombie getSummoner()
{
return (EntityZombie) entity;
}
@HasResult
public class SummonAidEvent extends ZombieEvent {
/**
* Populate this field to have a custom zombie instead of a normal zombie summoned
*/
public EntityZombie customSummonedAid;
public final World world;
public final int x;
public final int y;
public final int z;
public final EntityLivingBase attacker;
public final double summonChance;
public SummonAidEvent(EntityZombie entity, World world, int x, int y, int z, EntityLivingBase attacker, double summonChance)
{
super(entity);
this.world = world;
this.x = x;
this.y = y;
this.z = z;
this.attacker = attacker;
this.summonChance = summonChance;
}
}
}

View file

@ -1,14 +1,17 @@
--- ../src_base/minecraft/net/minecraft/entity/monster/EntityZombie.java
+++ ../src_work/minecraft/net/minecraft/entity/monster/EntityZombie.java
@@ -34,6 +34,7 @@
@@ -34,6 +34,10 @@
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
+import net.minecraftforge.common.ForgeDummyContainer;
+import net.minecraftforge.event.Event.Result;
+import net.minecraftforge.event.ForgeEventFactory;
+import net.minecraftforge.event.entity.living.ZombieEvent.SummonAidEvent;
public class EntityZombie extends EntityMob
{
@@ -70,7 +71,7 @@
@@ -70,7 +74,7 @@
this.getEntityAttribute(SharedMonsterAttributes.followRange).setAttribute(40.0D);
this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setAttribute(0.23000000417232513D);
this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setAttribute(3.0D);
@ -17,7 +20,52 @@
}
protected void entityInit()
@@ -442,7 +443,7 @@
@@ -211,13 +215,28 @@
entitylivingbase = (EntityLivingBase)par1DamageSource.getEntity();
}
- if (entitylivingbase != null && this.worldObj.difficultySetting >= 3 && (double)this.rand.nextFloat() < this.getEntityAttribute(field_110186_bp).getAttributeValue())
- {
- int i = MathHelper.floor_double(this.posX);
- int j = MathHelper.floor_double(this.posY);
- int k = MathHelper.floor_double(this.posZ);
- EntityZombie entityzombie = new EntityZombie(this.worldObj);
-
+ int i = MathHelper.floor_double(this.posX);
+ int j = MathHelper.floor_double(this.posY);
+ int k = MathHelper.floor_double(this.posZ);
+
+ SummonAidEvent summonAid = ForgeEventFactory.fireZombieSummonAid(this, worldObj, i, j, k, entitylivingbase, this.getEntityAttribute(field_110186_bp).getAttributeValue());
+
+ if (summonAid.getResult() == Result.DENY)
+ {
+ return true;
+ }
+ else if (summonAid.getResult() == Result.ALLOW || entitylivingbase != null && this.worldObj.difficultySetting >= 3 && (double)this.rand.nextFloat() < this.getEntityAttribute(field_110186_bp).getAttributeValue())
+ {
+ EntityZombie entityzombie;
+ if (summonAid.customSummonedAid != null && summonAid.getResult() == Result.ALLOW)
+ {
+ entityzombie = summonAid.customSummonedAid;
+ }
+ else
+ {
+ entityzombie = new EntityZombie(this.worldObj);
+ }
+
for (int l = 0; l < 50; ++l)
{
int i1 = i + MathHelper.getRandomIntegerInRange(this.rand, 7, 40) * MathHelper.getRandomIntegerInRange(this.rand, -1, 1);
@@ -231,7 +250,7 @@
if (this.worldObj.checkNoEntityCollision(entityzombie.boundingBox) && this.worldObj.getCollidingBoundingBoxes(entityzombie, entityzombie.boundingBox).isEmpty() && !this.worldObj.isAnyLiquid(entityzombie.boundingBox))
{
this.worldObj.spawnEntityInWorld(entityzombie);
- entityzombie.setAttackTarget(entitylivingbase);
+ if (entitylivingbase != null) entityzombie.setAttackTarget(entitylivingbase);
entityzombie.onSpawnWithEgg((EntityLivingData)null);
this.getEntityAttribute(field_110186_bp).applyModifier(new AttributeModifier("Zombie reinforcement caller charge", -0.05000000074505806D, 0));
entityzombie.getEntityAttribute(field_110186_bp).applyModifier(new AttributeModifier("Zombie reinforcement callee charge", -0.05000000074505806D, 0));
@@ -442,7 +461,7 @@
if (par1EntityLivingData1 == null)
{