use of micdoodle8.mods.galacticraft.core.wrappers.Footprint in project Galacticraft by micdoodle8.
the class WorldUtil method getFootprintPosition.
public static Vector3 getFootprintPosition(World world, float rotation, Vector3 startPosition, BlockVec3 playerCenter) {
Vector3 position = startPosition.clone();
float footprintScale = 0.375F;
int mainPosX = position.intX();
int mainPosY = position.intY();
int mainPosZ = position.intZ();
BlockPos posMain = new BlockPos(mainPosX, mainPosY, mainPosZ);
// If the footprint is hovering over air...
if (world.getBlockState(posMain).getBlock().isAir(world, posMain)) {
position.x += (playerCenter.x - mainPosX);
position.z += (playerCenter.z - mainPosZ);
BlockPos pos1 = new BlockPos(position.intX(), position.intY(), position.intZ());
// If the footprint is still over air....
Block b2 = world.getBlockState(pos1).getBlock();
if (b2 != null && b2.isAir(world, pos1)) {
for (EnumFacing direction : EnumFacing.VALUES) {
BlockPos offsetPos = posMain.offset(direction);
if (direction != EnumFacing.DOWN && direction != EnumFacing.UP) {
if (!world.getBlockState(offsetPos).getBlock().isAir(world, offsetPos)) {
position.x += direction.getFrontOffsetX();
position.z += direction.getFrontOffsetZ();
break;
}
}
}
}
}
mainPosX = position.intX();
mainPosZ = position.intZ();
double x0 = (Math.sin((45 - rotation) / Constants.RADIANS_TO_DEGREES_D) * footprintScale) + position.x;
double x1 = (Math.sin((135 - rotation) / Constants.RADIANS_TO_DEGREES_D) * footprintScale) + position.x;
double x2 = (Math.sin((225 - rotation) / Constants.RADIANS_TO_DEGREES_D) * footprintScale) + position.x;
double x3 = (Math.sin((315 - rotation) / Constants.RADIANS_TO_DEGREES_D) * footprintScale) + position.x;
double z0 = (Math.cos((45 - rotation) / Constants.RADIANS_TO_DEGREES_D) * footprintScale) + position.z;
double z1 = (Math.cos((135 - rotation) / Constants.RADIANS_TO_DEGREES_D) * footprintScale) + position.z;
double z2 = (Math.cos((225 - rotation) / Constants.RADIANS_TO_DEGREES_D) * footprintScale) + position.z;
double z3 = (Math.cos((315 - rotation) / Constants.RADIANS_TO_DEGREES_D) * footprintScale) + position.z;
double xMin = Math.min(Math.min(x0, x1), Math.min(x2, x3));
double xMax = Math.max(Math.max(x0, x1), Math.max(x2, x3));
double zMin = Math.min(Math.min(z0, z1), Math.min(z2, z3));
double zMax = Math.max(Math.max(z0, z1), Math.max(z2, z3));
if (xMin < mainPosX) {
position.x += mainPosX - xMin;
}
if (xMax > mainPosX + 1) {
position.x -= xMax - (mainPosX + 1);
}
if (zMin < mainPosZ) {
position.z += mainPosZ - zMin;
}
if (zMax > mainPosZ + 1) {
position.z -= zMax - (mainPosZ + 1);
}
return position;
}
use of micdoodle8.mods.galacticraft.core.wrappers.Footprint 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);
}
}
}
}
}
Aggregations