use of com.builtbroken.mc.imp.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.
the class ThreadLargeExplosion method run.
@Override
public void run() {
int steps = (int) Math.ceil(Math.PI / Math.atan(1.0D / this.radius));
for (int phi_n = 0; phi_n < 2 * steps; phi_n++) {
for (int theta_n = 0; theta_n < steps; theta_n++) {
double phi = Math.PI * 2 / steps * phi_n;
double theta = Math.PI / steps * theta_n;
Pos delta = new Pos(sin(theta) * cos(phi), cos(theta), sin(theta) * sin(phi));
float power = this.energy - (this.energy * this.position.world().rand.nextFloat() / 2);
Location t = position;
for (float d = 0.3F; power > 0f; power -= d * 0.75F * 10) {
if (t.distance(position) > this.radius) {
break;
}
Block block = t.getBlock();
if (block != null) {
if (block.getBlockHardness(this.position.world(), t.xi(), t.yi(), t.zi()) >= 0) {
power -= this.callBack.getResistance(this.position.world(), position, t, source, block);
if (power > 0f) {
this.results.add(t.toPos());
}
}
}
t = t.add(delta);
}
}
}
super.run();
}
use of com.builtbroken.mc.imp.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.
the class ThreadSmallExplosion method run.
@Override
public void run() {
if (!this.position.world().isRemote) {
for (int x = 0; x < this.radius; ++x) {
for (int y = 0; y < this.radius; ++y) {
for (int z = 0; z < this.radius; ++z) {
if (x == 0 || x == this.radius - 1 || y == 0 || y == this.radius - 1 || z == 0 || z == this.radius - 1) {
double xStep = x / (this.radius - 1.0F) * 2.0F - 1.0F;
double yStep = y / (this.radius - 1.0F) * 2.0F - 1.0F;
double zStep = z / (this.radius - 1.0F) * 2.0F - 1.0F;
double diagonalDistance = Math.sqrt(xStep * xStep + yStep * yStep + zStep * zStep);
xStep /= diagonalDistance;
yStep /= diagonalDistance;
zStep /= diagonalDistance;
float power = this.radius * (0.7F + this.position.world().rand.nextFloat() * 0.6F);
double var15 = position.x();
double var17 = position.y();
double var19 = position.z();
for (float var21 = 0.3F; power > 0.0F; power -= var21 * 0.75F) {
Pos targetPosition = new Pos(var15, var17, var19);
double distanceFromCenter = position.distance(targetPosition);
Block blockID = this.position.world().getBlock(targetPosition.xi(), targetPosition.yi(), targetPosition.zi());
if (blockID != null) {
float resistance = 0;
if (blockID.blockHardness < 0) {
break;
} else {
resistance = blockID.getExplosionResistance(this.source, this.position.world(), targetPosition.xi(), targetPosition.yi(), targetPosition.zi(), position.xi(), position.yi(), position.zi());
}
// TODO rather than remove power divert a percentage to the
// sides, and then calculate how much is absorbed by the block
power -= resistance;
}
if (power > 0.0F) {
this.results.add(targetPosition.clone());
}
var15 += xStep * var21;
var17 += yStep * var21;
var19 += zStep * var21;
}
}
}
}
}
}
super.run();
}
use of com.builtbroken.mc.imp.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.
the class BlastEnderman method doExplode.
@Override
public void doExplode() {
if (this.world().isRemote) {
int r = (int) (this.getRadius() - ((double) this.callCount / (double) this.duration) * this.getRadius());
for (int x = -r; x < r; x++) {
for (int z = -r; z < r; z++) {
for (int y = -r; y < r; y++) {
Location targetPosition = position.add(new Pos(x, y, z));
double distance = targetPosition.distance(position);
if (distance < r && distance > r - 1) {
if (targetPosition.getBlock(world()) != Blocks.air)
continue;
if (this.world().rand.nextFloat() < Math.max(0.001 * r, 0.01)) {
float velX = (float) ((targetPosition.x() - position.x()) * 0.6);
float velY = (float) ((targetPosition.y() - position.y()) * 0.6);
float velZ = (float) ((targetPosition.z() - position.z()) * 0.6);
ICBMClassic.proxy.spawnParticle("portal", world(), targetPosition, velX, velY, velZ, 5f, 1);
}
}
}
}
}
}
int radius = (int) this.getRadius();
AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(position.x() - radius, position.y() - radius, position.z() - radius, position.x() + radius, position.y() + radius, position.z() + radius);
List<Entity> allEntities = world().getEntitiesWithinAABB(Entity.class, bounds);
boolean explosionCreated = false;
for (Entity entity : allEntities) {
if (entity != this.controller) {
double xDifference = entity.posX - position.x();
double yDifference = entity.posY - position.y();
double zDifference = entity.posZ - position.z();
int r = (int) this.getRadius();
if (xDifference < 0)
r = (int) -this.getRadius();
entity.motionX -= (r - xDifference) * Math.abs(xDifference) * 0.0006;
r = (int) this.getRadius();
if (entity.posY > position.y())
r = (int) -this.getRadius();
entity.motionY += (r - yDifference) * Math.abs(yDifference) * 0.0011;
r = (int) this.getRadius();
if (zDifference < 0)
r = (int) -this.getRadius();
entity.motionZ -= (r - zDifference) * Math.abs(zDifference) * 0.0006;
if (new Pos(entity.posX, entity.posY, entity.posZ).distance(position) < 4) {
if (!explosionCreated && callCount % 5 == 0) {
world().spawnParticle("hugeexplosion", entity.posX, entity.posY, entity.posZ, 0.0D, 0.0D, 0.0D);
explosionCreated = true;
}
try {
/** If a target doesn't exist, search for a random one within 100 block
* range. */
if (this.teleportTarget == null) {
int checkY;
int checkX = this.world().rand.nextInt(300) - 150 + (int) this.controller.posX;
int checkZ = this.world().rand.nextInt(300) - 150 + (int) this.controller.posZ;
for (checkY = 63; !this.world().isAirBlock(checkX, checkY, checkZ) && !this.world().isAirBlock(checkX, checkY + 1, checkZ); ++checkY) {
;
}
this.teleportTarget = new Pos(checkX, checkY, checkZ);
}
this.world().playSoundAtEntity(entity, "mob.endermen.portal", 1.0F, 1.0F);
if (entity instanceof EntityPlayerMP) {
((EntityPlayerMP) entity).playerNetServerHandler.setPlayerLocation(this.teleportTarget.x() + 0.5, this.teleportTarget.y() + 0.5, this.teleportTarget.z() + 0.5, entity.rotationYaw, entity.rotationPitch);
} else {
entity.setPosition(this.teleportTarget.x() + 0.5, this.teleportTarget.y() + 0.5, this.teleportTarget.z() + 0.5);
}
} catch (Exception e) {
ICBMClassic.INSTANCE.logger().error("Failed to teleport entity to the End.", e);
}
}
}
}
this.world().playSound(this.position.x(), this.position.y(), this.position.z(), "portal.portal", 2F, world().rand.nextFloat() * 0.4F + 0.8F, false);
if (this.callCount > this.duration) {
this.controller.endExplosion();
}
}
use of com.builtbroken.mc.imp.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.
the class MissileAnti method update.
@Override
public void update(EntityMissile missileObj) {
if (missileObj.lockedTarget != null) {
Pos target = new Pos(missileObj.lockedTarget);
if (missileObj.lockedTarget.isDead) {
missileObj.explode();
return;
}
if (missileObj.lockedTarget instanceof EntityMissile) {
target = ((EntityMissile) missileObj.lockedTarget).getPredictedPosition(4);
}
missileObj.motionX = (target.x() - missileObj.posX) * (0.3F);
missileObj.motionY = (target.y() - missileObj.posY) * (0.3F);
missileObj.motionZ = (target.z() - missileObj.posZ) * (0.3F);
return;
}
AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(missileObj.posX - ABMRange, missileObj.posY - ABMRange, missileObj.posZ - ABMRange, missileObj.posX + ABMRange, missileObj.posY + ABMRange, missileObj.posZ + ABMRange);
// TODO: Check if this works.
Entity nearestEntity = missileObj.worldObj.findNearestEntityWithinAABB(EntityMissile.class, bounds, missileObj);
if (nearestEntity instanceof EntityMissile) {
// Lock target onto missileObj missile
missileObj.lockedTarget = nearestEntity;
missileObj.didTargetLockBefore = true;
missileObj.worldObj.playSoundAtEntity(missileObj, ICBMClassic.PREFIX + "targetlocked", 5F, 0.9F);
} else {
missileObj.motionX = missileObj.deltaPathX / missileObj.missileFlightTime;
missileObj.motionZ = missileObj.deltaPathZ / missileObj.missileFlightTime;
if (missileObj.didTargetLockBefore == true) {
missileObj.explode();
}
}
}
use of com.builtbroken.mc.imp.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.
the class MissileHoming method update.
@Override
public void update(EntityMissile missileObj) {
if (missileObj.getTicksInAir() > missileObj.missileFlightTime / 2 && missileObj.missileType == MissileType.MISSILE) {
WorldServer worldServer = (WorldServer) missileObj.worldObj;
Entity trackingEntity = worldServer.getEntityByID(missileObj.trackingVar);
if (trackingEntity != null) {
if (trackingEntity.equals(missileObj)) {
missileObj.setExplode();
}
missileObj.targetVector = new Pos(trackingEntity);
missileObj.missileType = MissileType.CruiseMissile;
missileObj.deltaPathX = missileObj.targetVector.x() - missileObj.posX;
missileObj.deltaPathY = missileObj.targetVector.y() - missileObj.posY;
missileObj.deltaPathZ = missileObj.targetVector.z() - missileObj.posZ;
missileObj.flatDistance = missileObj.sourceOfProjectile.toVector2().distance(missileObj.targetVector.toVector2());
missileObj.maxHeight = 150 + (int) (missileObj.flatDistance * 1.8);
missileObj.missileFlightTime = (float) Math.max(100, 2.4 * missileObj.flatDistance);
missileObj.acceleration = (float) missileObj.maxHeight * 2 / (missileObj.missileFlightTime * missileObj.missileFlightTime);
if (missileObj.xiaoDanMotion.equals(new Pos()) || missileObj.xiaoDanMotion == null) {
float suDu = 0.3f;
missileObj.xiaoDanMotion = new Pos(missileObj.deltaPathX / (missileObj.missileFlightTime * suDu), missileObj.deltaPathY / (missileObj.missileFlightTime * suDu), missileObj.deltaPathZ / (missileObj.missileFlightTime * suDu));
}
}
}
}
Aggregations