Search in sources :

Example 1 with EntitySpaceshipBase

use of micdoodle8.mods.galacticraft.api.prefab.entity.EntitySpaceshipBase in project Galacticraft by micdoodle8.

the class KeyHandlerClient method keyDown.

@Override
public void keyDown(Type types, KeyBinding kb, boolean tickEnd, boolean isRepeat) {
    if (KeyHandlerClient.mc.thePlayer != null && tickEnd) {
        EntityPlayerSP playerBase = PlayerUtil.getPlayerBaseClientFromPlayer(KeyHandlerClient.mc.thePlayer, false);
        if (playerBase == null) {
            return;
        }
        GCPlayerStatsClient stats = GCPlayerStatsClient.get(playerBase);
        if (kb.getKeyCode() == KeyHandlerClient.galaxyMap.getKeyCode()) {
            if (KeyHandlerClient.mc.currentScreen == null) {
                KeyHandlerClient.mc.thePlayer.openGui(GalacticraftCore.instance, GuiIdsCore.GALAXY_MAP, KeyHandlerClient.mc.theWorld, (int) KeyHandlerClient.mc.thePlayer.posX, (int) KeyHandlerClient.mc.thePlayer.posY, (int) KeyHandlerClient.mc.thePlayer.posZ);
            }
        } else if (kb.getKeyCode() == KeyHandlerClient.openFuelGui.getKeyCode()) {
            if (playerBase.ridingEntity instanceof EntitySpaceshipBase || playerBase.ridingEntity instanceof EntityBuggy) {
                GalacticraftCore.packetPipeline.sendToServer(new PacketSimple(EnumSimplePacket.S_OPEN_FUEL_GUI, GCCoreUtil.getDimensionID(mc.theWorld), new Object[] { PlayerUtil.getName(playerBase) }));
            }
        } else if (kb.getKeyCode() == KeyHandlerClient.toggleAdvGoggles.getKeyCode()) {
            if (playerBase != null) {
                stats.setUsingAdvancedGoggles(!stats.isUsingAdvancedGoggles());
            }
        }
    }
    if (KeyHandlerClient.mc.thePlayer != null && KeyHandlerClient.mc.currentScreen == null) {
        int keyNum = -1;
        if (kb == KeyHandlerClient.accelerateKey) {
            keyNum = 0;
        } else if (kb == KeyHandlerClient.decelerateKey) {
            keyNum = 1;
        } else if (kb == KeyHandlerClient.leftKey) {
            keyNum = 2;
        } else if (kb == KeyHandlerClient.rightKey) {
            keyNum = 3;
        } else if (kb == KeyHandlerClient.spaceKey) {
            keyNum = 4;
        } else if (kb == KeyHandlerClient.leftShiftKey) {
            keyNum = 5;
        }
        Entity entityTest = KeyHandlerClient.mc.thePlayer.ridingEntity;
        if (entityTest != null && entityTest instanceof IControllableEntity && keyNum != -1) {
            IControllableEntity entity = (IControllableEntity) entityTest;
            if (kb.getKeyCode() == KeyHandlerClient.mc.gameSettings.keyBindInventory.getKeyCode()) {
                KeyBinding.setKeyBindState(KeyHandlerClient.mc.gameSettings.keyBindInventory.getKeyCode(), false);
            }
            entity.pressKey(keyNum);
        } else if (entityTest != null && entityTest instanceof EntityAutoRocket) {
            EntityAutoRocket autoRocket = (EntityAutoRocket) entityTest;
            if (autoRocket.launchPhase == EnumLaunchPhase.LANDING.ordinal()) {
                if (kb == KeyHandlerClient.leftShiftKey) {
                    autoRocket.motionY -= 0.02D;
                    GalacticraftCore.packetPipeline.sendToServer(new PacketSimple(EnumSimplePacket.S_UPDATE_SHIP_MOTION_Y, GCCoreUtil.getDimensionID(mc.theWorld), new Object[] { autoRocket.getEntityId(), false }));
                }
                if (kb == KeyHandlerClient.spaceKey) {
                    autoRocket.motionY += 0.02D;
                    GalacticraftCore.packetPipeline.sendToServer(new PacketSimple(EnumSimplePacket.S_UPDATE_SHIP_MOTION_Y, GCCoreUtil.getDimensionID(mc.theWorld), new Object[] { autoRocket.getEntityId(), true }));
                }
            }
        }
    }
}
Also used : EntitySpaceshipBase(micdoodle8.mods.galacticraft.api.prefab.entity.EntitySpaceshipBase) Entity(net.minecraft.entity.Entity) IControllableEntity(micdoodle8.mods.galacticraft.core.entities.IControllableEntity) EntityBuggy(micdoodle8.mods.galacticraft.core.entities.EntityBuggy) GCPlayerStatsClient(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStatsClient) IControllableEntity(micdoodle8.mods.galacticraft.core.entities.IControllableEntity) PacketSimple(micdoodle8.mods.galacticraft.core.network.PacketSimple) EntityAutoRocket(micdoodle8.mods.galacticraft.api.prefab.entity.EntityAutoRocket) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP)

