Search in sources :

Example 1 with IFuelDock

use of micdoodle8.mods.galacticraft.api.tile.IFuelDock in project Galacticraft by micdoodle8.

the class EntityAutoRocket method failRocket.

@Override
protected void failRocket() {
    this.stopRocketSound();
    if (this.shouldCancelExplosion()) {
        // TODO: it would be good to land on an alternative neighbouring pad if there is already a rocket on the target pad
        for (int i = -3; i <= 3; i++) {
            BlockPos pos = new BlockPos((int) Math.floor(this.posX), (int) Math.floor(this.posY + i), (int) Math.floor(this.posZ));
            if (this.launchPhase == EnumLaunchPhase.LANDING.ordinal() && this.targetVec != null && this.worldObj.getTileEntity(pos) instanceof IFuelDock && this.posY - this.targetVec.getY() < 5) {
                for (int x = MathHelper.floor_double(this.posX) - 1; x <= MathHelper.floor_double(this.posX) + 1; x++) {
                    for (int y = MathHelper.floor_double(this.posY - 3.0D); y <= MathHelper.floor_double(this.posY) + 1; y++) {
                        for (int z = MathHelper.floor_double(this.posZ) - 1; z <= MathHelper.floor_double(this.posZ) + 1; z++) {
                            BlockPos pos1 = new BlockPos(x, y, z);
                            TileEntity tile = this.worldObj.getTileEntity(pos1);
                            if (tile instanceof IFuelDock) {
                                this.landEntity(pos1);
                                return;
                            }
                        }
                    }
                }
            }
        }
    }
    if (this.launchPhase >= EnumLaunchPhase.LAUNCHED.ordinal()) {
        super.failRocket();
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IFuelDock(micdoodle8.mods.galacticraft.api.tile.IFuelDock)

Example 2 with IFuelDock

use of micdoodle8.mods.galacticraft.api.tile.IFuelDock in project Galacticraft by micdoodle8.

the class EntityAutoRocket method onUpdate.

@Override
public void onUpdate() {
    // Weird, huh?
    if (this.worldObj.isRemote && this.addedToChunk) {
        Chunk chunk = this.worldObj.getChunkFromChunkCoords(this.chunkCoordX, this.chunkCoordZ);
        int cx = MathHelper.floor_double(this.posX) >> 4;
        int cz = MathHelper.floor_double(this.posZ) >> 4;
        if (chunk.isChunkLoaded && this.chunkCoordX == cx && this.chunkCoordZ == cz) {
            boolean thisfound = false;
            ClassInheritanceMultiMap<Entity> mapEntities = chunk.getEntityLists()[this.chunkCoordY];
            for (Entity ent : mapEntities) {
                if (ent == this) {
                    thisfound = true;
                    break;
                }
            }
            if (!thisfound) {
                chunk.addEntity(this);
            }
        }
    }
    if (this.launchPhase == EnumLaunchPhase.LANDING.ordinal() && this.hasValidFuel()) {
        if (this.targetVec != null) {
            double yDiff = this.posY - this.getOnPadYOffset() - this.targetVec.getY();
            this.motionY = Math.max(-2.0, (yDiff - 0.04) / -55.0);
            // Some lateral motion in case not exactly on target (happens if rocket was moving laterally during launch)
            double diff = this.posX - this.targetVec.getX() - 0.5D;
            double motX, motZ;
            if (diff > 0D) {
                motX = Math.max(-0.1, diff / -100.0D);
            } else if (diff < 0D) {
                motX = Math.min(0.1, diff / -100.0D);
            } else
                motX = 0D;
            diff = this.posZ - this.targetVec.getZ() - 0.5D;
            if (diff > 0D) {
                motZ = Math.max(-0.1, diff / -100.0D);
            } else if (diff < 0D) {
                motZ = Math.min(0.1, diff / -100.0D);
            } else
                motZ = 0D;
            if (motZ != 0D || motX != 0D) {
                double angleYaw = Math.atan(motZ / motX);
                double signed = motX < 0 ? 50D : -50D;
                double anglePitch = Math.atan(Math.sqrt(motZ * motZ + motX * motX) / signed) * 100D;
                this.rotationYaw = (float) angleYaw * Constants.RADIANS_TO_DEGREES;
                this.rotationPitch = (float) anglePitch * Constants.RADIANS_TO_DEGREES;
            } else
                this.rotationPitch = 0F;
            if (yDiff > 1D && yDiff < 4D) {
                for (Object o : this.worldObj.getEntitiesInAABBexcluding(this, this.getEntityBoundingBox().offset(0D, -3D, 0D), EntitySpaceshipBase.rocketSelector)) {
                    if (o instanceof EntitySpaceshipBase) {
                        ((EntitySpaceshipBase) o).dropShipAsItem();
                        ((EntitySpaceshipBase) o).setDead();
                    }
                }
            }
            if (yDiff < 0.4) {
                int yMin = MathHelper.floor_double(this.getEntityBoundingBox().minY - this.getOnPadYOffset() - 0.45D) - 2;
                int yMax = MathHelper.floor_double(this.getEntityBoundingBox().maxY) + 1;
                int zMin = MathHelper.floor_double(this.posZ) - 1;
                int zMax = MathHelper.floor_double(this.posZ) + 1;
                for (int x = MathHelper.floor_double(this.posX) - 1; x <= MathHelper.floor_double(this.posX) + 1; x++) {
                    for (int z = zMin; z <= zMax; z++) {
                        // Doing y as the inner loop may help with cacheing of chunks
                        for (int y = yMin; y <= yMax; y++) {
                            if (this.worldObj.getTileEntity(new BlockPos(x, y, z)) instanceof IFuelDock) {
                                // Land the rocket on the pad found
                                this.rotationPitch = 0F;
                                this.failRocket();
                            }
                        }
                    }
                }
            }
        }
    }
    super.onUpdate();
    if (!this.worldObj.isRemote) {
        if (this.statusMessageCooldown > 0) {
            this.statusMessageCooldown--;
        }
        if (this.statusMessageCooldown == 0 && this.lastStatusMessageCooldown > 0 && this.statusValid) {
            this.autoLaunch();
        }
        if (this.autoLaunchCountdown > 0 && (!(this instanceof EntityTieredRocket) || this.riddenByEntity != null)) {
            if (--this.autoLaunchCountdown <= 0) {
                this.autoLaunch();
            }
        }
        if (this.autoLaunchSetting == EnumAutoLaunch.ROCKET_IS_FUELED && this.fuelTank.getFluidAmount() == this.fuelTank.getCapacity() && (!(this instanceof EntityTieredRocket) || this.riddenByEntity != null)) {
            this.autoLaunch();
        }
        if (this.autoLaunchSetting == EnumAutoLaunch.INSTANT) {
            if (this.autoLaunchCountdown == 0 && (!(this instanceof EntityTieredRocket) || this.riddenByEntity != null)) {
                this.autoLaunch();
            }
        }
        if (this.autoLaunchSetting == EnumAutoLaunch.REDSTONE_SIGNAL) {
            if (this.ticks % 11 == 0 && this.activeLaunchController != null) {
                if (RedstoneUtil.isBlockReceivingRedstone(this.worldObj, this.activeLaunchController.toBlockPos())) {
                    this.autoLaunch();
                }
            }
        }
        if (this.launchPhase >= EnumLaunchPhase.LAUNCHED.ordinal()) {
            this.setPad(null);
        } else {
            if (this.launchPhase == EnumLaunchPhase.UNIGNITED.ordinal() && this.landingPad != null && this.ticks % 17 == 0) {
                this.updateControllerSettings(this.landingPad);
            }
        }
        this.lastStatusMessageCooldown = this.statusMessageCooldown;
    }
    if (this.launchPhase >= EnumLaunchPhase.IGNITED.ordinal()) {
        if (this.rocketSoundUpdater != null) {
            this.rocketSoundUpdater.update();
            this.rocketSoundToStop = true;
        }
    } else {
        // Not ignited - either because not yet launched, or because it has landed
        if (this.rocketSoundToStop) {
            this.stopRocketSound();
            this.rocketSoundUpdater = null;
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) IFuelDock(micdoodle8.mods.galacticraft.api.tile.IFuelDock) Chunk(net.minecraft.world.chunk.Chunk)

Example 3 with IFuelDock

use of micdoodle8.mods.galacticraft.api.tile.IFuelDock in project Galacticraft by micdoodle8.

the class EntityAutoRocket method updateControllerSettings.

public void updateControllerSettings(IFuelDock dock) {
    HashSet<ILandingPadAttachable> connectedTiles = dock.getConnectedTiles();
    try {
        for (ILandingPadAttachable updatedTile : connectedTiles) {
            if (controllerClass.isInstance(updatedTile)) {
                // This includes a check for whether it has enough energy to run (if it doesn't, then a launch would not go to the destination frequency and the rocket would be lost!)
                Boolean autoLaunchEnabled = controllerClass.getField("controlEnabled").getBoolean(updatedTile);
                this.activeLaunchController = new BlockVec3((TileEntity) updatedTile);
                if (autoLaunchEnabled) {
                    this.autoLaunchSetting = EnumAutoLaunch.values()[controllerClass.getField("launchDropdownSelection").getInt(updatedTile)];
                    switch(this.autoLaunchSetting) {
                        case INSTANT:
                            // Small countdown to give player a moment to exit the Launch Controller GUI
                            if (this.autoLaunchCountdown <= 0 || this.autoLaunchCountdown > 12)
                                this.autoLaunchCountdown = 12;
                            break;
                        // TODO: if autoLaunchCountdown > 0 add some smoke (but not flame) particle effects or other pre-flight test feedback so the player knows something is happening
                        case TIME_10_SECONDS:
                            if (this.autoLaunchCountdown <= 0 || this.autoLaunchCountdown > 200)
                                this.autoLaunchCountdown = 200;
                            break;
                        case TIME_30_SECONDS:
                            if (this.autoLaunchCountdown <= 0 || this.autoLaunchCountdown > 600)
                                this.autoLaunchCountdown = 600;
                            break;
                        case TIME_1_MINUTE:
                            if (this.autoLaunchCountdown <= 0 || this.autoLaunchCountdown > 1200)
                                this.autoLaunchCountdown = 1200;
                            break;
                        default:
                            break;
                    }
                } else {
                    // This LaunchController is out of power, disabled, invalid target or set not to launch
                    // No auto launch - but maybe another connectedTile will have some launch settings?
                    this.autoLaunchSetting = null;
                    this.autoLaunchCountdown = 0;
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ILandingPadAttachable(micdoodle8.mods.galacticraft.api.tile.ILandingPadAttachable) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 4 with IFuelDock

use of micdoodle8.mods.galacticraft.api.tile.IFuelDock in project Galacticraft by micdoodle8.

the class EntityAutoRocket method landEntity.

@Override
public void landEntity(BlockPos pos) {
    TileEntity tile = this.worldObj.getTileEntity(pos);
    if (tile instanceof IFuelDock) {
        IFuelDock dock = (IFuelDock) tile;
        if (this.isDockValid(dock)) {
            if (!this.worldObj.isRemote) {
                // Drop any existing rocket on the landing pad
                if (dock.getDockedEntity() instanceof EntitySpaceshipBase && dock.getDockedEntity() != this) {
                    ((EntitySpaceshipBase) dock.getDockedEntity()).dropShipAsItem();
                    ((EntitySpaceshipBase) dock.getDockedEntity()).setDead();
                }
                this.setPad(dock);
            }
            this.onRocketLand(pos);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IFuelDock(micdoodle8.mods.galacticraft.api.tile.IFuelDock)

Aggregations

TileEntity (net.minecraft.tileentity.TileEntity)4 IFuelDock (micdoodle8.mods.galacticraft.api.tile.IFuelDock)3 ILandingPadAttachable (micdoodle8.mods.galacticraft.api.tile.ILandingPadAttachable)1 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)1 Entity (net.minecraft.entity.Entity)1 Chunk (net.minecraft.world.chunk.Chunk)1