2016-03-16 17:49:28 +03:00
|
|
|
package emt.entity;
|
2014-10-02 23:04:17 -07:00
|
|
|
|
2016-05-29 19:06:08 +03:00
|
|
|
import cpw.mods.fml.common.registry.IThrowableEntity;
|
2014-10-02 23:04:17 -07:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
|
import net.minecraft.entity.IProjectile;
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import net.minecraft.util.AxisAlignedBB;
|
|
|
|
|
import net.minecraft.util.MathHelper;
|
|
|
|
|
import net.minecraft.util.MovingObjectPosition;
|
|
|
|
|
import net.minecraft.util.Vec3;
|
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
2016-05-29 19:06:08 +03:00
|
|
|
public class EntityLaser extends Entity implements IThrowableEntity, IProjectile {
|
2016-04-05 13:41:09 +03:00
|
|
|
private Block inTile;
|
|
|
|
|
public Entity shootingEntity;
|
|
|
|
|
|
2016-05-29 19:06:08 +03:00
|
|
|
private int xTile;
|
|
|
|
|
private int yTile;
|
|
|
|
|
private int zTile;
|
|
|
|
|
private int meta;
|
|
|
|
|
private boolean inGround = false;
|
2014-10-02 23:04:17 -07:00
|
|
|
private int ticksInGround;
|
|
|
|
|
private int ticksInAir;
|
2015-12-15 20:26:18 +03:00
|
|
|
private float explosionStrength = 2f;
|
2014-10-02 23:04:17 -07:00
|
|
|
|
2016-04-05 13:41:09 +03:00
|
|
|
public EntityLaser(World world) {
|
|
|
|
|
super(world);
|
2014-10-02 23:04:17 -07:00
|
|
|
|
|
|
|
|
this.renderDistanceWeight = 10.0D;
|
|
|
|
|
this.setSize(0.5F, 0.5F);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-05 13:41:09 +03:00
|
|
|
public EntityLaser(World world, EntityLivingBase entity, float speed) {
|
2015-12-06 19:47:41 +03:00
|
|
|
super(world);
|
2014-10-02 23:04:17 -07:00
|
|
|
this.renderDistanceWeight = 10.0D;
|
2015-12-06 19:47:41 +03:00
|
|
|
this.shootingEntity = entity;
|
2014-10-02 23:04:17 -07:00
|
|
|
|
|
|
|
|
this.setSize(0.5F, 0.5F);
|
2015-12-06 19:47:41 +03:00
|
|
|
this.setLocationAndAngles(entity.posX, entity.posY + (double) entity.getEyeHeight(), entity.posZ, entity.rotationYaw, entity.rotationPitch);
|
2014-10-02 23:04:17 -07:00
|
|
|
this.posX -= (double) (MathHelper.cos(this.rotationYaw / 180.0F * (float) Math.PI) * 0.16F);
|
|
|
|
|
this.posY -= 0.10000000149011612D;
|
|
|
|
|
this.posZ -= (double) (MathHelper.sin(this.rotationYaw / 180.0F * (float) Math.PI) * 0.16F);
|
|
|
|
|
this.yOffset = 0.0F;
|
2016-05-29 19:06:08 +03:00
|
|
|
|
2014-10-02 23:04:17 -07:00
|
|
|
this.motionX = (double) (-MathHelper.sin(this.rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float) Math.PI));
|
|
|
|
|
this.motionZ = (double) (MathHelper.cos(this.rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float) Math.PI));
|
|
|
|
|
this.motionY = (double) (-MathHelper.sin(this.rotationPitch / 180.0F * (float) Math.PI));
|
2016-05-29 19:06:08 +03:00
|
|
|
|
|
|
|
|
this.setThrowableHeading(this.motionX, this.motionY, this.motionZ, speed, 1.0F);
|
2014-10-02 23:04:17 -07:00
|
|
|
}
|
2016-05-29 19:06:08 +03:00
|
|
|
|
2016-04-05 13:41:09 +03:00
|
|
|
public void setExplosionStrengthModifier(float f) {
|
2015-12-15 20:26:18 +03:00
|
|
|
explosionStrength = f;
|
2015-12-14 23:30:00 +01:00
|
|
|
}
|
2014-10-02 23:04:17 -07:00
|
|
|
|
2016-04-05 13:41:09 +03:00
|
|
|
@Override
|
2014-10-02 23:04:17 -07:00
|
|
|
protected void entityInit() {
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-05 13:41:09 +03:00
|
|
|
@Override
|
|
|
|
|
public void setThrowableHeading(double x, double y, double z, float speed, float scale) {
|
2016-05-29 19:06:08 +03:00
|
|
|
this.motionX = x * speed;
|
|
|
|
|
this.motionY = y * speed;
|
|
|
|
|
this.motionZ = z * speed;
|
2014-10-02 23:04:17 -07:00
|
|
|
this.ticksInGround = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
2016-04-05 13:41:09 +03:00
|
|
|
public void setPositionAndRotation2(double x, double y, double z, float rotX, float rotY, int rotZ) {
|
|
|
|
|
this.setPosition(x, y, z);
|
|
|
|
|
this.setRotation(rotX, rotY);
|
2014-10-02 23:04:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
2016-05-29 19:06:08 +03:00
|
|
|
@Override
|
2016-04-05 13:41:09 +03:00
|
|
|
public void setVelocity(double velX, double velY, double velZ) {
|
|
|
|
|
this.motionX = velX;
|
|
|
|
|
this.motionY = velY;
|
|
|
|
|
this.motionZ = velZ;
|
2014-10-02 23:04:17 -07:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-05 13:41:09 +03:00
|
|
|
@Override
|
2014-10-02 23:04:17 -07:00
|
|
|
public void onUpdate() {
|
|
|
|
|
super.onUpdate();
|
|
|
|
|
|
|
|
|
|
Block block = this.worldObj.getBlock(this.xTile, this.yTile, this.zTile);
|
2016-05-29 19:06:08 +03:00
|
|
|
|
2014-10-02 23:04:17 -07:00
|
|
|
if (block.getMaterial() != Material.air) {
|
|
|
|
|
block.setBlockBoundsBasedOnState(this.worldObj, this.xTile, this.yTile, this.zTile);
|
|
|
|
|
AxisAlignedBB axisalignedbb = block.getCollisionBoundingBoxFromPool(this.worldObj, this.xTile, this.yTile, this.zTile);
|
|
|
|
|
|
|
|
|
|
if (axisalignedbb != null && axisalignedbb.isVecInside(Vec3.createVectorHelper(this.posX, this.posY, this.posZ))) {
|
|
|
|
|
this.inGround = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-29 19:06:08 +03:00
|
|
|
block.setBlockBoundsBasedOnState(this.worldObj, this.xTile, this.yTile, this.zTile);
|
|
|
|
|
AxisAlignedBB axisalignedbb = block.getCollisionBoundingBoxFromPool(this.worldObj, this.xTile, this.yTile, this.zTile);
|
2014-10-02 23:04:17 -07:00
|
|
|
|
|
|
|
|
if (axisalignedbb != null && axisalignedbb.isVecInside(Vec3.createVectorHelper(this.posX, this.posY, this.posZ))) {
|
|
|
|
|
this.inGround = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.inGround) {
|
|
|
|
|
int k = this.worldObj.getBlockMetadata(this.xTile, this.yTile, this.zTile);
|
2015-12-06 19:47:41 +03:00
|
|
|
if (!this.worldObj.isRemote) {
|
2015-12-15 20:26:18 +03:00
|
|
|
this.worldObj.createExplosion(this, (int) this.posX, (int) this.posY, (int) this.posZ, explosionStrength, true);
|
2015-09-13 21:24:58 +03:00
|
|
|
this.setDead();
|
|
|
|
|
}
|
2015-12-06 19:47:41 +03:00
|
|
|
|
2016-05-29 19:06:08 +03:00
|
|
|
if (block == this.inTile && k == this.meta) {
|
2014-10-02 23:04:17 -07:00
|
|
|
++this.ticksInGround;
|
2015-12-06 19:47:41 +03:00
|
|
|
|
2014-10-02 23:04:17 -07:00
|
|
|
if (this.ticksInGround == 1200) {
|
|
|
|
|
this.setDead();
|
|
|
|
|
}
|
2015-12-06 19:47:41 +03:00
|
|
|
}
|
|
|
|
|
else {
|
2014-10-02 23:04:17 -07:00
|
|
|
this.inGround = false;
|
|
|
|
|
this.motionX *= (double) (this.rand.nextFloat() * 0.2F);
|
|
|
|
|
this.motionY *= (double) (this.rand.nextFloat() * 0.2F);
|
|
|
|
|
this.motionZ *= (double) (this.rand.nextFloat() * 0.2F);
|
|
|
|
|
this.ticksInGround = 0;
|
|
|
|
|
this.ticksInAir = 0;
|
|
|
|
|
}
|
2015-12-06 19:47:41 +03:00
|
|
|
}
|
|
|
|
|
else {
|
2014-10-02 23:04:17 -07:00
|
|
|
++this.ticksInAir;
|
2016-04-05 13:41:09 +03:00
|
|
|
Vec3 vec3 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
|
|
|
|
|
Vec3 vec3next = Vec3.createVectorHelper(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
|
|
|
|
|
MovingObjectPosition movingobjectposition = this.worldObj.func_147447_a(vec3, vec3next, false, true, false);
|
|
|
|
|
vec3 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
|
|
|
|
|
vec3next = Vec3.createVectorHelper(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
|
2014-10-02 23:04:17 -07:00
|
|
|
|
|
|
|
|
if (movingobjectposition != null) {
|
2016-04-05 13:41:09 +03:00
|
|
|
vec3next = Vec3.createVectorHelper(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord);
|
2014-10-02 23:04:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
int l;
|
2016-05-29 19:06:08 +03:00
|
|
|
float down;
|
2014-10-02 23:04:17 -07:00
|
|
|
|
|
|
|
|
for (l = 0; l < list.size(); ++l) {
|
|
|
|
|
Entity entity1 = (Entity) list.get(l);
|
|
|
|
|
|
|
|
|
|
if (entity1.canBeCollidedWith() && (entity1 != this.shootingEntity || this.ticksInAir >= 5)) {
|
2016-05-29 19:06:08 +03:00
|
|
|
down = 0.3F;
|
|
|
|
|
AxisAlignedBB axisalignedbb1 = entity1.boundingBox.expand((double) down, (double) down, (double) down);
|
2016-04-05 13:41:09 +03:00
|
|
|
MovingObjectPosition movingobjectposition1 = axisalignedbb1.calculateIntercept(vec3next, vec3);
|
2014-10-02 23:04:17 -07:00
|
|
|
|
|
|
|
|
if (movingobjectposition1 != null) {
|
2016-04-05 13:41:09 +03:00
|
|
|
double d1 = vec3next.distanceTo(movingobjectposition1.hitVec);
|
2014-10-02 23:04:17 -07:00
|
|
|
|
|
|
|
|
if (d1 < d0 || d0 == 0.0D) {
|
|
|
|
|
entity = entity1;
|
|
|
|
|
d0 = d1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (entity != null) {
|
|
|
|
|
movingobjectposition = new MovingObjectPosition(entity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (movingobjectposition != null && movingobjectposition.entityHit != null && movingobjectposition.entityHit instanceof EntityPlayer) {
|
|
|
|
|
EntityPlayer entityplayer = (EntityPlayer) movingobjectposition.entityHit;
|
|
|
|
|
|
|
|
|
|
if (entityplayer.capabilities.disableDamage || this.shootingEntity instanceof EntityPlayer && !((EntityPlayer) this.shootingEntity).canAttackPlayer(entityplayer)) {
|
|
|
|
|
movingobjectposition = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float f2;
|
|
|
|
|
float f3;
|
|
|
|
|
|
|
|
|
|
if (movingobjectposition != null) {
|
|
|
|
|
if (movingobjectposition.entityHit != null) {
|
|
|
|
|
f2 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
|
2015-12-15 20:26:18 +03:00
|
|
|
if (!this.worldObj.isRemote) {
|
|
|
|
|
this.worldObj.createExplosion(this, (int) this.posX, (int) this.posY, (int) this.posZ, explosionStrength, true);
|
|
|
|
|
this.setDead();
|
2014-10-02 23:04:17 -07:00
|
|
|
}
|
2015-12-06 19:47:41 +03:00
|
|
|
}
|
|
|
|
|
else {
|
2014-10-02 23:04:17 -07:00
|
|
|
this.xTile = movingobjectposition.blockX;
|
|
|
|
|
this.yTile = movingobjectposition.blockY;
|
|
|
|
|
this.zTile = movingobjectposition.blockZ;
|
|
|
|
|
this.inTile = this.worldObj.getBlock(this.xTile, this.yTile, this.zTile);
|
2016-05-29 19:06:08 +03:00
|
|
|
this.meta = this.worldObj.getBlockMetadata(this.xTile, this.yTile, this.zTile);
|
2015-10-01 21:07:47 +03:00
|
|
|
this.motionX = movingobjectposition.hitVec.xCoord - this.posX;
|
|
|
|
|
this.motionY = movingobjectposition.hitVec.yCoord - this.posY;
|
|
|
|
|
this.motionZ = movingobjectposition.hitVec.zCoord - this.posZ;
|
2014-10-02 23:04:17 -07:00
|
|
|
f2 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
|
|
|
|
|
this.posX -= this.motionX / (double) f2 * 0.05000000074505806D;
|
|
|
|
|
this.posY -= this.motionY / (double) f2 * 0.05000000074505806D;
|
|
|
|
|
this.posZ -= this.motionZ / (double) f2 * 0.05000000074505806D;
|
|
|
|
|
this.inGround = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.posX += this.motionX;
|
|
|
|
|
this.posY += this.motionY;
|
|
|
|
|
this.posZ += this.motionZ;
|
|
|
|
|
f2 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
|
|
|
|
|
this.rotationYaw = (float) (Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
|
|
|
|
|
|
2015-12-15 20:26:18 +03:00
|
|
|
for (this.rotationPitch = (float) (Math.atan2(this.motionY, (double) f2) * 180.0D / Math.PI); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F);
|
2014-10-02 23:04:17 -07:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.isInWater()) {
|
|
|
|
|
for (int j1 = 0; j1 < 4; ++j1) {
|
|
|
|
|
f3 = 0.25F;
|
|
|
|
|
this.worldObj.spawnParticle("bubble", this.posX - this.motionX * (double) f3, this.posY - this.motionY * (double) f3, this.posZ - this.motionZ * (double) f3, this.motionX, this.motionY, this.motionZ);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
this.setPosition(this.posX, this.posY, this.posZ);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-05 13:41:09 +03:00
|
|
|
@Override
|
2015-12-06 19:47:41 +03:00
|
|
|
public void writeEntityToNBT(NBTTagCompound nbt) {
|
|
|
|
|
nbt.setShort("xTile", (short) this.xTile);
|
|
|
|
|
nbt.setShort("yTile", (short) this.yTile);
|
|
|
|
|
nbt.setShort("zTile", (short) this.zTile);
|
2016-04-05 13:41:09 +03:00
|
|
|
nbt.setShort("inTile", (short) Block.getIdFromBlock(this.inTile));
|
2016-05-29 19:06:08 +03:00
|
|
|
nbt.setByte("inData", (byte) this.meta);
|
2015-12-06 19:47:41 +03:00
|
|
|
nbt.setBoolean("inGround", this.inGround);
|
2015-12-15 20:26:18 +03:00
|
|
|
nbt.setFloat("explosionStrength", this.explosionStrength);
|
2014-10-02 23:04:17 -07:00
|
|
|
}
|
|
|
|
|
|
2016-04-05 13:41:09 +03:00
|
|
|
@Override
|
2015-12-06 19:47:41 +03:00
|
|
|
public void readEntityFromNBT(NBTTagCompound nbt) {
|
|
|
|
|
this.xTile = nbt.getShort("xTile");
|
|
|
|
|
this.yTile = nbt.getShort("yTile");
|
|
|
|
|
this.zTile = nbt.getShort("zTile");
|
2016-04-05 13:41:09 +03:00
|
|
|
this.inTile = Block.getBlockById(nbt.getShort("inTile"));
|
2016-05-29 19:06:08 +03:00
|
|
|
this.meta = nbt.getByte("inData") & 255;
|
2015-12-06 19:47:41 +03:00
|
|
|
this.inGround = nbt.getBoolean("inGround");
|
2015-12-15 20:26:18 +03:00
|
|
|
this.explosionStrength = nbt.getFloat("explosionStrength");
|
2014-10-02 23:04:17 -07:00
|
|
|
}
|
|
|
|
|
|
2016-05-29 19:06:08 +03:00
|
|
|
public void onCollide(Entity entity) {
|
2016-04-05 13:41:09 +03:00
|
|
|
if (!this.worldObj.isRemote) {
|
2015-12-15 20:26:18 +03:00
|
|
|
this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, explosionStrength, true);
|
2014-10-02 23:04:17 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
2016-04-05 13:41:09 +03:00
|
|
|
@Override
|
2014-10-02 23:04:17 -07:00
|
|
|
public float getShadowSize() {
|
|
|
|
|
return 0.0F;
|
|
|
|
|
}
|
2016-05-29 19:06:08 +03:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Entity getThrower() {
|
|
|
|
|
return shootingEntity;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setThrower(Entity entity) {
|
|
|
|
|
shootingEntity = entity;
|
|
|
|
|
}
|
2014-10-02 23:04:17 -07:00
|
|
|
}
|