Example 2 with EntitySpaceshipBase

use of micdoodle8.mods.galacticraft.api.prefab.entity.EntitySpaceshipBase 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 EntitySpaceshipBase

use of micdoodle8.mods.galacticraft.api.prefab.entity.EntitySpaceshipBase 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)

Example 4 with EntitySpaceshipBase

use of micdoodle8.mods.galacticraft.api.prefab.entity.EntitySpaceshipBase in project Galacticraft by micdoodle8.

the class FreefallHandler method testFreefall.

@SideOnly(Side.CLIENT)
private boolean testFreefall(EntityPlayerSP p, boolean flag) {
    World world = p.worldObj;
    WorldProvider worldProvider = world.provider;
    if (!(worldProvider instanceof IZeroGDimension)) {
        return false;
    }
    ZeroGravityEvent zeroGEvent = new ZeroGravityEvent.InFreefall(p);
    MinecraftForge.EVENT_BUS.post(zeroGEvent);
    if (zeroGEvent.isCanceled()) {
        return false;
    }
    if (this.pjumpticks > 0 || (stats.isSsOnGroundLast() && p.movementInput.jump)) {
        return false;
    }
    if (p.ridingEntity != null) {
        Entity e = p.ridingEntity;
        if (e instanceof EntitySpaceshipBase) {
            return ((EntitySpaceshipBase) e).getLaunched();
        }
        if (e instanceof EntityLanderBase) {
            return false;
        }
    // TODO: should check whether lander has landed (whatever that means)
    // TODO: could check other ridden entities - every entity should have its own freefall check :(
    }
    // This is an "on the ground" check
    if (!flag) {
        return false;
    } else {
        float rY = p.rotationYaw % 360F;
        double zreach = 0D;
        double xreach = 0D;
        if (rY < 80F || rY > 280F) {
            zreach = 0.2D;
        }
        if (rY < 170F && rY > 10F) {
            xreach = 0.2D;
        }
        if (rY < 260F && rY > 100F) {
            zreach = -0.2D;
        }
        if (rY < 350F && rY > 190F) {
            xreach = -0.2D;
        }
        AxisAlignedBB playerReach = p.getEntityBoundingBox().addCoord(xreach, 0, zreach);
        boolean checkBlockWithinReach;
        if (worldProvider instanceof WorldProviderSpaceStation) {
            SpinManager spinManager = ((WorldProviderSpaceStation) worldProvider).getSpinManager();
            checkBlockWithinReach = playerReach.maxX >= spinManager.ssBoundsMinX && playerReach.minX <= spinManager.ssBoundsMaxX && playerReach.maxY >= spinManager.ssBoundsMinY && playerReach.minY <= spinManager.ssBoundsMaxY && playerReach.maxZ >= spinManager.ssBoundsMinZ && playerReach.minZ <= spinManager.ssBoundsMaxZ;
        // Player is somewhere within the space station boundaries
        } else {
            checkBlockWithinReach = true;
        }
        if (checkBlockWithinReach) {
            // Check if the player's bounding box is in the same block coordinates as any non-vacuum block (including torches etc)
            // If so, it's assumed the player has something close enough to grab onto, so is not in freefall
            // Note: breatheable air here means the player is definitely not in freefall
            int xm = MathHelper.floor_double(playerReach.minX);
            int xx = MathHelper.floor_double(playerReach.maxX);
            int ym = MathHelper.floor_double(playerReach.minY);
            int yy = MathHelper.floor_double(playerReach.maxY);
            int zm = MathHelper.floor_double(playerReach.minZ);
            int zz = MathHelper.floor_double(playerReach.maxZ);
            for (int x = xm; x <= xx; x++) {
                for (int y = ym; y <= yy; y++) {
                    for (int z = zm; z <= zz; z++) {
                        // Blocks.air is hard vacuum - we want to check for that, here
                        Block b = world.getBlockState(new BlockPos(x, y, z)).getBlock();
                        if (Blocks.air != b && GCBlocks.brightAir != b) {
                            this.onWall = true;
                            return false;
                        }
                    }
                }
            }
        }
    }
    /*
        if (freefall)
        {
            //If that check didn't produce a result, see if the player is inside the walls
            //TODO: could apply special weightless movement here like Coriolis force - the player is inside the walls,  not touching them, and in a vacuum
            int quadrant = 0;
            double xd = p.posX - this.spinCentreX;
            double zd = p.posZ - this.spinCentreZ;
            if (xd<0)
            {
                if (xd<-Math.abs(zd))
                {
                    quadrant = 2;
                } else
                    quadrant = (zd<0) ? 3 : 1;
            } else
                if (xd>Math.abs(zd))
                {
                    quadrant = 0;
                } else
                    quadrant = (zd<0) ? 3 : 1;

            int ymin = MathHelper.floor_double(p.boundingBox.minY)-1;
            int ymax = MathHelper.floor_double(p.boundingBox.maxY);
            int xmin, xmax, zmin, zmax;

            switch (quadrant)
            {
            case 0:
                xmin = MathHelper.floor_double(p.boundingBox.maxX);
                xmax = this.ssBoundsMaxX - 1;
                zmin = MathHelper.floor_double(p.boundingBox.minZ)-1;
                zmax = MathHelper.floor_double(p.boundingBox.maxZ)+1;
                break;
            case 1:
                xmin = MathHelper.floor_double(p.boundingBox.minX)-1;
                xmax = MathHelper.floor_double(p.boundingBox.maxX)+1;
                zmin = MathHelper.floor_double(p.boundingBox.maxZ);
                zmax = this.ssBoundsMaxZ - 1;
                break;
            case 2:
                zmin = MathHelper.floor_double(p.boundingBox.minZ)-1;
                zmax = MathHelper.floor_double(p.boundingBox.maxZ)+1;
                xmin = this.ssBoundsMinX;
                xmax = MathHelper.floor_double(p.boundingBox.minX);
                break;
            case 3:
            default:
                xmin = MathHelper.floor_double(p.boundingBox.minX)-1;
                xmax = MathHelper.floor_double(p.boundingBox.maxX)+1;
                zmin = this.ssBoundsMinZ;
                zmax = MathHelper.floor_double(p.boundingBox.minZ);
                break;
            }

            //This block search could cost a lot of CPU (but client side) - maybe optimise later
            BLOCKCHECK0:
            for(int x = xmin; x <= xmax; x++)
                for (int z = zmin; z <= zmax; z++)
                    for (int y = ymin; y <= ymax; y++)
                        if (Blocks.air != this.worldProvider.worldObj.getBlock(x, y, z))
                        {
                            freefall = false;
                            break BLOCKCHECK0;
                        }
        }*/
    this.onWall = false;
    return true;
}
Also used : ZeroGravityEvent(micdoodle8.mods.galacticraft.api.event.ZeroGravityEvent) EntitySpaceshipBase(micdoodle8.mods.galacticraft.api.prefab.entity.EntitySpaceshipBase) AxisAlignedBB(net.minecraft.util.AxisAlignedBB) Entity(net.minecraft.entity.Entity) World(net.minecraft.world.World) SpinManager(micdoodle8.mods.galacticraft.core.dimension.SpinManager) EntityLanderBase(micdoodle8.mods.galacticraft.core.entities.EntityLanderBase) WorldProviderSpaceStation(micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation) WorldProvider(net.minecraft.world.WorldProvider) EntityFallingBlock(net.minecraft.entity.item.EntityFallingBlock) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.BlockPos) IZeroGDimension(micdoodle8.mods.galacticraft.api.world.IZeroGDimension) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 5 with EntitySpaceshipBase

