diff options
Diffstat (limited to 'src/main/java/gtPlusPlus/core/entity')
16 files changed, 3929 insertions, 0 deletions
diff --git a/src/main/java/gtPlusPlus/core/entity/EntityPrimedMiningExplosive.java b/src/main/java/gtPlusPlus/core/entity/EntityPrimedMiningExplosive.java new file mode 100644 index 0000000000..9abd07392d --- /dev/null +++ b/src/main/java/gtPlusPlus/core/entity/EntityPrimedMiningExplosive.java @@ -0,0 +1,216 @@ +package gtPlusPlus.core.entity; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.item.EntityTNTPrimed; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; + +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.world.explosions.ExplosionHandler; + +public class EntityPrimedMiningExplosive extends EntityTNTPrimed +{ + /** How long the fuse is */ + private EntityLivingBase tntPlacedBy; + + public EntityPrimedMiningExplosive(final World world){ + super(world); + this.fuse = 160; + this.preventEntitySpawning = true; + this.setSize(0.98F, 0.98F); + this.yOffset = this.height / 2.0F; + } + + public EntityPrimedMiningExplosive(final World world, final double x, final double y, final double z, final EntityLivingBase placingEntity) + { + this(world); + this.setPosition(x, y, z); + final float f = (float)(Math.random() * Math.PI * 2.0D); + this.motionX = -((float)Math.sin(f)) * 0.02F; + this.motionY = 0.20000000298023224D; + this.motionZ = -((float)Math.cos(f)) * 0.02F; + this.fuse = 160; + this.prevPosX = x; + this.prevPosY = y; + this.prevPosZ = z; + this.tntPlacedBy = placingEntity; + } + + @Override + protected void entityInit() {} + + /** + * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to + * prevent them from trampling crops + */ + @Override + protected boolean canTriggerWalking() + { + return false; + } + + /** + * Returns true if other Entities should be prevented from moving through this Entity. + */ + @Override + public boolean canBeCollidedWith() + { + return !this.isDead; + } + + /** + * Called to update the entity's position/logic. + */ + @Override + public void onUpdate() + { + this.prevPosX = this.posX; + this.prevPosY = this.posY; + this.prevPosZ = this.posZ; + this.motionY -= 0.03999999910593033D; + this.moveEntity(this.motionX, this.motionY, this.motionZ); + this.motionX *= 0.9800000190734863D; + this.motionY *= 0.9800000190734863D; + this.motionZ *= 0.9800000190734863D; + + if (this.onGround) + { + this.motionX *= 0.699999988079071D; + this.motionZ *= 0.699999988079071D; + this.motionY *= -0.5D; + } + + if (this.fuse-- <= 0) + { + this.setDead(); + + if (!this.worldObj.isRemote) + { + this.explode(); + } + } + else + { + + int t = MathUtils.randInt(0, 15); + + if (t <= 2){ + int e = MathUtils.randInt(0, 3); + if (e <= 1){ + this.worldObj.spawnParticle("smoke", this.posX, this.posY + 0.5D, this.posZ, 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("largesmoke", this.posX+MathUtils.randDouble(0, 1), this.posY+MathUtils.randDouble(0, 1), this.posZ+MathUtils.randDouble(0, 1), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("cloud", this.posX+MathUtils.randDouble(0, 1), this.posY+MathUtils.randDouble(0, 1), this.posZ+MathUtils.randDouble(0, 1), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("flame", this.posX+MathUtils.randDouble(0, 1), this.posY+MathUtils.randDouble(0, 1), this.posZ+MathUtils.randDouble(0, 1), 0.0D, 0.0D, 0.0D); + } + else if (e == 2){ + this.worldObj.spawnParticle("explode", this.posX+MathUtils.randDouble(0, 1), this.posY+MathUtils.randDouble(0, 1), this.posZ+MathUtils.randDouble(0, 1), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("largeexplode", this.posX+MathUtils.randDouble(0, 1), this.posY+MathUtils.randDouble(0, 1), this.posZ+MathUtils.randDouble(0, 1), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("hugeexplosion", this.posX+MathUtils.randDouble(0, 1), this.posY+MathUtils.randDouble(0, 1), this.posZ+MathUtils.randDouble(0, 1), 0.0D, 0.0D, 0.0D); + + } + } + else if (t <= 4){ + int e = MathUtils.randInt(0, 5); + if (e <= 1){ + this.worldObj.spawnParticle("smoke", this.posX, this.posY + 0.5D, this.posZ, 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("largesmoke", this.posX+MathUtils.randDouble(0, 1), this.posY+MathUtils.randDouble(0, 1), this.posZ+MathUtils.randDouble(0, 1), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("cloud", this.posX+MathUtils.randDouble(0, 1), this.posY+MathUtils.randDouble(0, 1), this.posZ+MathUtils.randDouble(0, 1), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("flame", this.posX+MathUtils.randDouble(0, 1), this.posY+MathUtils.randDouble(0, 1), this.posZ+MathUtils.randDouble(0, 1), 0.0D, 0.0D, 0.0D); + } + else if (e == 2){ + this.worldObj.spawnParticle("explode", this.posX+MathUtils.randDouble(0, 1), this.posY+MathUtils.randDouble(0, 1), this.posZ+MathUtils.randDouble(0, 1), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("largeexplode", this.posX+MathUtils.randDouble(0, 1), this.posY+MathUtils.randDouble(0, 1), this.posZ+MathUtils.randDouble(0, 1), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("hugeexplosion", this.posX+MathUtils.randDouble(0, 1), this.posY+MathUtils.randDouble(0, 1), this.posZ+MathUtils.randDouble(0, 1), 0.0D, 0.0D, 0.0D); + + } + } + else if (t <= 6){ + int e = MathUtils.randInt(0, 4); + if (e <= 1){ + this.worldObj.spawnParticle("smoke", this.posX, this.posY + 0.5D, this.posZ, 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("largesmoke", this.posX+MathUtils.randDouble(0, 1), this.posY+MathUtils.randDouble(0, 1), this.posZ+MathUtils.randDouble(0, 1), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("cloud", this.posX+MathUtils.randDouble(0, 1), this.posY+MathUtils.randDouble(0, 1), this.posZ+MathUtils.randDouble(0, 1), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("flame", this.posX+MathUtils.randDouble(0, 1), this.posY+MathUtils.randDouble(0, 1), this.posZ+MathUtils.randDouble(0, 1), 0.0D, 0.0D, 0.0D); + } + else if (e == 2){ + this.worldObj.spawnParticle("explode", this.posX+MathUtils.randDouble(0, 1), this.posY+MathUtils.randDouble(0, 1), this.posZ+MathUtils.randDouble(0, 1), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("largeexplode", this.posX+MathUtils.randDouble(0, 1), this.posY+MathUtils.randDouble(0, 1), this.posZ+MathUtils.randDouble(0, 1), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("hugeexplosion", this.posX+MathUtils.randDouble(0, 1), this.posY+MathUtils.randDouble(0, 1), this.posZ+MathUtils.randDouble(0, 1), 0.0D, 0.0D, 0.0D); + + } + } + else if (t <= 8){ + int e = MathUtils.randInt(0, 1); + if (e <= 1){ + this.worldObj.spawnParticle("smoke", this.posX, this.posY + 0.5D, this.posZ, 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("largesmoke", this.posX+MathUtils.randDouble(0, 1), this.posY+MathUtils.randDouble(0, 1), this.posZ+MathUtils.randDouble(0, 1), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("cloud", this.posX+MathUtils.randDouble(0, 1), this.posY+MathUtils.randDouble(0, 1), this.posZ+MathUtils.randDouble(0, 1), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("flame", this.posX+MathUtils.randDouble(0, 1), this.posY+MathUtils.randDouble(0, 1), this.posZ+MathUtils.randDouble(0, 1), 0.0D, 0.0D, 0.0D); + } + else if (e == 2){ + this.worldObj.spawnParticle("explode", this.posX+MathUtils.randDouble(0, 1), this.posY+MathUtils.randDouble(0, 1), this.posZ+MathUtils.randDouble(0, 1), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("largeexplode", this.posX+MathUtils.randDouble(0, 1), this.posY+MathUtils.randDouble(0, 1), this.posZ+MathUtils.randDouble(0, 1), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("hugeexplosion", this.posX+MathUtils.randDouble(0, 1), this.posY+MathUtils.randDouble(0, 1), this.posZ+MathUtils.randDouble(0, 1), 0.0D, 0.0D, 0.0D); + + } + } + else if (t <= 10){ + int e = MathUtils.randInt(0, 6); + if (e <= 1){ + this.worldObj.spawnParticle("smoke", this.posX, this.posY + 0.5D, this.posZ, 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("largesmoke", this.posX+MathUtils.randDouble(0, 1), this.posY+MathUtils.randDouble(0, 1), this.posZ+MathUtils.randDouble(0, 1), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("cloud", this.posX+MathUtils.randDouble(0, 1), this.posY+MathUtils.randDouble(0, 1), this.posZ+MathUtils.randDouble(0, 1), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("flame", this.posX+MathUtils.randDouble(0, 1), this.posY+MathUtils.randDouble(0, 1), this.posZ+MathUtils.randDouble(0, 1), 0.0D, 0.0D, 0.0D); + } + else if (e >= 2){ + this.worldObj.spawnParticle("explode", this.posX+MathUtils.randDouble(0, 1), this.posY+MathUtils.randDouble(0, 1), this.posZ+MathUtils.randDouble(0, 1), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("largeexplode", this.posX+MathUtils.randDouble(0, 1), this.posY+MathUtils.randDouble(0, 1), this.posZ+MathUtils.randDouble(0, 1), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("hugeexplosion", this.posX+MathUtils.randDouble(0, 1), this.posY+MathUtils.randDouble(0, 1), this.posZ+MathUtils.randDouble(0, 1), 0.0D, 0.0D, 0.0D); + + } + } + + } + } + + private void explode() + { + final float f = 100.0F; + + ExplosionHandler explode = new ExplosionHandler(); + explode.createExplosion(this.worldObj, this, this.posX, this.posY, this.posZ, f, false, true); + + /*this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, f, true); + this.worldObj.createExplosion(this, this.posX+MathUtils.randDouble(-10, 10), this.posY, this.posZ+MathUtils.randDouble(-10, 10), f+MathUtils.randFloat(-5F, 5F), true); + this.worldObj.createExplosion(this, this.posX+MathUtils.randDouble(-10, 10), this.posY, this.posZ+MathUtils.randDouble(-10, 10), f+MathUtils.randFloat(-5F, 5F), true); + this.worldObj.createExplosion(this, this.posX+MathUtils.randDouble(-10, 10), this.posY, this.posZ+MathUtils.randDouble(-10, 10), f+MathUtils.randFloat(-5F, 5F), true); + this.worldObj.createExplosion(this, this.posX+MathUtils.randDouble(-10, 10), this.posY, this.posZ+MathUtils.randDouble(-10, 10), f+MathUtils.randFloat(-5F, 5F), true);*/ + } + + /** + * (abstract) Protected helper method to write subclass entity data to NBT. + */ + @Override + protected void writeEntityToNBT(final NBTTagCompound tag) + { + tag.setByte("Fuse", (byte)this.fuse); + } + + /** + * (abstract) Protected helper method to read subclass entity data from NBT. + */ + @Override + protected void readEntityFromNBT(final NBTTagCompound tag) + { + this.fuse = tag.getByte("Fuse"); + } + + /** + * returns null or the entityliving it was placed or ignited by + */ + @Override + public EntityLivingBase getTntPlacedBy() + { + return this.tntPlacedBy; + } +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/core/entity/EntityTeleportFX.java b/src/main/java/gtPlusPlus/core/entity/EntityTeleportFX.java new file mode 100644 index 0000000000..ea667b8667 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/entity/EntityTeleportFX.java @@ -0,0 +1,247 @@ +package gtPlusPlus.core.entity; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; + +public class EntityTeleportFX extends Entity +{ + /** 'x' location the eye should float towards. */ + private double targetX; + /** 'y' location the eye should float towards. */ + private double targetY; + /** 'z' location the eye should float towards. */ + private double targetZ; + private int despawnTimer; + private boolean shatterOrDrop; + private static final String __OBFID = "CL_00001716"; + + public EntityTeleportFX(final World p_i1757_1_) + { + super(p_i1757_1_); + this.setSize(0.25F, 0.25F); + } + + @Override + protected void entityInit() {} + + /** + * Checks if the entity is in range to render by using the past in distance and comparing it to its average edge + * length * 64 * renderDistanceWeight Args: distance + */ + @Override + @SideOnly(Side.CLIENT) + public boolean isInRangeToRenderDist(final double p_70112_1_) + { + double d1 = this.boundingBox.getAverageEdgeLength() * 4.0D; + d1 *= 64.0D; + return p_70112_1_ < (d1 * d1); + } + + public EntityTeleportFX(final World p_i1758_1_, final double p_i1758_2_, final double p_i1758_4_, final double p_i1758_6_) + { + super(p_i1758_1_); + this.despawnTimer = 0; + this.setSize(0.25F, 0.25F); + this.setPosition(p_i1758_2_, p_i1758_4_, p_i1758_6_); + this.yOffset = 0.0F; + } + + /** + * The location the eye should float/move towards. Currently used for moving towards the nearest stronghold. Args: + * strongholdX, strongholdY, strongholdZ + */ + public void moveTowards(final double p_70220_1_, final int p_70220_3_, final double p_70220_4_) + { + final double d2 = p_70220_1_ - this.posX; + final double d3 = p_70220_4_ - this.posZ; + final float f = MathHelper.sqrt_double((d2 * d2) + (d3 * d3)); + + if (f > 12.0F) + { + this.targetX = this.posX + ((d2 / f) * 12.0D); + this.targetZ = this.posZ + ((d3 / f) * 12.0D); + this.targetY = this.posY + 8.0D; + } + else + { + this.targetX = p_70220_1_; + this.targetY = p_70220_3_; + this.targetZ = p_70220_4_; + } + + this.despawnTimer = 0; + this.shatterOrDrop = this.rand.nextInt(5) > 0; + } + + /** + * Sets the velocity to the args. Args: x, y, z + */ + @Override + @SideOnly(Side.CLIENT) + public void setVelocity(final double p_70016_1_, final double p_70016_3_, final double p_70016_5_) + { + this.motionX = p_70016_1_; + this.motionY = p_70016_3_; + this.motionZ = p_70016_5_; + + if ((this.prevRotationPitch == 0.0F) && (this.prevRotationYaw == 0.0F)) + { + final float f = MathHelper.sqrt_double((p_70016_1_ * p_70016_1_) + (p_70016_5_ * p_70016_5_)); + this.prevRotationYaw = this.rotationYaw = (float)((Math.atan2(p_70016_1_, p_70016_5_) * 180.0D) / Math.PI); + this.prevRotationPitch = this.rotationPitch = (float)((Math.atan2(p_70016_3_, f) * 180.0D) / Math.PI); + } + } + + /** + * Called to update the entity's position/logic. + */ + @Override + public void onUpdate() + { + this.lastTickPosX = this.posX; + this.lastTickPosY = this.posY; + this.lastTickPosZ = this.posZ; + super.onUpdate(); + this.posX += this.motionX; + this.posY += this.motionY; + this.posZ += this.motionZ; + final float f = MathHelper.sqrt_double((this.motionX * this.motionX) + (this.motionZ * this.motionZ)); + this.rotationYaw = (float)((Math.atan2(this.motionX, this.motionZ) * 180.0D) / Math.PI); + + for (this.rotationPitch = (float)((Math.atan2(this.motionY, f) * 180.0D) / Math.PI); (this.rotationPitch - this.prevRotationPitch) < -180.0F; this.prevRotationPitch -= 360.0F) + { + ; + } + + while ((this.rotationPitch - this.prevRotationPitch) >= 180.0F) + { + this.prevRotationPitch += 360.0F; + } + + while ((this.rotationYaw - this.prevRotationYaw) < -180.0F) + { + this.prevRotationYaw -= 360.0F; + } + + while ((this.rotationYaw - this.prevRotationYaw) >= 180.0F) + { + this.prevRotationYaw += 360.0F; + } + + this.rotationPitch = this.prevRotationPitch + ((this.rotationPitch - this.prevRotationPitch) * 0.2F); + this.rotationYaw = this.prevRotationYaw + ((this.rotationYaw - this.prevRotationYaw) * 0.2F); + + if (!this.worldObj.isRemote) + { + final double d0 = this.targetX - this.posX; + final double d1 = this.targetZ - this.posZ; + final float f1 = (float)Math.sqrt((d0 * d0) + (d1 * d1)); + final float f2 = (float)Math.atan2(d1, d0); + double d2 = f + ((f1 - f) * 0.0025D); + + if (f1 < 1.0F) + { + d2 *= 0.8D; + this.motionY *= 0.8D; + } + + this.motionX = Math.cos(f2) * d2; + this.motionZ = Math.sin(f2) * d2; + + if (this.posY < this.targetY) + { + this.motionY += (1.0D - this.motionY) * 0.014999999664723873D; + } + else + { + this.motionY += (-1.0D - this.motionY) * 0.014999999664723873D; + } + } + + final float f3 = 0.25F; + + if (this.isInWater()) + { + for (int i = 0; i < 4; ++i) + { + this.worldObj.spawnParticle("bubble", this.posX - (this.motionX * f3), this.posY - (this.motionY * f3), this.posZ - (this.motionZ * f3), this.motionX, this.motionY, this.motionZ); + } + } + else + { + this.worldObj.spawnParticle("portal", ((this.posX - (this.motionX * f3)) + (this.rand.nextDouble() * 0.6D)) - 0.3D, this.posY - (this.motionY * f3) - 0.5D, ((this.posZ - (this.motionZ * f3)) + (this.rand.nextDouble() * 0.6D)) - 0.3D, this.motionX, this.motionY, this.motionZ); + } + + if (!this.worldObj.isRemote) + { + this.setPosition(this.posX, this.posY, this.posZ); + ++this.despawnTimer; + + if ((this.despawnTimer > 80) && !this.worldObj.isRemote) + { + this.setDead(); + + if (this.shatterOrDrop) + { + this.worldObj.spawnEntityInWorld(new EntityItem(this.worldObj, this.posX, this.posY, this.posZ, new ItemStack(Items.ender_eye))); + } + else + { + this.worldObj.playAuxSFX(2003, (int)Math.round(this.posX), (int)Math.round(this.posY), (int)Math.round(this.posZ), 0); + } + } + } + } + + /** + * (abstract) Protected helper method to write subclass entity data to NBT. + */ + @Override + public void writeEntityToNBT(final NBTTagCompound p_70014_1_) {} + + /** + * (abstract) Protected helper method to read subclass entity data from NBT. + */ + @Override + public void readEntityFromNBT(final NBTTagCompound p_70037_1_) {} + + @Override + @SideOnly(Side.CLIENT) + public float getShadowSize() + { + return 0.0F; + } + + /** + * Gets how bright this entity is. + */ + @Override + public float getBrightness(final float p_70013_1_) + { + return 1.0F; + } + + @Override + @SideOnly(Side.CLIENT) + public int getBrightnessForRender(final float p_70070_1_) + { + return 15728880; + } + + /** + * If returns false, the item will not inflict any damage against entities. + */ + @Override + public boolean canAttackWithItem() + { + return false; + } +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/core/entity/EntityTeslaTowerLightning.java b/src/main/java/gtPlusPlus/core/entity/EntityTeslaTowerLightning.java new file mode 100644 index 0000000000..bf629bd147 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/entity/EntityTeslaTowerLightning.java @@ -0,0 +1,168 @@ +package gtPlusPlus.core.entity; +import java.util.List; +import java.util.Random; +import java.util.UUID; + +import net.minecraft.block.material.Material; +import net.minecraft.entity.Entity; +import net.minecraft.entity.effect.EntityWeatherEffect; +import net.minecraft.init.Blocks; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.MathHelper; +import net.minecraft.world.EnumDifficulty; +import net.minecraft.world.World; + +import gtPlusPlus.api.damage.DamageTeslaTower; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.random.XSTR; +import gtPlusPlus.core.util.minecraft.EntityUtils; + +public class EntityTeslaTowerLightning extends EntityWeatherEffect +{ + /** Declares which state the lightning bolt is in. Whether it's in the air, hit the ground, etc. */ + private int lightningState; + /** A random long that is used to change the vertex of the lightning rendered in RenderLightningBolt */ + public long boltVertex; + /** Determines the time before the EntityLightningBolt is destroyed. It is a random integer decremented over time. */ + private int boltLivingTime; + + private final UUID boltID; + private final UUID boltOwnerID; + + private final Entity boltValidDamageTarget; + + + public EntityTeslaTowerLightning(World p_i1703_1_, double p_i1703_2_, double p_i1703_4_, double p_i1703_6_, Entity valid, UUID owner) + { + super(p_i1703_1_); + Logger.INFO("Plasma Bolt - Created."); + Random rand = new XSTR(p_i1703_1_.getSeed()); + this.setLocationAndAngles(p_i1703_2_, p_i1703_4_, p_i1703_6_, 0.0F, 0.0F); + this.lightningState = 2; + this.boltVertex = rand.nextLong(); + this.boltLivingTime = (1) + rand.nextInt(3) + 1; + this.boltValidDamageTarget = valid; + this.boltID = UUID.randomUUID(); + this.boltOwnerID = owner; + + //Puts fires out + if (!p_i1703_1_.isRemote && p_i1703_1_.getGameRules().getGameRuleBooleanValue("doFireTick") && (p_i1703_1_.difficultySetting == EnumDifficulty.NORMAL || p_i1703_1_.difficultySetting == EnumDifficulty.HARD) && p_i1703_1_.doChunksNearChunkExist(MathHelper.floor_double(p_i1703_2_), MathHelper.floor_double(p_i1703_4_), MathHelper.floor_double(p_i1703_6_), 10)) + { + Logger.INFO("Plasma Bolt - Putting out fires?."); + int i = MathHelper.floor_double(p_i1703_2_); + int j = MathHelper.floor_double(p_i1703_4_); + int k = MathHelper.floor_double(p_i1703_6_); + + if (p_i1703_1_.getBlock(i, j, k).getMaterial() == Material.fire) + { + p_i1703_1_.setBlock(i, j, k, Blocks.air); + } + + for (i = 0; i < 4; ++i) + { + j = MathHelper.floor_double(p_i1703_2_) + rand.nextInt(3) - 1; + k = MathHelper.floor_double(p_i1703_4_) + rand.nextInt(3) - 1; + int l = MathHelper.floor_double(p_i1703_6_) + rand.nextInt(3) - 1; + + if (p_i1703_1_.getBlock(j, k, l).getMaterial() == Material.fire) + { + p_i1703_1_.setBlock(j, k, l, Blocks.air); + } + } + } + } + + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() + { + //Logger.INFO("Zap"); + super.onUpdate(); + Logger.INFO("Plasma Bolt - Tick."); + Random rand = new XSTR(this.worldObj.getSeed()); + + if (this.lightningState == 2) + { + Logger.INFO("Plasma Bolt - Playing Sound."); + this.worldObj.playSoundEffect(this.posX, this.posY, this.posZ, "ambient.weather.thunder", 10000.0F, 0.8F + rand.nextFloat() * 0.2F); + } + --this.lightningState; + + + if (this.lightningState >= 0) + { + Logger.INFO("Plasma Bolt - state >= 0."); + if (this.worldObj.isRemote) + { + Logger.INFO("Plasma Bolt - World is remote, resetting state to 2."); + this.worldObj.lastLightningBolt = 2; + } + else + { + Logger.INFO("Plasma Bolt - World is server side."); + double d0 = 3.0D; + List<Entity> list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, AxisAlignedBB.getBoundingBox(this.posX - d0, this.posY - d0, this.posZ - d0, this.posX + d0, this.posY + 6.0D + d0, this.posZ + d0)); + + for (int l = 0; l < list.size(); ++l) + { + Entity entity = list.get(l); + if (this.boltValidDamageTarget.getUniqueID().equals(entity.getUniqueID())){ + if (!entity.getUniqueID().equals(boltOwnerID)){ + Logger.INFO("Plasma Bolt - Hurting Entity."); + Logger.INFO("Plasma Bolt - "+entity.getCommandSenderName()+"."); + //if (!net.minecraftforge.event.ForgeEventFactory.onEntityStruckByLightning(entity, this)) + EntityUtils.doFireDamage(entity, 5); + EntityUtils.doDamage(entity, new DamageTeslaTower(entity), 20); + } + } + } + + } + } + + if (this.lightningState < 0) + { + Logger.INFO("Plasma Bolt - state < 0."); + if (this.boltLivingTime == 0) + { + Logger.INFO("Plasma Bolt - setting dead."); + this.setDead(); + } + else if (this.lightningState < -rand.nextInt(10)) + { + Logger.INFO("Plasma Bolt - dunno."); + --this.boltLivingTime; + this.lightningState = 1; + this.boltVertex = rand.nextLong(); + //Puts fires out. + if (!this.worldObj.isRemote && this.worldObj.getGameRules().getGameRuleBooleanValue("doFireTick") && this.worldObj.doChunksNearChunkExist(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posY), MathHelper.floor_double(this.posZ), 10)) + { + Logger.INFO("Plasma Bolt - Putting fires out [2]."); + int i = MathHelper.floor_double(this.posX); + int j = MathHelper.floor_double(this.posY); + int k = MathHelper.floor_double(this.posZ); + + if (this.worldObj.getBlock(i, j, k).getMaterial() == Material.fire) + { + this.worldObj.setBlock(i, j, k, Blocks.air); + } + } + + } + } + } + + protected void entityInit() {} + + /** + * (abstract) Protected helper method to read subclass entity data from NBT. + */ + protected void readEntityFromNBT(NBTTagCompound p_70037_1_) {} + + /** + * (abstract) Protected helper method to write subclass entity data to NBT. + */ + protected void writeEntityToNBT(NBTTagCompound p_70014_1_) {} +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/core/entity/InternalEntityRegistry.java b/src/main/java/gtPlusPlus/core/entity/InternalEntityRegistry.java new file mode 100644 index 0000000000..6b88d5775c --- /dev/null +++ b/src/main/java/gtPlusPlus/core/entity/InternalEntityRegistry.java @@ -0,0 +1,96 @@ +package gtPlusPlus.core.entity; + +import cpw.mods.fml.common.registry.EntityRegistry; + +import gtPlusPlus.GTplusplus; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.australia.entity.type.EntityAustralianSpiderBase; +import gtPlusPlus.australia.entity.type.EntityBoar; +import gtPlusPlus.australia.entity.type.EntityDingo; +import gtPlusPlus.australia.entity.type.EntityOctopus; +import gtPlusPlus.core.entity.monster.EntityBatKing; +import gtPlusPlus.core.entity.monster.EntityGiantChickenBase; +import gtPlusPlus.core.entity.monster.EntitySickBlaze; +import gtPlusPlus.core.entity.monster.EntityStaballoyConstruct; +import gtPlusPlus.core.entity.projectile.EntityHydrofluoricAcidPotion; +import gtPlusPlus.core.entity.projectile.EntityLightningAttack; +import gtPlusPlus.core.entity.projectile.EntitySulfuricAcidPotion; +import gtPlusPlus.core.entity.projectile.EntityThrowableBomb; +import gtPlusPlus.core.entity.projectile.EntityToxinballSmall; +import gtPlusPlus.core.item.general.spawn.ItemCustomSpawnEgg; +import gtPlusPlus.core.util.Utils; + +public class InternalEntityRegistry { + + static int mEntityID = 0; + + public static void registerEntities(){ + Logger.INFO("Registering GT++ Entities."); + + //EntityRegistry.registerGlobalEntityID(EntityPrimedMiningExplosive.class, "MiningCharge", EntityRegistry.findGlobalUniqueEntityId(), Utils.rgbtoHexValue(0, 0, 0), Utils.rgbtoHexValue(125, 125, 125)); + EntityRegistry.registerModEntity(EntityPrimedMiningExplosive.class, "MiningCharge", mEntityID++, GTplusplus.instance, 64, 20, true); + + //EntityRegistry.registerGlobalEntityID(EntitySulfuricAcidPotion.class, "throwablePotionSulfuric", EntityRegistry.findGlobalUniqueEntityId(), Utils.rgbtoHexValue(200, 0, 200), Utils.rgbtoHexValue(125, 125, 125)); + EntityRegistry.registerModEntity(EntitySulfuricAcidPotion.class, "throwablePotionSulfuric", mEntityID++, GTplusplus.instance, 64, 20, true); + + + //EntityRegistry.registerGlobalEntityID(EntityHydrofluoricAcidPotion.class, "throwablePotionHydrofluoric", EntityRegistry.findGlobalUniqueEntityId(), Utils.rgbtoHexValue(0, 0, 0), Utils.rgbtoHexValue(255, 255, 255)); + EntityRegistry.registerModEntity(EntityHydrofluoricAcidPotion.class, "throwablePotionHydrofluoric", mEntityID++, GTplusplus.instance, 64, 20, true); + + + //EntityRegistry.registerGlobalEntityID(EntityToxinballSmall.class, "toxinBall", EntityRegistry.findGlobalUniqueEntityId(), Utils.rgbtoHexValue(0, 25, 0), Utils.rgbtoHexValue(0, 125, 0)); + EntityRegistry.registerModEntity(EntityToxinballSmall.class, "toxinBall", mEntityID++, GTplusplus.instance, 64, 20, true); + + + //EntityRegistry.registerGlobalEntityID(EntityStaballoyConstruct.class, "constructStaballoy", EntityRegistry.findGlobalUniqueEntityId(), Utils.rgbtoHexValue(0, 75, 0), Utils.rgbtoHexValue(50, 220, 50)); + EntityRegistry.registerModEntity(EntityStaballoyConstruct.class, "constructStaballoy", mEntityID++, GTplusplus.instance, 64, 20, true); + ItemCustomSpawnEgg.registerEntityForSpawnEgg(0, "constructStaballoy", Utils.rgbtoHexValue(20, 200, 20), Utils.rgbtoHexValue(20, 20, 20)); + + //EntityRegistry.registerGlobalEntityID(EntitySickBlaze.class, "sickBlaze", EntityRegistry.findGlobalUniqueEntityId(), Utils.rgbtoHexValue(0, 75, 0), Utils.rgbtoHexValue(75, 175, 75)); + EntityRegistry.registerModEntity(EntitySickBlaze.class, "sickBlaze", mEntityID++, GTplusplus.instance, 64, 20, true); + ItemCustomSpawnEgg.registerEntityForSpawnEgg(1, "sickBlaze", Utils.rgbtoHexValue(40, 180, 40), Utils.rgbtoHexValue(75, 75, 75)); + + //EntityRegistry.registerGlobalEntityID(EntityTeslaTowerLightning.class, "plasmaBolt", EntityRegistry.findGlobalUniqueEntityId(), Utils.rgbtoHexValue(255, 0, 0), Utils.rgbtoHexValue(125, 125, 125)); + EntityRegistry.registerModEntity(EntityTeslaTowerLightning.class, "plasmaBolt", mEntityID++, GTplusplus.instance, 64, 5, true); + + EntityRegistry.registerModEntity(EntityThrowableBomb.class, "EntityThrowableBomb", mEntityID++, GTplusplus.instance, 64, 10, true); + + EntityRegistry.registerModEntity(EntityLightningAttack.class, "EntityLightningAttack", mEntityID++, GTplusplus.instance, 64, 20, true); + + /** + * Globals, which generate spawn eggs. (Currently required for Giant chicken spawning) + */ + + EntityRegistry.registerModEntity(EntityGiantChickenBase.class, "bigChickenFriendly", mEntityID++, GTplusplus.instance, 64, 20, true); + ItemCustomSpawnEgg.registerEntityForSpawnEgg(2, "bigChickenFriendly", Utils.rgbtoHexValue(255, 0, 0), Utils.rgbtoHexValue(175, 175, 175)); + EntityRegistry.registerModEntity(EntityBatKing.class, "batKing", mEntityID++, GTplusplus.instance, 64, 20, true); + ItemCustomSpawnEgg.registerEntityForSpawnEgg(3, "batKing", Utils.rgbtoHexValue(175, 175, 0), Utils.rgbtoHexValue(0, 175, 175)); + //EntityRegistry.registerModEntity(EntityGiantChickenBase.class, "bigChickenFriendly", mEntityID++, GTplusplus.instance, 64, 20, true); + + + + + + //Australia + EntityRegistry.registerModEntity(EntityAustralianSpiderBase.class, "AusSpider", mEntityID++, GTplusplus.instance, 64, 20, true); + ItemCustomSpawnEgg.registerEntityForSpawnEgg(30, "AusSpider", Utils.rgbtoHexValue(125, 0, 125), Utils.rgbtoHexValue(175, 175, 175)); + EntityRegistry.registerModEntity(EntityBoar.class, "AusBoar", mEntityID++, GTplusplus.instance, 64, 20, true); + ItemCustomSpawnEgg.registerEntityForSpawnEgg(31, "AusBoar", Utils.rgbtoHexValue(75, 75, 0), Utils.rgbtoHexValue(175, 175, 75)); + EntityRegistry.registerModEntity(EntityDingo.class, "AusDingo", mEntityID++, GTplusplus.instance, 64, 20, true); + ItemCustomSpawnEgg.registerEntityForSpawnEgg(32, "AusDingo", Utils.rgbtoHexValue(175, 125, 0), Utils.rgbtoHexValue(175, 75, 175)); + EntityRegistry.registerModEntity(EntityOctopus.class, "AusOctopus", mEntityID++, GTplusplus.instance, 32, 20, true); + ItemCustomSpawnEgg.registerEntityForSpawnEgg(33, "AusOctopus", Utils.rgbtoHexValue(150, 50, 150), Utils.rgbtoHexValue(75, 175, 175)); + //EntityRegistry.registerGlobalEntityID(EntityAustralianSpiderBase.class, "AusSpider", EntityRegistry.findGlobalUniqueEntityId(), Utils.rgbtoHexValue(255, 0, 0), Utils.rgbtoHexValue(175, 175, 175)); + //EntityRegistry.registerGlobalEntityID(EntityBoar.class, "AusBoar", EntityRegistry.findGlobalUniqueEntityId(), Utils.rgbtoHexValue(255, 0, 0), Utils.rgbtoHexValue(175, 175, 175)); + //EntityRegistry.registerGlobalEntityID(EntityDingo.class, "AusDingo", EntityRegistry.findGlobalUniqueEntityId(), Utils.rgbtoHexValue(255, 0, 0), Utils.rgbtoHexValue(175, 175, 175)); + //EntityRegistry.registerGlobalEntityID(EntityOctopus.class, "AusOctopus", EntityRegistry.findGlobalUniqueEntityId(), Utils.rgbtoHexValue(255, 0, 0), Utils.rgbtoHexValue(175, 175, 175)); + + + + + + + + } + +} diff --git a/src/main/java/gtPlusPlus/core/entity/ai/batking/EntityAIBatKingAttack.java b/src/main/java/gtPlusPlus/core/entity/ai/batking/EntityAIBatKingAttack.java new file mode 100644 index 0000000000..52d1d6100c --- /dev/null +++ b/src/main/java/gtPlusPlus/core/entity/ai/batking/EntityAIBatKingAttack.java @@ -0,0 +1,406 @@ +package gtPlusPlus.core.entity.ai.batking; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.entity.monster.EntityBatKing; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.EntityUtils; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.IRangedAttackMob; +import net.minecraft.entity.ai.EntityAIBase; +import net.minecraft.pathfinding.PathEntity; +import net.minecraft.pathfinding.PathPoint; +import net.minecraft.util.MathHelper; + +public class EntityAIBatKingAttack extends EntityAIBase { + + private final Ranged mRangedAI; + private final Melee mMeleeAI; + private boolean mIsMelee = false; + + /** The Bat King in control of this AI. */ + private final EntityBatKing mAttackingEntity; + + /** The PathEntity of our entity. */ + private PathEntity mEntityPathEntity; + + /** The current target of Bat King in control of this AI. */ + private EntityLivingBase mEntityTarget; + + private final Class mClassTarget; + + public EntityAIBatKingAttack(EntityBatKing aAttacker, Class aClassTarget, + double aMovementSpeed, int someInt, int aMaxRangedAttackTime, float someFloat, boolean aLongMemory) { + mRangedAI = new Ranged(this, aMovementSpeed, someInt, 5, someFloat); + mMeleeAI = new Melee(this, aClassTarget, aMovementSpeed, aLongMemory); + mAttackingEntity = aAttacker; + mClassTarget = aClassTarget; + } + + @Override + public boolean shouldExecute() { + determineCombatStyle(); + EntityLivingBase entitylivingbase = this.mAttackingEntity.getAttackTarget(); + if (entitylivingbase == null) { + this.mEntityTarget = null; + return false; + } else if (!entitylivingbase.isEntityAlive()) { + return false; + } else if (this.mClassTarget != null && !this.mClassTarget.isAssignableFrom(entitylivingbase.getClass())) { + return false; + } else { + if (this.mIsMelee) { + return this.mMeleeAI.shouldExecute(); + } + else { + this.mEntityTarget = entitylivingbase; + this.mEntityPathEntity = this.mAttackingEntity.getNavigator().getPathToEntityLiving(entitylivingbase); + return mRangedAI != null && mMeleeAI != null && hasValidTarget(); + } + } + } + + public EntityBatKing getBatKing() { + return this.mAttackingEntity; + } + + public IRangedAttackMob getBatKingAsIRangedAttackMob() { + return this.mAttackingEntity; + } + + public boolean hasValidTarget() { + return this.mEntityTarget != null; + } + + public EntityLivingBase getTarget() { + return mEntityTarget; + } + + @Override + public boolean continueExecuting() { + determineCombatStyle(); + if (mIsMelee) { + return mMeleeAI.continueExecuting(); + } else { + return mRangedAI.continueExecuting(); + } + } + + @Override + public boolean isInterruptible() { + if (mIsMelee) { + + } else { + + } + return super.isInterruptible(); + } + + @Override + public void startExecuting() { + determineCombatStyle(); + if (mIsMelee) { + mMeleeAI.startExecuting(); + } else { + mRangedAI.startExecuting(); + } + } + + @Override + public void resetTask() { + determineCombatStyle(); + if (mIsMelee) { + mMeleeAI.resetTask(); + } else { + mRangedAI.resetTask(); + } + } + + @Override + public void updateTask() { + determineCombatStyle(); + if (mIsMelee) { + mMeleeAI.updateTask(); + } else { + mRangedAI.updateTask(); + } + } + + + private final void determineCombatStyle() { + boolean aisMeleeNow = this.mIsMelee; + if (this.mEntityTarget != null && EntityUtils.getDistance(getBatKing(), mEntityTarget) < 4) { + this.mIsMelee = true; + } + else { + this.mIsMelee = false; + } + if (aisMeleeNow != this.mIsMelee) { + Logger.INFO("Bat King changed combat style from "+(aisMeleeNow ? "Melee" : "Ranged")+" to "+(this.mIsMelee ? "Melee" : "Ranged")); + } + } + + private class Ranged { + + private final EntityAIBatKingAttack parentAI; + + /** + * A decrementing tick that spawns a ranged attack once this value reaches 0. It + * is then set back to the maxRangedAttackTime. + */ + private int rangedAttackTime; + private double entityMoveSpeed; + private int mCooldownTime; + private int field_96561_g; + /** + * The maximum time the AI has to wait before performing another ranged attack. + */ + private int maxRangedAttackTime; + private float field_96562_i; + private float field_82642_h; //Max range + + public Ranged(EntityAIBatKingAttack aParent, double aMovementSpeed, int someInt, + int aMaxRangedAttackTime, float someFloat) { + this.rangedAttackTime = -1; + this.parentAI = aParent; + this.entityMoveSpeed = aMovementSpeed; + this.field_96561_g = someInt; + this.maxRangedAttackTime = aMaxRangedAttackTime; + this.field_96562_i = someFloat; + this.field_82642_h = someFloat * someFloat * 8; + parentAI.setMutexBits(3); + + } + + /** + * Execute a one shot task or start executing a continuous task + */ + public void startExecuting() { + parentAI.getBatKing().getNavigator().setPath(parentAI.mEntityPathEntity, this.entityMoveSpeed); + } + + /** + * Returns whether an in-progress EntityAIBase should continue executing + */ + public boolean continueExecuting() { + return parentAI.shouldExecute() || !parentAI.getBatKing().getNavigator().noPath(); + } + + /** + * Resets the task + */ + public void resetTask() { + parentAI.mEntityTarget = null; + this.mCooldownTime = 0; + this.rangedAttackTime = -1; + } + + /** + * Updates the task + */ + public void updateTask() { + + if (MathUtils.randInt(0, 100) == 0) { + maxRangedAttackTime = MathUtils.balance(maxRangedAttackTime, 20, 40); + } + + double d0 = parentAI.getBatKing().getDistanceSq(parentAI.mEntityTarget.posX, parentAI.mEntityTarget.boundingBox.minY, + parentAI.mEntityTarget.posZ); + boolean flag = parentAI.getBatKing().getEntitySenses().canSee(parentAI.mEntityTarget); + + if (flag) { + ++this.mCooldownTime; + } else { + this.mCooldownTime = 0; + } + + if (d0 <= (double) this.field_82642_h && this.mCooldownTime >= 20) { + parentAI.getBatKing().getNavigator().clearPathEntity(); + } else { + if (parentAI.getBatKing().getNavigator().tryMoveToEntityLiving(parentAI.mEntityTarget, this.entityMoveSpeed)) { + Logger.INFO("Doing Ranged Ai Task."); + } + else { + Logger.INFO("Not Doing Ranged Ai Task."); + } + } + + parentAI.getBatKing().getLookHelper().setLookPositionWithEntity(parentAI.mEntityTarget, 30.0F, 30.0F); + float f; + Logger.INFO("Ranged AI - "+rangedAttackTime); + + if (--this.rangedAttackTime == 0) { + if (d0 > (double) this.field_82642_h || !flag) { + Logger.INFO("Stopping ranged attack. "+flag+"|"+(d0 > (double) this.field_82642_h)+"|"+d0+"|"+(double) this.field_82642_h); + return; + } + + f = MathHelper.sqrt_double(d0) / this.field_96562_i; + float f1 = f; + + if (f < 0.1F) { + f1 = 0.1F; + } + + if (f1 > 1.0F) { + f1 = 1.0F; + } + Logger.INFO("Trying to do a ranged attack."); + parentAI.getBatKingAsIRangedAttackMob().attackEntityWithRangedAttack(parentAI.mEntityTarget, f1); + this.rangedAttackTime = MathHelper.floor_float( + f * (float) (this.maxRangedAttackTime - this.field_96561_g) + (float) this.field_96561_g); + } else if (this.rangedAttackTime < 0) { + f = MathHelper.sqrt_double(d0) / this.field_96562_i; + this.rangedAttackTime = MathHelper.floor_float( + f * (float) (this.maxRangedAttackTime - this.field_96561_g) + (float) this.field_96561_g); + } + } + + } + + private class Melee { + + private final EntityAIBatKingAttack parentAI; + + /** + * An amount of decrementing ticks that allows the entity to attack once the + * tick reaches 0. + */ + int attackTick; + /** The speed with which the mob will approach the target */ + double speedTowardsTarget; + /** + * When true, the mob will continue chasing its target, even if it can't find a + * path to them right now. + */ + boolean longMemory; + Class classTarget; + private int field_75445_i; + private double field_151497_i; + private double field_151495_j; + private double field_151496_k; + + private int failedPathFindingPenalty; + + public Melee(EntityAIBatKingAttack aParent, Class aClassTarget, + double aMoveToTargetSpeed, boolean aLongMemory) { + this.parentAI = aParent; + this.classTarget = aClassTarget; + this.speedTowardsTarget = aMoveToTargetSpeed; + this.longMemory = aLongMemory; + parentAI.setMutexBits(3); + } + + /** + * Returns whether the EntityAIBase should begin execution. + */ + public boolean shouldExecute() { + if (!parentAI.hasValidTarget()) { + return false; + } + EntityLivingBase entitylivingbase = parentAI.getTarget(); + + if (entitylivingbase == null) { + return false; + } else if (!entitylivingbase.isEntityAlive()) { + return false; + } else if (this.classTarget != null && !this.classTarget.isAssignableFrom(entitylivingbase.getClass())) { + return false; + } else { + if (--this.field_75445_i <= 0) { + parentAI.mEntityPathEntity = parentAI.mAttackingEntity.getNavigator().getPathToEntityLiving(entitylivingbase); + this.field_75445_i = 4 + parentAI.mAttackingEntity.getRNG().nextInt(7); + return parentAI.mEntityPathEntity != null; + } else { + return true; + } + } + } + + /** + * Returns whether an in-progress EntityAIBase should continue executing + */ + public boolean continueExecuting() { + EntityLivingBase entitylivingbase = parentAI.mAttackingEntity.getAttackTarget(); + return entitylivingbase == null ? false + : (!entitylivingbase.isEntityAlive() ? false + : (!this.longMemory ? !parentAI.mAttackingEntity.getNavigator().noPath() + : parentAI.mAttackingEntity.isWithinHomeDistance(MathHelper.floor_double(entitylivingbase.posX), + MathHelper.floor_double(entitylivingbase.posY), + MathHelper.floor_double(entitylivingbase.posZ)))); + } + + /** + * Execute a one shot task or start executing a continuous task + */ + public void startExecuting() { + parentAI.mAttackingEntity.getNavigator().setPath(parentAI.mEntityPathEntity, this.speedTowardsTarget); + this.field_75445_i = 0; + } + + /** + * Resets the task + */ + public void resetTask() { + parentAI.mAttackingEntity.getNavigator().clearPathEntity(); + } + + /** + * Updates the task + */ + public void updateTask() { + EntityLivingBase entitylivingbase = parentAI.mAttackingEntity.getAttackTarget(); + parentAI.mAttackingEntity.getLookHelper().setLookPositionWithEntity(entitylivingbase, 30.0F, 30.0F); + double d0 = parentAI.mAttackingEntity.getDistanceSq(entitylivingbase.posX, entitylivingbase.boundingBox.minY, + entitylivingbase.posZ); + double d1 = (double) (parentAI.mAttackingEntity.width * 2.0F * parentAI.mAttackingEntity.width * 2.0F + entitylivingbase.width); + --this.field_75445_i; + + if ((this.longMemory || parentAI.mAttackingEntity.getEntitySenses().canSee(entitylivingbase)) && this.field_75445_i <= 0 + && (this.field_151497_i == 0.0D && this.field_151495_j == 0.0D && this.field_151496_k == 0.0D + || entitylivingbase.getDistanceSq(this.field_151497_i, this.field_151495_j, + this.field_151496_k) >= 1.0D + || parentAI.mAttackingEntity.getRNG().nextFloat() < 0.05F)) { + this.field_151497_i = entitylivingbase.posX; + this.field_151495_j = entitylivingbase.boundingBox.minY; + this.field_151496_k = entitylivingbase.posZ; + this.field_75445_i = failedPathFindingPenalty + 4 + parentAI.mAttackingEntity.getRNG().nextInt(7); + + if (parentAI.mAttackingEntity.getNavigator().getPath() != null) { + PathPoint finalPathPoint = parentAI.mAttackingEntity.getNavigator().getPath().getFinalPathPoint(); + if (finalPathPoint != null && entitylivingbase.getDistanceSq(finalPathPoint.xCoord, + finalPathPoint.yCoord, finalPathPoint.zCoord) < 1) { + failedPathFindingPenalty = 0; + } else { + failedPathFindingPenalty += 10; + } + } else { + failedPathFindingPenalty += 10; + } + + if (d0 > 1024.0D) { + this.field_75445_i += 10; + } else if (d0 > 256.0D) { + this.field_75445_i += 5; + } + + if (!parentAI.mAttackingEntity.getNavigator().tryMoveToEntityLiving(entitylivingbase, this.speedTowardsTarget)) { + this.field_75445_i += 15; + } + } + + this.attackTick = Math.max(this.attackTick - 1, 0); + + if (d0 <= d1 && this.attackTick <= 20) { + this.attackTick = 20; + + if (parentAI.mAttackingEntity.getHeldItem() != null) { + parentAI.mAttackingEntity.swingItem(); + } + + parentAI.mAttackingEntity.attackEntityAsMob(entitylivingbase); + } + } + + } + +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/core/entity/item/ItemEntityGiantEgg.java b/src/main/java/gtPlusPlus/core/entity/item/ItemEntityGiantEgg.java new file mode 100644 index 0000000000..8e0b1b48ce --- /dev/null +++ b/src/main/java/gtPlusPlus/core/entity/item/ItemEntityGiantEgg.java @@ -0,0 +1,117 @@ +package gtPlusPlus.core.entity.item; + +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.entity.monster.EntityGiantChickenBase; +import gtPlusPlus.core.item.ModItems; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.minecraft.NBTUtils; + +public class ItemEntityGiantEgg extends EntityItem { + + /** + * The maximum age of this Chicken Egg. The item will try hatch once this is reached. + */ + public int mEggAge = 10000; + public int mEggSize = -1; + + public ItemEntityGiantEgg(World aWorld) { + super(aWorld); + } + + public ItemEntityGiantEgg(World aWorld, double aX, double aY, double aZ) { + super(aWorld, aX, aY, aZ); + } + + public ItemEntityGiantEgg(World aWorld, double aX, double aY, double aZ, ItemStack aStack) { + super(aWorld, aX, aY, aZ, aStack); + } + + private boolean spawnGiantChicken() { + try { + EntityGiantChickenBase entitychicken = new EntityGiantChickenBase(this.worldObj); + entitychicken.setGrowingAge(-MathUtils.randInt(20000, 40000)); + entitychicken.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, 0.0F); + return this.worldObj.spawnEntityInWorld(entitychicken); + } + catch (Throwable t) { + return false; + } + } + + //These eggs also do not combine. + @Override + public boolean combineItems(EntityItem p_70289_1_) { + return false; + } + + @Override + public void writeEntityToNBT(NBTTagCompound aNBT) { + super.writeEntityToNBT(aNBT); + aNBT.setInteger("mEggAge", mEggAge); + aNBT.setInteger("mTicksExisted", this.age); + } + + @Override + public void readEntityFromNBT(NBTTagCompound aNBT) { + super.readEntityFromNBT(aNBT); + mEggAge = aNBT.getInteger("mEggAge"); + } + + //They're fireproof + @Override + public void setFire(int p_70015_1_) { + } + + @Override + public boolean isBurning() { + return false; + } + + @Override + public void onEntityUpdate() { + super.onEntityUpdate(); + Logger.INFO("1"); + //Large eggs don't despawn, because they will try hatch first. + if (this.lifespan != Integer.MAX_VALUE-1) { + this.lifespan = Integer.MAX_VALUE-1; + } + + if (this.getEntityItem() != null) { + ItemStack g = this.getEntityItem(); + NBTUtils.setInteger(g, "mTicksExisted", this.age); + NBTUtils.setInteger(g, "lifespan", this.lifespan); + NBTUtils.setBoolean(g, "playerHeld", false); + this.setEntityItemStack(g); + Logger.INFO("Writing age to NBT of stored stack item."); + } + else { + ItemStack g = ItemUtils.getSimpleStack(ModItems.itemBigEgg); + NBTUtils.setInteger(g, "mTicksExisted", this.age); + NBTUtils.setInteger(g, "lifespan", this.lifespan); + NBTUtils.setBoolean(g, "playerHeld", false); + this.setEntityItemStack(g); + Logger.INFO("Writing age to NBT of new stack item."); + + } + + if (this.age >= 1000) { + //Cache the value for efficiency + if (mEggSize == -1) + mEggSize = (this.getEntityItem() != null ? (this.getEntityItem().hasTagCompound() ? (this.getEntityItem().getTagCompound().hasKey("size") ? this.getEntityItem().getTagCompound().getInteger("size") : 1) : 1) : 1); + if (MathUtils.randInt(100*mEggSize, 1000) >= MathUtils.randInt(950, 1000)) { + //Spawn Chicken + if (spawnGiantChicken()) { + this.kill(); + } + } + } + } + + +} diff --git a/src/main/java/gtPlusPlus/core/entity/monster/EntityBatKing.java b/src/main/java/gtPlusPlus/core/entity/monster/EntityBatKing.java new file mode 100644 index 0000000000..55e0f4c571 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/entity/monster/EntityBatKing.java @@ -0,0 +1,712 @@ +package gtPlusPlus.core.entity.monster; + +import java.lang.reflect.Field; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.minecraft.BlockPos; +import gtPlusPlus.core.entity.ai.batking.EntityAIBatKingAttack; +import gtPlusPlus.core.entity.projectile.EntityThrowableBomb; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.EntityUtils; +import gtPlusPlus.core.util.reflect.ReflectionUtils; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.EnumCreatureAttribute; +import net.minecraft.entity.IRangedAttackMob; +import net.minecraft.entity.SharedMonsterAttributes; +import net.minecraft.entity.ai.EntityAIAttackOnCollide; +import net.minecraft.entity.ai.EntityAIHurtByTarget; +import net.minecraft.entity.ai.EntityAINearestAttackableTarget; +import net.minecraft.entity.ai.EntityAIWander; +import net.minecraft.entity.ai.RandomPositionGenerator; +import net.minecraft.entity.monster.EntityMob; +import net.minecraft.entity.passive.EntityBat; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.projectile.EntityArrow; +import net.minecraft.entity.projectile.EntityLargeFireball; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.DamageSource; +import net.minecraft.util.MathHelper; +import net.minecraft.util.Vec3; +import net.minecraft.world.EnumDifficulty; +import net.minecraft.world.World; + +public class EntityBatKing extends EntityMob implements IRangedAttackMob { + + public int courseChangeCooldown; + public double waypointX; + public double waypointY; + public double waypointZ; + private Entity targetedEntity; + private int aggroCooldown; + public int prevAttackCounter; + public int attackCounter; + private int explosionStrength = 1; + + private EntityAIBatKingAttack aiAttack = new EntityAIBatKingAttack(this, null, 1.0D, 20, 60, 15.0F, true); + private EntityAIAttackOnCollide aiAttackOnCollide = new EntityAIAttackOnCollide(this, EntityPlayer.class, 1.2D, + false); + + public EntityBatKing(World p_i1680_1_) { + super(p_i1680_1_); + this.setSize(2.5F, 1.5F); + + this.setIsBatHanging(false); + this.isImmuneToFire = true; + this.experienceValue = 1000; + + this.tasks.addTask(3, this.aiAttack); + //this.tasks.addTask(4, this.aiAttackOnCollide); + //this.tasks.addTask(4, new EntityAIRestrictSun(this)); + //this.tasks.addTask(5, new EntityAIFleeSun(this, 1.0D)); + this.tasks.addTask(4, new EntityAIWander(this, 1.0D)); + //this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F)); + //this.tasks.addTask(6, new EntityAILookIdle(this)); + + this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true)); + //this.targetTasks.addTask(2, this.aiAttack); + this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 0, true)); + this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityBat.class, 0, false)); + + } + + protected void entityInit() { + super.entityInit(); + } + + /** + * Get this Entity's EnumCreatureAttribute + */ + public EnumCreatureAttribute getCreatureAttribute() { + return EnumCreatureAttribute.UNDEAD; + } + + /** + * Gets the pitch of living sounds in living entities. + */ + protected float getSoundPitch() { + return super.getSoundPitch() * 0.15F; + } + + /** + * Returns the sound this mob makes while it's alive. + */ + protected String getLivingSound() { + int aRand = MathUtils.randInt(0, 10); + if (aRand < 6) { + return null; + } else if (aRand <= 8) { + return "mob.bat.idle"; + } else { + return "mob.blaze.breathe"; + } + } + + /** + * Returns the sound this mob makes when it is hurt. + */ + protected String getHurtSound() { + return "mob.blaze.hit"; + } + + /** + * Returns the sound this mob makes on death. + */ + protected String getDeathSound() { + return "mob.bat.death"; + } + + /** + * Returns true if this entity should push and be pushed by other entities when + * colliding. + */ + public boolean canBePushed() { + return true; + } + + protected void collideWithEntity(Entity aEntity) { + if (aEntity != null) { + if (aEntity instanceof EntityPlayer) { + EntityUtils.doDamage(aEntity, DamageSource.magic, (int) (((EntityPlayer) aEntity).getHealth() / 20)); + } + } + } + + protected void collideWithNearbyEntities() { + } + + protected void applyEntityAttributes() { + + this.getAttributeMap().registerAttribute(SharedMonsterAttributes.maxHealth); + this.getAttributeMap().registerAttribute(SharedMonsterAttributes.attackDamage); + this.getAttributeMap().registerAttribute(SharedMonsterAttributes.knockbackResistance); + this.getAttributeMap().registerAttribute(SharedMonsterAttributes.movementSpeed); + this.getAttributeMap().registerAttribute(SharedMonsterAttributes.followRange); + + this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(250.0D); + this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(6.0D); + this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(1D); + this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(120.0D); + } + + public boolean getIsBatHanging() { + return false; + } + + public void setIsBatHanging(boolean p_82236_1_) { + generateParticles(this); + generateParticles(this); + generateParticles(this); + for (int i = 0; i < 32; ++i) { + // + String particleName = "lava"; + if (MathUtils.randInt(0, 3) <= 2) { + particleName = "crit"; + } + this.worldObj.spawnParticle(particleName, + this.posX + (this.rand.nextDouble() - 0.5D) * (double) this.width, + this.posY + this.rand.nextDouble() * (double) this.height, + this.posZ + (this.rand.nextDouble() - 0.5D) * (double) this.width, 0.0D, 0.0D, 0.0D); + } + + } + + /** + * Returns true if the newer Entity AI code should be run + */ + protected boolean isAIEnabled() { + return true; + } + + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() { + super.onUpdate(); + generateParticles(this); + + if (!this.worldObj.isRemote && (this.targetedEntity == null || this.aggroCooldown-- <= 0)) { + this.targetedEntity = this.worldObj.getClosestVulnerablePlayerToEntity(this, 100.0D); + + if (this.targetedEntity != null) { + this.aggroCooldown = 30; + if (aiAttack.hasValidTarget()) { + this.setAttackTarget(aiAttack.getTarget()); + } + else { + Logger.INFO("No valid target."); + if (ReflectionUtils.doesFieldExist(aiAttack.getClass(), "mEntityTarget")) { + Logger.INFO("Found field."); + } + else { + Logger.INFO("Did not find field."); + } + Field target = ReflectionUtils.getField(EntityAIBatKingAttack.class, "mEntityTarget"); + if (target != null) { + ReflectionUtils.setField(aiAttack, target, this.targetedEntity); + Logger.INFO("Set target."); + } + else { + Logger.INFO("Could not set via reflection."); + } + + + } + } + else { + Vec3 vec3 = RandomPositionGenerator.findRandomTarget(this, 32, 20); + if (vec3 != null) { + double xPosition = vec3.xCoord; + double yPosition = vec3.yCoord; + double zPosition = vec3.zCoord; + this.getNavigator().tryMoveToXYZ(xPosition, yPosition, zPosition, 3); + } + } + } + + } + + private static void generateParticles(EntityBatKing aKing) { + for (int i = 0; i < 20; ++i) { + // + if (MathUtils.randInt(0, 50) <= 1) { + String particleName = "smoke"; + if (MathUtils.randInt(0, 3) <= 2) { + particleName = "largesmoke"; + } + aKing.worldObj.spawnParticle(particleName, + aKing.posX + (aKing.rand.nextDouble() - 0.5D) * (double) aKing.width, + aKing.posY + aKing.rand.nextDouble() * (double) aKing.height, + aKing.posZ + (aKing.rand.nextDouble() - 0.5D) * (double) aKing.width, 0.0D, 0.0D, 0.0D); + } + if (MathUtils.randInt(0, 100) <= 1) { + String particleName = "smoke"; + int test2 = MathUtils.randInt(0, 3); + if (test2 == 2) { + particleName = "dripLava"; + } else if (test2 == 3) { + particleName = "portal"; + } + aKing.worldObj.spawnParticle(particleName, + aKing.posX + (aKing.rand.nextDouble() - 0.5D) * (double) aKing.width, + aKing.posY + aKing.rand.nextDouble() * (double) aKing.height, + aKing.posZ + (aKing.rand.nextDouble() - 0.5D) * (double) aKing.width, 0.0D, 0.0D, 0.0D); + } + } + } + + protected void updateAITasks() { + super.updateAITasks(); + } + + private boolean isFlying() { + if (this.onGround) { + return false; + } + return true; + } + + private boolean hasAir() { + BlockPos p = EntityUtils.findBlockPosUnderEntity(this); + int y = p.yPos; + int yOriginal = p.yPos; + + for (int u = 0; u<5;u++) { + if (u > 50 || y <= 0) { + break; + } + if (!this.worldObj.isAirBlock(p.xPos, y, p.zPos)) { + break; + } + y--; + } + if (yOriginal != y) { + for (int i = 0; i < y; y++) { + this.jump(); + } + return true; + } + return false; + } + + /** + * returns if this entity triggers Block.onEntityWalking on the blocks they walk + * on. used for spiders and wolves to prevent them from trampling crops + */ + protected boolean canTriggerWalking() { + return false; + } + + /** + * Return whether this entity should NOT trigger a pressure plate or a tripwire. + */ + public boolean doesEntityNotTriggerPressurePlate() { + return true; + } + + /** + * Called when the entity is attacked. + */ + public boolean attackEntityFrom(DamageSource p_70097_1_, float p_70097_2_) { + if (this.isEntityInvulnerable()) { + return false; + } else { + if (!this.worldObj.isRemote && this.getIsBatHanging()) { + this.setIsBatHanging(false); + } + + return super.attackEntityFrom(p_70097_1_, p_70097_2_); + } + } + + /** + * (abstract) Protected helper method to read subclass entity data from NBT. + */ + public void readEntityFromNBT(NBTTagCompound p_70037_1_) { + super.readEntityFromNBT(p_70037_1_); + if (p_70037_1_.hasKey("ExplosionPower", 99)) { + this.explosionStrength = p_70037_1_.getInteger("ExplosionPower"); + } + } + + /** + * (abstract) Protected helper method to write subclass entity data to NBT. + */ + public void writeEntityToNBT(NBTTagCompound p_70014_1_) { + super.writeEntityToNBT(p_70014_1_); + p_70014_1_.setInteger("ExplosionPower", this.explosionStrength); + } + + /** + * Attack the specified entity using a ranged attack. + */ + @Override + public void attackEntityWithRangedAttack(EntityLivingBase p_82196_1_, float p_82196_2_) { + Logger.INFO("Trying to do ranged attack 1 |"+(this.targetedEntity != null)+"|"); + + if (!this.isFlying() || !this.isAirBorne) { + //this.hasAir(); + /* + * for (int i=0;i<3;i++) { this.jump(); } + */ + } + + + double d4 = 64.0D; + if (this.targetedEntity != null && this.targetedEntity.getDistanceSqToEntity(this) < d4 * d4 * 8) { + Logger.INFO("Trying to do ranged attack 2"); + double d5 = this.targetedEntity.posX - this.posX; + double d6 = this.targetedEntity.boundingBox.minY + (double) (this.targetedEntity.height / 2.0F) + - (this.posY + (double) (this.height / 2.0F)); + double d7 = this.targetedEntity.posZ - this.posZ; + this.renderYawOffset = this.rotationYaw = -((float) Math.atan2(d5, d7)) * 180.0F / (float) Math.PI; + + ++this.attackCounter; + + if (this.canEntityBeSeen(this.targetedEntity)) { + Logger.INFO("Trying to do ranged attack 3a | "+attackCounter); + + + if (this.attackCounter >= 2) { + Logger.INFO("Trying to do ranged attack 3a1"); + + this.worldObj.playAuxSFXAtEntity((EntityPlayer) null, 1008, (int) this.posX, (int) this.posY, + (int) this.posZ, 0); + setIsBatHanging(true); + + EntityThrowableBomb entitylargefireball = new EntityThrowableBomb(this.worldObj, this/*d5, d6, d7*/); + //entitylargefireball.field_92057_e = this.explosionStrength; + //entitylargefireball.accelerationX *= 2; + //entitylargefireball.accelerationY *= 2; + //entitylargefireball.accelerationZ *= 2; + double d8 = 4.0D; + Vec3 vec3 = this.getLook(1.0F); + entitylargefireball.posX = this.posX + vec3.xCoord * d8; + entitylargefireball.posY = this.posY + (double) (this.height / 2.0F) + 0.5D; + entitylargefireball.posZ = this.posZ + vec3.zCoord * d8; + this.worldObj.spawnEntityInWorld(entitylargefireball); + + for (int u=0; u<MathUtils.randInt(2, 10);u++) { + if (this.attackCounter > 0) { + Logger.INFO("Trying to do ranged attack 5a"); + --this.attackCounter; + EntityArrow entityarrow = new EntityArrow(this.worldObj, this, p_82196_1_, MathUtils.randFloat(1f, 3f), + (float) (14 - this.worldObj.difficultySetting.getDifficultyId() * 4)); + int i = MathUtils.randInt(0, 4); + int j = MathUtils.randInt(0, 3); + int k = MathUtils.randInt(0, 3); + entityarrow.setDamage((double) (p_82196_2_ * 2.0F) + this.rand.nextGaussian() * 0.25D + + (double) ((float) this.worldObj.difficultySetting.getDifficultyId() * 0.11F)); + + boolean boostAttack = MathUtils.randInt(0, 100) <= 21; + if (boostAttack) { + if (i > 0) { + entityarrow.setDamage(entityarrow.getDamage() + (double) i * 0.5D + 0.5D); + } + + if (j > 0) { + entityarrow.setKnockbackStrength(j); + } + if (k > 0) { + entityarrow.setFire(50 * k); + } + } + + this.playSound("mob.skeleton.say", 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F)); + this.worldObj.spawnEntityInWorld(entityarrow); + Logger.INFO("Trying to do ranged attack 5a done"); + } + } + + + + + this.attackCounter = 0; + } + } else if (this.attackCounter > 0) { + Logger.INFO("Trying to do ranged attack 3b"); + --this.attackCounter; + } + } else { + Logger.INFO("Trying to do ranged attack 4a"); + this.renderYawOffset = this.rotationYaw = -((float) Math.atan2(this.motionX, this.motionZ)) * 180.0F + / (float) Math.PI; + + if (this.attackCounter > 0) { + Logger.INFO("Trying to do ranged attack 5a"); + --this.attackCounter; + EntityArrow entityarrow = new EntityArrow(this.worldObj, this, p_82196_1_, 1.6F, + (float) (14 - this.worldObj.difficultySetting.getDifficultyId() * 4)); + int i = MathUtils.randInt(0, 4); + int j = MathUtils.randInt(0, 3); + int k = MathUtils.randInt(0, 3); + entityarrow.setDamage((double) (p_82196_2_ * 2.0F) + this.rand.nextGaussian() * 0.25D + + (double) ((float) this.worldObj.difficultySetting.getDifficultyId() * 0.11F)); + + boolean boostAttack = MathUtils.randInt(0, 100) <= 21; + if (boostAttack) { + if (i > 0) { + entityarrow.setDamage(entityarrow.getDamage() + (double) i * 0.5D + 0.5D); + } + + if (j > 0) { + entityarrow.setKnockbackStrength(j); + } + if (k > 0) { + entityarrow.setFire(50 * k); + } + } + + this.playSound("mob.skeleton.say", 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F)); + this.worldObj.spawnEntityInWorld(entityarrow); + Logger.INFO("Trying to do ranged attack 5a done"); + } + + } + + } + + /** + * Returns the volume for the sounds this mob makes. + */ + protected float getSoundVolume() { + return 10.0F; + } + + /** + * Checks if the entity's current position is a valid location to spawn this + * entity. + */ + public boolean getCanSpawnHere() { + return super.getCanSpawnHere() && this.worldObj.difficultySetting != EnumDifficulty.PEACEFUL; + } + + /** + * Will return how many at most can spawn in a chunk at once. + */ + public int getMaxSpawnedInChunk() { + return 1; + } + + protected Item getDropItem() { + return Items.gunpowder; + } + + /** + * Drop 0-2 items of this living's type. @param par1 - Whether this entity has + * recently been hit by a player. @param par2 - Level of Looting used to kill + * this mob. + */ + protected void dropFewItems(boolean p_70628_1_, int p_70628_2_) { + int j = this.rand.nextInt(2) + this.rand.nextInt(1 + p_70628_2_); + int k; + + for (k = 0; k < j; ++k) { + this.dropItem(Items.ghast_tear, 1); + } + + j = this.rand.nextInt(3) + this.rand.nextInt(1 + p_70628_2_); + + for (k = 0; k < j; ++k) { + this.dropItem(Items.gunpowder, 1); + } + } + + @Override + protected void updateEntityActionState() { + if (!this.worldObj.isRemote && this.worldObj.difficultySetting == EnumDifficulty.PEACEFUL) { + this.setDead(); + } + + this.despawnEntity(); + this.prevAttackCounter = this.attackCounter; + double d0 = this.waypointX - this.posX; + double d1 = this.waypointY - this.posY; + double d2 = this.waypointZ - this.posZ; + double d3 = d0 * d0 + d1 * d1 + d2 * d2; + + if (d3 < 1.0D || d3 > 3600.0D) { + this.waypointX = this.posX + (double) ((this.rand.nextFloat() * 2.0F - 1.0F) * 16.0F); + this.waypointY = this.posY + (double) ((this.rand.nextFloat() * 2.0F - 1.0F) * 16.0F); + this.waypointZ = this.posZ + (double) ((this.rand.nextFloat() * 2.0F - 1.0F) * 16.0F); + } + + if (this.courseChangeCooldown-- <= 0) { + this.courseChangeCooldown += this.rand.nextInt(5) + 2; + d3 = (double) MathHelper.sqrt_double(d3); + + if (this.isCourseTraversable(this.waypointX, this.waypointY, this.waypointZ, d3)) { + this.motionX += d0 / d3 * 0.1D; + this.motionY += d1 / d3 * 0.1D; + this.motionZ += d2 / d3 * 0.1D; + } else { + this.waypointX = this.posX; + this.waypointY = this.posY; + this.waypointZ = this.posZ; + } + } + + if (this.targetedEntity != null && this.targetedEntity.isDead) { + this.targetedEntity = null; + } + + if (this.targetedEntity == null || this.aggroCooldown-- <= 0) { + this.targetedEntity = this.worldObj.getClosestVulnerablePlayerToEntity(this, 100.0D); + + if (this.targetedEntity != null) { + this.aggroCooldown = 20; + } + } + + double d4 = 64.0D; + + if (this.targetedEntity != null && this.targetedEntity.getDistanceSqToEntity(this) < d4 * d4) { + double d5 = this.targetedEntity.posX - this.posX; + double d6 = this.targetedEntity.boundingBox.minY + (double) (this.targetedEntity.height / 2.0F) + - (this.posY + (double) (this.height / 2.0F)); + double d7 = this.targetedEntity.posZ - this.posZ; + this.renderYawOffset = this.rotationYaw = -((float) Math.atan2(d5, d7)) * 180.0F / (float) Math.PI; + + if (this.canEntityBeSeen(this.targetedEntity)) { + if (this.attackCounter == 10) { + this.worldObj.playAuxSFXAtEntity((EntityPlayer) null, 1007, (int) this.posX, (int) this.posY, + (int) this.posZ, 0); + } + + ++this.attackCounter; + + if (this.attackCounter == 20) { + this.worldObj.playAuxSFXAtEntity((EntityPlayer) null, 1008, (int) this.posX, (int) this.posY, + (int) this.posZ, 0); + EntityLargeFireball entitylargefireball = new EntityLargeFireball(this.worldObj, this, d5, d6, d7); + entitylargefireball.field_92057_e = this.explosionStrength; + double d8 = 4.0D; + Vec3 vec3 = this.getLook(1.0F); + entitylargefireball.posX = this.posX + vec3.xCoord * d8; + entitylargefireball.posY = this.posY + (double) (this.height / 2.0F) + 0.5D; + entitylargefireball.posZ = this.posZ + vec3.zCoord * d8; + this.worldObj.spawnEntityInWorld(entitylargefireball); + this.attackCounter = -40; + } + } else if (this.attackCounter > 0) { + --this.attackCounter; + } + } else { + this.renderYawOffset = this.rotationYaw = -((float) Math.atan2(this.motionX, this.motionZ)) * 180.0F + / (float) Math.PI; + + if (this.attackCounter > 0) { + --this.attackCounter; + } + } + + if (!this.worldObj.isRemote) { + byte b1 = this.dataWatcher.getWatchableObjectByte(16); + byte b0 = (byte) (this.attackCounter > 10 ? 1 : 0); + + if (b1 != b0) { + this.dataWatcher.updateObject(16, Byte.valueOf(b0)); + } + } + } + + /** + * True if the ghast has an unobstructed line of travel to the waypoint. + */ + private boolean isCourseTraversable(double p_70790_1_, double p_70790_3_, double p_70790_5_, double p_70790_7_) { + double d4 = (this.waypointX - this.posX) / p_70790_7_; + double d5 = (this.waypointY - this.posY) / p_70790_7_; + double d6 = (this.waypointZ - this.posZ) / p_70790_7_; + AxisAlignedBB axisalignedbb = this.boundingBox.copy(); + + for (int i = 1; (double) i < p_70790_7_; ++i) { + axisalignedbb.offset(d4, d5, d6); + + /* + * if (!this.worldObj.getCollidingBoundingBoxes(this, axisalignedbb).isEmpty()) + * { return false; } + */ + } + + return true; + } + + /** + * Called when the mob is falling. Calculates and applies fall damage. + */ + protected void fall(float p_70069_1_) { + } + + /** + * Takes in the distance the entity has fallen this tick and whether its on the + * ground to update the fall distance and deal fall damage if landing on the + * ground. Args: distanceFallenThisTick, onGround + */ + protected void updateFallState(double p_70064_1_, boolean p_70064_3_) { + } + + /** + * Moves the entity based on the specified heading. Args: strafe, forward + */ + public void moveEntityWithHeading(float p_70612_1_, float p_70612_2_) { + if (this.isInWater()) { + this.moveFlying(p_70612_1_, p_70612_2_, 0.02F); + this.moveEntity(this.motionX, this.motionY, this.motionZ); + this.motionX *= 0.800000011920929D; + this.motionY *= 0.800000011920929D; + this.motionZ *= 0.800000011920929D; + } else if (this.handleLavaMovement()) { + this.moveFlying(p_70612_1_, p_70612_2_, 0.02F); + this.moveEntity(this.motionX, this.motionY, this.motionZ); + this.motionX *= 0.5D; + this.motionY *= 0.5D; + this.motionZ *= 0.5D; + } else { + float f2 = 0.91F; + + if (this.onGround) { + f2 = this.worldObj.getBlock(MathHelper.floor_double(this.posX), + MathHelper.floor_double(this.boundingBox.minY) - 1, + MathHelper.floor_double(this.posZ)).slipperiness * 0.91F; + } + + float f3 = 0.16277136F / (f2 * f2 * f2); + this.moveFlying(p_70612_1_, p_70612_2_, this.onGround ? 0.1F * f3 : 0.02F); + f2 = 0.91F; + + if (this.onGround) { + f2 = this.worldObj.getBlock(MathHelper.floor_double(this.posX), + MathHelper.floor_double(this.boundingBox.minY) - 1, + MathHelper.floor_double(this.posZ)).slipperiness * 0.91F; + } + + this.moveEntity(this.motionX, this.motionY, this.motionZ); + this.motionX *= (double) f2; + this.motionY *= (double) f2; + this.motionZ *= (double) f2; + } + + this.prevLimbSwingAmount = this.limbSwingAmount; + double d1 = this.posX - this.prevPosX; + double d0 = this.posZ - this.prevPosZ; + float f4 = MathHelper.sqrt_double(d1 * d1 + d0 * d0) * 4.0F; + + if (f4 > 1.0F) { + f4 = 1.0F; + } + + this.limbSwingAmount += (f4 - this.limbSwingAmount) * 0.4F; + this.limbSwing += this.limbSwingAmount; + } + + /** + * returns true if this entity is by a ladder, false otherwise + */ + public boolean isOnLadder() { + return false; + } + +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/core/entity/monster/EntityGiantChickenBase.java b/src/main/java/gtPlusPlus/core/entity/monster/EntityGiantChickenBase.java new file mode 100644 index 0000000000..3a094e129b --- /dev/null +++ b/src/main/java/gtPlusPlus/core/entity/monster/EntityGiantChickenBase.java @@ -0,0 +1,311 @@ +package gtPlusPlus.core.entity.monster; + +import net.minecraft.entity.*; +import net.minecraft.entity.ai.*; +import net.minecraft.entity.effect.EntityLightningBolt; +import net.minecraft.entity.passive.EntityChicken; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.potion.Potion; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; + +import gtPlusPlus.core.item.ModItems; +import gtPlusPlus.core.item.general.ItemGemShards; +import gtPlusPlus.core.util.math.MathUtils; +import net.minecraftforge.common.ForgeHooks; + +public class EntityGiantChickenBase extends EntityChicken { + + /** The time until the next egg is spawned. */ + public int timeUntilNextBigEgg; + + public EntityGiantChickenBase(World aWorld) + { + super(aWorld); + this.setSize(0.6F, 1.4F); //Double + this.timeUntilNextEgg = this.rand.nextInt(6000) + 6000; + this.timeUntilNextBigEgg = this.rand.nextInt(16000) + 4000; + this.tasks.addTask(0, new EntityAISwimming(this)); + this.tasks.addTask(1, new EntityAIPanic(this, 1.4D)); + this.tasks.addTask(2, new EntityAIMate(this, 1.0D)); + this.tasks.addTask(3, new EntityAITempt(this, 1.0D, ModItems.itemGemShards, false)); + this.tasks.addTask(4, new EntityAIFollowParent(this, 1.1D)); + this.tasks.addTask(4, new EntityAIEatGrass(this)); + this.tasks.addTask(5, new EntityAIWander(this, 1.0D)); + this.tasks.addTask(5, new EntityAILookIdle(this)); + this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F)); + + } + + protected void applyEntityAttributes() + { + super.applyEntityAttributes(); + this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(40.0D); + this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.35D); + } + + /** + * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons + * use this to react to sunlight and start to burn. + */ + public void onLivingUpdate() + { + super.onLivingUpdate(); + this.field_70888_h = this.field_70886_e; + this.field_70884_g = this.destPos; + this.destPos = (float)((double)this.destPos + (double)(this.onGround ? -1 : 4) * 0.3D); + + if (this.destPos < 0.0F) + { + this.destPos = 0.0F; + } + + if (this.destPos > 1.0F) + { + this.destPos = 1.0F; + } + + if (!this.onGround && this.field_70889_i < 1.0F) + { + this.field_70889_i = 1.0F; + } + + this.field_70889_i = (float)((double)this.field_70889_i * 0.9D); + + if (!this.onGround && this.motionY < 0.0D) + { + this.motionY *= 0.6D; + } + + if (MathUtils.randInt(0, 10000) <= 5) { + jump(); + } + + this.field_70886_e += this.field_70889_i * 2.0F; + + if (!this.worldObj.isRemote && --this.timeUntilNextEgg <= 0) + { + this.playSound("mob.chicken.plop", 1.0F, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F); + this.dropItem(Items.egg, 1); + this.timeUntilNextEgg = this.rand.nextInt(6000) + 6000; + } + if (!this.worldObj.isRemote && !this.isChild() && --this.timeUntilNextEgg <= 0) + { + this.playSound("mob.chicken.plop", 1.0F, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F); + this.dropItem(ModItems.itemBigEgg, MathUtils.randInt(1, 4)); + this.timeUntilNextBigEgg = this.rand.nextInt(16000) + 4000; + } + } + + /** + * Called when the mob is falling. Calculates and applies fall damage. + */ + protected void fall(float p_70069_1_) { + + if (MathUtils.randInt(0, 10) <= 5) { + jump(); + } + + } + + protected Item getDropItem() + { + return ModItems.itemBigEgg; + } + + /** + * Drop 0-2 items of this living's type. @param par1 - Whether this entity has recently been hit by a player. @param + * par2 - Level of Looting used to kill this mob. + */ + protected void dropFewItems(boolean recentHit, int lootLevel) + { + int j = this.rand.nextInt(3) + this.rand.nextInt(1 + lootLevel); + + for (int k = 0; k < j; ++k) + { + this.dropItem(Items.feather, 1); + } + + //Large Egg Chance + for (int k = 0; k < j*2; ++k) + { + this.dropItem(ModItems.itemBigEgg, MathUtils.getRandomFromArray(new int[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2})); + } + + //Chicken Corpses Dropped + int mBodies = MathUtils.getRandomFromArray(new int[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6}); + if (this.isBurning()) + { + this.dropItem(Items.cooked_chicken, mBodies); + } + else + { + this.dropItem(Items.chicken, mBodies); + } + } + + public EntityGiantChickenBase createChild(EntityAgeable p_90011_1_) + { + return new EntityGiantChickenBase(this.worldObj); + } + + /** + * Checks if the parameter is an item which this animal can be fed to breed it (wheat, carrots or seeds depending on + * the animal type) + */ + public boolean isBreedingItem(ItemStack aStack) + { + return aStack != null && aStack.getItem() instanceof ItemGemShards; + } + + /** + * (abstract) Protected helper method to read subclass entity data from NBT. + */ + public void readEntityFromNBT(NBTTagCompound aNBT) + { + super.readEntityFromNBT(aNBT); + timeUntilNextBigEgg = aNBT.getInteger("timeUntilNextBigEgg"); + } + + /** + * Get the experience points the entity currently has. + */ + protected int getExperiencePoints(EntityPlayer p_70693_1_) + { + return this.isChickenJockey() ? 20 : super.getExperiencePoints(p_70693_1_); + } + + /** + * (abstract) Protected helper method to write subclass entity data to NBT. + */ + public void writeEntityToNBT(NBTTagCompound aNBT) + { + super.writeEntityToNBT(aNBT); + aNBT.setInteger("timeUntilNextBigEgg", timeUntilNextBigEgg); + } + + /** + * Determines if an entity can be despawned, used on idle far away entities + */ + protected boolean canDespawn() + { + return this.isChickenJockey() && this.riddenByEntity == null; + } + + public void updateRiderPosition() + { + super.updateRiderPosition(); + float f = MathHelper.sin(this.renderYawOffset * (float)Math.PI / 180.0F); + float f1 = MathHelper.cos(this.renderYawOffset * (float)Math.PI / 180.0F); + float f2 = 0.1F; + float f3 = 0.0F; + this.riddenByEntity.setPosition(this.posX + (double)(f2 * f), this.posY + (double)(this.height * 0.5F) + this.riddenByEntity.getYOffset() + (double)f3, this.posZ - (double)(f2 * f1)); + + if (this.riddenByEntity instanceof EntityLivingBase) + { + ((EntityLivingBase)this.riddenByEntity).renderYawOffset = this.renderYawOffset; + } + } + + public boolean isChickenJockey() { + return func_152116_bZ(); + } + public void setIsChickenJockey(boolean isJockey) { + func_152117_i(isJockey); + } + + @Override + protected Entity findPlayerToAttack() { + // TODO Auto-generated method stub + return super.findPlayerToAttack(); + } + + @Override + public boolean interact(EntityPlayer p_70085_1_) { + // TODO Auto-generated method stub + return super.interact(p_70085_1_); + } + + @Override + public void setHomeArea(int p_110171_1_, int p_110171_2_, int p_110171_3_, int p_110171_4_) { + // TODO Auto-generated method stub + super.setHomeArea(p_110171_1_, p_110171_2_, p_110171_3_, p_110171_4_); + } + + @Override + public ChunkCoordinates getHomePosition() { + // TODO Auto-generated method stub + return super.getHomePosition(); + } + + @Override + public void detachHome() { + // TODO Auto-generated method stub + super.detachHome(); + } + + @Override + public boolean hasHome() { + // TODO Auto-generated method stub + return super.hasHome(); + } + + @Override + public void eatGrassBonus() { + if (this.isChild()) { + this.addGrowth(60); + } + } + + @Override + public float getRenderSizeModifier() { + return 1.0f; + } + + @Override + protected void jump() { + this.motionY = 0.68999998688697815D; + this.motionY += 0.068999998688697815D; + if (this.isPotionActive(Potion.jump)) + { + this.motionY += (double)((float)(this.getActivePotionEffect(Potion.jump).getAmplifier() + 1) * 0.5F); + } + + if (this.isSprinting()) + { + float f = this.rotationYaw * 0.017453292F; + this.motionX -= (double)(MathHelper.sin(f) * 0.2F); + this.motionZ += (double)(MathHelper.cos(f) * 0.2F); + } + + this.isAirBorne = true; + + if (MathUtils.randInt(0, 10) < 10) { + jump(); + } + + ForgeHooks.onLivingJump(this); + } + + @Override + public void onStruckByLightning(EntityLightningBolt p_70077_1_) { + this.spawnExplosionParticle(); + this.spawnExplosionParticle(); + this.spawnExplosionParticle(); + this.spawnExplosionParticle(); + this.spawnExplosionParticle(); + this.spawnExplosionParticle(); + this.spawnExplosionParticle(); + super.onStruckByLightning(p_70077_1_); + } + + @Override + public boolean shouldDismountInWater(Entity rider) { + return true; + } +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/core/entity/monster/EntitySickBlaze.java b/src/main/java/gtPlusPlus/core/entity/monster/EntitySickBlaze.java new file mode 100644 index 0000000000..a530f294e1 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/entity/monster/EntitySickBlaze.java @@ -0,0 +1,225 @@ +package gtPlusPlus.core.entity.monster; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.SharedMonsterAttributes; +import net.minecraft.entity.monster.EntityMob; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.util.DamageSource; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; + +import gtPlusPlus.core.entity.projectile.EntityToxinballSmall; + +public class EntitySickBlaze extends EntityMob { + /** Random offset used in floating behaviour */ + private float heightOffset = 0.5F; + /** ticks until heightOffset is randomized */ + private int heightOffsetUpdateTime; + private int field_70846_g; + private final int mDataWatcherID = 30; + + public EntitySickBlaze(World p_i1731_1_) { + super(p_i1731_1_); + this.isImmuneToFire = true; + this.experienceValue = 10; + } + + @Override + protected void applyEntityAttributes() { + super.applyEntityAttributes(); + this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20.0D); + this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(1.5D); + this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(6.0D); + } + + @Override + protected void entityInit() { + super.entityInit(); + this.dataWatcher.addObject(mDataWatcherID, new Byte((byte) 0)); + } + + /** + * Returns the sound this mob makes while it's alive. + */ + @Override + protected String getLivingSound() { + return "mob.blaze.breathe"; + } + + /** + * Returns the sound this mob makes when it is hurt. + */ + @Override + protected String getHurtSound() { + return "mob.blaze.hit"; + } + + /** + * Returns the sound this mob makes on death. + */ + @Override + protected String getDeathSound() { + return "mob.blaze.death"; + } + + @Override + @SideOnly(Side.CLIENT) + public int getBrightnessForRender(float p_70070_1_) { + return 15728880; + } + + /** + * Gets how bright this entity is. + */ + @Override + public float getBrightness(float p_70013_1_) { + return p_70013_1_; + } + + /** + * Called frequently so the entity can update its state every tick as + * required. For example, zombies and skeletons use this to react to + * sunlight and start to burn. + */ + @Override + public void onLivingUpdate() { + if (!this.worldObj.isRemote) { + if (this.isWet()) { + this.attackEntityFrom(DamageSource.drown, 1.0F); + } + + --this.heightOffsetUpdateTime; + + if (this.heightOffsetUpdateTime <= 0) { + this.heightOffsetUpdateTime = 100; + this.heightOffset = 0.5F + (float) this.rand.nextGaussian() * 3.0F; + } + + if (this.getEntityToAttack() != null && this.getEntityToAttack().posY + + this.getEntityToAttack().getEyeHeight() > this.posY + this.getEyeHeight() + this.heightOffset) { + this.motionY += (0.30000001192092896D - this.motionY) * 0.30000001192092896D; + } + } + + if (this.rand.nextInt(24) == 0) { + /*this.worldObj.playSoundEffect(this.posX + 0.5D, this.posY + 0.5D, this.posZ + 0.5D, "fire.fire", + 1.0F + this.rand.nextFloat(), this.rand.nextFloat() * 0.7F + 0.3F);*/ + } + + if (!this.onGround && this.motionY < 0.0D) { + this.motionY *= 0.6D; + } + + for (int i = 0; i < 2; ++i) { + this.worldObj.spawnParticle("crit", this.posX + (this.rand.nextDouble() - 0.5D) * this.width, + this.posY + this.rand.nextDouble() * this.height, + this.posZ + (this.rand.nextDouble() - 0.5D) * this.width, 0.0D, 0.0D, 0.0D); + } + + super.onLivingUpdate(); + } + + /** + * Basic mob attack. Default to touch of death in EntityCreature. Overridden + * by each mob to define their attack. + */ + @Override + protected void attackEntity(Entity entity, float p_70785_2_) { + if (this.attackTime <= 0 && p_70785_2_ < 2.0F && entity.boundingBox.maxY > this.boundingBox.minY + && entity.boundingBox.minY < this.boundingBox.maxY) { + this.attackTime = 20; + this.attackEntityAsMob(entity); + } + else if (p_70785_2_ < 30.0F) { + double d0 = entity.posX - this.posX; + double d1 = entity.boundingBox.minY + entity.height / 2.0F - (this.posY + this.height / 2.0F); + double d2 = entity.posZ - this.posZ; + + if (this.attackTime == 0) { + ++this.field_70846_g; + + if (this.field_70846_g == 1) { + this.attackTime = 60; + } + else if (this.field_70846_g <= 4) { + this.attackTime = 6; + } + else { + this.attackTime = 100; + this.field_70846_g = 0; + } + + if (this.field_70846_g > 1) { + float f1 = MathHelper.sqrt_float(p_70785_2_) * 0.5F; + this.worldObj.playAuxSFXAtEntity((EntityPlayer) null, 1009, (int) this.posX, (int) this.posY, + (int) this.posZ, 0); + + for (int i = 0; i < 1; ++i) { + EntityToxinballSmall entitysmalltoxinball = new EntityToxinballSmall(this.worldObj, this, + d0 + this.rand.nextGaussian() * f1, d1, d2 + this.rand.nextGaussian() * f1); + entitysmalltoxinball.posY = this.posY + this.height / 2.0F + 0.5D; + this.worldObj.spawnEntityInWorld(entitysmalltoxinball); + } + } + } + + this.rotationYaw = (float) (Math.atan2(d2, d0) * 180.0D / Math.PI) - 90.0F; + this.hasAttacked = true; + } + } + + /** + * Called when the mob is falling. Calculates and applies fall damage. + */ + @Override + protected void fall(float p_70069_1_) { + } + + @Override + protected Item getDropItem() { + return Items.slime_ball; + } + + /** + * Returns true if the entity is on fire. Used by render to add the fire + * effect on rendering. + */ + @Override + public boolean isBurning() { + return false; + } + + /** + * Drop 0-2 items of this living's type. @param par1 - Whether this entity + * has recently been hit by a player. @param par2 - Level of Looting used to + * kill this mob. + */ + @Override + protected void dropFewItems(boolean p_70628_1_, int p_70628_2_) { + if (p_70628_1_) { + int j = this.rand.nextInt(2 + p_70628_2_); + + for (int k = 0; k < j; ++k) { + this.dropItem(getDropItem(), 1); + } + } + } + + /** + * Checks to make sure the light is not too bright where the mob is spawning + */ + @Override + protected boolean isValidLightLevel() { + return true; + } + + @Override + public int getMaxSpawnedInChunk() { + return 8; + } +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/core/entity/monster/EntityStaballoyConstruct.java b/src/main/java/gtPlusPlus/core/entity/monster/EntityStaballoyConstruct.java new file mode 100644 index 0000000000..f6f397f59e --- /dev/null +++ b/src/main/java/gtPlusPlus/core/entity/monster/EntityStaballoyConstruct.java @@ -0,0 +1,553 @@ +package gtPlusPlus.core.entity.monster; + +import java.lang.reflect.Field; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.reflect.ReflectionUtils; +import gtPlusPlus.core.world.explosions.ExplosionHandler; +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.entity.*; +import net.minecraft.entity.ai.*; +import net.minecraft.entity.effect.EntityLightningBolt; +import net.minecraft.entity.monster.EntityIronGolem; +import net.minecraft.entity.monster.IMob; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.DamageSource; +import net.minecraft.util.MathHelper; +import net.minecraft.village.Village; +import net.minecraft.world.World; + +public class EntityStaballoyConstruct extends EntityIronGolem { + + /* + * Determines whether or not the entity is in a fluid at all. + */ + private boolean inFluid = false; + private boolean mReflectFirstUpdate = true; + private boolean isReadyToExplode = false; + private int fuse = 60; + private int attackTimer; + + public EntityStaballoyConstruct(World world) { + super(world); + this.experienceValue = 250; + this.setSize(1.4F, 2.9F); + this.getNavigator().setAvoidsWater(true); + this.getNavigator().setBreakDoors(true); + this.getNavigator().setCanSwim(false); + this.getNavigator().setAvoidSun(false); + this.tasks.addTask(1, new EntityAIAttackOnCollide(this, 1.0D, true)); + this.tasks.addTask(2, new EntityAIMoveTowardsTarget(this, 0.9D, 32.0F)); + //this.tasks.addTask(3, new EntityAIMoveThroughVillage(this, 0.6D, true)); + this.tasks.addTask(3, new EntityAIMoveTowardsRestriction(this, 1.0D)); + this.tasks.addTask(4, new EntityAIWander(this, 0.6D)); + this.tasks.addTask(5, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F)); + this.tasks.addTask(6, new EntityAILookIdle(this)); + this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false)); + this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityLiving.class, 0, false, true, IMob.mobSelector)); + } + + /** + * (abstract) Protected helper method to write subclass entity data to NBT. + */ + @Override + public void writeEntityToNBT(NBTTagCompound p_70014_1_) { + super.writeEntityToNBT(p_70014_1_); + p_70014_1_.setBoolean("inFluid", this.inFluid); + p_70014_1_.setBoolean("isReadyToExplode", this.isReadyToExplode); + p_70014_1_.setInteger("fuse", this.fuse); + } + + /** + * (abstract) Protected helper method to read subclass entity data from NBT. + */ + @Override + public void readEntityFromNBT(NBTTagCompound p_70037_1_) { + super.readEntityFromNBT(p_70037_1_); + this.inFluid = p_70037_1_.getBoolean("inFluid"); + this.isReadyToExplode = p_70037_1_.getBoolean("isReadyToExplode"); + this.fuse = p_70037_1_.getInteger("fuse"); + } + + @Override + protected void entityInit() { + super.entityInit(); + this.dataWatcher.addObject(17, Byte.valueOf((byte) 0)); + } + + /** + * Returns true if the newer Entity AI code should be run + */ + @Override + public boolean isAIEnabled() { + return true; + } + + /** + * main AI tick function, replaces updateEntityActionState + */ + @Override + protected void updateAITick() { + super.updateAITick(); + } + + @Override + protected void applyEntityAttributes() { + super.applyEntityAttributes(); + this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(500.0D); + this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.5D); + } + + /** + * Decrements the entity's air supply when underwater + */ + @Override + protected int decreaseAirSupply(int p_70682_1_) { + return 0; + } + + @Override + protected void collideWithEntity(Entity p_82167_1_) { + if (p_82167_1_ instanceof IMob && this.getRNG().nextInt(20) == 0) { + this.setAttackTarget((EntityLivingBase) p_82167_1_); + } + + super.collideWithEntity(p_82167_1_); + } + + /** + * Called frequently so the entity can update its state every tick as + * required. For example, zombies and skeletons use this to react to + * sunlight and start to burn. + */ + @Override + public void onLivingUpdate() { + super.onLivingUpdate(); + + if (this.attackTimer > 0) { + --this.attackTimer; + } + + if (this.motionX * this.motionX + this.motionZ * this.motionZ > 2.500000277905201E-7D + && this.rand.nextInt(5) == 0) { + int i = MathHelper.floor_double(this.posX); + int j = MathHelper.floor_double(this.posY - 0.20000000298023224D - this.yOffset); + int k = MathHelper.floor_double(this.posZ); + Block block = this.worldObj.getBlock(i, j, k); + + + + if (block.getMaterial() != Material.air) { + this.worldObj.spawnParticle( + "blockcrack_" + Block.getIdFromBlock(block) + "_" + this.worldObj.getBlockMetadata(i, j, k), + this.posX + (this.rand.nextFloat() - 0.5D) * this.width, + this.boundingBox.minY + 0.1D, + this.posZ + (this.rand.nextFloat() - 0.5D) * this.width, + 4.0D * (this.rand.nextFloat() - 0.5D), 0.5D, + (this.rand.nextFloat() - 0.5D) * 4.0D); + } + } + } + + /** + * Returns true if this entity can attack entities of the specified class. + */ + @Override + public boolean canAttackClass(Class clazz) { + return clazz.equals(this.getClass()) ? false : true; + } + + @Override + public boolean attackEntityAsMob(Entity p_70652_1_) { + this.attackTimer = 10; + this.worldObj.setEntityState(this, (byte) 4); + boolean flag = p_70652_1_.attackEntityFrom(DamageSource.causeMobDamage(this), + 7 + this.rand.nextInt(15)); + + if (flag) { + p_70652_1_.motionY += 0.4000000059604645D; + } + + this.playSound("mob.irongolem.throw", 1.0F, 1.0F); + return flag; + } + + @Override + @SideOnly(Side.CLIENT) + public void handleHealthUpdate(byte p_70103_1_) { + if (p_70103_1_ == 4) { + this.attackTimer = 10; + this.playSound("mob.irongolem.throw", 1.0F, 1.0F); + } + else { + super.handleHealthUpdate(p_70103_1_); + } + } + + @Override + public Village getVillage() { + return null; + } + + @Override + @SideOnly(Side.CLIENT) + public int getAttackTimer() { + return this.attackTimer; + } + + /** + * Returns the sound this mob makes when it is hurt. + */ + @Override + protected String getHurtSound() { + return "mob.irongolem.hit"; + } + + /** + * Returns the sound this mob makes on death. + */ + @Override + protected String getDeathSound() { + return "mob.irongolem.death"; + } + + @Override + protected void func_145780_a(int p_145780_1_, int p_145780_2_, int p_145780_3_, Block p_145780_4_) { + this.playSound("mob.irongolem.walk", 1.0F, 1.0F); + } + + /** + * Drop 0-2 items of this living's type. @param par1 - Whether this entity + * has recently been hit by a player. @param par2 - Level of Looting used to + * kill this mob. + */ + @Override + protected void dropFewItems(boolean p_70628_1_, int p_70628_2_) { + int lootingChance = p_70628_2_+1; + int j = this.rand.nextInt(3); + int k; + + for (k = 0; k < j; ++k) { + this.entityDropItem(ItemUtils.getItemStackOfAmountFromOreDict("blockStaballoy", 1), 0f); + } + + k = 3 + this.rand.nextInt(3); + + for (int l = 0; l < k; ++l) { + this.entityDropItem(ItemUtils.getItemStackOfAmountFromOreDict("ingotStaballoy", lootingChance), 0f); + if (MathUtils.randInt(0, 2) == 0){ + this.entityDropItem(ItemUtils.getItemStackOfAmountFromOreDict("plateStaballoy", lootingChance), 0f); + } + } + } + + @Override + public boolean isPlayerCreated() { + return false; + } + + @Override + public void setPlayerCreated(boolean p_70849_1_) { + + } + + /** + * Called when the mob's health reaches 0. + */ + @Override + public void onDeath(DamageSource p_70645_1_) { + super.onDeath(p_70645_1_); + } + + @Override + protected String getLivingSound() { //TODO + return super.getLivingSound(); + } + + @Override + public int getTalkInterval() { + return 0; + } + + @Override + protected boolean canDespawn() { + return true; + } + + @Override + public void onEntityUpdate() { + //Set Fire Immunity + if (!this.isImmuneToFire){ + this.isImmuneToFire = true; + } + + if (!this.worldObj.isRemote) { + final float hp = getHealth(); + final float modifier = MathUtils.randInt(5,10)/100F; + final float amountToExplode = (hp*modifier); + + if (hp <= amountToExplode && !isReadyToExplode){ + if (this.ticksExisted >= 50) { + //Logger.INFO("Construct has low hp, trying to enable explosions. HP: "+this.getHealth()+", Max: "+this.getMaxHealth()+", Mod: "+modifier); + //Logger.INFO("Construct required HP to be <= "+amountToExplode); + float r = MathUtils.randFloat(0, 10); + if (r <= 0.1){ + this.isReadyToExplode = true; + //Logger.INFO("Construct can now explode."); + } + } + } + //Handle Exploding + else if (hp <= amountToExplode && isReadyToExplode){ + //Logger.INFO("Trying to explode. ["+this.fuse+"]"); + if (this.fuse-- <= 0){ + //Logger.INFO("Fuse has run out."); + this.setDead(); + if (!this.worldObj.isRemote) + { + this.explode(); + } + } + else { + //Logger.INFO("Ticking fuse and spawning particles."); + + int maxFuse = 60; + int fuseUsed = maxFuse-this.fuse; + float var2 = (float) (fuseUsed * 0.1); + + this.setSize(1.4F+(var2/2), 2.9F+(var2/2)); + + float r = MathUtils.randFloat(0, 1); + int r2 = MathUtils.randInt(5, 15); + for (int o=0;o<r2;o++){ + if (r <= 0.3){ + this.worldObj.spawnParticle("smoke", this.posX+MathUtils.randDouble(-2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + + } + else if (r <= 0.6){ + this.worldObj.spawnParticle("largesmoke", this.posX+MathUtils.randDouble(-2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + + } + if (r <= 0.3){ + this.worldObj.spawnParticle("cloud", this.posX+MathUtils.randDouble(-2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + + } + else if (r <= 0.7){ + this.worldObj.spawnParticle("flame", this.posX+MathUtils.randDouble(-2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + + } + if (r <= 0.2){ + this.worldObj.spawnParticle("explode", this.posX+MathUtils.randDouble(-2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + + } + else if (r <= 0.5){ + this.worldObj.spawnParticle("largeexplode", this.posX+MathUtils.randDouble(-2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + + } + else if (r <= 0.7){ + this.worldObj.spawnParticle("hugeexplosion", this.posX+MathUtils.randDouble(-2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + + } + } + + + } + } + else { + + } + + //Get a private field from a super class if it exists. + if (mFirstUpdateField == null) { + mFirstUpdateField = ReflectionUtils.getField(this.getClass(), "firstUpdate"); + } + if (mFirstUpdateField != null && mReflectFirstUpdate == true){ + try { + this.mReflectFirstUpdate = (boolean) mFirstUpdateField.get(this); + } + catch (IllegalArgumentException | IllegalAccessException e) {} + } + } + super.onEntityUpdate(); + } + + private static Field mFirstUpdateField; + + @Override + public int getMaxSpawnedInChunk() { + return 1; + } + + @Override + public boolean canBreatheUnderwater() { + return true; + } + + @Override + public void knockBack(Entity p_70653_1_, float p_70653_2_, double p_70653_3_, double p_70653_5_) { + // Do Nothing because he weighs metric shittonnes. + } + + @Override + protected void setOnFireFromLava() { + extinguish(); + } + + @Override + public void setFire(int p_70015_1_) { + extinguish(); + } + + @Override + protected void dealFireDamage(int p_70081_1_) { + + } + + @Override + public boolean isInWater() { + if (super.isInWater()){ + return true; + } + else { + this.moveForward *= 0.98F; + return false; + } + } + + @Override + public boolean handleWaterMovement() { + this.moveForward *= 0.74F; + return handleFluidMovement(Material.water); + } + + @Override + public boolean handleLavaMovement() { + this.moveForward *= 0.74F; + return handleFluidMovement(Material.lava); + } + + /** + * Returns if this entity is in water and will end up adding the waters velocity to the entity + */ + public boolean handleFluidMovement(Material fluid){ + + + + if (this.worldObj.handleMaterialAcceleration(this.boundingBox.expand(0.0D, -0.4000000059604645D, 0.0D).contract(0.001D, 0.001D, 0.001D), fluid, this)) + { + if (!this.inFluid && !this.mReflectFirstUpdate) + { + float f = MathHelper.sqrt_double(this.motionX * this.motionX * 0.20000000298023224D + this.motionY * this.motionY + this.motionZ * this.motionZ * 0.20000000298023224D) * 0.2F; + + if (f > 1.0F) + { + f = 1.0F; + } + + this.playSound(this.getSplashSound(), f, 1.0F + (this.rand.nextFloat() - this.rand.nextFloat()) * 0.4F); + float f1 = MathHelper.floor_double(this.boundingBox.minY); + int i; + float f2; + float f3; + + for (i = 0; i < 1.0F + this.width * 20.0F; ++i) + { + f2 = (this.rand.nextFloat() * 2.0F - 1.0F) * this.width; + f3 = (this.rand.nextFloat() * 2.0F - 1.0F) * this.width; + this.worldObj.spawnParticle("bubble", this.posX + f2, f1 + 1.0F, this.posZ + f3, this.motionX, this.motionY - this.rand.nextFloat() * 0.2F, this.motionZ); + } + + for (i = 0; i < 1.0F + this.width * 20.0F; ++i) + { + f2 = (this.rand.nextFloat() * 2.0F - 1.0F) * this.width; + f3 = (this.rand.nextFloat() * 2.0F - 1.0F) * this.width; + this.worldObj.spawnParticle("splash", this.posX + f2, f1 + 1.0F, this.posZ + f3, this.motionX, this.motionY, this.motionZ); + } + } + this.fallDistance = 0.0F; + this.inFluid = true; + } + else + { + this.inFluid = false; + } + return this.inFluid; + } + + @Override + public void onChunkLoad() { + // TODO Auto-generated method stub + super.onChunkLoad(); + } + + @Override + public void onStruckByLightning(EntityLightningBolt p_70077_1_) { + this.isReadyToExplode = true; + this.fuse = 20; + } + + private void explode(){ + /* float f = 12.0F; + this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, f, true);*/ + + if (!this.worldObj.isRemote) { + final float f = 6.5F; + ExplosionHandler explode = new ExplosionHandler(); + explode.createExplosion(this.worldObj, this, this.posX, this.posY, this.posZ, f, true, true); + + float r = MathUtils.randFloat(0, 1); + int r2 = MathUtils.randInt(20, 40); + for (int o=0;o<r2;o++){ + if (r <= 0.3){ + this.worldObj.spawnParticle("smoke", this.posX+MathUtils.randDouble(-4, 4), this.posY+MathUtils.randDouble(0, 3), this.posZ+MathUtils.randDouble(-4, 4), 0.0D, 0.0D, 0.0D); + + } + else if (r <= 0.6){ + this.worldObj.spawnParticle("largesmoke", this.posX+MathUtils.randDouble(-4, 4), this.posY+MathUtils.randDouble(-4, 4), this.posZ+MathUtils.randDouble(-4, 4), 0.0D, 0.0D, 0.0D); + + } + if (r <= 0.3){ + this.worldObj.spawnParticle("cloud", this.posX+MathUtils.randDouble(-4, 4), this.posY+MathUtils.randDouble(-4, 4), this.posZ+MathUtils.randDouble(-4, 4), 0.0D, 0.0D, 0.0D); + + } + else if (r <= 0.7){ + this.worldObj.spawnParticle("flame", this.posX+MathUtils.randDouble(-4, 4), this.posY+MathUtils.randDouble(-4, 4), this.posZ+MathUtils.randDouble(-4, 4), 0.0D, 0.0D, 0.0D); + + } + if (r <= 0.2){ + this.worldObj.spawnParticle("explode", this.posX+MathUtils.randDouble(-4, 4), this.posY+MathUtils.randDouble(-4, 4), this.posZ+MathUtils.randDouble(-4, 4), 0.0D, 0.0D, 0.0D); + + } + else if (r <= 0.5){ + this.worldObj.spawnParticle("largeexplode", this.posX+MathUtils.randDouble(-4, 4), this.posY+MathUtils.randDouble(-4, 4), this.posZ+MathUtils.randDouble(-4, 4), 0.0D, 0.0D, 0.0D); + + } + else if (r <= 0.7){ + this.worldObj.spawnParticle("hugeexplosion", this.posX+MathUtils.randDouble(-4, 4), this.posY+MathUtils.randDouble(-4, 4), this.posZ+MathUtils.randDouble(-4, 4), 0.0D, 0.0D, 0.0D); + + } + } + } + + } + + @Override + public boolean canAttackWithItem() { + return true; + } + + @Override + public boolean canRenderOnFire() { + return false; + } + + @Override + public boolean isPushedByWater() { + return false; + } +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/core/entity/projectile/EntityHydrofluoricAcidPotion.java b/src/main/java/gtPlusPlus/core/entity/projectile/EntityHydrofluoricAcidPotion.java new file mode 100644 index 0000000000..9f3e6b8bf1 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/entity/projectile/EntityHydrofluoricAcidPotion.java @@ -0,0 +1,127 @@ +package gtPlusPlus.core.entity.projectile; + +import net.minecraft.block.Block; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.projectile.EntityThrowable; +import net.minecraft.init.Blocks; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.DamageSource; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; + +import gregtech.api.util.GT_Utility; + +import gtPlusPlus.api.objects.minecraft.BlockPos; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.EntityUtils; + +public class EntityHydrofluoricAcidPotion extends EntityThrowable { + + public EntityHydrofluoricAcidPotion(World world) { + super(world); + } + + public EntityHydrofluoricAcidPotion(World world, EntityLivingBase entity) { + super(world, entity); + } + + public EntityHydrofluoricAcidPotion(World world, double posX, double posY, double posZ) { + super(world, posX, posY, posZ); + } + + /** + * Called when this EntityThrowable hits a block or entity. + */ + @Override + protected void onImpact(MovingObjectPosition object) { + int xBlock = object.blockX; + int yBlock = object.blockY; + int zBlock = object.blockZ; + if (object.entityHit != null) { + byte b0 = 6; + if (!GT_Utility.isWearingFullRadioHazmat((EntityLivingBase) object.entityHit)){ + object.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), b0); + EntityUtils.setEntityOnFire(object.entityHit, 5); + + if (object.entityHit instanceof EntityPlayer){ + EntityPlayer mPlayer = (EntityPlayer) object.entityHit; + mPlayer.addPotionEffect(new PotionEffect(Potion.blindness.getId(), 200, 1)); + mPlayer.addPotionEffect(new PotionEffect(Potion.moveSlowdown.getId(), 300, 2)); + mPlayer.addPotionEffect(new PotionEffect(Potion.confusion.getId(), 250, 2)); + } + + object.entityHit.fireResistance = 0; + ravage(EntityUtils.findBlockPosUnderEntity(object.entityHit)); + + } + } + if (object.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK){ + ravage(new BlockPos(xBlock, yBlock, zBlock)); + } + + String mParticleType = "reddust"; + int e=0; + for (int i = 0; i < 24; ++i) { + if ((e = MathUtils.randInt(0, 5)) <= 1){ + if (e==0) + mParticleType = "largesmoke"; + if (e==1) + mParticleType = "flame"; + } + this.worldObj.spawnParticle(mParticleType, this.posX+MathUtils.randDouble(-2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + } + + if (!this.worldObj.isRemote) { + this.setDead(); + } + } + + private boolean ravage(BlockPos blockpos){ + + int radius = 2; + + for (int i=(blockpos.xPos-radius);i<(blockpos.xPos+radius);i++){ + for (int j=(blockpos.yPos-radius);j<(blockpos.yPos+radius);j++){ + for (int h=(blockpos.zPos-radius);h<(blockpos.zPos+radius);h++){ + + int mChance = MathUtils.randInt(1, 10); + if (mChance <= 3){ + Block mBlockhit = worldObj.getBlock(i, j, h); + this.worldObj.spawnParticle("flame", this.posX+MathUtils.randDouble(-2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("largesmoke", this.posX+MathUtils.randDouble(2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + + //GT_Pollution.addPollution(worldObj.getChunkFromBlockCoords(blockpos.xPos, blockpos.zPos), mPol); + + if (mBlockhit == Blocks.grass || mBlockhit == Blocks.mycelium){ + worldObj.setBlock(i, j+1, h, Blocks.fire); + worldObj.setBlock(i, j, h, Blocks.dirt); + } + else if (mBlockhit == Blocks.leaves || mBlockhit == Blocks.leaves2){ + worldObj.setBlock(i, j, h, Blocks.fire); + } + else if (mBlockhit == Blocks.tallgrass){ + worldObj.setBlock(i, j, h, Blocks.fire); + if (worldObj.getBlock(i, j-1, h) == Blocks.grass){ + worldObj.setBlock(i, j-1, h, Blocks.dirt); + } + } + else if (mBlockhit == Blocks.carrots || mBlockhit == Blocks.melon_block || mBlockhit == Blocks.pumpkin || mBlockhit == Blocks.potatoes){ + worldObj.setBlock(i, j+1, h, Blocks.fire); + worldObj.setBlock(i, j, h, Blocks.dirt); + } + else if (mBlockhit == Blocks.air){ + worldObj.setBlock(i, j, h, Blocks.fire); + } + } + } + } + } + + + return true; + } + + +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/core/entity/projectile/EntityLightningAttack.java b/src/main/java/gtPlusPlus/core/entity/projectile/EntityLightningAttack.java new file mode 100644 index 0000000000..868517d1db --- /dev/null +++ b/src/main/java/gtPlusPlus/core/entity/projectile/EntityLightningAttack.java @@ -0,0 +1,76 @@ +package gtPlusPlus.core.entity.projectile; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.projectile.EntityWitherSkull; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.DamageSource; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.EnumDifficulty; +import net.minecraft.world.World; + +public class EntityLightningAttack extends EntityWitherSkull { + + public EntityLightningAttack(World p_i1793_1_) + { + super(p_i1793_1_); + this.setSize(0.3125F, 0.3125F); + } + + public EntityLightningAttack(World p_i1794_1_, EntityLivingBase p_i1794_2_, double p_i1794_3_, double p_i1794_5_, double p_i1794_7_) + { + super(p_i1794_1_, p_i1794_2_, p_i1794_3_, p_i1794_5_, p_i1794_7_); + this.setSize(0.3125F, 0.3125F); + } + + @SideOnly(Side.CLIENT) + public EntityLightningAttack(World p_i1795_1_, double p_i1795_2_, double p_i1795_4_, double p_i1795_6_, double p_i1795_8_, double p_i1795_10_, double p_i1795_12_) + { + super(p_i1795_1_, p_i1795_2_, p_i1795_4_, p_i1795_6_, p_i1795_8_, p_i1795_10_, p_i1795_12_); + this.setSize(0.3125F, 0.3125F); + } + + + /** + * Called when this EntityFireball hits a block or entity. + */ + protected void onImpact(MovingObjectPosition p_70227_1_) { + + if (!this.worldObj.isRemote) { + if (p_70227_1_.entityHit != null) { + if (this.shootingEntity != null) { + if (p_70227_1_.entityHit.attackEntityFrom(DamageSource.causeMobDamage(this.shootingEntity), 8.0F) + && !p_70227_1_.entityHit.isEntityAlive()) { + this.shootingEntity.heal(0.5F); + } + } else { + p_70227_1_.entityHit.attackEntityFrom(DamageSource.lava, 10.0F); + } + + if (p_70227_1_.entityHit instanceof EntityLivingBase) { + byte b0 = 0; + + if (this.worldObj.difficultySetting == EnumDifficulty.NORMAL) { + b0 = 10; + } else if (this.worldObj.difficultySetting == EnumDifficulty.HARD) { + b0 = 40; + } + + if (b0 > 0) { + ((EntityLivingBase) p_70227_1_.entityHit).addPotionEffect(new PotionEffect(Potion.poison.id, 20 * b0, 1)); + ((EntityLivingBase) p_70227_1_.entityHit).addPotionEffect(new PotionEffect(Potion.confusion.id, 20 * b0, 1)); + ((EntityLivingBase) p_70227_1_.entityHit).addPotionEffect(new PotionEffect(Potion.weakness.id, 20 * b0, 1)); + } + } + } + + this.worldObj.newExplosion(this, this.posX, this.posY, this.posZ, 1.0F, false, + this.worldObj.getGameRules().getGameRuleBooleanValue("mobGriefing")); + this.setDead(); + } + } + + +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/core/entity/projectile/EntitySulfuricAcidPotion.java b/src/main/java/gtPlusPlus/core/entity/projectile/EntitySulfuricAcidPotion.java new file mode 100644 index 0000000000..7660dd1b75 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/entity/projectile/EntitySulfuricAcidPotion.java @@ -0,0 +1,115 @@ +package gtPlusPlus.core.entity.projectile; + +import net.minecraft.block.Block; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.projectile.EntityThrowable; +import net.minecraft.init.Blocks; +import net.minecraft.util.DamageSource; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; + +import gregtech.api.util.GT_Utility; + +import gtPlusPlus.api.objects.minecraft.BlockPos; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.EntityUtils; + +public class EntitySulfuricAcidPotion extends EntityThrowable { + + public EntitySulfuricAcidPotion(World world) { + super(world); + } + + public EntitySulfuricAcidPotion(World world, EntityLivingBase entity) { + super(world, entity); + } + + public EntitySulfuricAcidPotion(World world, double posX, double posY, double posZ) { + super(world, posX, posY, posZ); + } + + /** + * Called when this EntityThrowable hits a block or entity. + */ + @Override + protected void onImpact(MovingObjectPosition object) { + int xBlock = object.blockX; + int yBlock = object.blockY; + int zBlock = object.blockZ; + if (object.entityHit != null) { + byte b0 = 6; + if (!GT_Utility.isWearingFullRadioHazmat((EntityLivingBase) object.entityHit)){ + object.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), b0); + EntityUtils.setEntityOnFire(object.entityHit, 10); + object.entityHit.fireResistance = 0; + ravage(EntityUtils.findBlockPosUnderEntity(object.entityHit)); + } + } + if (object.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK){ + ravage(new BlockPos(xBlock, yBlock, zBlock)); + } + + String mParticleType = "reddust"; + int e=0; + for (int i = 0; i < 24; ++i) { + if ((e = MathUtils.randInt(0, 5)) <= 1){ + if (e==0) + mParticleType = "largesmoke"; + if (e==1) + mParticleType = "flame"; + } + this.worldObj.spawnParticle(mParticleType, this.posX+MathUtils.randDouble(-2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + } + + if (!this.worldObj.isRemote) { + this.setDead(); + } + } + + private boolean ravage(BlockPos blockpos){ + + int radius = 1; + + for (int i=(blockpos.xPos-radius);i<(blockpos.xPos+radius);i++){ + for (int j=(blockpos.yPos-radius);j<(blockpos.yPos+radius);j++){ + for (int h=(blockpos.zPos-radius);h<(blockpos.zPos+radius);h++){ + + int mChance = MathUtils.randInt(1, 10); + if (mChance <= 3){ + Block mBlockhit = worldObj.getBlock(i, j, h); + this.worldObj.spawnParticle("flame", this.posX+MathUtils.randDouble(-2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("largesmoke", this.posX+MathUtils.randDouble(2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + + //GT_Pollution.addPollution(worldObj.getChunkFromBlockCoords(blockpos.xPos, blockpos.zPos), mPol); + + if (mBlockhit == Blocks.grass || mBlockhit == Blocks.mycelium){ + worldObj.setBlock(i, j+1, h, Blocks.fire); + worldObj.setBlock(i, j, h, Blocks.dirt); + } + else if (mBlockhit == Blocks.leaves || mBlockhit == Blocks.leaves2){ + worldObj.setBlock(i, j, h, Blocks.fire); + } + else if (mBlockhit == Blocks.tallgrass){ + worldObj.setBlock(i, j, h, Blocks.fire); + if (worldObj.getBlock(i, j-1, h) == Blocks.grass){ + worldObj.setBlock(i, j-1, h, Blocks.dirt); + } + } + else if (mBlockhit == Blocks.carrots || mBlockhit == Blocks.melon_block || mBlockhit == Blocks.pumpkin || mBlockhit == Blocks.potatoes){ + worldObj.setBlock(i, j+1, h, Blocks.fire); + worldObj.setBlock(i, j, h, Blocks.dirt); + } + else if (mBlockhit == Blocks.air){ + worldObj.setBlock(i, j, h, Blocks.fire); + } + } + } + } + } + + + return true; + } + + +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/core/entity/projectile/EntityThrowableBomb.java b/src/main/java/gtPlusPlus/core/entity/projectile/EntityThrowableBomb.java new file mode 100644 index 0000000000..49daa459e0 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/entity/projectile/EntityThrowableBomb.java @@ -0,0 +1,145 @@ +package gtPlusPlus.core.entity.projectile; + +import net.minecraft.block.Block; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.projectile.EntityThrowable; +import net.minecraft.init.Blocks; +import net.minecraft.util.DamageSource; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; + +import gregtech.api.util.GT_Utility; + +import gtPlusPlus.api.objects.minecraft.BlockPos; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.EntityUtils; +import gtPlusPlus.core.util.minecraft.gregtech.PollutionUtils; + +public class EntityThrowableBomb extends EntityThrowable { + + public EntityThrowableBomb(World world) { + super(world); + } + + public EntityThrowableBomb(World world, EntityLivingBase entity) { + super(world, entity); + } + + public EntityThrowableBomb(World world, double posX, double posY, double posZ) { + super(world, posX, posY, posZ); + } + + /** + * Called when this EntityThrowable hits a block or entity. + */ + @Override + protected void onImpact(MovingObjectPosition object) { + int xBlock = object.blockX; + int yBlock = object.blockY; + int zBlock = object.blockZ; + if (object.entityHit != null) { + byte b0 = 6; + if (!GT_Utility.isWearingFullRadioHazmat((EntityLivingBase) object.entityHit)){ + object.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 20); + EntityUtils.setEntityOnFire(object.entityHit, 20); + object.entityHit.fireResistance = 0; + ravage(EntityUtils.findBlockPosUnderEntity(object.entityHit)); + } + } + if (object.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK){ + + ravage(new BlockPos(xBlock, yBlock, zBlock)); + for (BlockPos aSur : new BlockPos(xBlock, yBlock, zBlock).getSurroundingBlocks()) { + ravage(new BlockPos(aSur.xPos, aSur.yPos, aSur.zPos)); + for (BlockPos aSur2 : new BlockPos(aSur.xPos, aSur.yPos, aSur.zPos).getSurroundingBlocks()) { + //ravage(new BlockPos(aSur2.xPos, aSur2.yPos, aSur2.zPos)); + } + } + } + + String mParticleType = "reddust"; + int e=0; + for (int i = 0; i < 127; ++i) { + if ((e = MathUtils.randInt(0, 5)) <= 1){ + if (e==0) + mParticleType = "largesmoke"; + if (e==1) + mParticleType = "flame"; + } + this.worldObj.spawnParticle(mParticleType, this.posX+MathUtils.randDouble(-2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + } + + if (!this.worldObj.isRemote) { + this.setDead(); + } + } + + private boolean ravage(BlockPos blockpos){ + + int radius = 5; + + for (int i=(blockpos.xPos-radius);i<(blockpos.xPos+radius);i++){ + for (int j=(blockpos.yPos-radius);j<(blockpos.yPos+radius);j++){ + for (int h=(blockpos.zPos-radius);h<(blockpos.zPos+radius);h++){ + + int mChance = MathUtils.randInt(0, 100); + if (mChance <= 3){ + Block mBlockhit = worldObj.getBlock(i, j, h); + this.worldObj.spawnParticle("flame", this.posX+MathUtils.randDouble(-2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("largesmoke", this.posX+MathUtils.randDouble(2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("flame", this.posX+MathUtils.randDouble(-2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("largesmoke", this.posX+MathUtils.randDouble(2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("flame", this.posX+MathUtils.randDouble(-2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("largesmoke", this.posX+MathUtils.randDouble(2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("flame", this.posX+MathUtils.randDouble(-2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("largesmoke", this.posX+MathUtils.randDouble(2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("flame", this.posX+MathUtils.randDouble(-2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("largesmoke", this.posX+MathUtils.randDouble(2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("flame", this.posX+MathUtils.randDouble(-2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("largesmoke", this.posX+MathUtils.randDouble(2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("flame", this.posX+MathUtils.randDouble(-2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("largesmoke", this.posX+MathUtils.randDouble(2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("flame", this.posX+MathUtils.randDouble(-2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("largesmoke", this.posX+MathUtils.randDouble(2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("flame", this.posX+MathUtils.randDouble(-2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("largesmoke", this.posX+MathUtils.randDouble(2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("flame", this.posX+MathUtils.randDouble(-2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("largesmoke", this.posX+MathUtils.randDouble(2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("flame", this.posX+MathUtils.randDouble(-2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("largesmoke", this.posX+MathUtils.randDouble(2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("flame", this.posX+MathUtils.randDouble(-2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + this.worldObj.spawnParticle("largesmoke", this.posX+MathUtils.randDouble(2, 2), this.posY+MathUtils.randDouble(-2, 2), this.posZ+MathUtils.randDouble(-2, 2), 0.0D, 0.0D, 0.0D); + + PollutionUtils.addPollution(worldObj.getChunkFromBlockCoords(blockpos.xPos, blockpos.zPos), 500); + this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, 0.01f, true); + if (mBlockhit == Blocks.grass || mBlockhit == Blocks.mycelium){ + worldObj.setBlock(i, j+1, h, Blocks.fire); + worldObj.setBlock(i, j, h, Blocks.dirt); + } + else if (mBlockhit == Blocks.leaves || mBlockhit == Blocks.leaves2){ + worldObj.setBlock(i, j, h, Blocks.fire); + } + else if (mBlockhit == Blocks.tallgrass){ + worldObj.setBlock(i, j, h, Blocks.fire); + if (worldObj.getBlock(i, j-1, h) == Blocks.grass){ + worldObj.setBlock(i, j-1, h, Blocks.dirt); + } + } + else if (mBlockhit == Blocks.carrots || mBlockhit == Blocks.melon_block || mBlockhit == Blocks.pumpkin || mBlockhit == Blocks.potatoes){ + worldObj.setBlock(i, j+1, h, Blocks.fire); + worldObj.setBlock(i, j, h, Blocks.dirt); + } + else if (mBlockhit == Blocks.air){ + worldObj.setBlock(i, j, h, Blocks.fire); + } + } + } + } + } + + + return true; + } + + +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/core/entity/projectile/EntityToxinball.java b/src/main/java/gtPlusPlus/core/entity/projectile/EntityToxinball.java new file mode 100644 index 0000000000..4fe72345b2 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/entity/projectile/EntityToxinball.java @@ -0,0 +1,327 @@ +package gtPlusPlus.core.entity.projectile; + +import java.util.List; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.projectile.EntityFireball; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.*; +import net.minecraft.world.World; + +public abstract class EntityToxinball extends EntityFireball { + protected int entityX = -1; + protected int entityY = -1; + protected int entityZ = -1; + private Block block; + private boolean inGround; + private int ticksAlive; + private int ticksInAir; + + public EntityToxinball(World world) { + super(world); + this.setSize(1.0F, 1.0F); + } + + @Override + protected void entityInit() { + } + + /** + * Checks if the entity is in range to render by using the past in distance + * and comparing it to its average edge length * 64 * renderDistanceWeight + * Args: distance + */ + @Override + @SideOnly(Side.CLIENT) + public boolean isInRangeToRenderDist(double p_70112_1_) { + double d1 = this.boundingBox.getAverageEdgeLength() * 4.0D; + d1 *= 64.0D; + return p_70112_1_ < d1 * d1; + } + + public EntityToxinball(World world, double x, double y, double z, double f1, double f2, double f3) { + super(world); + this.setSize(1.0F, 1.0F); + this.setLocationAndAngles(x, y, z, this.rotationYaw, this.rotationPitch); + this.setPosition(x, y, z); + double d6 = MathHelper + .sqrt_double(f1 * f1 + f2 * f2 + f3 * f3); + this.accelerationX = f1 / d6 * 0.1D; + this.accelerationY = f2 / d6 * 0.1D; + this.accelerationZ = f3 / d6 * 0.1D; + } + + public EntityToxinball(World world, EntityLivingBase entity, double x, double y, double z) { + super(world); + this.shootingEntity = entity; + this.setSize(1.0F, 1.0F); + this.setLocationAndAngles(entity.posX, entity.posY, entity.posZ, entity.rotationYaw, + entity.rotationPitch); + this.setPosition(this.entityX, this.entityY, this.entityZ); + this.yOffset = 0.0F; + this.motionX = this.motionY = this.motionZ = 0.0D; + x += this.rand.nextGaussian() * 0.4D; + y += this.rand.nextGaussian() * 0.4D; + z += this.rand.nextGaussian() * 0.4D; + double d3 = MathHelper.sqrt_double(x * x + y * y + z * z); + this.accelerationX = x / d3 * 0.1D; + this.accelerationY = y / d3 * 0.1D; + this.accelerationZ = z / d3 * 0.1D; + } + + /** + * Called to update the entity's position/logic. + */ + @Override + public void onUpdate() { + if (!this.worldObj.isRemote && (this.shootingEntity != null && this.shootingEntity.isDead + || !this.worldObj.blockExists(this.entityX, this.entityY, this.entityZ))) { + this.setDead(); + } + else { + super.onUpdate(); + this.setFire(1); + + if (this.inGround) { + if (this.worldObj.getBlock(this.entityX, this.entityY, + this.entityZ) == this.block) { + ++this.ticksAlive; + + if (this.ticksAlive == 600) { + this.setDead(); + } + + return; + } + + this.inGround = false; + this.motionX *= this.rand.nextFloat() * 0.2F; + this.motionY *= this.rand.nextFloat() * 0.2F; + this.motionZ *= this.rand.nextFloat() * 0.2F; + this.ticksAlive = 0; + this.ticksInAir = 0; + } + else { + ++this.ticksInAir; + } + + Vec3 vec3 = Vec3.createVectorHelper(this.entityX, this.entityY, this.entityZ); + Vec3 vec31 = Vec3.createVectorHelper(this.entityX + this.motionX, this.entityY + this.motionY, + this.entityZ + this.motionZ); + MovingObjectPosition movingobjectposition = this.worldObj.rayTraceBlocks(vec3, vec31); + vec3 = Vec3.createVectorHelper(this.entityX, this.entityY, this.entityZ); + vec31 = Vec3.createVectorHelper(this.entityX + this.motionX, this.entityY + this.motionY, + this.entityZ + this.motionZ); + + if (movingobjectposition != null) { + vec31 = Vec3.createVectorHelper(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, + movingobjectposition.hitVec.zCoord); + } + + Entity entity = null; + List<?> list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, + this.boundingBox.addCoord(this.motionX, this.motionY, this.motionZ).expand(1.0D, 1.0D, 1.0D)); + double d0 = 0.0D; + + for (int i = 0; i < list.size(); ++i) { + Entity entity1 = (Entity) list.get(i); + + if (entity1.canBeCollidedWith() + && (!entity1.isEntityEqual(this.shootingEntity) || this.ticksInAir >= 25)) { + float f = 0.3F; + AxisAlignedBB axisalignedbb = entity1.boundingBox.expand(f, f, f); + MovingObjectPosition movingobjectposition1 = axisalignedbb.calculateIntercept(vec3, vec31); + + if (movingobjectposition1 != null) { + double d1 = vec3.distanceTo(movingobjectposition1.hitVec); + + if (d1 < d0 || d0 == 0.0D) { + entity = entity1; + d0 = d1; + } + } + } + } + + if (entity != null) { + movingobjectposition = new MovingObjectPosition(entity); + } + + if (movingobjectposition != null) { + this.onImpact(movingobjectposition); + } + + this.entityX += this.motionX; + this.entityY += this.motionY; + this.entityZ += this.motionZ; + float f1 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ); + this.rotationYaw = (float) (Math.atan2(this.motionZ, this.motionX) * 180.0D / Math.PI) + 90.0F; + + for (this.rotationPitch = (float) (Math.atan2(f1, this.motionY) * 180.0D / Math.PI) + - 90.0F; this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F) { + ; + } + + while (this.rotationPitch - this.prevRotationPitch >= 180.0F) { + this.prevRotationPitch += 360.0F; + } + + while (this.rotationYaw - this.prevRotationYaw < -180.0F) { + this.prevRotationYaw -= 360.0F; + } + + while (this.rotationYaw - this.prevRotationYaw >= 180.0F) { + this.prevRotationYaw += 360.0F; + } + + this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F; + this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F; + float f2 = this.getMotionFactor(); + + if (this.isInWater()) { + for (int j = 0; j < 4; ++j) { + float f3 = 0.25F; + this.worldObj.spawnParticle("bubble", this.entityX - this.motionX * f3, this.entityY - this.motionY * f3, + this.entityZ - this.motionZ * f3, this.motionX, this.motionY, this.motionZ); + } + + f2 = 0.8F; + } + + this.motionX += this.accelerationX; + this.motionY += this.accelerationY; + this.motionZ += this.accelerationZ; + this.motionX *= f2; + this.motionY *= f2; + this.motionZ *= f2; + this.worldObj.spawnParticle("smoke", this.entityX, this.entityY + 0.5D, this.entityZ, 0.0D, 0.0D, 0.0D); + this.setPosition(this.entityX, this.entityY, this.entityZ); + } + } + + /** + * Return the motion factor for this projectile. The factor is multiplied by + * the original motion. + */ + @Override + protected float getMotionFactor() { + return 0.95F; + } + + /** + * Called when this EntityFireball hits a block or entity. + */ + @Override + protected abstract void onImpact(MovingObjectPosition p_70227_1_); + + /** + * (abstract) Protected helper method to write subclass entity data to NBT. + */ + @Override + public void writeEntityToNBT(NBTTagCompound aTag) { + aTag.setShort("xTile", (short) this.entityX); + aTag.setShort("yTile", (short) this.entityY); + aTag.setShort("zTile", (short) this.entityZ); + aTag.setByte("inTile", (byte) Block.getIdFromBlock(this.block)); + aTag.setByte("inGround", (byte) (this.inGround ? 1 : 0)); + aTag.setTag("direction", + this.newDoubleNBTList(new double[] { this.motionX, this.motionY, this.motionZ })); + } + + /** + * (abstract) Protected helper method to read subclass entity data from NBT. + */ + @Override + public void readEntityFromNBT(NBTTagCompound aTag) { + this.entityX = aTag.getShort("xTile"); + this.entityY = aTag.getShort("yTile"); + this.entityZ = aTag.getShort("zTile"); + this.block = Block.getBlockById(aTag.getByte("inTile") & 255); + this.inGround = aTag.getByte("inGround") == 1; + + if (aTag.hasKey("direction", 9)) { + NBTTagList nbttaglist = aTag.getTagList("direction", 6); + this.motionX = nbttaglist.func_150309_d(0); + this.motionY = nbttaglist.func_150309_d(1); + this.motionZ = nbttaglist.func_150309_d(2); + } + else { + this.setDead(); + } + } + + /** + * Returns true if other Entities should be prevented from moving through + * this Entity. + */ + @Override + public boolean canBeCollidedWith() { + return true; + } + + @Override + public float getCollisionBorderSize() { + return 1.0F; + } + + /** + * Called when the entity is attacked. + */ + @Override + public boolean attackEntityFrom(DamageSource damage, float p_70097_2_) { + if (this.isEntityInvulnerable()) { + return false; + } + else { + this.setBeenAttacked(); + + if (damage.getEntity() != null) { + Vec3 vec3 = damage.getEntity().getLookVec(); + + if (vec3 != null) { + this.motionX = vec3.xCoord; + this.motionY = vec3.yCoord; + this.motionZ = vec3.zCoord; + this.accelerationX = this.motionX * 0.1D; + this.accelerationY = this.motionY * 0.1D; + this.accelerationZ = this.motionZ * 0.1D; + } + + if (damage.getEntity() instanceof EntityLivingBase) { + this.shootingEntity = (EntityLivingBase) damage.getEntity(); + } + + return true; + } + else { + return false; + } + } + } + + @Override + @SideOnly(Side.CLIENT) + public float getShadowSize() { + return 0.0F; + } + + /** + * Gets how bright this entity is. + */ + @Override + public float getBrightness(float p_70013_1_) { + return 1.0F; + } + + @Override + @SideOnly(Side.CLIENT) + public int getBrightnessForRender(float p_70070_1_) { + return 15728880; + } +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/core/entity/projectile/EntityToxinballSmall.java b/src/main/java/gtPlusPlus/core/entity/projectile/EntityToxinballSmall.java new file mode 100644 index 0000000000..78469c9dad --- /dev/null +++ b/src/main/java/gtPlusPlus/core/entity/projectile/EntityToxinballSmall.java @@ -0,0 +1,88 @@ +package gtPlusPlus.core.entity.projectile; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.init.Blocks; +import net.minecraft.util.DamageSource; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; + +public class EntityToxinballSmall extends EntityToxinball { + + public EntityToxinballSmall(World p_i1770_1_) { + super(p_i1770_1_); + this.setSize(0.3125F, 0.3125F); + } + + public EntityToxinballSmall(World world, EntityLivingBase entity, double x, double y, double z) { + super(world, entity, x, y, z); + this.setSize(0.3125F, 0.3125F); + } + + public EntityToxinballSmall(World p_i1772_1_, double p_i1772_2_, double p_i1772_4_, double p_i1772_6_, double p_i1772_8_, double p_i1772_10_, double p_i1772_12_) { + super(p_i1772_1_, p_i1772_2_, p_i1772_4_, p_i1772_6_, p_i1772_8_, p_i1772_10_, p_i1772_12_); + this.setSize(0.3125F, 0.3125F); + } + + /** + * Called when this EntityFireball hits a block or entity. + */ + @Override + protected void onImpact(MovingObjectPosition MoP) { + if (!this.worldObj.isRemote) { + if (MoP.entityHit != null) { + if (!MoP.entityHit.isImmuneToFire() && MoP.entityHit + .attackEntityFrom(DamageSource.causeFireballDamage(this, this.shootingEntity), 5.0F)) { + MoP.entityHit.setFire(5); + } + } + else { + int i = MoP.blockX; + int j = MoP.blockY; + int k = MoP.blockZ; + + switch (MoP.sideHit) { + case 0: + --j; + break; + case 1: + ++j; + break; + case 2: + --k; + break; + case 3: + ++k; + break; + case 4: + --i; + break; + case 5: + ++i; + } + + if (this.worldObj.isAirBlock(i, j, k)) { + this.worldObj.setBlock(i, j, k, Blocks.fire); + } + } + + this.setDead(); + } + } + + /** + * Returns true if other Entities should be prevented from moving through + * this Entity. + */ + @Override + public boolean canBeCollidedWith() { + return false; + } + + /** + * Called when the entity is attacked. + */ + @Override + public boolean attackEntityFrom(DamageSource p_70097_1_, float p_70097_2_) { + return false; + } +}
\ No newline at end of file |