Search in sources :

Example 11 with Footprint

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;
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) Block(net.minecraft.block.Block) Vector3(micdoodle8.mods.galacticraft.api.vector.Vector3) BlockPos(net.minecraft.util.BlockPos)

Example 12 with Footprint

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);
                }
            }
        }
    }
}
Also used : Footprint(micdoodle8.mods.galacticraft.core.wrappers.Footprint) IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.BlockPos) Vector3(micdoodle8.mods.galacticraft.api.vector.Vector3) TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint) Footprint(micdoodle8.mods.galacticraft.core.wrappers.Footprint) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Aggregations

Footprint (micdoodle8.mods.galacticraft.core.wrappers.Footprint)10 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)7 Vector3 (micdoodle8.mods.galacticraft.api.vector.Vector3)6 BlockPos (net.minecraft.util.BlockPos)5 FlagData (micdoodle8.mods.galacticraft.core.wrappers.FlagData)3 IBlockState (net.minecraft.block.state.IBlockState)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 GuiCelestialSelection (micdoodle8.mods.galacticraft.core.client.gui.screen.GuiCelestialSelection)2 WorldProviderSpaceStation (micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation)2 EnergyStorage (micdoodle8.mods.galacticraft.core.energy.tile.EnergyStorage)2 TileBaseConductor (micdoodle8.mods.galacticraft.core.energy.tile.TileBaseConductor)2 FluidNetwork (micdoodle8.mods.galacticraft.core.fluid.FluidNetwork)2 PacketSimple (micdoodle8.mods.galacticraft.core.network.PacketSimple)2 Block (net.minecraft.block.Block)2 Minecraft (net.minecraft.client.Minecraft)2 EntityPlayerSP (net.minecraft.client.entity.EntityPlayerSP)2 WorldClient (net.minecraft.client.multiplayer.WorldClient)2 Entity (net.minecraft.entity.Entity)2