use of micdoodle8.mods.galacticraft.api.prefab.entity.EntitySpaceshipBase in project Galacticraft by micdoodle8.

the class GCEntityClientPlayerMP method getLocationCape.

// 
// @Override
// @SideOnly(Side.CLIENT)
// public void setVelocity(double xx, double yy, double zz)
// {
// if (this.worldObj.provider instanceof WorldProviderOrbit)
// {
// ((WorldProviderOrbit)this.worldObj.provider).setVelocityClient(this, xx, yy, zz);
// }
// super.setVelocity(xx, yy, zz);
// }
// 
/*@Override
    public void setInPortal()
    {
    	if (!(this.worldObj.provider instanceof IGalacticraftWorldProvider))
    	{
    		super.setInPortal();
    	}
    } TODO Fix disable of portal */
@Override
public ResourceLocation getLocationCape() {
    if (this.ridingEntity instanceof EntitySpaceshipBase) {
        // Don't draw any cape if riding a rocket (the cape renders outside the rocket model!)
        return null;
    }
    ResourceLocation vanillaCape = super.getLocationCape();
    if (!this.checkedCape) {
        NetworkPlayerInfo networkplayerinfo = this.getPlayerInfo();
        this.galacticraftCape = ClientProxyCore.capeMap.get(networkplayerinfo.getGameProfile().getName());
        this.checkedCape = true;
    }
    if ((ConfigManagerCore.overrideCapes || vanillaCape == null) && galacticraftCape != null) {
        return galacticraftCape;
    }
    return vanillaCape;
}
Also used : EntitySpaceshipBase(micdoodle8.mods.galacticraft.api.prefab.entity.EntitySpaceshipBase) NetworkPlayerInfo(net.minecraft.client.network.NetworkPlayerInfo) ResourceLocation(net.minecraft.util.ResourceLocation)

