Search in sources :

Example 21 with ShipData

use of org.valkyrienskies.mod.common.ships.ShipData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class WorldShipLoadingController method determineLoadAndUnload.

/**
 * Tells the WorldServerShipManager which ships to load/unload/load in background.
 */
void determineLoadAndUnload() {
    for (ShipData data : QueryableShipData.get(shipManager.getWorld())) {
        ShipTransform transform = data.getShipTransform();
        Vec3d shipPos = transform.getShipPositionVec3d();
        if (shipManager.getPhysObjectFromUUID(data.getUuid()) == null) {
            if (existsPlayerWithinDistanceXZ(shipManager.getWorld(), shipPos, VSConfig.SHIP_LOADING_SETTINGS.loadDistance)) {
                shipManager.queueShipLoad(data.getUuid());
            } else {
                if (VSConfig.SHIP_LOADING_SETTINGS.permanentlyLoaded || existsPlayerWithinDistanceXZ(shipManager.getWorld(), shipPos, VSConfig.SHIP_LOADING_SETTINGS.loadBackgroundDistance)) {
                    shipManager.queueShipLoadBackground(data.getUuid());
                }
            }
        } else {
            if (!VSConfig.SHIP_LOADING_SETTINGS.permanentlyLoaded && !existsPlayerWithinDistanceXZ(shipManager.getWorld(), shipPos, VSConfig.SHIP_LOADING_SETTINGS.unloadDistance)) {
                shipManager.queueShipUnload(data.getUuid());
            }
        }
    }
}
Also used : ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) ShipData(org.valkyrienskies.mod.common.ships.ShipData) QueryableShipData(org.valkyrienskies.mod.common.ships.QueryableShipData) Vec3d(net.minecraft.util.math.Vec3d)

Example 22 with ShipData

use of org.valkyrienskies.mod.common.ships.ShipData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class EntityCollisionInjector method alterEntityMovementPost.

