Search in sources :

Example 1 with EntityCelestialFake

use of micdoodle8.mods.galacticraft.core.entities.EntityCelestialFake in project Galacticraft by micdoodle8.

the class WorldUtil method teleportEntity.

private static Entity teleportEntity(World worldNew, Entity entity, int dimID, ITeleportType type, boolean transferInv, EntityAutoRocket ridingRocket) {
    Entity otherRiddenEntity = null;
    if (entity.ridingEntity != null) {
        if (entity.ridingEntity instanceof EntitySpaceshipBase) {
            entity.mountEntity(entity.ridingEntity);
        } else if (entity.ridingEntity instanceof EntityCelestialFake) {
            entity.ridingEntity.setDead();
            entity.mountEntity(null);
        } else {
            otherRiddenEntity = entity.ridingEntity;
            entity.mountEntity(null);
        }
    }
    boolean dimChange = entity.worldObj != worldNew;
    // Make sure the entity is added to the correct chunk in the OLD world so that it will be properly removed later if it needs to be unloaded from that world
    entity.worldObj.updateEntityWithOptionalForce(entity, false);
    EntityPlayerMP player = null;
    Vector3 spawnPos = null;
    int oldDimID = GCCoreUtil.getDimensionID(entity.worldObj);
    if (ridingRocket != null) {
        ArrayList<TileEntityTelemetry> tList = ridingRocket.getTelemetry();
        NBTTagCompound nbt = new NBTTagCompound();
        ridingRocket.isDead = false;
        ridingRocket.riddenByEntity = null;
        ridingRocket.writeToNBTOptional(nbt);
        ((WorldServer) ridingRocket.worldObj).getEntityTracker().untrackEntity(ridingRocket);
        removeEntityFromWorld(ridingRocket.worldObj, ridingRocket, true);
        ridingRocket = (EntityAutoRocket) EntityList.createEntityFromNBT(nbt, worldNew);
        if (ridingRocket != null) {
            ridingRocket.setWaitForPlayer(true);
            if (ridingRocket instanceof IWorldTransferCallback) {
                ((IWorldTransferCallback) ridingRocket).onWorldTransferred(worldNew);
            }
        }
    }
    if (dimChange) {
        if (entity instanceof EntityPlayerMP) {
            player = (EntityPlayerMP) entity;
            World worldOld = player.worldObj;
            GCPlayerStats stats = GCPlayerStats.get(player);
            stats.setUsingPlanetSelectionGui(false);
            player.dimension = dimID;
            if (ConfigManagerCore.enableDebug) {
                GCLog.info("DEBUG: Sending respawn packet to player for dim " + dimID);
            }
            player.playerNetServerHandler.sendPacket(new S07PacketRespawn(dimID, player.worldObj.getDifficulty(), player.worldObj.getWorldInfo().getTerrainType(), player.theItemInWorldManager.getGameType()));
            if (worldNew.provider instanceof WorldProviderSpaceStation) {
                if (WorldUtil.registeredSpaceStations.containsKey(dimID)) // TODO This has never been effective before due to the earlier bug - what does it actually do?
                {
                    NBTTagCompound var2 = new NBTTagCompound();
                    SpaceStationWorldData.getStationData(worldNew, dimID, player).writeToNBT(var2);
                    GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_UPDATE_SPACESTATION_DATA, GCCoreUtil.getDimensionID(player.worldObj), new Object[] { dimID, var2 }), player);
                }
            }
            removeEntityFromWorld(worldOld, player, true);
            if (ridingRocket != null) {
                spawnPos = new Vector3(ridingRocket);
            } else {
                spawnPos = type.getPlayerSpawnLocation((WorldServer) worldNew, player);
            }
            forceMoveEntityToPos(entity, (WorldServer) worldNew, spawnPos, true);
            GCLog.info("Server attempting to transfer player " + PlayerUtil.getName(player) + " to dimension " + GCCoreUtil.getDimensionID(worldNew));
            if (worldNew.provider instanceof WorldProviderSpaceStation) {
                GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_RESET_THIRD_PERSON, GCCoreUtil.getDimensionID(worldNew), new Object[] {}), player);
            }
            player.capabilities.isFlying = false;
            player.mcServer.getConfigurationManager().preparePlayer(player, (WorldServer) worldOld);
            player.theItemInWorldManager.setWorld((WorldServer) worldNew);
            player.mcServer.getConfigurationManager().updateTimeAndWeatherForPlayer(player, (WorldServer) worldNew);
            player.mcServer.getConfigurationManager().syncPlayerInventory(player);
            for (Object o : player.getActivePotionEffects()) {
                PotionEffect var10 = (PotionEffect) o;
                player.playerNetServerHandler.sendPacket(new S1DPacketEntityEffect(player.getEntityId(), var10));
            }
            player.playerNetServerHandler.sendPacket(new S1FPacketSetExperience(player.experience, player.experienceTotal, player.experienceLevel));
        } else // Non-player entity transfer i.e. it's an EntityCargoRocket or an empty rocket
        {
            ArrayList<TileEntityTelemetry> tList = null;
            if (entity instanceof EntitySpaceshipBase) {
                tList = ((EntitySpaceshipBase) entity).getTelemetry();
            }
            WorldUtil.removeEntityFromWorld(entity.worldObj, entity, true);
            NBTTagCompound nbt = new NBTTagCompound();
            entity.isDead = false;
            entity.writeToNBTOptional(nbt);
            entity = EntityList.createEntityFromNBT(nbt, worldNew);
            if (entity == null) {
                return null;
            }
            if (entity instanceof IWorldTransferCallback) {
                ((IWorldTransferCallback) entity).onWorldTransferred(worldNew);
            }
            forceMoveEntityToPos(entity, (WorldServer) worldNew, new Vector3(entity), true);
            if (tList != null && tList.size() > 0) {
                for (TileEntityTelemetry t : tList) {
                    t.addTrackedEntity(entity);
                }
            }
        }
    } else {
        // Same dimension player transfer
        if (entity instanceof EntityPlayerMP) {
            player = (EntityPlayerMP) entity;
            player.closeScreen();
            GCPlayerStats stats = GCPlayerStats.get(player);
            stats.setUsingPlanetSelectionGui(false);
            if (ridingRocket != null) {
                spawnPos = new Vector3(ridingRocket);
            } else {
                spawnPos = type.getPlayerSpawnLocation((WorldServer) entity.worldObj, (EntityPlayerMP) entity);
            }
            forceMoveEntityToPos(entity, (WorldServer) worldNew, spawnPos, false);
            GCLog.info("Server attempting to transfer player " + PlayerUtil.getName(player) + " within same dimension " + GCCoreUtil.getDimensionID(worldNew));
            if (worldNew.provider instanceof WorldProviderSpaceStation) {
                GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_RESET_THIRD_PERSON, GCCoreUtil.getDimensionID(worldNew), new Object[] {}), player);
            }
            player.capabilities.isFlying = false;
        }
    // Cargo rocket does not needs its location setting here, it will do that itself
    }
    // Update PlayerStatsGC
    if (player != null) {
        GCPlayerStats stats = GCPlayerStats.get(player);
        if (ridingRocket == null && type.useParachute() && stats.getExtendedInventory().getStackInSlot(4) != null && stats.getExtendedInventory().getStackInSlot(4).getItem() instanceof ItemParaChute) {
            GCPlayerHandler.setUsingParachute(player, stats, true);
        } else {
            GCPlayerHandler.setUsingParachute(player, stats, false);
        }
        if (stats.getRocketStacks() != null && stats.getRocketStacks().length > 0) {
            for (int stack = 0; stack < stats.getRocketStacks().length; stack++) {
                if (transferInv) {
                    if (stats.getRocketStacks()[stack] == null) {
                        if (stack == stats.getRocketStacks().length - 1) {
                            if (stats.getRocketItem() != null) {
                                stats.getRocketStacks()[stack] = new ItemStack(stats.getRocketItem(), 1, stats.getRocketType());
                            }
                        } else if (stack == stats.getRocketStacks().length - 2) {
                            stats.getRocketStacks()[stack] = stats.getLaunchpadStack();
                            stats.setLaunchpadStack(null);
                        }
                    }
                } else {
                    stats.getRocketStacks()[stack] = null;
                }
            }
        }
        if (transferInv && stats.getChestSpawnCooldown() == 0) {
            stats.setChestSpawnVector(type.getParaChestSpawnLocation((WorldServer) entity.worldObj, player, new Random()));
            stats.setChestSpawnCooldown(200);
        }
    }
    if (ridingRocket != null) {
        ridingRocket.forceSpawn = true;
        worldNew.spawnEntityInWorld(ridingRocket);
        ridingRocket.setWorld(worldNew);
        worldNew.updateEntityWithOptionalForce(ridingRocket, true);
        entity.mountEntity(ridingRocket);
        GCLog.debug("Entering rocket at : " + entity.posX + "," + entity.posZ + " rocket at: " + ridingRocket.posX + "," + ridingRocket.posZ);
    } else if (otherRiddenEntity != null) {
        if (dimChange) {
            World worldOld = otherRiddenEntity.worldObj;
            NBTTagCompound nbt = new NBTTagCompound();
            otherRiddenEntity.writeToNBTOptional(nbt);
            removeEntityFromWorld(worldOld, otherRiddenEntity, true);
            otherRiddenEntity = EntityList.createEntityFromNBT(nbt, worldNew);
            worldNew.spawnEntityInWorld(otherRiddenEntity);
            otherRiddenEntity.setWorld(worldNew);
        }
        otherRiddenEntity.setPositionAndRotation(entity.posX, entity.posY - 10, entity.posZ, otherRiddenEntity.rotationYaw, otherRiddenEntity.rotationPitch);
        worldNew.updateEntityWithOptionalForce(otherRiddenEntity, true);
    }
    if (entity instanceof EntityPlayerMP) {
        if (dimChange)
            FMLCommonHandler.instance().firePlayerChangedDimensionEvent((EntityPlayerMP) entity, oldDimID, dimID);
        // Spawn in a lander if appropriate
        type.onSpaceDimensionChanged(worldNew, (EntityPlayerMP) entity, ridingRocket != null);
    }
    return entity;
}
Also used : EntitySpaceshipBase(micdoodle8.mods.galacticraft.api.prefab.entity.EntitySpaceshipBase) Entity(net.minecraft.entity.Entity) TileEntityTelemetry(micdoodle8.mods.galacticraft.core.tile.TileEntityTelemetry) S07PacketRespawn(net.minecraft.network.play.server.S07PacketRespawn) PotionEffect(net.minecraft.potion.PotionEffect) EntityCelestialFake(micdoodle8.mods.galacticraft.core.entities.EntityCelestialFake) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) S1DPacketEntityEffect(net.minecraft.network.play.server.S1DPacketEntityEffect) PacketSimple(micdoodle8.mods.galacticraft.core.network.PacketSimple) Vector3(micdoodle8.mods.galacticraft.api.vector.Vector3) ItemParaChute(micdoodle8.mods.galacticraft.core.items.ItemParaChute) IWorldTransferCallback(micdoodle8.mods.galacticraft.api.entity.IWorldTransferCallback) WorldProviderSpaceStation(micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation) S1FPacketSetExperience(net.minecraft.network.play.server.S1FPacketSetExperience) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack)

