use of icbm.classic.content.blocks.launcher.frame.TileLauncherFrame 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;
}
}
}
}
}
Aggregations