Search in sources :

Example 1 with EntityPlayerSeat

use of icbm.classic.content.entity.EntityPlayerSeat 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;
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EntityPlayerSeat(icbm.classic.content.entity.EntityPlayerSeat) Pos(icbm.classic.lib.transform.vector.Pos) BlockPos(net.minecraft.util.math.BlockPos) TileLauncherFrame(icbm.classic.content.blocks.launcher.frame.TileLauncherFrame) EnumFacing(net.minecraft.util.EnumFacing) TileLauncherScreen(icbm.classic.content.blocks.launcher.screen.TileLauncherScreen)

Aggregations

TileLauncherFrame (icbm.classic.content.blocks.launcher.frame.TileLauncherFrame)1 TileLauncherScreen (icbm.classic.content.blocks.launcher.screen.TileLauncherScreen)1 EntityPlayerSeat (icbm.classic.content.entity.EntityPlayerSeat)1 Pos (icbm.classic.lib.transform.vector.Pos)1 TileEntity (net.minecraft.tileentity.TileEntity)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1