Example 2 with EntityCelestialFake

use of micdoodle8.mods.galacticraft.core.entities.EntityCelestialFake in project Galacticraft by micdoodle8.

the class WorldUtil method toCelestialSelection.

public static void toCelestialSelection(EntityPlayerMP player, GCPlayerStats stats, int tier) {
    player.mountEntity(null);
    stats.setSpaceshipTier(tier);
    HashMap<String, Integer> map = WorldUtil.getArrayOfPossibleDimensions(tier, player);
    String dimensionList = "";
    int count = 0;
    for (Entry<String, Integer> entry : map.entrySet()) {
        dimensionList = dimensionList.concat(entry.getKey() + (count < map.entrySet().size() - 1 ? "?" : ""));
        count++;
    }
    GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_UPDATE_DIMENSION_LIST, GCCoreUtil.getDimensionID(player.worldObj), new Object[] { PlayerUtil.getName(player), dimensionList }), player);
    stats.setUsingPlanetSelectionGui(true);
    stats.setSavedPlanetList(dimensionList);
    Entity fakeEntity = new EntityCelestialFake(player.worldObj, player.posX, player.posY, player.posZ);
    player.worldObj.spawnEntityInWorld(fakeEntity);
    player.mountEntity(fakeEntity);
}
Also used : Entity(net.minecraft.entity.Entity) EntityCelestialFake(micdoodle8.mods.galacticraft.core.entities.EntityCelestialFake) PacketSimple(micdoodle8.mods.galacticraft.core.network.PacketSimple)