public static void alterEntityMovementPost(Entity entity, IntermediateMovementVariableStorage storage) {
    double dx = storage.dxyz.x();
    double dy = storage.dxyz.y();
    double dz = storage.dxyz.z();
    double origDx = storage.origDxyz.x();
    double origDy = storage.origDxyz.y();
    double origDz = storage.origDxyz.z();
    double origPosX = storage.origPosXyz.x();
    double origPosY = storage.origPosXyz.y();
    double origPosZ = storage.origPosXyz.z();
    boolean alreadyOnGround = storage.alreadyOnGround;
    double motionYBefore = storage.motionYBefore;
    float oldFallDistance = storage.oldFallDistance;
    ShipData worldBelow = ValkyrienUtils.getLastShipTouchedByEntity(entity);
    entity.collidedHorizontally = (motionInterfering(dx, origDx)) || (motionInterfering(dz, origDz));
    entity.collidedVertically = isDifSignificant(dy, origDy);
    entity.onGround = entity.collidedVertically && origDy < 0 || alreadyOnGround || entity.onGround;
    entity.collided = entity.collidedHorizontally || entity.collidedVertically;
    Vector3d entityPosInShip = new Vector3d(entity.posX, entity.posY - 0.20000000298023224D, entity.posZ);
    worldBelow.getShipTransform().transformPosition(entityPosInShip, TransformType.GLOBAL_TO_SUBSPACE);
    int j4 = MathHelper.floor(entityPosInShip.x);
    int l4 = MathHelper.floor(entityPosInShip.y);
    int i5 = MathHelper.floor(entityPosInShip.z);
    BlockPos blockpos = new BlockPos(j4, l4, i5);
    IBlockState iblockstate = entity.world.getBlockState(blockpos);
    Block block = iblockstate.getBlock();
    // fixes slime blocks
    if (block instanceof BlockSlime && !entity.isInWeb) {
        entity.motionY = motionYBefore;
    }
    entity.fallDistance = oldFallDistance;
    if (entity instanceof EntityLivingBase) {
        if (!entity.world.isRemote && entity.fallDistance > 3.0F && entity.onGround) {
            // System.out.println("LAND DAMNIT!");
            float f = MathHelper.ceil(entity.fallDistance - 3.0F);
            if (!iblockstate.getBlock().isAir(iblockstate, entity.world, blockpos)) {
                double d0 = Math.min(0.2F + f / 15.0F, 2.5D);
                int i = (int) (150.0D * d0);
                if (!iblockstate.getBlock().addLandingEffects(iblockstate, (WorldServer) entity.world, blockpos, iblockstate, (EntityLivingBase) entity, i)) {
                    ((WorldServer) entity.world).spawnParticle(EnumParticleTypes.BLOCK_DUST, entity.posX, entity.posY, entity.posZ, i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D, Block.getStateId(iblockstate));
                }
            }
        }
    }
    if (entity.onGround) {
        if (entity.fallDistance > 0.0F) {
            // Responsible for breaking crops when you jump on them
            iblockstate.getBlock().onFallenUpon(entity.world, blockpos, entity, entity.fallDistance);
        }
        entity.fallDistance = 0.0F;
    } else if (entity.motionY < 0.0D) {
        entity.fallDistance = (float) (entity.fallDistance - entity.motionY);
    }
    if (/* entity.canTriggerWalking() **/
    entity instanceof EntityPlayer && !entity.isRiding()) {
        if (dy != origDy) {
            // if (!(entity.motionY > 0 && dy > 0)) {
            block.onLanded(entity.world, entity);
        // }
        }
        if (block != null && entity.onGround) {
            block.onEntityWalk(entity.world, blockpos, entity);
        }
        if (entity.distanceWalkedOnStepModified > entity.nextStepDistance && iblockstate.getMaterial() != Material.AIR) {
            entity.nextStepDistance = (int) entity.distanceWalkedOnStepModified + 1;
            /*
                 * if (this.isInWater()) { float f = MathHelper.sqrt_double(this.motionX *
                 * this.motionX * 0.20000000298023224D + this.motionY * this.motionY +
                 * this.motionZ * this.motionZ * 0.20000000298023224D) * 0.35F;
                 *
                 * if (f > 1.0F) { f = 1.0F; }
                 *
                 * this.playSound(this.getSwimSound(), f, 1.0F + (this.rand.nextFloat() -
                 * this.rand.nextFloat()) * 0.4F); }
                 */
            // System.out.println("Play a sound!");
            // entity.playStepSound(blockpos, block);
            // TODO: In future, replace this with entity.playStepSound()
            SoundType soundtype = block.getSoundType(entity.world.getBlockState(blockpos), entity.world, blockpos, entity);
            if (entity.world.getBlockState(blockpos.up()).getBlock() == Blocks.SNOW_LAYER) {
                soundtype = Blocks.SNOW_LAYER.getSoundType();
                entity.playSound(soundtype.getStepSound(), soundtype.getVolume() * 0.15F, soundtype.getPitch());
            } else if (!block.getDefaultState().getMaterial().isLiquid()) {
                entity.playSound(soundtype.getStepSound(), soundtype.getVolume() * 0.15F, soundtype.getPitch());
            }
        }
    }
    if (dx != origDx) {
        entity.motionX = dx;
    }
    if (dy != origDy) {
        if (!(entity.motionY > 0 && dy > 0)) {
            entity.motionY = 0;
        }
    }
    if (dz != origDz) {
        entity.motionZ = dz;
    }
}
Also used : SoundType(net.minecraft.block.SoundType) IBlockState(net.minecraft.block.state.IBlockState) ShipData(org.valkyrienskies.mod.common.ships.ShipData) WorldServer(net.minecraft.world.WorldServer) BlockSlime(net.minecraft.block.BlockSlime) Vector3d(org.joml.Vector3d) EntityLivingBase(net.minecraft.entity.EntityLivingBase) Block(net.minecraft.block.Block) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos)

Example 23 with ShipData

use of org.valkyrienskies.mod.common.ships.ShipData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class EntityDraggable method addEntityVelocityFromShipBelow.

/**
 * Adds the ship below velocity to entity.
 */
