aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/entity/EntityTeslaTowerLightning.java
diff options
context:
space:
mode:
authorJordan Byrne <draknyte1@hotmail.com>2017-12-24 21:45:03 +1000
committerJordan Byrne <draknyte1@hotmail.com>2017-12-24 21:45:03 +1000
commit2b9da4a0f048300e14bf359b705a4c04c05064ba (patch)
tree565681007584bb5a527d3496dd14dfaaec87582e /src/Java/gtPlusPlus/core/entity/EntityTeslaTowerLightning.java
parentecf908e98ccee72a713091e8ab547e35a41d7436 (diff)
downloadGT5-Unofficial-2b9da4a0f048300e14bf359b705a4c04c05064ba.tar.gz
GT5-Unofficial-2b9da4a0f048300e14bf359b705a4c04c05064ba.tar.bz2
GT5-Unofficial-2b9da4a0f048300e14bf359b705a4c04c05064ba.zip
+ Added the Tesla Tower for base defence.
Diffstat (limited to 'src/Java/gtPlusPlus/core/entity/EntityTeslaTowerLightning.java')
-rw-r--r--src/Java/gtPlusPlus/core/entity/EntityTeslaTowerLightning.java133
1 files changed, 133 insertions, 0 deletions
diff --git a/src/Java/gtPlusPlus/core/entity/EntityTeslaTowerLightning.java b/src/Java/gtPlusPlus/core/entity/EntityTeslaTowerLightning.java
new file mode 100644
index 0000000000..2a7effbe8a
--- /dev/null
+++ b/src/Java/gtPlusPlus/core/entity/EntityTeslaTowerLightning.java
@@ -0,0 +1,133 @@
+package gtPlusPlus.core.entity;
+import java.util.List;
+
+import gtPlusPlus.api.damage.DamageTeslaTower;
+import gtPlusPlus.api.objects.Logger;
+import gtPlusPlus.core.util.entity.EntityUtils;
+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;
+
+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;
+
+ public EntityTeslaTowerLightning(World p_i1703_1_, double p_i1703_2_, double p_i1703_4_, double p_i1703_6_)
+ {
+ super(p_i1703_1_);
+ this.setLocationAndAngles(p_i1703_2_, p_i1703_4_, p_i1703_6_, 0.0F, 0.0F);
+ this.lightningState = 2;
+ this.boltVertex = this.rand.nextLong();
+ this.boltLivingTime = this.rand.nextInt(3) + 1;
+
+ //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))
+ {
+ 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_) + this.rand.nextInt(3) - 1;
+ k = MathHelper.floor_double(p_i1703_4_) + this.rand.nextInt(3) - 1;
+ int l = MathHelper.floor_double(p_i1703_6_) + this.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();
+
+ if (this.lightningState == 2)
+ {
+ this.worldObj.playSoundEffect(this.posX, this.posY, this.posZ, "ambient.weather.thunder", 10000.0F, 0.8F + this.rand.nextFloat() * 0.2F);
+ }
+ --this.lightningState;
+ if (this.lightningState < 0)
+ {
+ if (this.boltLivingTime == 0)
+ {
+ this.setDead();
+ }
+ else if (this.lightningState < -this.rand.nextInt(10))
+ {
+ --this.boltLivingTime;
+ this.lightningState = 1;
+ this.boltVertex = this.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))
+ {
+ 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);
+ }
+ }
+
+ }
+ }
+
+ if (this.lightningState >= 0)
+ {
+ if (this.worldObj.isRemote)
+ {
+ this.worldObj.lastLightningBolt = 2;
+ }
+ else
+ {
+ double d0 = 3.0D;
+ List 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 = (Entity)list.get(l);
+ //if (!net.minecraftforge.event.ForgeEventFactory.onEntityStruckByLightning(entity, this))
+ EntityUtils.doFireDamage(entity, 5);
+ EntityUtils.doDamage(entity, new DamageTeslaTower(entity), 20);
+ }
+ }
+ }
+ }
+
+ 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