Example 3 with EntityCelestialFake

use of micdoodle8.mods.galacticraft.core.entities.EntityCelestialFake in project Galacticraft by micdoodle8.

the class GCPlayerHandler method checkOxygen.

protected void checkOxygen(EntityPlayerMP player, GCPlayerStats stats) {
    if ((player.dimension == 0 || player.worldObj.provider instanceof IGalacticraftWorldProvider) && (!(player.dimension == 0 || ((IGalacticraftWorldProvider) player.worldObj.provider).hasBreathableAtmosphere()) || player.posY > GCPlayerHandler.OXYGENHEIGHTLIMIT) && !player.capabilities.isCreativeMode && !(player.ridingEntity instanceof EntityLanderBase) && !(player.ridingEntity instanceof EntityAutoRocket) && !(player.ridingEntity instanceof EntityCelestialFake) && !CompatibilityManager.isAndroid(player)) {
        final ItemStack tankInSlot = stats.getExtendedInventory().getStackInSlot(2);
        final ItemStack tankInSlot2 = stats.getExtendedInventory().getStackInSlot(3);
        final int drainSpacing = OxygenUtil.getDrainSpacing(tankInSlot, tankInSlot2);
        if (tankInSlot == null) {
            stats.setAirRemaining(0);
        } else {
            stats.setAirRemaining(tankInSlot.getMaxDamage() - tankInSlot.getItemDamage());
        }
        if (tankInSlot2 == null) {
            stats.setAirRemaining2(0);
        } else {
            stats.setAirRemaining2(tankInSlot2.getMaxDamage() - tankInSlot2.getItemDamage());
        }
        if (drainSpacing > 0) {
            if ((player.ticksExisted - 1) % drainSpacing == 0 && !OxygenUtil.isAABBInBreathableAirBlock(player) && !stats.isUsingPlanetSelectionGui()) {
                int toTake = 1;
                // Take 1 oxygen from Tank 1
                if (stats.getAirRemaining() > 0) {
                    tankInSlot.damageItem(1, player);
                    stats.setAirRemaining(stats.getAirRemaining() - 1);
                    toTake = 0;
                }
                // Alternatively, take 1 oxygen from Tank 2
                if (toTake > 0 && stats.getAirRemaining2() > 0) {
                    tankInSlot2.damageItem(1, player);
                    stats.setAirRemaining2(stats.getAirRemaining2() - 1);
                    toTake = 0;
                }
            }
        } else {
            if ((player.ticksExisted - 1) % 60 == 0) {
                if (OxygenUtil.isAABBInBreathableAirBlock(player)) {
                    if (stats.getAirRemaining() < 90 && tankInSlot != null) {
                        stats.setAirRemaining(Math.min(stats.getAirRemaining() + 1, tankInSlot.getMaxDamage() - tankInSlot.getItemDamage()));
                    }
                    if (stats.getAirRemaining2() < 90 && tankInSlot2 != null) {
                        stats.setAirRemaining2(Math.min(stats.getAirRemaining2() + 1, tankInSlot2.getMaxDamage() - tankInSlot2.getItemDamage()));
                    }
                } else {
                    if (stats.getAirRemaining() > 0) {
                        stats.setAirRemaining(stats.getAirRemaining() - 1);
                    }
                    if (stats.getAirRemaining2() > 0) {
                        stats.setAirRemaining2(stats.getAirRemaining2() - 1);
                    }
                }
            }
        }
        final boolean airEmpty = stats.getAirRemaining() <= 0 && stats.getAirRemaining2() <= 0;
        if (player.isOnLadder()) {
            stats.setOxygenSetupValid(stats.isLastOxygenSetupValid());
        } else {
            stats.setOxygenSetupValid(!((!OxygenUtil.hasValidOxygenSetup(player) || airEmpty) && !OxygenUtil.isAABBInBreathableAirBlock(player)));
        }
        if (!player.worldObj.isRemote && player.isEntityAlive()) {
            if (!stats.isOxygenSetupValid()) {
                GCCoreOxygenSuffocationEvent suffocationEvent = new GCCoreOxygenSuffocationEvent.Pre(player);
                MinecraftForge.EVENT_BUS.post(suffocationEvent);
                if (!suffocationEvent.isCanceled()) {
                    if (stats.getDamageCounter() == 0) {
                        stats.setDamageCounter(ConfigManagerCore.suffocationCooldown);
                        player.attackEntityFrom(DamageSourceGC.oxygenSuffocation, ConfigManagerCore.suffocationDamage * (2 + stats.getIncrementalDamage()) / 2);
                        if (ConfigManagerCore.hardMode)
                            stats.setIncrementalDamage(stats.getIncrementalDamage() + 1);
                        GCCoreOxygenSuffocationEvent suffocationEventPost = new GCCoreOxygenSuffocationEvent.Post(player);
                        MinecraftForge.EVENT_BUS.post(suffocationEventPost);
                    }
                } else
                    stats.setOxygenSetupValid(true);
            } else
                stats.setIncrementalDamage(0);
        }
    } else if ((player.ticksExisted - 1) % 20 == 0 && !player.capabilities.isCreativeMode && stats.getAirRemaining() < 90) {
        stats.setAirRemaining(stats.getAirRemaining() + 1);
        stats.setAirRemaining2(stats.getAirRemaining2() + 1);
    } else if (player.capabilities.isCreativeMode) {
        stats.setAirRemaining(90);
        stats.setAirRemaining2(90);
    } else {
        stats.setOxygenSetupValid(true);
    }
}
Also used : EntityLanderBase(micdoodle8.mods.galacticraft.core.entities.EntityLanderBase) IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) EntityCelestialFake(micdoodle8.mods.galacticraft.core.entities.EntityCelestialFake) GCCoreOxygenSuffocationEvent(micdoodle8.mods.galacticraft.api.event.oxygen.GCCoreOxygenSuffocationEvent) EntityAutoRocket(micdoodle8.mods.galacticraft.api.prefab.entity.EntityAutoRocket) ItemStack(net.minecraft.item.ItemStack) TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint) Footprint(micdoodle8.mods.galacticraft.core.wrappers.Footprint)