Aggregations

EntitySpaceshipBase (micdoodle8.mods.galacticraft.api.prefab.entity.EntitySpaceshipBase)10 Entity (net.minecraft.entity.Entity)5 EntityPlayerSP (net.minecraft.client.entity.EntityPlayerSP)4 EntityAutoRocket (micdoodle8.mods.galacticraft.api.prefab.entity.EntityAutoRocket)3 WorldProviderSpaceStation (micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation)3 Footprint (micdoodle8.mods.galacticraft.core.wrappers.Footprint)3 TileEntity (net.minecraft.tileentity.TileEntity)3 BlockPos (net.minecraft.util.BlockPos)3 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)3 IFuelDock (micdoodle8.mods.galacticraft.api.tile.IFuelDock)2 Vector3 (micdoodle8.mods.galacticraft.api.vector.Vector3)2 IGalacticraftWorldProvider (micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider)2 EntityBuggy (micdoodle8.mods.galacticraft.core.entities.EntityBuggy)2 IControllableEntity (micdoodle8.mods.galacticraft.core.entities.IControllableEntity)2 GCPlayerStatsClient (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStatsClient)2 FluidNetwork (micdoodle8.mods.galacticraft.core.fluid.FluidNetwork)2 PacketSimple (micdoodle8.mods.galacticraft.core.network.PacketSimple)2 Minecraft (net.minecraft.client.Minecraft)2 NetworkPlayerInfo (net.minecraft.client.network.NetworkPlayerInfo)2 ResourceLocation (net.minecraft.util.ResourceLocation)2