diff --git a/src/dark/api/IAimable.java b/src/dark/api/IAimable.java new file mode 100644 index 000000000..f4a450726 --- /dev/null +++ b/src/dark/api/IAimable.java @@ -0,0 +1,23 @@ +package dark.api; + +import universalelectricity.core.vector.Vector3; + +/** Applied to objects that can be aimed by yaw and pitch. This is used by things like sentry guns, + * vehicles, or mining tools. + * + * @author DarkGuardsman */ +public interface IAimable +{ + /** Vector which runs from the objects eyes(or gun) to what it is looking at. Should be right + * outside the objects bounds but no farther than that. Used for ray traces mainly */ + public Vector3 getLook(); + + /** X pitch, Y is yaw, z is roll but is not used for basic aiming */ + public Vector3 getRotation(); + + /** This does not set the rotation but rather moves the current rotation by the given values */ + public void updateRotation(float pitch, float yaw, float roll); + + /** Forces the rotation to the angles */ + public void setRotation(float pitch, float yaw, float roll); +} diff --git a/src/dark/api/ISentryGun.java b/src/dark/api/ISentryGun.java index 15f06a000..dfd2f9cd8 100644 --- a/src/dark/api/ISentryGun.java +++ b/src/dark/api/ISentryGun.java @@ -1,11 +1,14 @@ package dark.api; import net.minecraft.tileentity.TileEntity; +import dark.core.interfaces.IBlockActivated; +import dark.core.interfaces.IControlReceiver; +import dark.core.interfaces.IDamageableTile; /** Applied to tile entities that are sentry guns * * @author DarkGuardsman */ -public interface ISentryGun +public interface ISentryGun extends IAimable, IDamageableTile, IControlReceiver, IBlockActivated { /** Gets the type of sentry */ public SentryType getType(); diff --git a/src/dark/api/events/LaserEvent.java b/src/dark/api/events/LaserEvent.java index ecd9f70bb..a714c8ef6 100644 --- a/src/dark/api/events/LaserEvent.java +++ b/src/dark/api/events/LaserEvent.java @@ -18,6 +18,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; +import net.minecraftforge.common.IPlantable; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.Cancelable; import net.minecraftforge.event.Event; @@ -178,14 +179,6 @@ public class LaserEvent extends Event world.setBlock(vec.intX(), vec.intY(), vec.intZ(), Block.lavaStill.blockID, 15, 3); return; } - else if (block.blockID == Block.tnt.blockID) - { - world.setBlock(vec.intX(), vec.intY(), vec.intZ(), 0, 0, 3); - EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(world, (double) ((float) vec.intX() + 0.5F), (double) ((float) vec.intY() + 0.5F), (double) ((float) vec.intZ() + 0.5F), player instanceof EntityLivingBase ? ((EntityLivingBase) player) : null); - entitytntprimed.fuse = world.rand.nextInt(entitytntprimed.fuse / 4) + entitytntprimed.fuse / 8; - world.spawnEntityInWorld(entitytntprimed); - return; - } } MinecraftForge.EVENT_BUS.post(new LaserEvent.LaserMeltBlockEvent(world, start, vec, player)); } @@ -214,14 +207,24 @@ public class LaserEvent extends Event try { - int id2 = vec.clone().modifyPositionFromSide(ForgeDirection.UP).getBlockID(world); - Block block2 = Block.blocksList[id2]; + Block blockBellow = Block.blocksList[vec.clone().modifyPositionFromSide(ForgeDirection.DOWN).getBlockID(world)]; if (block != null) { + if (block.blockID == Block.tnt.blockID) + { + world.setBlock(vec.intX(), vec.intY(), vec.intZ(), 0, 0, 3); + EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(world, (double) ((float) vec.intX() + 0.5F), (double) ((float) vec.intY() + 0.5F), (double) ((float) vec.intZ() + 0.5F), player instanceof EntityLivingBase ? ((EntityLivingBase) player) : null); + entitytntprimed.fuse = world.rand.nextInt(entitytntprimed.fuse / 4) + entitytntprimed.fuse / 8; + world.spawnEntityInWorld(entitytntprimed); + return; + } if (EnumTool.AX.effecticVsMaterials.contains(block.blockMaterial) || block.blockMaterial == Material.plants || block.blockMaterial == Material.pumpkin || block.blockMaterial == Material.cloth || block.blockMaterial == Material.web) { - //TODO turn tilled dirt into dirt - world.setBlock(vec.intX(), vec.intY(), vec.intZ(), Block.fire.blockID, 0, 3); + if (blockBellow != null && blockBellow.blockID == Block.tilledField.blockID && block instanceof IPlantable) + { + vec.clone().translate(new Vector3(0, -1, 0)).setBlock(world, Block.dirt.blockID, 0, 3); + } + vec.setBlock(world, Block.fire.blockID, 0, 3); return; } List items = block.getBlockDropped(world, vec.intX(), vec.intY(), vec.intZ(), meta, 1); @@ -229,6 +232,7 @@ public class LaserEvent extends Event { items = new ArrayList(); } + //TODO have glass refract the laser causing it to hit random things if (id == Block.glass.blockID) { items.add(new ItemStack(Block.glass, 1, meta)); diff --git a/src/dark/core/client/FXBeam.java b/src/dark/core/client/FXBeam.java index 804afd9f4..c26e33132 100644 --- a/src/dark/core/client/FXBeam.java +++ b/src/dark/core/client/FXBeam.java @@ -24,18 +24,13 @@ import dark.core.common.DarkMain; @SideOnly(Side.CLIENT) public class FXBeam extends EntityFX { - double movX = 0.0D; - double movY = 0.0D; - double movZ = 0.0D; + double movX = 0.0D, movY = 0.0D, movZ = 0.0D; private float length = 0.0F; - private float rotYaw = 0.0F; - private float rotPitch = 0.0F; - private int rotSpeed = 20; + private float rotYaw = 0.0F, rotPitch = 0.0F, rotSpeed = 20; - private float prevYaw = 0.0F; - private float prevPitch = 0.0F; + private float prevYaw = 0.0F, prevPitch = 0.0F; private Vector3 endLocation = new Vector3(); @@ -77,7 +72,7 @@ public class FXBeam extends EntityFX float xd = (float) (this.posX - this.endLocation.x); float yd = (float) (this.posY - this.endLocation.y); float zd = (float) (this.posZ - this.endLocation.z); - this.length = (float) new Vector3(this).distanceTo(this.endLocation); + this.length = (float) new Vector3(this).distance(this.endLocation); double var7 = MathHelper.sqrt_double(xd * xd + zd * zd); this.rotYaw = ((float) (Math.atan2(xd, zd) * 180.0D / 3.141592653589793D)); this.rotPitch = ((float) (Math.atan2(yd, var7) * 180.0D / 3.141592653589793D)); @@ -230,6 +225,6 @@ public class FXBeam extends EntityFX tessellator.startDrawingQuads(); this.prevSize = size; - FMLClientHandler.instance().getClient().renderEngine.bindTexture(new ResourceLocation("/particles.png")); + FMLClientHandler.instance().getClient().renderEngine.bindTexture(new ResourceLocation("textures/particle/particles.png")); } } \ No newline at end of file diff --git a/src/dark/core/interfaces/IDamageableTile.java b/src/dark/core/interfaces/IDamageableTile.java index c4ac9ef23..b7acc5ee6 100644 --- a/src/dark/core/interfaces/IDamageableTile.java +++ b/src/dark/core/interfaces/IDamageableTile.java @@ -31,7 +31,7 @@ public interface IDamageableTile extends IBlockActivated public void setHealth(float health); /** Max hit points of the object */ - public int getMaxHealth(); + public float getMaxHealth(); /** Can the potion be used on the Entity that is translating damage for the TileEntity */ public boolean canApplyPotion(PotionEffect par1PotionEffect); diff --git a/src/dark/core/prefab/sentry/TileEntityAutoSentry.java b/src/dark/core/prefab/sentry/TileEntityAutoSentry.java index 1a4d698e5..59506813f 100644 --- a/src/dark/core/prefab/sentry/TileEntityAutoSentry.java +++ b/src/dark/core/prefab/sentry/TileEntityAutoSentry.java @@ -3,6 +3,11 @@ package dark.core.prefab.sentry; public class TileEntityAutoSentry extends TileEntitySentry { + public TileEntityAutoSentry(float maxDamage) + { + super(maxDamage); + } + @Override public SentryType getType() { diff --git a/src/dark/core/prefab/sentry/TileEntityMountedSentry.java b/src/dark/core/prefab/sentry/TileEntityMountedSentry.java index 2488baa47..abeee0666 100644 --- a/src/dark/core/prefab/sentry/TileEntityMountedSentry.java +++ b/src/dark/core/prefab/sentry/TileEntityMountedSentry.java @@ -3,6 +3,11 @@ package dark.core.prefab.sentry; public class TileEntityMountedSentry extends TileEntitySentry { + public TileEntityMountedSentry(float maxDamage) + { + super(maxDamage); + } + @Override public SentryType getType() { diff --git a/src/dark/core/prefab/sentry/TileEntitySentry.java b/src/dark/core/prefab/sentry/TileEntitySentry.java index f3e1d785e..4ee239446 100644 --- a/src/dark/core/prefab/sentry/TileEntitySentry.java +++ b/src/dark/core/prefab/sentry/TileEntitySentry.java @@ -2,37 +2,170 @@ package dark.core.prefab.sentry; import java.util.List; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.potion.PotionEffect; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.DamageSource; import net.minecraftforge.common.ForgeDirection; import universalelectricity.core.vector.Vector3; import universalelectricity.prefab.tile.TileEntityAdvanced; import dark.api.ISentryGun; import dark.core.prefab.EntityTileDamage; +import dark.core.prefab.machine.TileEntityMachine; -public class TileEntitySentry extends TileEntityAdvanced implements ISentryGun +public abstract class TileEntitySentry extends TileEntityMachine implements ISentryGun { protected EntityTileDamage entitySentry = null; protected TileEntityGunPlatform platform; protected ForgeDirection mountingSide = ForgeDirection.DOWN; - protected boolean isAlive = true; + protected boolean isAlive = true, isRunning = false, requiresPlatform = true; + private float damage = 0.0f; + private final float maxDamage; + + private Vector3 rotation = new Vector3(), newRotation = new Vector3(), prevRotation = new Vector3(); + + public TileEntitySentry(float maxDamage) + { + this.maxDamage = maxDamage; + } + + /* ****************************************************** + * Logic code + * ****************************************************** */ @Override public void updateEntity() { - super.updateEntity(); - if (this.isAlive && this.entitySentry == null) + super.updateEntity(); + if (this.isFunctioning()) { - this.getDamageEntity(true); + if (this.entitySentry == null) + { + this.getDamageEntity(true); + } + this.updateRotation(); } } + @Override + public boolean canFunction() + { + return super.canFunction() && this.isAlive() && (!this.requiresPlatform || this.requiresPlatform && this.getPlatform() != null); + } + + /* ****************************************************** + * Sentry code + * ****************************************************** */ + @Override public SentryType getType() { return SentryType.AIMED; } + @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; + } + + /* ****************************************************** + * Rotation code + * ****************************************************** */ + public void updateRotation() + { + + } + + @Override + public Vector3 getLook() + { + // TODO Auto-generated method stub + return null; + } + + @Override + public Vector3 getRotation() + { + if (this.rotation == null) + { + this.rotation = new Vector3(); + } + return rotation; + } + + @Override + public void updateRotation(float pitch, float yaw, float roll) + { + if (this.newRotation == null) + { + this.newRotation = this.getRotation(); + } + this.newRotation.x += pitch; + this.newRotation.y += yaw; + this.newRotation.z += roll; + } + + @Override + public void setRotation(float pitch, float yaw, float roll) + { + this.getRotation().x = pitch; + this.getRotation().y = yaw; + this.getRotation().z = roll; + } + + /* ****************************************************** + * Damage Code + * ****************************************************** */ + + @Override + public boolean onDamageTaken(DamageSource source, float ammount) + { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isAlive() + { + return this.isAlive; + } + + @Override + public float health() + { + return this.damage; + } + + @Override + public void setHealth(float health) + { + this.damage = health; + } + + @Override + public float getMaxHealth() + { + + return this.maxDamage; + } + + @Override + public boolean canApplyPotion(PotionEffect par1PotionEffect) + { + return false; + } + public EntityTileDamage getDamageEntity() { return this.getDamageEntity(isAlive); @@ -60,18 +193,21 @@ public class TileEntitySentry extends TileEntityAdvanced implements ISentryGun return entitySentry; } + /* ****************************************************** + * Player interaction + * ****************************************************** */ + @Override - public TileEntity getPlatform() + public boolean onActivated(EntityPlayer entityPlayer) { - 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; + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean keyTyped(EntityPlayer player, int keycode) + { + // TODO Auto-generated method stub + return false; } }