Aggregations

EntityCelestialFake (micdoodle8.mods.galacticraft.core.entities.EntityCelestialFake)3 PacketSimple (micdoodle8.mods.galacticraft.core.network.PacketSimple)2 Entity (net.minecraft.entity.Entity)2 ItemStack (net.minecraft.item.ItemStack)2 IWorldTransferCallback (micdoodle8.mods.galacticraft.api.entity.IWorldTransferCallback)1 GCCoreOxygenSuffocationEvent (micdoodle8.mods.galacticraft.api.event.oxygen.GCCoreOxygenSuffocationEvent)1 EntityAutoRocket (micdoodle8.mods.galacticraft.api.prefab.entity.EntityAutoRocket)1 EntitySpaceshipBase (micdoodle8.mods.galacticraft.api.prefab.entity.EntitySpaceshipBase)1 Vector3 (micdoodle8.mods.galacticraft.api.vector.Vector3)1 IGalacticraftWorldProvider (micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider)1 WorldProviderSpaceStation (micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation)1 EntityLanderBase (micdoodle8.mods.galacticraft.core.entities.EntityLanderBase)1 GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)1 ItemParaChute (micdoodle8.mods.galacticraft.core.items.ItemParaChute)1 TileEntityTelemetry (micdoodle8.mods.galacticraft.core.tile.TileEntityTelemetry)1 Footprint (micdoodle8.mods.galacticraft.core.wrappers.Footprint)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 S07PacketRespawn (net.minecraft.network.play.server.S07PacketRespawn)1 S1DPacketEntityEffect (net.minecraft.network.play.server.S1DPacketEntityEffect)1