Search in sources :

Example 1 with EventLandingPadRemoval

use of micdoodle8.mods.galacticraft.core.event.EventLandingPadRemoval in project Galacticraft by micdoodle8.

the class EntityAutoRocket method onLaunch.

@Override
public void onLaunch() {
    if (!(this.worldObj.provider.getDimensionId() == GalacticraftCore.planetOverworld.getDimensionID() || this.worldObj.provider instanceof IGalacticraftWorldProvider)) {
        if (ConfigManagerCore.disableRocketLaunchAllNonGC) {
            this.cancelLaunch();
            return;
        }
        // No rocket flight in the Nether, the End etc
        for (int i = ConfigManagerCore.disableRocketLaunchDimensions.length - 1; i >= 0; i--) {
            if (ConfigManagerCore.disableRocketLaunchDimensions[i] == this.worldObj.provider.getDimensionId()) {
                this.cancelLaunch();
                return;
            }
        }
    }
    super.onLaunch();
    if (!this.worldObj.isRemote) {
        GCPlayerStats stats = null;
        if (this.riddenByEntity != null && this.riddenByEntity instanceof EntityPlayerMP) {
            stats = GCPlayerStats.get(this.riddenByEntity);
            if (!(this.worldObj.provider instanceof IOrbitDimension)) {
                stats.setCoordsTeleportedFromX(this.riddenByEntity.posX);
                stats.setCoordsTeleportedFromZ(this.riddenByEntity.posZ);
            }
        }
        int amountRemoved = 0;
        PADSEARCH: 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; 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 pos = new BlockPos(x, y, z);
                    final Block block = this.worldObj.getBlockState(pos).getBlock();
                    if (block != null && block instanceof BlockLandingPadFull) {
                        if (amountRemoved < 9) {
                            EventLandingPadRemoval event = new EventLandingPadRemoval(this.worldObj, pos);
                            MinecraftForge.EVENT_BUS.post(event);
                            if (event.allow) {
                                this.worldObj.setBlockToAir(pos);
                                amountRemoved = 9;
                            }
                            break PADSEARCH;
                        }
                    }
                }
            }
        }
        // Set the player's launchpad item for return on landing - or null if launchpads not removed
        if (stats != null) {
            stats.setLaunchpadStack(amountRemoved == 9 ? new ItemStack(GCBlocks.landingPad, 9, 0) : null);
        }
        this.playSound("random.pop", 0.2F, ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
    }
}
Also used : IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) EventLandingPadRemoval(micdoodle8.mods.galacticraft.core.event.EventLandingPadRemoval) Block(net.minecraft.block.Block) BlockLandingPadFull(micdoodle8.mods.galacticraft.core.blocks.BlockLandingPadFull) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) IOrbitDimension(micdoodle8.mods.galacticraft.api.world.IOrbitDimension) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IGalacticraftWorldProvider (micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider)1 IOrbitDimension (micdoodle8.mods.galacticraft.api.world.IOrbitDimension)1 BlockLandingPadFull (micdoodle8.mods.galacticraft.core.blocks.BlockLandingPadFull)1 GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)1 EventLandingPadRemoval (micdoodle8.mods.galacticraft.core.event.EventLandingPadRemoval)1 Block (net.minecraft.block.Block)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 ItemStack (net.minecraft.item.ItemStack)1