private static void addEntityVelocityFromShipBelow(final Entity entity) {
    final IDraggable draggable = EntityDraggable.getDraggableFromEntity(entity);
    final EntityShipMountData mountData = ValkyrienUtils.getMountedShipAndPos(entity);
    final EntityShipMovementData oldEntityShipMovementData = draggable.getEntityShipMovementData();
    final ShipData lastShipTouchedPlayer = oldEntityShipMovementData.getLastTouchedShip();
    final int oldTicksSinceTouchedShip = oldEntityShipMovementData.getTicksSinceTouchedShip();
    final Vector3dc oldVelocityAdded = oldEntityShipMovementData.getAddedLinearVelocity();
    final double oldYawVelocityAdded = oldEntityShipMovementData.getAddedYawVelocity();
    if (lastShipTouchedPlayer == null || oldTicksSinceTouchedShip >= VSConfig.ticksToStickToShip) {
        if (entity.onGround) {
            // Player is on ground and not on a ship, therefore set their added velocity to 0.
            draggable.setEntityShipMovementData(oldEntityShipMovementData.withAddedLinearVelocity(new Vector3d()).withAddedYawVelocity(0));
        } else {
            if (entity instanceof EntityPlayer) {
                EntityPlayer player = (EntityPlayer) entity;
                if (player.isCreative() && player.capabilities.isFlying) {
                    // If the player is flying, then slow down their added velocity significantly every tick
                    final Vector3dc newVelocityAdded = oldVelocityAdded.mul(.95, new Vector3d());
                    final double newYawVelocityAdded = oldYawVelocityAdded * .95 * .95;
                    final EntityShipMovementData newMovementData = oldEntityShipMovementData.withAddedLinearVelocity(newVelocityAdded).withAddedYawVelocity(newYawVelocityAdded);
                    draggable.setEntityShipMovementData(newMovementData);
                } else {
                    // Otherwise only slow down their added velocity slightly every tick
                    final Vector3dc newVelocityAdded = oldVelocityAdded.mul(.99, new Vector3d());
                    final double newYawVelocityAdded = oldYawVelocityAdded * .95;
                    final EntityShipMovementData newMovementData = oldEntityShipMovementData.withAddedLinearVelocity(newVelocityAdded).withAddedYawVelocity(newYawVelocityAdded);
                    draggable.setEntityShipMovementData(newMovementData);
                }
            }
        }
    } else {
        final float rotYaw = entity.rotationYaw;
        final float rotPitch = entity.rotationPitch;
        final float prevYaw = entity.prevRotationYaw;
        final float prevPitch = entity.prevRotationPitch;
        final Vector3dc oldPos = new Vector3d(entity.posX, entity.posY, entity.posZ);
        final Matrix4d betweenTransform = ShipTransform.createTransform(lastShipTouchedPlayer.getPrevTickShipTransform(), lastShipTouchedPlayer.getShipTransform());
        ValkyrienUtils.transformEntity(betweenTransform, entity, false);
        final Vector3dc newPos = new Vector3d(entity.posX, entity.posY, entity.posZ);
        // Move the entity back to its old position, the added velocity will be used
        // afterwards
        entity.setPosition(oldPos.x(), oldPos.y(), oldPos.z());
        final Vector3dc addedVel = newPos.sub(oldPos, new Vector3d());
        // Now compute the added yaw velocity
        entity.rotationYaw = rotYaw;
        entity.rotationPitch = rotPitch;
        entity.prevRotationYaw = prevYaw;
        entity.prevRotationPitch = prevPitch;
        // Ignore the pitch, calculate the look vector using only the yaw
        final Vector3d newLookYawVec;
        if (entity instanceof EntityLivingBase && !(entity instanceof EntityPlayer)) {
            newLookYawVec = new Vector3d(-MathHelper.sin(-entity.getRotationYawHead() * 0.017453292F - (float) Math.PI), 0, -MathHelper.cos(-entity.getRotationYawHead() * 0.017453292F - (float) Math.PI));
        } else {
            newLookYawVec = new Vector3d(-MathHelper.sin(-entity.rotationYaw * 0.017453292F - (float) Math.PI), 0, -MathHelper.cos(-entity.rotationYaw * 0.017453292F - (float) Math.PI));
        }
        // Transform the player look vector
        betweenTransform.transformDirection(newLookYawVec);
        // Calculate the yaw of the transformed player look vector
        final Tuple<Double, Double> newPlayerLookYawOnly = VSMath.getPitchYawFromVector(newLookYawVec);
        final double wrappedYaw = MathHelper.wrapDegrees(newPlayerLookYawOnly.getSecond());
        final double wrappedRotYaw;
        // [Changed because EntityPlayerSP is a 'client' class]
        if (entity instanceof EntityLivingBase && !(entity instanceof EntityPlayer)) {
            wrappedRotYaw = MathHelper.wrapDegrees(entity.getRotationYawHead());
        } else {
            wrappedRotYaw = MathHelper.wrapDegrees(entity.rotationYaw);
        }
        double yawDif = wrappedYaw - wrappedRotYaw;
        if (Math.abs(yawDif) > 180D) {
            if (yawDif < 0) {
                yawDif += 360D;
            } else {
                yawDif -= 360D;
            }
        }
        yawDif %= 360D;
        final double threshold = .1D;
        if (Math.abs(yawDif) < threshold) {
            yawDif = 0D;
        }
        draggable.setEntityShipMovementData(oldEntityShipMovementData.withAddedLinearVelocity(addedVel.mul(1, new Vector3d())).withAddedYawVelocity(yawDif));
    }
    final EntityShipMovementData newEntityShipMovementData = draggable.getEntityShipMovementData();
    // it unless we have to.
    if (newEntityShipMovementData.getAddedLinearVelocity().lengthSquared() > 0) {
        // Now that we've determined the added velocity, move the entity forward by that amount
        final boolean originallySneaking = entity.isSneaking();
        entity.setSneaking(false);
        // The added velocity vector of the player, except we have made sure that it won't push the player inside of a
        // solid block.
        final Vector3dc addedVelocityNoNoClip = applyAddedVelocity(newEntityShipMovementData.getAddedLinearVelocity(), entity);
        draggable.setEntityShipMovementData(oldEntityShipMovementData.withAddedLinearVelocity(addedVelocityNoNoClip));
        entity.setSneaking(originallySneaking);
    }
    // Add the yaw velocity to the player as well, because its possible for addedVelocity=0 and yawVel != 0
    final double addedYawVelocity = newEntityShipMovementData.getAddedYawVelocity();
    if (!mountData.isMounted() && addedYawVelocity != 0) {
        entity.setRotationYawHead((float) (entity.getRotationYawHead() + addedYawVelocity));
        entity.rotationYaw += addedYawVelocity;
    }
}
Also used : EntityShipMovementData(org.valkyrienskies.mod.common.entity.EntityShipMovementData) ShipData(org.valkyrienskies.mod.common.ships.ShipData) Vector3dc(org.joml.Vector3dc) Matrix4d(org.joml.Matrix4d) Vector3d(org.joml.Vector3d) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 24 with ShipData

