Skip to content

Commit

Permalink
Freefall - smoother motion and enable other mods jetpacks. Fixes #1298
Browse files Browse the repository at this point in the history
  • Loading branch information
radfast committed May 2, 2015
1 parent ef3387b commit 6eaea73
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 154 deletions.
Expand Up @@ -12,7 +12,9 @@
import micdoodle8.mods.galacticraft.api.world.ISolarLevel;
import micdoodle8.mods.galacticraft.core.GalacticraftCore;
import micdoodle8.mods.galacticraft.core.blocks.BlockSpinThruster;
import micdoodle8.mods.galacticraft.core.blocks.GCBlocks;
import micdoodle8.mods.galacticraft.core.client.SkyProviderOrbit;
import micdoodle8.mods.galacticraft.core.entities.player.FreefallHandler;
import micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStatsClient;
import micdoodle8.mods.galacticraft.core.network.PacketSimple;
import micdoodle8.mods.galacticraft.core.network.PacketSimple.EnumSimplePacket;
Expand Down Expand Up @@ -86,9 +88,16 @@ public class WorldProviderOrbit extends WorldProviderSpace implements IOrbitDime
private double pPrevMotionX = 0D;
public double pPrevMotionY = 0D;
private double pPrevMotionZ = 0D;
private double pPrevMotionServerX = 0D;
public double pPrevMotionServerY = 0D;
private double pPrevMotionServerZ = 0D;
private int pjumpticks = 0;
private boolean pWasOnGround = false;

private double pPrevPosY;

private double pPrevdY;

@Override
public void setDimension(int var1)
{
Expand Down Expand Up @@ -559,25 +568,22 @@ public float getSoundVolReductionAmount()
}

@SideOnly(Side.CLIENT)
public void preVanillaMotion(EntityPlayerSP p, boolean flag)
public void preVanillaMotion(EntityPlayerSP p)
{
boolean freefall = this.testFreefall(p, flag);

GCPlayerStatsClient stats = GCPlayerStatsClient.get(p);
stats.inFreefallLast = stats.inFreefall;
stats.inFreefall = freefall;
stats.inFreefallFirstCheck = true;
this.pPrevMotionX = p.motionX;
this.pPrevMotionY = p.motionY;
this.pPrevMotionZ = p.motionZ;
FreefallHandler.setupFreefallPre(p);
this.pWasOnGround = p.onGround;
stats.downMotionLast = p.motionY;
}

