did a bit of work on the sentry prefabs

This commit is contained in:
Robert 2013-11-12 20:35:10 -05:00
parent 83a43748c2
commit 3f7df44b3f
8 changed files with 211 additions and 40 deletions

View file

@ -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);
}

View file

@ -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();

View file

@ -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<ItemStack> items = block.getBlockDropped(world, vec.intX(), vec.intY(), vec.intZ(), meta, 1);
@ -229,6 +232,7 @@ public class LaserEvent extends Event
{
items = new ArrayList<ItemStack>();
}
//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));

View file

@ -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"));
}
}

View file

@ -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);

View file

@ -3,6 +3,11 @@ package dark.core.prefab.sentry;
public class TileEntityAutoSentry extends TileEntitySentry
{
public TileEntityAutoSentry(float maxDamage)
{
super(maxDamage);
}
@Override
public SentryType getType()
{

View file

@ -3,6 +3,11 @@ package dark.core.prefab.sentry;
public class TileEntityMountedSentry extends TileEntitySentry
{
public TileEntityMountedSentry(float maxDamage)
{
super(maxDamage);
}
@Override
public SentryType getType()
{

View file

@ -2,30 +2,61 @@ 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)
if (this.isFunctioning())
{
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()
@ -33,6 +64,108 @@ public class TileEntitySentry extends TileEntityAdvanced implements ISentryGun
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;
// TODO Auto-generated method stub
return false;
}
}
return platform;
@Override
public boolean keyTyped(EntityPlayer player, int keycode)
{
// TODO Auto-generated method stub
return false;
}
}