use of icbm.classic.lib.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.
the class EntityPlayerSeat method readSpawnData.
@Override
public void readSpawnData(ByteBuf additionalData) {
height = additionalData.readFloat();
width = additionalData.readFloat();
setSize(width, height);
if (additionalData.readBoolean()) {
rideOffset = new Pos(additionalData);
}
}
use of icbm.classic.lib.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.
the class TileLauncherBase method launchMissile.
/**
* Launches the missile
*
* @param target - The target in which the missile will land in
* @param lockHeight - height to wait before curving the missile
*/
public boolean launchMissile(Pos target, int lockHeight) {
// Allow canceling missile launches
if (MinecraftForge.EVENT_BUS.post(new LauncherEvent.PreLaunch(missileLauncher, missileHolder))) {
return false;
}
final ItemStack stack = getMissileStack();
if (// TODO capability
stack.getItem() == ItemReg.itemMissile) {
IExplosiveData explosiveData = ICBMClassicHelpers.getExplosive(stack.getItemDamage(), true);
if (explosiveData != null) {
target = applyInaccuracy(target);
if (isServer()) {
// TODO generate entity from item using handler
EntityMissile missile = new EntityMissile(getWorld());
// Set data
missile.explosiveID = explosiveData.getRegistryID();
// TODO store our launcher instance or UUID
missile.launcherPos = new Pos((TileEntity) this);
// TODO store offset
missile.setPosition(xi() + 0.5, yi() + 3, zi() + 0.5);
// Trigger launch event
missile.capabilityMissile.launch(target.x(), target.y(), target.z(), lockHeight);
// Spawn entity
((WorldServer) getWorld()).addScheduledTask(() -> getWorld().spawnEntity(missile));
// Grab rider
if (// TODO add hook to disable riding some missiles
seat != null && seat.getRidingEntity() != null) {
Entity entity = seat.getRidingEntity();
seat.getRidingEntity().startRiding(null);
entity.startRiding(missile);
}
// Remove item
getInventory().decrStackSize(0, 1);
}
return true;
}
}
return false;
}
use of icbm.classic.lib.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.
the class BlastEnderman method doExplode.
@Override
public boolean doExplode(int callCount) {
if (this.world().isRemote) {
int r = (int) (this.getBlastRadius() - ((double) this.callCount / (double) this.duration) * this.getBlastRadius());
for (int x = -r; x < r; x++) {
for (int z = -r; z < r; z++) {
for (int y = -r; y < r; y++) {
// TODO replace with mutable blockpos
Location targetPosition = location.add(new Pos(x, y, z));
double distance = targetPosition.distance(location);
if (distance < r && distance > r - 1) {
if (!targetPosition.getBlock(world()).isAir(targetPosition.getBlockState(world()), world(), targetPosition.toBlockPos())) {
continue;
}
if (this.world().rand.nextFloat() < Math.max(0.001 * r, 0.01)) {
float velX = (float) ((targetPosition.x() - location.x()) * 0.6);
float velY = (float) ((targetPosition.y() - location.y()) * 0.6);
float velZ = (float) ((targetPosition.z() - location.z()) * 0.6);
world.spawnParticle(EnumParticleTypes.PORTAL, targetPosition.x(), targetPosition.y(), targetPosition.z(), velX, velY, velZ);
}
}
}
}
}
}
int radius = (int) this.getBlastRadius();
AxisAlignedBB bounds = new AxisAlignedBB(location.x() - radius, location.y() - radius, location.z() - radius, location.x() + radius, location.y() + radius, location.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 - location.x();
double yDifference = entity.posY - location.y();
double zDifference = entity.posZ - location.z();
int r = (int) this.getBlastRadius();
if (xDifference < 0) {
r = (int) -this.getBlastRadius();
}
entity.motionX -= (r - xDifference) * Math.abs(xDifference) * 0.0006;
r = (int) this.getBlastRadius();
if (entity.posY > location.y()) {
r = (int) -this.getBlastRadius();
}
entity.motionY += (r - yDifference) * Math.abs(yDifference) * 0.0011;
r = (int) this.getBlastRadius();
if (zDifference < 0) {
r = (int) -this.getBlastRadius();
}
entity.motionZ -= (r - zDifference) * Math.abs(zDifference) * 0.0006;
if (new Pos(entity.posX, entity.posY, entity.posZ).distance(location) < 4) {
if (!explosionCreated && callCount % 5 == 0) {
world().spawnParticle(EnumParticleTypes.EXPLOSION_HUGE, 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) Math.floor(this.controller.posY);
int checkX = this.world().rand.nextInt(300) - 150 + (int) this.controller.posX;
int checkZ = this.world().rand.nextInt(300) - 150 + (int) this.controller.posZ;
// Look for space with air gap
BlockPos pos;
BlockPos pos2;
do {
pos = new BlockPos(checkX, checkY, checkZ);
pos2 = pos.up();
checkY++;
} while (this.world().isAirBlock(pos) && !this.world().isAirBlock(pos2) && checkY < 254);
this.teleportTarget = new Pos(checkX, checkY, checkZ);
}
this.world().playSound(null, entity.posX, entity.posY, entity.posZ, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.BLOCKS, 1.0F, 1.0F);
if (entity instanceof EntityPlayerMP) {
((EntityPlayerMP) entity).connection.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.logger().error("Failed to teleport entity to the End.", e);
}
}
}
}
this.world().playSound(null, this.location.x(), this.location.y(), this.location.z(), SoundEvents.BLOCK_PORTAL_AMBIENT, SoundCategory.BLOCKS, 2F, world().rand.nextFloat() * 0.4F + 0.8F);
return this.callCount > this.duration;
}
use of icbm.classic.lib.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.
the class BlastTNT method pushEntities.
public // TODO convert to delay action
void pushEntities(// TODO convert to delay action
float radius, // TODO convert to delay action
float force, // TODO convert to delay action
PushType type) {
// Step 2: Damage all entities
Pos minCoord = location.toPos();
minCoord = minCoord.add(-radius - 1);
Pos maxCoord = location.toPos();
maxCoord = maxCoord.add(radius + 1);
Cube region = new Cube(minCoord, maxCoord);
List<Entity> entities = world.getEntitiesWithinAABB(Entity.class, region.getAABB());
for (Entity entity : entities) {
double var13 = entity.getDistance(location.x(), location.y(), location.z()) / radius;
if (var13 <= 1.0D) {
// Get delta
double xDifference = entity.posX - location.x();
double yDifference = entity.posY - location.y();
double zDifference = entity.posZ - location.z();
// Get magnitude
double mag = MathHelper.sqrt(xDifference * xDifference + yDifference * yDifference + zDifference * zDifference);
// Normalize difference
xDifference /= mag;
yDifference /= mag;
zDifference /= mag;
if (type == PushType.ATTRACT) {
double modifier = var13 * force * (entity instanceof EntityPlayer ? 0.5 : 1);
entity.addVelocity(-xDifference * modifier, -yDifference * modifier, -zDifference * modifier);
} else if (type == PushType.REPEL) {
double modifier = (1.0D - var13) * force * (entity instanceof EntityPlayer ? 0.5 : 1);
entity.addVelocity(xDifference * modifier, yDifference * modifier, zDifference * modifier);
}
}
}
}
use of icbm.classic.lib.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.
the class BlastNuclear method setupBlast.
@Override
public boolean setupBlast() {
super.setupBlast();
if (this.world() != null) {
if (this.spawnMoreParticles) {
// Spawn nuclear cloud.
for (int y = 0; y < 26; y++) {
int r = 4;
if (y < 8) {
r = Math.max(Math.min((8 - y) * 2, 10), 4);
} else if (y > 15) {
r = Math.max(Math.min((y - 15) * 2, 15), 5);
}
for (int x = -r; x < r; x++) {
for (int z = -r; z < r; z++) {
double distance = MathHelper.sqrt(x * x + z * z);
if (r > distance && r - 3 < distance) {
Location spawnPosition = location.add(new Pos(x * 2, (y - 2) * 2, z * 2));
float xDiff = (float) (spawnPosition.x() - location.x());
float zDiff = (float) (spawnPosition.z() - location.z());
world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, spawnPosition.x(), spawnPosition.y(), spawnPosition.z(), xDiff * 0.3 * world().rand.nextFloat(), -world().rand.nextFloat(), // (float) (distance / this.getRadius()) * oldWorld().rand.nextFloat(), 0, //0, 8F, 1.2F);
zDiff * 0.3 * world().rand.nextFloat());
}
}
}
}
}
this.doDamageEntities(this.getBlastRadius(), this.energy * 1000);
ICBMSounds.EXPLOSION.play(world, this.location.x(), this.location.y(), this.location.z(), 7.0F, (1.0F + (this.world().rand.nextFloat() - this.world().rand.nextFloat()) * 0.2F) * 0.7F, true);
}
return true;
}
Aggregations