@SideOnly(Side.CLIENT)
public void postVanillaMotion(EntityPlayerSP p, boolean flag)
public void postVanillaMotion(EntityPlayerSP p)
{
boolean freefall = flag;
GCPlayerStatsClient stats = GCPlayerStatsClient.get(p);
boolean freefall = stats.inFreefall;
if (freefall) p.ySize = 0F; //Undo the sneak height adjust
freefall = this.testFreefall(p, freefall);
stats.inFreefall = freefall;
stats.inFreefallFirstCheck = true;

boolean doGravity = true;

if (freefall)
Expand Down Expand Up @@ -684,78 +690,7 @@ public void postVanillaMotion(EntityPlayerSP p, boolean flag)
//Do freefall motion
if (!p.capabilities.isCreativeMode)
{
double dx = p.motionX - this.pPrevMotionX;
double dy = p.motionY - this.pPrevMotionY;
double dz = p.motionZ - this.pPrevMotionZ;
/* double dyaw = p.rotationYaw - p.prevRotationYaw;
p.rotationYaw -= dyaw * 0.8D;
double dyawh = p.rotationYawHead - p.prevRotationYawHead;
p.rotationYawHead -= dyawh * 0.8D;
while (p.rotationYaw > 360F)
{
p.rotationYaw -= 360F;
}
while (p.rotationYaw < 0F)
{
p.rotationYaw += 360F;
}
while (p.rotationYawHead > 360F)
{
p.rotationYawHead -= 360F;
}
while (p.rotationYawHead < 0F)
{
p.rotationYawHead += 360F;
}
*/
//if (p.capabilities.isFlying)
///Undo whatever vanilla tried to do to our y motion
p.motionY -= dy;
p.motionX -= dx;
p.motionZ -= dz;

if (p.movementInput.moveForward != 0)
{
p.motionX -= p.movementInput.moveForward * MathHelper.sin(p.rotationYaw / 57.29578F) / (ConfigManagerCore.hardMode ? 600F : 200F);
p.motionZ += p.movementInput.moveForward * MathHelper.cos(p.rotationYaw / 57.29578F) / (ConfigManagerCore.hardMode ? 600F : 200F);
}

if (p.movementInput.sneak)
{
p.motionY -= ConfigManagerCore.hardMode ? 0.0012D : 0.0032D;
}

if (p.movementInput.jump)
{
p.motionY += ConfigManagerCore.hardMode ? 0.0012D : 0.0032D;
}

float speedLimit = ConfigManagerCore.hardMode ? 0.9F : 0.7F;

if (p.motionX > speedLimit)
{
p.motionX = speedLimit;
}
if (p.motionX < -speedLimit)
{
p.motionX = -speedLimit;
}
if (p.motionY > speedLimit)
{
p.motionY = speedLimit;
}
if (p.motionY < -speedLimit)
{
p.motionY = -speedLimit;
}
if (p.motionZ > speedLimit)
{
p.motionZ = speedLimit;
}
if (p.motionZ < -speedLimit)
{
p.motionZ = -speedLimit;
}
FreefallHandler.freefallMotion(p);
}
else
{
Expand Down Expand Up @@ -794,7 +729,6 @@ public void postVanillaMotion(EntityPlayerSP p, boolean flag)
}
//TODO: Think about endless drift?
//Player may run out of oxygen - that will kill the player eventually if can't get back to SS
//Maybe player needs a 'suicide' button if floating helplessly in space and with no tether
//Could auto-kill + respawn the player if floats too far away (config option whether to lose items or not)
//But we want players to be able to enjoy the view of the spinning space station from the outside
//Arm and leg movements could start tumbling the player?
Expand All @@ -817,7 +751,7 @@ public void postVanillaMotion(EntityPlayerSP p, boolean flag)
}
else
{
p.motionY += 0.003D;
p.motionY += 0.015D;
if (this.pjumpticks == 0)
{
p.motionY -= dy;
Expand All @@ -828,7 +762,7 @@ else if (p.movementInput.sneak)
{
if (!p.onGround)
{
p.motionY -= 0.003D;
p.motionY -= 0.015D;
}
this.pjumpticks = 0;
}
Expand Down Expand Up @@ -888,6 +822,10 @@ else if (xd > Math.abs(zd))
p.motionZ -= accel;
}
}
this.pPrevMotionX = p.motionX;
this.pPrevMotionY = p.motionY;
this.pPrevMotionZ = p.motionZ;
this.pPrevPosY = p.posY;
}

@SideOnly(Side.CLIENT)
Expand All @@ -903,31 +841,45 @@ private boolean testFreefall(EntityPlayerSP p, boolean flag)
{
return false;
}
else if (p.boundingBox.maxX >= this.ssBoundsMinX && p.boundingBox.minX <= this.ssBoundsMaxX && p.boundingBox.maxY >= this.ssBoundsMinY && p.boundingBox.minY <= this.ssBoundsMaxY && p.boundingBox.maxZ >= this.ssBoundsMinZ && p.boundingBox.minZ <= this.ssBoundsMaxZ)
//Player is somewhere within the space station boundaries
else
{
//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 xmx = MathHelper.floor_double(p.boundingBox.maxX);
int ym = MathHelper.floor_double(p.boundingBox.minY);
int yy = MathHelper.floor_double(p.boundingBox.maxY);
int zm = MathHelper.floor_double(p.boundingBox.minZ);
int zz = MathHelper.floor_double(p.boundingBox.maxZ);
for (int x = MathHelper.floor_double(p.boundingBox.minX); x <= xmx; 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
if (Blocks.air != this.worldObj.getBlock(x, y, z))
{
return false;
}
}
}
}
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.boundingBox.addCoord(xreach, 0, zreach);

if (playerReach.maxX >= this.ssBoundsMinX && playerReach.minX <= this.ssBoundsMaxX && playerReach.maxY >= this.ssBoundsMinY && playerReach.minY <= this.ssBoundsMaxY && playerReach.maxZ >= this.ssBoundsMinZ && playerReach.minZ <= this.ssBoundsMaxZ)
//Player is somewhere within the space station boundaries
{
//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 = this.worldObj.getBlock(x, y, z);
if (Blocks.air != b && GCBlocks.brightAir != b)
{
return false;
}
}
}
}
}
}

