@SubscribeEvent public void onZombieSummonAid(SummonAidEvent event) { if (event.entity instanceof EntityEvolvedZombie) { event.customSummonedAid = new EntityEvolvedZombie(event.world); if (((EntityLivingBase) event.entity).getRNG().nextFloat() < ((EntityEvolvedZombie) event.entity).getEntityAttribute(((EntityEvolvedZombie) event.entity).getReinforcementsAttribute()).getAttributeValue()) { event.setResult(Result.ALLOW); } else { event.setResult(Result.DENY); } } }
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; }
@SubscribeEvent public void onSummonAid(SummonAidEvent event) { if (!cache.isEmpty() && cache.remove(event.getSummoner())) { event.setResult(Result.DENY); } }
public boolean attackEntityFrom(DamageSource p_70097_1_, float p_70097_2_) { if (!super.attackEntityFrom(p_70097_1_, p_70097_2_)) { return false; } else { EntityLivingBase entitylivingbase = this.getAttackTarget(); if (entitylivingbase == null && this.getEntityToAttack() instanceof EntityLivingBase) { entitylivingbase = (EntityLivingBase)this.getEntityToAttack(); } if (entitylivingbase == null && p_70097_1_.getEntity() instanceof EntityLivingBase) { entitylivingbase = (EntityLivingBase)p_70097_1_.getEntity(); } 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 == EnumDifficulty.HARD && (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); int j1 = j + MathHelper.getRandomIntegerInRange(this.rand, 7, 40) * MathHelper.getRandomIntegerInRange(this.rand, -1, 1); int k1 = k + MathHelper.getRandomIntegerInRange(this.rand, 7, 40) * MathHelper.getRandomIntegerInRange(this.rand, -1, 1); if (World.doesBlockHaveSolidTopSurface(this.worldObj, i1, j1 - 1, k1) && this.worldObj.getBlockLightValue(i1, j1, k1) < 10) { entityzombie.setPosition((double)i1, (double)j1, (double)k1); if (this.worldObj.checkNoEntityCollision(entityzombie.boundingBox) && this.worldObj.getCollidingBoundingBoxes(entityzombie, entityzombie.boundingBox).isEmpty() && !this.worldObj.isAnyLiquid(entityzombie.boundingBox)) { this.worldObj.addEntity(entityzombie, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.REINFORCEMENTS); // CraftBukkit if (entitylivingbase != null) entityzombie.setAttackTarget(entitylivingbase); entityzombie.onSpawnWithEgg((IEntityLivingData)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)); break; } } } } return true; } }
public boolean attackEntityFrom(DamageSource p_70097_1_, float p_70097_2_) { if (!super.attackEntityFrom(p_70097_1_, p_70097_2_)) { return false; } else { EntityLivingBase entitylivingbase = this.getAttackTarget(); if (entitylivingbase == null && this.getEntityToAttack() instanceof EntityLivingBase) { entitylivingbase = (EntityLivingBase)this.getEntityToAttack(); } if (entitylivingbase == null && p_70097_1_.getEntity() instanceof EntityLivingBase) { entitylivingbase = (EntityLivingBase)p_70097_1_.getEntity(); } 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 == EnumDifficulty.HARD && (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); int j1 = j + MathHelper.getRandomIntegerInRange(this.rand, 7, 40) * MathHelper.getRandomIntegerInRange(this.rand, -1, 1); int k1 = k + MathHelper.getRandomIntegerInRange(this.rand, 7, 40) * MathHelper.getRandomIntegerInRange(this.rand, -1, 1); if (World.doesBlockHaveSolidTopSurface(this.worldObj, i1, j1 - 1, k1) && this.worldObj.getBlockLightValue(i1, j1, k1) < 10) { entityzombie.setPosition((double)i1, (double)j1, (double)k1); if (this.worldObj.checkNoEntityCollision(entityzombie.boundingBox) && this.worldObj.getCollidingBoundingBoxes(entityzombie, entityzombie.boundingBox).isEmpty() && !this.worldObj.isAnyLiquid(entityzombie.boundingBox)) { this.worldObj.spawnEntityInWorld(entityzombie); if (entitylivingbase != null) entityzombie.setAttackTarget(entitylivingbase); entityzombie.onSpawnWithEgg((IEntityLivingData)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)); break; } } } } return true; } }
/** * Called when the entity is attacked. */ public boolean attackEntityFrom(DamageSource par1DamageSource, float par2) { if (!super.attackEntityFrom(par1DamageSource, par2)) { return false; } else { EntityLivingBase entitylivingbase = this.getAttackTarget(); if (entitylivingbase == null && this.getEntityToAttack() instanceof EntityLivingBase) { entitylivingbase = (EntityLivingBase)this.getEntityToAttack(); } if (entitylivingbase == null && par1DamageSource.getEntity() instanceof EntityLivingBase) { entitylivingbase = (EntityLivingBase)par1DamageSource.getEntity(); } 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); int j1 = j + MathHelper.getRandomIntegerInRange(this.rand, 7, 40) * MathHelper.getRandomIntegerInRange(this.rand, -1, 1); int k1 = k + MathHelper.getRandomIntegerInRange(this.rand, 7, 40) * MathHelper.getRandomIntegerInRange(this.rand, -1, 1); if (this.worldObj.doesBlockHaveSolidTopSurface(i1, j1 - 1, k1) && this.worldObj.getBlockLightValue(i1, j1, k1) < 10) { entityzombie.setPosition((double)i1, (double)j1, (double)k1); if (this.worldObj.checkNoEntityCollision(entityzombie.boundingBox) && this.worldObj.getCollidingBoundingBoxes(entityzombie, entityzombie.boundingBox).isEmpty() && !this.worldObj.isAnyLiquid(entityzombie.boundingBox)) { this.worldObj.spawnEntityInWorld(entityzombie); 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)); break; } } } } return true; } }
@Override public boolean attackEntityFrom(DamageSource dmgSource, float damageAmount){ if (!super.attackEntityFrom(dmgSource, damageAmount)){ return false; } else{ EntityLivingBase entitylivingbase = this.getAttackTarget(); if (entitylivingbase == null && this.getEntityToAttack() instanceof EntityLivingBase){ entitylivingbase = (EntityLivingBase)this.getEntityToAttack(); } if (entitylivingbase == null && dmgSource.getEntity() instanceof EntityLivingBase){ entitylivingbase = (EntityLivingBase)dmgSource.getEntity(); } int i = MathHelper.floor_double(this.posX); int j = MathHelper.floor_double(this.posY); int k = MathHelper.floor_double(this.posZ); // Calculate whether or not to summon Aid SummonAidEvent summonAid = ForgeEventFactory.fireZombieSummonAid(this, worldObj, i, j, k, entitylivingbase, this.getEntityAttribute(groundhogReinforce).getAttributeValue()); if (summonAid.getResult() == Result.DENY){ return true; } else if (summonAid.getResult() == Result.ALLOW || entitylivingbase != null && this.worldObj.difficultySetting == EnumDifficulty.HARD && (double)this.rand.nextFloat() < this.getEntityAttribute(groundhogReinforce).getAttributeValue()){ EntityGroundhog entityGroundhog; if (summonAid.customSummonedAid != null && summonAid.getResult() == Result.ALLOW){ entityGroundhog = (EntityGroundhog) summonAid.customSummonedAid; } else{ entityGroundhog = new EntityGroundhog(this.worldObj); } for (int l = 0; l < 50; ++l){ int i1 = i + MathHelper.getRandomIntegerInRange(this.rand, 7, 40) * MathHelper.getRandomIntegerInRange(this.rand, -1, 1); int j1 = j + MathHelper.getRandomIntegerInRange(this.rand, 7, 40) * MathHelper.getRandomIntegerInRange(this.rand, -1, 1); int k1 = k + MathHelper.getRandomIntegerInRange(this.rand, 7, 40) * MathHelper.getRandomIntegerInRange(this.rand, -1, 1); if (World.doesBlockHaveSolidTopSurface(this.worldObj, i1, j1 - 1, k1) && this.worldObj.getBlockLightValue(i1, j1, k1) < 10){ entityGroundhog.setPosition((double)i1, (double)j1, (double)k1); if (this.worldObj.checkNoEntityCollision(entityGroundhog.boundingBox) && this.worldObj.getCollidingBoundingBoxes(entityGroundhog, entityGroundhog.boundingBox).isEmpty() && !this.worldObj.isAnyLiquid(entityGroundhog.boundingBox)){ this.worldObj.spawnEntityInWorld(entityGroundhog); if (entitylivingbase != null) entityGroundhog.setAttackTarget(entitylivingbase); entityGroundhog.onSpawnWithEgg((IEntityLivingData)null); this.getEntityAttribute(groundhogReinforce).applyModifier(new AttributeModifier("Groundhog reinforcement caller charge", -0.05000000074505806D, 0)); entityGroundhog.getEntityAttribute(groundhogReinforce).applyModifier(new AttributeModifier("Groundhog reinforcement callee charge", -0.05000000074505806D, 0)); break; } } } } } if (this.isEntityInvulnerable()){ return false; } else{ // Get close groundhogs and set them to attack the player Entity entity = dmgSource.getEntity(); if (entity instanceof EntityPlayer){ List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.expand(32.0D, 32.0D, 32.0D)); for (int i = 0; i < list.size(); ++i){ Entity entity1 = (Entity)list.get(i); if (entity1 instanceof EntityGroundhog){ EntityGroundhog entitypigzombie = (EntityGroundhog)entity1; entitypigzombie.becomeAngryAt(entity); } } this.becomeAngryAt(entity); } return true; } }
@SubscribeEvent public static void onSummonAid(SummonAidEvent event) { if (!cache.isEmpty() && cache.remove(event.getSummoner().getUniqueID())) { event.setResult(Result.DENY); } }