use of micdoodle8.mods.galacticraft.api.galaxies.Moon in project Galacticraft by micdoodle8.
the class GCPlayerHandler method updateFeet.
protected static void updateFeet(EntityPlayerMP player, double motionX, double motionZ) {
double motionSqrd = motionX * motionX + motionZ * motionZ;
if (motionSqrd > 0.001D && !player.capabilities.isFlying) {
int iPosX = MathHelper.floor_double(player.posX);
int iPosY = MathHelper.floor_double(player.posY - 0.05);
int iPosZ = MathHelper.floor_double(player.posZ);
// If the block below is the moon block
IBlockState state = player.worldObj.getBlockState(new BlockPos(iPosX, iPosY, iPosZ));
if (state.getBlock() == GCBlocks.blockMoon) {
// And is the correct metadata (moon turf)
if (state.getValue(BlockBasicMoon.BASIC_TYPE_MOON) == BlockBasicMoon.EnumBlockBasicMoon.MOON_TURF) {
GCPlayerStats stats = GCPlayerStats.get(player);
// If it has been long enough since the last step
if (stats.getDistanceSinceLastStep() > 0.35D) {
Vector3 pos = new Vector3(player);
// Set the footprint position to the block below and add random number to stop z-fighting
pos.y = MathHelper.floor_double(player.posY - 1D) + player.worldObj.rand.nextFloat() / 100.0F;
// Adjust footprint to left or right depending on step count
switch(stats.getLastStep()) {
case 0:
float a = (-player.rotationYaw + 90F) / Constants.RADIANS_TO_DEGREES;
pos.translate(new Vector3(MathHelper.sin(a) * 0.25F, 0, MathHelper.cos(a) * 0.25F));
break;
case 1:
a = (-player.rotationYaw - 90F) / Constants.RADIANS_TO_DEGREES;
pos.translate(new Vector3(MathHelper.sin(a) * 0.25, 0, MathHelper.cos(a) * 0.25));
break;
}
float rotation = player.rotationYaw - 180;
pos = WorldUtil.getFootprintPosition(player.worldObj, rotation, pos, new BlockVec3(player));
long chunkKey = ChunkCoordIntPair.chunkXZ2Int(pos.intX() >> 4, pos.intZ() >> 4);
TickHandlerServer.addFootprint(chunkKey, new Footprint(GCCoreUtil.getDimensionID(player.worldObj), pos, rotation, player.getName()), GCCoreUtil.getDimensionID(player.worldObj));
// Increment and cap step counter at 1
stats.setLastStep((stats.getLastStep() + 1) % 2);
stats.setDistanceSinceLastStep(0);
} else {
stats.setDistanceSinceLastStep(stats.getDistanceSinceLastStep() + motionSqrd);
}
}
}
}
}
use of micdoodle8.mods.galacticraft.api.galaxies.Moon in project MorePlanets by SteveKunG.
the class TeleportUtils method teleportPlayerToPlanet.
public static EntityPlayer teleportPlayerToPlanet(EntityPlayerMP player, MinecraftServer server, int sourceDim, int targetDim) {
WorldServer sourceWorld = server.getWorld(sourceDim);
WorldServer targetWorld = server.getWorld(targetDim);
BlockPos spawnPos = targetWorld.getTopSolidOrLiquidBlock(targetWorld.getSpawnPoint());
PlayerList playerList = server.getPlayerList();
GCPlayerStats stats = GCPlayerStats.get(player);
InventoryExtended inv = stats.getExtendedInventory();
player.dimension = targetDim;
player.connection.sendPacket(new SPacketRespawn(player.dimension, targetWorld.getDifficulty(), targetWorld.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));
playerList.updatePermissionLevel(player);
sourceWorld.removeEntityDangerously(player);
player.isDead = false;
// world transfer
player.setLocationAndAngles(spawnPos.getX(), spawnPos.getY(), spawnPos.getZ(), player.rotationYaw, player.rotationPitch);
player.connection.setPlayerLocation(spawnPos.getX(), spawnPos.getY(), spawnPos.getZ(), player.rotationYaw, player.rotationPitch);
targetWorld.spawnEntity(player);
targetWorld.updateEntityWithOptionalForce(player, false);
player.setWorld(targetWorld);
// prevent kicked from LAN or server world
MorePlanetsMod.PROXY.resetFloatingTick(player);
playerList.preparePlayer(player, sourceWorld);
player.connection.setPlayerLocation(spawnPos.getX(), spawnPos.getY(), spawnPos.getZ(), player.rotationYaw, player.rotationPitch);
player.interactionManager.setWorld(targetWorld);
player.connection.sendPacket(new SPacketPlayerAbilities(player.capabilities));
playerList.updateTimeAndWeatherForPlayer(player, targetWorld);
playerList.syncPlayerInventory(player);
if (targetWorld.provider instanceof IStartedDimension) {
IStartedDimension dimension = (IStartedDimension) targetWorld.provider;
LoggerMP.info("Setting up survival player gear");
dimension.setup(player);
} else if (targetWorld.provider instanceof WorldProviderMoon) {
LoggerMP.info("Setting up default survival player gear for Moon");
inv.setInventorySlotContents(0, new ItemStack(GCItems.oxMask));
inv.setInventorySlotContents(1, new ItemStack(GCItems.oxygenGear));
inv.setInventorySlotContents(2, new ItemStack(GCItems.oxTankMedium));
inv.setInventorySlotContents(3, new ItemStack(GCItems.oxTankMedium));
inv.setInventorySlotContents(4, new ItemStack(GCItems.parachute));
inv.setInventorySlotContents(5, new ItemStack(GCItems.basicItem, 1, 19));
player.inventory.addItemStackToInventory(new ItemStack(Blocks.LOG, 32 + player.world.rand.nextInt(32)));
player.inventory.addItemStackToInventory(new ItemStack(Blocks.COBBLESTONE, 32 + player.world.rand.nextInt(32)));
player.inventory.addItemStackToInventory(new ItemStack(Blocks.DIRT, 16));
player.inventory.addItemStackToInventory(new ItemStack(Blocks.SAPLING, 8 + player.world.rand.nextInt(8)));
player.inventory.addItemStackToInventory(new ItemStack(Items.IRON_INGOT, 32 + player.world.rand.nextInt(16)));
player.inventory.addItemStackToInventory(new ItemStack(Items.WHEAT_SEEDS, 16 + player.world.rand.nextInt(16)));
player.inventory.addItemStackToInventory(new ItemStack(Items.POTATO, 16 + player.world.rand.nextInt(16)));
player.inventory.addItemStackToInventory(new ItemStack(Items.CARROT, 16 + player.world.rand.nextInt(16)));
player.inventory.addItemStackToInventory(new ItemStack(Items.WATER_BUCKET));
player.inventory.addItemStackToInventory(new ItemStack(Items.WATER_BUCKET));
player.inventory.addItemStackToInventory(new ItemStack(GCBlocks.landingPad, 9));
ItemStack rocket = new ItemStack(GCItems.rocketTier1);
rocket.setTagCompound(new NBTTagCompound());
rocket.getTagCompound().setInteger("RocketFuel", 1000);
player.inventory.addItemStackToInventory(rocket);
player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
} else if (targetWorld.provider instanceof WorldProviderMars) {
LoggerMP.info("Setting up default survival player gear for Mars");
// Knows how to build T2 rocket
SchematicRegistry.unlockNewPage(player, new ItemStack(GCItems.schematic, 1, 1));
inv.setInventorySlotContents(0, new ItemStack(GCItems.oxMask));
inv.setInventorySlotContents(1, new ItemStack(GCItems.oxygenGear));
inv.setInventorySlotContents(2, new ItemStack(GCItems.oxTankMedium));
inv.setInventorySlotContents(3, new ItemStack(GCItems.oxTankMedium));
inv.setInventorySlotContents(4, new ItemStack(GCItems.parachute));
inv.setInventorySlotContents(5, new ItemStack(GCItems.basicItem, 1, 19));
inv.setInventorySlotContents(6, new ItemStack(AsteroidsItems.thermalPadding));
inv.setInventorySlotContents(7, new ItemStack(AsteroidsItems.thermalPadding, 1, 1));
inv.setInventorySlotContents(8, new ItemStack(AsteroidsItems.thermalPadding, 1, 2));
inv.setInventorySlotContents(9, new ItemStack(AsteroidsItems.thermalPadding, 1, 3));
player.inventory.addItemStackToInventory(new ItemStack(Blocks.LOG, 32 + player.world.rand.nextInt(32)));
player.inventory.addItemStackToInventory(new ItemStack(Blocks.COBBLESTONE, 32 + player.world.rand.nextInt(32)));
player.inventory.addItemStackToInventory(new ItemStack(Blocks.DIRT, 16));
player.inventory.addItemStackToInventory(new ItemStack(Blocks.SAPLING, 8 + player.world.rand.nextInt(8)));
player.inventory.addItemStackToInventory(new ItemStack(Items.IRON_INGOT, 32 + player.world.rand.nextInt(16)));
player.inventory.addItemStackToInventory(new ItemStack(Items.WHEAT_SEEDS, 16 + player.world.rand.nextInt(16)));
player.inventory.addItemStackToInventory(new ItemStack(Items.POTATO, 16 + player.world.rand.nextInt(16)));
player.inventory.addItemStackToInventory(new ItemStack(Items.CARROT, 16 + player.world.rand.nextInt(16)));
player.inventory.addItemStackToInventory(new ItemStack(Items.WATER_BUCKET));
player.inventory.addItemStackToInventory(new ItemStack(Items.WATER_BUCKET));
player.inventory.addItemStackToInventory(new ItemStack(GCBlocks.landingPad, 9));
ItemStack rocket = new ItemStack(MarsItems.rocketMars);
rocket.setTagCompound(new NBTTagCompound());
rocket.getTagCompound().setInteger("RocketFuel", 1000);
player.inventory.addItemStackToInventory(rocket);
player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
} else if (targetWorld.provider instanceof WorldProviderVenus) {
LoggerMP.info("Setting up default survival player gear for Venus");
// Knows how to build T2 rocket
SchematicRegistry.unlockNewPage(player, new ItemStack(GCItems.schematic, 1, 1));
// Knows how to build T3 rocket
SchematicRegistry.unlockNewPage(player, new ItemStack(MarsItems.schematic, 1, 0));
inv.setInventorySlotContents(0, new ItemStack(GCItems.oxMask));
inv.setInventorySlotContents(1, new ItemStack(GCItems.oxygenGear));
inv.setInventorySlotContents(2, new ItemStack(GCItems.oxTankHeavy));
inv.setInventorySlotContents(3, new ItemStack(GCItems.oxTankHeavy));
inv.setInventorySlotContents(4, new ItemStack(GCItems.parachute));
inv.setInventorySlotContents(5, new ItemStack(GCItems.basicItem, 1, 19));
inv.setInventorySlotContents(6, new ItemStack(VenusItems.thermalPaddingTier2));
inv.setInventorySlotContents(7, new ItemStack(VenusItems.thermalPaddingTier2, 1, 1));
inv.setInventorySlotContents(8, new ItemStack(VenusItems.thermalPaddingTier2, 1, 2));
inv.setInventorySlotContents(9, new ItemStack(VenusItems.thermalPaddingTier2, 1, 3));
inv.setInventorySlotContents(10, new ItemStack(VenusItems.basicItem));
player.inventory.addItemStackToInventory(new ItemStack(Blocks.LOG, 32 + player.world.rand.nextInt(32)));
player.inventory.addItemStackToInventory(new ItemStack(Blocks.COBBLESTONE, 32 + player.world.rand.nextInt(32)));
player.inventory.addItemStackToInventory(new ItemStack(Blocks.DIRT, 16));
player.inventory.addItemStackToInventory(new ItemStack(Blocks.SAPLING, 8 + player.world.rand.nextInt(8)));
player.inventory.addItemStackToInventory(new ItemStack(Items.IRON_INGOT, 32 + player.world.rand.nextInt(16)));
player.inventory.addItemStackToInventory(new ItemStack(Items.WHEAT_SEEDS, 16 + player.world.rand.nextInt(16)));
player.inventory.addItemStackToInventory(new ItemStack(Items.POTATO, 16 + player.world.rand.nextInt(16)));
player.inventory.addItemStackToInventory(new ItemStack(Items.CARROT, 16 + player.world.rand.nextInt(16)));
player.inventory.addItemStackToInventory(new ItemStack(Items.WATER_BUCKET));
player.inventory.addItemStackToInventory(new ItemStack(Items.WATER_BUCKET));
player.inventory.addItemStackToInventory(new ItemStack(GCBlocks.landingPad, 9));
ItemStack rocket = new ItemStack(AsteroidsItems.tier3Rocket);
rocket.setTagCompound(new NBTTagCompound());
rocket.getTagCompound().setInteger("RocketFuel", 1000);
player.inventory.addItemStackToInventory(rocket);
player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
} else if (targetWorld.provider instanceof WorldProviderAsteroids) {
LoggerMP.info("Setting up default survival player gear for Asteroids");
ITeleportType type = GalacticraftRegistry.getTeleportTypeForDimension(targetWorld.provider.getClass());
Vector3 spawnPosVec = type.getPlayerSpawnLocation(targetWorld, player);
ChunkPos pair = targetWorld.getChunk(spawnPosVec.intX() >> 4, spawnPosVec.intZ() >> 4).getPos();
player.setLocationAndAngles(spawnPosVec.x, spawnPosVec.y, spawnPosVec.z, player.rotationYaw, player.rotationPitch);
player.setSpawnChunk(new BlockPos(spawnPosVec.intX(), spawnPosVec.intY(), spawnPosVec.intZ()), true, GCCoreUtil.getDimensionID(targetWorld));
targetWorld.getChunkProvider().loadChunk(pair.x, pair.z);
type.setupAdventureSpawn(player);
type.onSpaceDimensionChanged(targetWorld, player, false);
} else {
LoggerMP.info("Setting up default survival player gear for Non-IStartedDimension world");
// Knows how to build T2 rocket
SchematicRegistry.unlockNewPage(player, new ItemStack(GCItems.schematic, 1, 1));
// Knows how to build T3 rocket
SchematicRegistry.unlockNewPage(player, new ItemStack(MarsItems.schematic, 1, 0));
inv.setInventorySlotContents(0, new ItemStack(GCItems.oxMask));
inv.setInventorySlotContents(1, new ItemStack(GCItems.oxygenGear));
inv.setInventorySlotContents(2, new ItemStack(GCItems.oxTankHeavy));
inv.setInventorySlotContents(3, new ItemStack(GCItems.oxTankHeavy));
inv.setInventorySlotContents(5, new ItemStack(GCItems.basicItem, 1, 19));
inv.setInventorySlotContents(6, new ItemStack(AsteroidsItems.thermalPadding));
inv.setInventorySlotContents(7, new ItemStack(AsteroidsItems.thermalPadding, 1, 1));
inv.setInventorySlotContents(8, new ItemStack(AsteroidsItems.thermalPadding, 1, 2));
inv.setInventorySlotContents(9, new ItemStack(AsteroidsItems.thermalPadding, 1, 3));
player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
}
player.addPotionEffect(new PotionEffect(MobEffects.RESISTANCE, 15 * 20, 5));
player.getActivePotionEffects().forEach(potion -> player.connection.sendPacket(new SPacketEntityEffect(player.getEntityId(), potion)));
player.connection.sendPacket(new SPacketSetExperience(player.experience, player.experienceTotal, player.experienceLevel));
player.connection.sendPacket(new SPacketSpawnPosition(spawnPos));
AttributeMap attributemap = (AttributeMap) player.getAttributeMap();
Collection<IAttributeInstance> watchedAttribs = attributemap.getWatchedAttributes();
if (!watchedAttribs.isEmpty()) {
player.connection.sendPacket(new SPacketEntityProperties(player.getEntityId(), watchedAttribs));
}
FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, sourceDim, targetDim);
if (!(targetWorld.provider instanceof WorldProviderAsteroids)) {
player.setLocationAndAngles(spawnPos.getX(), spawnPos.getY(), spawnPos.getZ(), player.rotationYaw, player.rotationPitch);
player.setSpawnChunk(spawnPos, true, GCCoreUtil.getDimensionID(player.world));
}
if (!(targetWorld.provider instanceof WorldProviderAsteroids) && player.onGround && player.getBedLocation(GCCoreUtil.getDimensionID(player.world)) == null) {
int i = 30000000;
int x = Math.min(i, Math.max(-i, MathHelper.floor(player.posX + 0.5D)));
int y = Math.min(256, Math.max(0, MathHelper.floor(player.posY + 1.5D)));
int z = Math.min(i, Math.max(-i, MathHelper.floor(player.posZ + 0.5D)));
BlockPos spawnChunkPos = targetWorld.getTopSolidOrLiquidBlock(new BlockPos(x, y, z));
player.setSpawnChunk(spawnChunkPos, true, GCCoreUtil.getDimensionID(player.world));
}
GalacticraftCore.packetPipeline.sendTo(new PacketSimpleMP(EnumSimplePacketMP.C_RELOAD_RENDERER, player.dimension), player);
GalacticraftCore.packetPipeline.sendTo(new PacketSimpleMP(EnumSimplePacketMP.C_MESSAGE_SURVIVAL_PLANET, player.dimension, new Object[] { WorldUtil.getProviderForDimensionServer(targetDim).getDimensionType().getName() }), player);
return player;
}
Aggregations