/*
Expand Down Expand Up @@ -1519,4 +1471,19 @@ public float getWindLevel()
{
return 0.1F;
}
//
// public void setVelocityClient(EntityPlayerSP p, double xx, double yy, double zz)
// {
// if (GCPlayerStatsClient.get(p).inFreefall)
// {
// //Apply server velocity delta to freefall client
// //this.pPrevMotionX += xx - this.pPrevMotionServerX;
// //this.pPrevMotionY += yy - this.pPrevMotionServerY;
// //this.pPrevMotionZ += zz - this.pPrevMotionServerZ;
// this.pPrevMotionServerX = xx;
// this.pPrevMotionServerY = yy;
// this.pPrevMotionServerZ = zz;
// System.out.println("SetVelocity received: " + xx + " " + yy + " " + zz);
// }
// }
}
Expand Up @@ -73,4 +73,16 @@ public float getBedOrientationInDegrees()
{
return ClientProxyCore.playerClientHandler.getBedOrientationInDegrees(this, super.getBedOrientationInDegrees());
}
//
// @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);
// }
//
}
@@ -1,6 +1,7 @@
package micdoodle8.mods.galacticraft.core.entities.player;

import com.mojang.authlib.GameProfile;

import micdoodle8.mods.galacticraft.core.GalacticraftCore;
import micdoodle8.mods.galacticraft.core.tile.TileEntityTelemetry;
import net.minecraft.entity.Entity;
Expand Down
Expand Up @@ -3,6 +3,7 @@
import api.player.client.ClientPlayerAPI;
import api.player.client.ClientPlayerBase;
import cpw.mods.fml.common.Loader;
import micdoodle8.mods.galacticraft.core.dimension.WorldProviderOrbit;
import micdoodle8.mods.galacticraft.core.proxy.ClientProxyCore;
import micdoodle8.mods.galacticraft.core.util.WorldUtil;

Expand Down Expand Up @@ -67,6 +68,18 @@ public void onUpdate()
super.onUpdate();
}

@Override
public boolean isSneaking()
{
if (this.player.worldObj.provider instanceof WorldProviderOrbit)
{
GCPlayerStatsClient stats = GCPlayerStatsClient.get(this.player);
if (!this.player.onGround) return false;
if (stats.landingTicks > 0) return true;
}
return super.isSneaking();
}

// @Override
// @SideOnly(Side.CLIENT)
// public float getBedOrientationInDegrees()
Expand Down
Expand Up @@ -949,9 +949,13 @@ private void onPlayerUpdate(EntityPlayerMP player)
{
int tick = player.ticksExisted - 1;

//This will speed things up a little
final GCPlayerStats GCPlayer = GCPlayerStats.get(player);
final boolean isInGCDimension = player.worldObj.provider instanceof IGalacticraftWorldProvider;

if (tick >= 25)
{
if (!GCPlayerStats.get(player).openedSpaceRaceManager)
if (!GCPlayer.openedSpaceRaceManager)
{
SpaceRace race = SpaceRaceManager.getSpaceRaceFromPlayer(player.getGameProfile().getName());

Expand All @@ -960,14 +964,10 @@ private void onPlayerUpdate(EntityPlayerMP player)
GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_OPEN_SPACE_RACE_GUI, new Object[] { }), player);
}

GCPlayerStats.get(player).openedSpaceRaceManager = true;
GCPlayer.openedSpaceRaceManager = true;
}
}

//This will speed things up a little
final GCPlayerStats GCPlayer = GCPlayerStats.get(player);
final boolean isInGCDimension = player.worldObj.provider instanceof IGalacticraftWorldProvider;

if (GCPlayer.cryogenicChamberCooldown > 0)
{
GCPlayer.cryogenicChamberCooldown--;
Expand Down Expand Up @@ -1074,7 +1074,7 @@ private void onPlayerUpdate(EntityPlayerMP player)
try {
if (ftc == null)
{
ftc = player.playerNetServerHandler.getClass().getField("floatingTickCount");
ftc = player.playerNetServerHandler.getClass().getField(VersionUtil.getNameDynamic(VersionUtil.KEY_FIELD_FLOATINGTICKCOUNT));
ftc.setAccessible(true);
}
//Prevent kicks for flying
Expand Down

0 comments on commit 6eaea73

Please sign in to comment.