From 4acb350cfdd0a5c125c8b0e039252dada580ce87 Mon Sep 17 00:00:00 2001 From: Robert Date: Tue, 12 Nov 2013 15:42:08 -0500 Subject: [PATCH] Started work on the base sentry prefab going to actually stop here for the moment and pick this up later --- src/dark/api/ISentryGun.java | 16 ++++ src/dark/core/prefab/EntityTileDamage.java | 14 +++- .../core/prefab/sentry/BlockSentryGun.java | 9 +-- .../core/prefab/sentry/EntitySentryGun.java | 40 ---------- .../prefab/sentry/TileEntityAutoSentry.java | 9 ++- .../prefab/sentry/TileEntityGunPlatform.java | 8 ++ .../sentry/TileEntityMountedSentry.java | 9 ++- .../core/prefab/sentry/TileEntitySentry.java | 75 ++++++++++++++++++- .../prefab/sentry/TileEntityTerminal.java | 6 -- 9 files changed, 127 insertions(+), 59 deletions(-) delete mode 100644 src/dark/core/prefab/sentry/EntitySentryGun.java create mode 100644 src/dark/core/prefab/sentry/TileEntityGunPlatform.java delete mode 100644 src/dark/core/prefab/sentry/TileEntityTerminal.java diff --git a/src/dark/api/ISentryGun.java b/src/dark/api/ISentryGun.java index 30d5aa31..15f06a00 100644 --- a/src/dark/api/ISentryGun.java +++ b/src/dark/api/ISentryGun.java @@ -1,9 +1,25 @@ package dark.api; +import net.minecraft.tileentity.TileEntity; + /** Applied to tile entities that are sentry guns * * @author DarkGuardsman */ public interface ISentryGun { + /** Gets the type of sentry */ + public SentryType getType(); + /** Gets the tileEntity this sentry is attached too. Null if its self supporting */ + public TileEntity getPlatform(); + + public static enum SentryType + { + /** Sentry guns that act like entities and are self moving */ + AUTOMATED(), + /** Sentry guns that are manually moved by assisted input and are basically blocks */ + AIMED(), + /** Sentry guns that are mounted by entities like players and are an extension of that entity */ + MOUNTED(); + } } diff --git a/src/dark/core/prefab/EntityTileDamage.java b/src/dark/core/prefab/EntityTileDamage.java index 492e73b8..4674ff07 100644 --- a/src/dark/core/prefab/EntityTileDamage.java +++ b/src/dark/core/prefab/EntityTileDamage.java @@ -29,7 +29,7 @@ import dark.core.interfaces.IDamageableTile; public class EntityTileDamage extends EntityLiving implements IEntityAdditionalSpawnData { - private TileEntity host; + public TileEntity host; int hp = 100; public EntityTileDamage(World par1World) @@ -46,6 +46,18 @@ public class EntityTileDamage extends EntityLiving implements IEntityAdditionalS this.host = c; } + public EntityTileDamage(Vector3 v, TileEntity c) + { + this(c.worldObj); + this.setPosition(v); + this.host = c; + } + + public void setPosition(Vector3 vec) + { + this.setPosition(vec.x, vec.y, vec.z); + } + @Override public boolean attackEntityFrom(DamageSource source, float ammount) { diff --git a/src/dark/core/prefab/sentry/BlockSentryGun.java b/src/dark/core/prefab/sentry/BlockSentryGun.java index 46656d73..180badec 100644 --- a/src/dark/core/prefab/sentry/BlockSentryGun.java +++ b/src/dark/core/prefab/sentry/BlockSentryGun.java @@ -2,11 +2,12 @@ package dark.core.prefab.sentry; import java.util.Set; -import com.builtbroken.common.Pair; - import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.tileentity.TileEntity; + +import com.builtbroken.common.Pair; + import dark.core.common.DarkMain; import dark.core.prefab.machine.BlockMachine; import dark.core.registration.ModObjectRegistry; @@ -94,10 +95,6 @@ public class BlockSentryGun extends BlockMachine sentryBlockIds[b] = block.blockID; } } - for (int t = 0; t < sentryGuns.length; t++) - { - - } } } diff --git a/src/dark/core/prefab/sentry/EntitySentryGun.java b/src/dark/core/prefab/sentry/EntitySentryGun.java deleted file mode 100644 index 37c5db55..00000000 --- a/src/dark/core/prefab/sentry/EntitySentryGun.java +++ /dev/null @@ -1,40 +0,0 @@ -package dark.core.prefab.sentry; - -import net.minecraft.entity.Entity; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.World; - -/** Since we are going to need an entity for the sentries to take damage with we are actually going - * to do more with the entity than redirect damage. - * - * @author DarkGuardsman */ -public class EntitySentryGun extends Entity -{ - - public EntitySentryGun(World par1World) - { - super(par1World); - } - - @Override - protected void entityInit() - { - // TODO Auto-generated method stub - - } - - @Override - protected void readEntityFromNBT(NBTTagCompound nbttagcompound) - { - // TODO Auto-generated method stub - - } - - @Override - protected void writeEntityToNBT(NBTTagCompound nbttagcompound) - { - // TODO Auto-generated method stub - - } - -} diff --git a/src/dark/core/prefab/sentry/TileEntityAutoSentry.java b/src/dark/core/prefab/sentry/TileEntityAutoSentry.java index 9f56a8dc..1a4d698e 100644 --- a/src/dark/core/prefab/sentry/TileEntityAutoSentry.java +++ b/src/dark/core/prefab/sentry/TileEntityAutoSentry.java @@ -1,6 +1,11 @@ package dark.core.prefab.sentry; -public class TileEntityAutoSentry -{ +public class TileEntityAutoSentry extends TileEntitySentry +{ + @Override + public SentryType getType() + { + return SentryType.AUTOMATED; + } } diff --git a/src/dark/core/prefab/sentry/TileEntityGunPlatform.java b/src/dark/core/prefab/sentry/TileEntityGunPlatform.java new file mode 100644 index 00000000..e6253db2 --- /dev/null +++ b/src/dark/core/prefab/sentry/TileEntityGunPlatform.java @@ -0,0 +1,8 @@ +package dark.core.prefab.sentry; + +import dark.core.prefab.terminal.TileEntityTerminal; + +public class TileEntityGunPlatform extends TileEntityTerminal +{ + +} diff --git a/src/dark/core/prefab/sentry/TileEntityMountedSentry.java b/src/dark/core/prefab/sentry/TileEntityMountedSentry.java index 566163fa..2488baa4 100644 --- a/src/dark/core/prefab/sentry/TileEntityMountedSentry.java +++ b/src/dark/core/prefab/sentry/TileEntityMountedSentry.java @@ -1,6 +1,11 @@ package dark.core.prefab.sentry; -public class TileEntityMountedSentry -{ +public class TileEntityMountedSentry extends TileEntitySentry +{ + @Override + public SentryType getType() + { + return SentryType.MOUNTED; + } } diff --git a/src/dark/core/prefab/sentry/TileEntitySentry.java b/src/dark/core/prefab/sentry/TileEntitySentry.java index f74e6622..f3e1d785 100644 --- a/src/dark/core/prefab/sentry/TileEntitySentry.java +++ b/src/dark/core/prefab/sentry/TileEntitySentry.java @@ -1,6 +1,77 @@ package dark.core.prefab.sentry; -public class TileEntitySentry -{ +import java.util.List; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraftforge.common.ForgeDirection; +import universalelectricity.core.vector.Vector3; +import universalelectricity.prefab.tile.TileEntityAdvanced; +import dark.api.ISentryGun; +import dark.core.prefab.EntityTileDamage; + +public class TileEntitySentry extends TileEntityAdvanced implements ISentryGun +{ + protected EntityTileDamage entitySentry = null; + protected TileEntityGunPlatform platform; + protected ForgeDirection mountingSide = ForgeDirection.DOWN; + protected boolean isAlive = true; + + @Override + public void updateEntity() + { + super.updateEntity(); + if (this.isAlive && this.entitySentry == null) + { + this.getDamageEntity(true); + } + } + + @Override + public SentryType getType() + { + return SentryType.AIMED; + } + + public EntityTileDamage getDamageEntity() + { + return this.getDamageEntity(isAlive); + } + + public EntityTileDamage getDamageEntity(boolean create) + { + if (entitySentry == null || entitySentry.isDead && create) + { + AxisAlignedBB box = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1); + List list = this.worldObj.getEntitiesWithinAABB(EntityTileDamage.class, box); + for (EntityTileDamage entity : list) + { + if (!entity.isDead && (entity.host == null || entity.host == this)) + { + entity.host = this; + this.entitySentry = entity; + } + else + { + this.entitySentry = new EntityTileDamage(this); + } + } + } + return entitySentry; + } + + @Override + public TileEntity getPlatform() + { + Vector3 mountVec = new Vector3(this).modifyPositionFromSide(mountingSide); + if (platform == null || platform.isInvalid() || !new Vector3(platform).equals(mountVec)) + { + TileEntity entity = mountVec.getTileEntity(this.worldObj); + if (entity instanceof TileEntityGunPlatform) + { + this.platform = (TileEntityGunPlatform) entity; + } + } + return platform; + } } diff --git a/src/dark/core/prefab/sentry/TileEntityTerminal.java b/src/dark/core/prefab/sentry/TileEntityTerminal.java deleted file mode 100644 index 1e232c4a..00000000 --- a/src/dark/core/prefab/sentry/TileEntityTerminal.java +++ /dev/null @@ -1,6 +0,0 @@ -package dark.core.prefab.sentry; - -public class TileEntityTerminal -{ - -}