use of org.valkyrienskies.mod.common.ships.ShipData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class ValkyrienUtils method assembleShipAsOrderedByPlayer.

public void assembleShipAsOrderedByPlayer(World world, @Nullable EntityPlayerMP creator, BlockPos physicsInfuserPos, BlockFinder.BlockFinderType blockFinderType) {
    if (world.isRemote) {
        throw new IllegalStateException("This method cannot be invoked on client side!");
    }
    if (!(world instanceof WorldServer)) {
        throw new IllegalStateException("The world " + world + " wasn't an instance of WorldServer");
    }
    // Create the ship data that we will use to make the ship with later.
    ShipData shipData = createNewShip(world, physicsInfuserPos);
    // Queue the ship spawn operation
    ((WorldServerShipManager) ValkyrienUtils.getPhysObjWorld(world)).queueShipSpawn(shipData, physicsInfuserPos, blockFinderType);
}
Also used : QueryableShipData(org.valkyrienskies.mod.common.ships.QueryableShipData) ShipData(org.valkyrienskies.mod.common.ships.ShipData) WorldServer(net.minecraft.world.WorldServer) WorldServerShipManager(org.valkyrienskies.mod.common.ships.ship_world.WorldServerShipManager)

Example 25 with ShipData

use of org.valkyrienskies.mod.common.ships.ShipData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class ITransformablePacket method doPreProcessing.

/**
 * Puts the player into local coordinates and makes a record of where they used to be.
 */
default void doPreProcessing(INetHandlerPlayServer server, boolean callingFromSponge) {
    if (isPacketOnMainThread(server, callingFromSponge)) {
        // System.out.println("Pre packet process");
        NetHandlerPlayServer serverHandler = (NetHandlerPlayServer) server;
        EntityPlayerMP player = serverHandler.player;
        ShipData physicsObject = getPacketParent(serverHandler);
        if (physicsObject != null) {
            // First make a backup of the player position
            ICapabilityEntityBackup entityBackup = player.getCapability(VSCapabilityRegistry.VS_ENTITY_BACKUP, null);
            entityBackup.backupEntityPosition(player);
            // Then put the player into ship coordinates.
            physicsObject.getShipTransform().transform(player, TransformType.GLOBAL_TO_SUBSPACE, true);
        }
    }
}
Also used : ShipData(org.valkyrienskies.mod.common.ships.ShipData) ICapabilityEntityBackup(org.valkyrienskies.mod.common.capability.entity_backup.ICapabilityEntityBackup) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) NetHandlerPlayServer(net.minecraft.network.NetHandlerPlayServer) INetHandlerPlayServer(net.minecraft.network.play.INetHandlerPlayServer)

Aggregations

ShipData (org.valkyrienskies.mod.common.ships.ShipData)25 QueryableShipData (org.valkyrienskies.mod.common.ships.QueryableShipData)14 Vector3d (org.joml.Vector3d)9 ShipTransform (org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform)6 Chunk (net.minecraft.world.chunk.Chunk)4 UUID (java.util.UUID)3 IBlockState (net.minecraft.block.state.IBlockState)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 BlockPos (net.minecraft.util.math.BlockPos)3 Vec3d (net.minecraft.util.math.Vec3d)3 World (net.minecraft.world.World)3 Inject (org.spongepowered.asm.mixin.injection.Inject)3 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 PacketBuffer (net.minecraft.network.PacketBuffer)2 TileEntity (net.minecraft.tileentity.TileEntity)2 ChunkPos (net.minecraft.util.math.ChunkPos)2 TextComponentString (net.minecraft.util.text.TextComponentString)2 WorldServer (net.minecraft.world.WorldServer)2