use of micdoodle8.mods.galacticraft.api.world.ITeleportType 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;
}
use of micdoodle8.mods.galacticraft.api.world.ITeleportType in project Galacticraft by micdoodle8.
the class WorldUtil method transferEntityToDimension.
/**
* It is not necessary to use entity.setDead() following calling this method.
* If the entity left the old world it was in, it will now automatically be removed from that old world before the next update tick.
* (See WorldUtil.removeEntityFromWorld())
*/
public static Entity transferEntityToDimension(Entity entity, int dimensionID, WorldServer world, boolean transferInv, EntityAutoRocket ridingRocket) {
if (!world.isRemote) {
// GalacticraftCore.packetPipeline.sendToAll(new PacketSimple(EnumSimplePacket.C_UPDATE_PLANETS_LIST, WorldUtil.getPlanetList()));
MinecraftServer mcServer = world.getMinecraftServer();
if (mcServer != null) {
final WorldServer var6 = mcServer.worldServerForDimension(dimensionID);
if (var6 == null) {
System.err.println("Cannot Transfer Entity to Dimension: Could not get World for Dimension " + dimensionID);
return null;
}
final ITeleportType type = GalacticraftRegistry.getTeleportTypeForDimension(var6.provider.getClass());
if (type != null) {
return WorldUtil.teleportEntity(var6, entity, dimensionID, type, transferInv, ridingRocket);
}
}
}
return null;
}
use of micdoodle8.mods.galacticraft.api.world.ITeleportType in project Galacticraft by micdoodle8.
the class GCPlayerHandler method onPlayerUpdate.
public void onPlayerUpdate(EntityPlayerMP player) {
int tick = player.ticksExisted - 1;
// This will speed things up a little
GCPlayerStats stats = GCPlayerStats.get(player);
if ((ConfigManagerCore.challengeSpawnHandling) && stats.getUnlockedSchematics().size() == 0) {
if (stats.getStartDimension().length() > 0) {
stats.setStartDimension("");
} else {
// PlayerAPI is installed
WorldServer worldOld = (WorldServer) player.worldObj;
try {
worldOld.getPlayerManager().removePlayer(player);
} catch (Exception e) {
}
worldOld.playerEntities.remove(player);
worldOld.updateAllPlayersSleepingFlag();
worldOld.loadedEntityList.remove(player);
worldOld.onEntityRemoved(player);
worldOld.getEntityTracker().untrackEntity(player);
if (player.addedToChunk && worldOld.getChunkProvider().chunkExists(player.chunkCoordX, player.chunkCoordZ)) {
Chunk chunkOld = worldOld.getChunkFromChunkCoords(player.chunkCoordX, player.chunkCoordZ);
chunkOld.removeEntity(player);
chunkOld.setChunkModified();
}
WorldServer worldNew = WorldUtil.getStartWorld(worldOld);
int dimID = GCCoreUtil.getDimensionID(worldNew);
player.dimension = dimID;
GCLog.debug("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) {
GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_RESET_THIRD_PERSON, GCCoreUtil.getDimensionID(player.worldObj), new Object[] {}), player);
}
worldNew.spawnEntityInWorld(player);
player.setWorld(worldNew);
player.mcServer.getConfigurationManager().preparePlayer(player, (WorldServer) worldOld);
}
// This is a mini version of the code at WorldUtil.teleportEntity
player.theItemInWorldManager.setWorld((WorldServer) player.worldObj);
final ITeleportType type = GalacticraftRegistry.getTeleportTypeForDimension(player.worldObj.provider.getClass());
Vector3 spawnPos = type.getPlayerSpawnLocation((WorldServer) player.worldObj, player);
ChunkCoordIntPair pair = player.worldObj.getChunkFromChunkCoords(spawnPos.intX() >> 4, spawnPos.intZ() >> 4).getChunkCoordIntPair();
GCLog.debug("Loading first chunk in new dimension.");
((WorldServer) player.worldObj).theChunkProviderServer.loadChunk(pair.chunkXPos, pair.chunkZPos);
player.setLocationAndAngles(spawnPos.x, spawnPos.y, spawnPos.z, player.rotationYaw, player.rotationPitch);
type.setupAdventureSpawn(player);
type.onSpaceDimensionChanged(player.worldObj, player, false);
player.setSpawnChunk(new BlockPos(spawnPos.intX(), spawnPos.intY(), spawnPos.intZ()), true, GCCoreUtil.getDimensionID(player.worldObj));
stats.setNewAdventureSpawn(true);
}
final boolean isInGCDimension = player.worldObj.provider instanceof IGalacticraftWorldProvider;
if (tick >= 25) {
if (ConfigManagerCore.enableSpaceRaceManagerPopup && !stats.hasOpenedSpaceRaceManager()) {
SpaceRace race = SpaceRaceManager.getSpaceRaceFromPlayer(PlayerUtil.getName(player));
if (race == null || race.teamName.equals(SpaceRace.DEFAULT_NAME)) {
GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_OPEN_SPACE_RACE_GUI, GCCoreUtil.getDimensionID(player.worldObj), new Object[] {}), player);
}
stats.setOpenedSpaceRaceManager(true);
}
if (!stats.hasSentFlags()) {
GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_UPDATE_STATS, GCCoreUtil.getDimensionID(player.worldObj), stats.getMiscNetworkedStats()), player);
stats.setSentFlags(true);
}
}
if (stats.getCryogenicChamberCooldown() > 0) {
stats.setCryogenicChamberCooldown(stats.getCryogenicChamberCooldown() - 1);
}
if (!player.onGround && stats.isLastOnGround()) {
stats.setTouchedGround(true);
}
if (stats.getTeleportCooldown() > 0) {
stats.setTeleportCooldown(stats.getTeleportCooldown() - 1);
}
if (stats.getChatCooldown() > 0) {
stats.setChatCooldown(stats.getChatCooldown() - 1);
}
if (stats.getOpenPlanetSelectionGuiCooldown() > 0) {
stats.setOpenPlanetSelectionGuiCooldown(stats.getOpenPlanetSelectionGuiCooldown() - 1);
if (stats.getOpenPlanetSelectionGuiCooldown() == 1 && !stats.hasOpenedPlanetSelectionGui()) {
WorldUtil.toCelestialSelection(player, stats, stats.getSpaceshipTier());
stats.setHasOpenedPlanetSelectionGui(true);
}
}
if (stats.isUsingParachute()) {
if (stats.getLastParachuteInSlot() != null) {
player.fallDistance = 0.0F;
}
if (player.onGround) {
GCPlayerHandler.setUsingParachute(player, stats, false);
}
}
this.checkCurrentItem(player);
if (stats.isUsingPlanetSelectionGui()) {
// This sends the planets list again periodically (forcing the Celestial Selection screen to open) in case of server/client lag
// #PACKETSPAM
this.sendPlanetList(player, stats);
}
/* if (isInGCDimension || player.usingPlanetSelectionGui)
{
player.playerNetServerHandler.ticksForFloatKick = 0;
}
*/
if (stats.getDamageCounter() > 0) {
stats.setDamageCounter(stats.getDamageCounter() - 1);
}
if (isInGCDimension) {
if (tick % 10 == 0) {
boolean doneDungeon = false;
ItemStack current = player.inventory.getCurrentItem();
if (current != null && current.getItem() == GCItems.dungeonFinder) {
this.sendDungeonDirectionPacket(player, stats);
doneDungeon = true;
}
if (tick % 30 == 0) {
GCPlayerHandler.sendAirRemainingPacket(player, stats);
this.sendThermalLevelPacket(player, stats);
if (!doneDungeon) {
for (ItemStack stack : player.inventory.mainInventory) {
if (stack != null && stack.getItem() == GCItems.dungeonFinder) {
this.sendDungeonDirectionPacket(player, stats);
break;
}
}
}
}
}
if (player.ridingEntity instanceof EntityLanderBase) {
stats.setInLander(true);
stats.setJustLanded(false);
} else {
if (stats.isInLander()) {
stats.setJustLanded(true);
}
stats.setInLander(false);
}
if (player.onGround && stats.hasJustLanded()) {
stats.setJustLanded(false);
// Set spawn point here if just descended from a lander for the first time
if (player.getBedLocation(GCCoreUtil.getDimensionID(player.worldObj)) == null || stats.isNewAdventureSpawn()) {
int i = 30000000;
int j = Math.min(i, Math.max(-i, MathHelper.floor_double(player.posX + 0.5D)));
int k = Math.min(256, Math.max(0, MathHelper.floor_double(player.posY + 1.5D)));
int l = Math.min(i, Math.max(-i, MathHelper.floor_double(player.posZ + 0.5D)));
BlockPos coords = new BlockPos(j, k, l);
player.setSpawnChunk(coords, true, GCCoreUtil.getDimensionID(player.worldObj));
stats.setNewAdventureSpawn(false);
}
GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_RESET_THIRD_PERSON, GCCoreUtil.getDimensionID(player.worldObj), new Object[] {}), player);
}
if (player.worldObj.provider instanceof WorldProviderSpaceStation || player.worldObj.provider instanceof IZeroGDimension || GalacticraftCore.isPlanetsLoaded && player.worldObj.provider instanceof WorldProviderAsteroids) {
this.preventFlyingKicks(player);
if (player.worldObj.provider instanceof WorldProviderSpaceStation && stats.isNewInOrbit()) {
((WorldProviderSpaceStation) player.worldObj.provider).getSpinManager().sendPackets(player);
stats.setNewInOrbit(false);
}
} else {
stats.setNewInOrbit(true);
}
} else {
stats.setNewInOrbit(true);
}
checkGear(player, stats, false);
if (stats.getChestSpawnCooldown() > 0) {
stats.setChestSpawnCooldown(stats.getChestSpawnCooldown() - 1);
if (stats.getChestSpawnCooldown() == 180) {
if (stats.getChestSpawnVector() != null) {
EntityParachest chest = new EntityParachest(player.worldObj, stats.getRocketStacks(), stats.getFuelLevel());
chest.setPosition(stats.getChestSpawnVector().x, stats.getChestSpawnVector().y, stats.getChestSpawnVector().z);
chest.color = stats.getParachuteInSlot() == null ? EnumDyeColor.WHITE : ItemParaChute.getDyeEnumFromParachuteDamage(stats.getParachuteInSlot().getItemDamage());
if (!player.worldObj.isRemote) {
player.worldObj.spawnEntityInWorld(chest);
}
}
}
}
if (stats.getLaunchAttempts() > 0 && player.ridingEntity == null) {
stats.setLaunchAttempts(0);
}
this.checkThermalStatus(player, stats);
this.checkOxygen(player, stats);
this.checkShield(player, stats);
if (isInGCDimension && (stats.isOxygenSetupValid() != stats.isLastOxygenSetupValid() || tick % 100 == 0)) {
GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_UPDATE_OXYGEN_VALIDITY, GCCoreUtil.getDimensionID(player.worldObj), new Object[] { stats.isOxygenSetupValid() }), player);
}
this.throwMeteors(player);
this.updateSchematics(player, stats);
if (tick % 250 == 0 && stats.getFrequencyModuleInSlot() == null && !stats.hasReceivedSoundWarning() && isInGCDimension && player.onGround && tick > 0 && ((IGalacticraftWorldProvider) player.worldObj.provider).getSoundVolReductionAmount() > 1.0F) {
String[] string2 = GCCoreUtil.translate("gui.frequencymodule.warning1").split(" ");
StringBuilder sb = new StringBuilder();
for (String aString2 : string2) {
sb.append(" ").append(EnumColor.YELLOW).append(aString2);
}
player.addChatMessage(new ChatComponentText(EnumColor.YELLOW + GCCoreUtil.translate("gui.frequencymodule.warning0") + " " + EnumColor.AQUA + GCItems.basicItem.getItemStackDisplayName(new ItemStack(GCItems.basicItem, 1, 19)) + sb.toString()));
stats.setReceivedSoundWarning(true);
}
// Player moves and sprints 18% faster with full set of Titanium Armor
if (GalacticraftCore.isPlanetsLoaded && tick % 40 == 1 && player.inventory != null) {
int titaniumCount = 0;
for (int i = 0; i < 4; i++) {
ItemStack armorPiece = player.getCurrentArmor(i);
if (armorPiece != null && armorPiece.getItem() instanceof ItemArmorAsteroids) {
titaniumCount++;
}
}
if (stats.getSavedSpeed() == 0F) {
if (titaniumCount == 4) {
float speed = player.capabilities.getWalkSpeed();
if (speed < 0.118F) {
try {
Field f = player.capabilities.getClass().getDeclaredField(GCCoreUtil.isDeobfuscated() ? "walkSpeed" : "field_75097_g");
f.setAccessible(true);
f.set(player.capabilities, 0.118F);
stats.setSavedSpeed(speed);
} catch (Exception e) {
e.printStackTrace();
}
}
}
} else if (titaniumCount < 4) {
try {
Field f = player.capabilities.getClass().getDeclaredField(GCCoreUtil.isDeobfuscated() ? "walkSpeed" : "field_75097_g");
f.setAccessible(true);
f.set(player.capabilities, stats.getSavedSpeed());
stats.setSavedSpeed(0F);
} catch (Exception e) {
e.printStackTrace();
}
}
}
stats.setLastOxygenSetupValid(stats.isOxygenSetupValid());
stats.setLastUnlockedSchematics(stats.getUnlockedSchematics());
stats.setLastOnGround(player.onGround);
}
Aggregations