use of icbm.classic.lib.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.
the class TileLauncherBase method update.
/**
* Allows the entity to update its state. Overridden in most subclasses, e.g. the mob spawner
* uses this to count ticks and creates a new spawn inside its implementation.
*/
@Override
public void update() {
super.update();
if (isServer()) {
if (ticks % 3 == 0) {
// Update seat position
if (seat != null) {
seat.setPosition(x() + 0.5, y() + 0.5, z() + 0.5);
}
// Create seat if missile
if (// TODO add hook to disable riding some missiles
!getMissileStack().isEmpty() && seat == null) {
seat = new EntityPlayerSeat(world);
seat.host = this;
seat.rideOffset = new Pos(getRotation()).multiply(0.5, 1, 0.5);
seat.setPosition(x() + 0.5, y() + 0.5, z() + 0.5);
seat.setSize(0.5f, 2.5f);
world.spawnEntity(seat);
} else // Destroy seat if no missile
if (getMissileStack().isEmpty() && seat != null) {
if (seat.getRidingEntity() != null) {
seat.getRidingEntity().startRiding(null);
}
seat.setDead();
seat = null;
}
}
}
// 1 second update
if (ticks % 20 == 0) {
// Only update if frame or screen is invalid
if (this.supportFrame == null || launchScreen == null || launchScreen.isInvalid() || this.supportFrame.isInvalid()) {
// Reset data
if (this.supportFrame != null) {
this.supportFrame.launcherBase = null;
}
this.supportFrame = null;
this.launchScreen = null;
// Check on all 4 sides
for (EnumFacing rotation : EnumFacing.HORIZONTALS) {
// Get tile entity on side
Pos position = new Pos(getPos()).add(rotation);
TileEntity tileEntity = this.world.getTileEntity(position.toBlockPos());
// If frame update rotation
if (tileEntity instanceof TileLauncherFrame) {
this.supportFrame = (TileLauncherFrame) tileEntity;
this.supportFrame.launcherBase = this;
if (isServer()) {
this.supportFrame.setRotation(getRotation());
}
} else // If screen, tell the screen the base exists
if (tileEntity instanceof TileLauncherScreen) {
this.launchScreen = (TileLauncherScreen) tileEntity;
}
}
}
}
}
use of icbm.classic.lib.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.
the class EntityMissile method getPredictedPosition.
public Pos getPredictedPosition(int t) {
Pos position = new Pos((IPos3D) this);
double tempMotionY = this.motionY;
if (this.ticksInAir > 20) {
for (int i = 0; i < t; i++) {
if (this.missileType.movesDirectly) {
position = position.add(this.motionVector);
} else {
position = position.add(motionX, tempMotionY - this.acceleration, motionZ);
}
}
}
return position;
}
use of icbm.classic.lib.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.
the class BlastGasBase method setEffectBoundsAndSpawnParticles.
private void setEffectBoundsAndSpawnParticles(int timePassed) {
final int maxSize = (int) Math.ceil(this.getBlastRadius());
// Get and validate radius
final int radius = (int) Math.floor(maxSize * sizePercentageOverTime(timePassed));
if (lastRadius == radius) {
return;
}
lastRadius = radius;
// Get radius sq for distance checks
final int currentDistanceSQ = radius * radius;
// Init path data
if (affectedBlocks.isEmpty()) {
affectedBlocks.add(getPos());
edgeBlocks.add(getPos());
}
if (edgeBlocks.isEmpty()) {
affectedBlocks.stream().filter((pos) -> Math.random() > 0.5).forEach(pos -> edgeBlocks.add(pos));
}
// Track blocks we pathed but didn't need
final HashSet<BlockPos> hasPathed = new HashSet();
// Track blocks we need to path next tick
final Queue<BlockPos> nextSet = new LinkedList();
// Loop edges from last tick
while (edgeBlocks.peek() != null) {
// Current edge block
final BlockPos edge = edgeBlocks.poll();
// Loop all 6 sides of the edge
for (EnumFacing facing : EnumFacing.values()) {
// Move our check pos to current target
checkPos.setPos(edge);
checkPos.move(facing);
// Don't repath
if (!hasPathed.contains(checkPos) && !affectedBlocks.contains(checkPos)) {
// Check that it is in range
if (isInRange(checkPos, currentDistanceSQ)) {
// Validate
if (isValidPath(checkPos)) {
final BlockPos pos = checkPos.toImmutable();
affectedBlocks.add(pos);
nextSet.add(pos);
spawnGasParticles(pos);
} else // Ignore if invalid
{
hasPathed.add(checkPos.toImmutable());
}
}
}
}
}
// Add next set to follow up queue
edgeBlocks.addAll(nextSet);
}
use of icbm.classic.lib.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.
the class Cube method subtract.
public Cube subtract(double x, double y, double z) {
if (isValid() && canEdit) {
pointOne = new Pos(pointOne.x() - x, pointOne.y() - y, pointOne.z() - z);
pointTwo = new Pos(pointTwo.x() - x, pointTwo.y() - y, pointTwo.z() - z);
recalc();
}
return this;
}
use of icbm.classic.lib.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.
the class Cube method cropToWorld.
/**
* Limits the cube to the world bounds
*
* @return this
*/
public Cube cropToWorld() {
Pos one = min();
Pos two = max();
if (min().y() < 0) {
one = new Pos(min().x(), 0, min().y());
}
if (max().y() > ICBMClassic.MAP_HEIGHT) {
two = new Pos(min().x(), ICBMClassic.MAP_HEIGHT, min().y());
}
set(one, two);
return this;
}
Aggregations