Search in sources :

Example 26 with Vector3d

use of org.joml.Vector3d in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class MixinWorld method spawnParticle.

/**
 * This is easier to have as an overwrite because there's less laggy hackery to be done then :P
 *
 * @author DaPorkchop_
 */
@Overwrite
public void spawnParticle(int particleID, boolean ignoreRange, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed, int... parameters) {
    BlockPos pos = new BlockPos(x, y, z);
    Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(World.class.cast(this), pos);
    if (physicsObject.isPresent()) {
        Vector3d newPosVec = new Vector3d(x, y, z);
        // RotationMatrices.applyTransform(wrapper.wrapping.coordTransform.lToWTransform,
        // newPosVec);
        physicsObject.get().getShipTransformationManager().getCurrentTickTransform().transformPosition(newPosVec, TransformType.SUBSPACE_TO_GLOBAL);
        x = newPosVec.x;
        y = newPosVec.y;
        z = newPosVec.z;
    }
    for (int i = 0; i < this.eventListeners.size(); ++i) {
        this.eventListeners.get(i).spawnParticle(particleID, ignoreRange, x, y, z, xSpeed, ySpeed, zSpeed, parameters);
    }
}
Also used : Vector3d(org.joml.Vector3d) IPhysObjectWorld(org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld) World(net.minecraft.world.World) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)

Example 27 with Vector3d

use of org.joml.Vector3d in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class MixinWorld method preGetCollisionBoxes.

/**
 * Used for two purposes. The first, is to prevent the game from freezing by limiting the size of aabb. The second
 * is to fix player sneaking on ships.
 */
@Inject(method = "getCollisionBoxes(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/math/AxisAlignedBB;ZLjava/util/List;)Z", at = @At("HEAD"), cancellable = true)
private void preGetCollisionBoxes(@Nullable Entity entityIn, AxisAlignedBB aabb, boolean p_191504_3_, @Nullable List<AxisAlignedBB> outList, CallbackInfoReturnable<Boolean> callbackInfo) {
    double deltaX = Math.abs(aabb.maxX - aabb.minX);
    double deltaY = Math.abs(aabb.maxY - aabb.minY);
    double deltaZ = Math.abs(aabb.maxZ - aabb.minZ);
    if (Math.max(deltaX, Math.max(deltaY, deltaZ)) > 99999D) {
        System.err.println(entityIn + "\ntried going extremely fast during the collision step");
        new Exception().printStackTrace();
        callbackInfo.setReturnValue(Boolean.FALSE);
        callbackInfo.cancel();
    }
    // direction, and uses that to determine if can you sneak.
    if (entityIn instanceof EntityPlayer && entityIn.isSneaking()) {
        // Add at most once ship block AABB that is colliding with the player. This is ONLY to properly allow
        // players to sneak while on ships.
        List<PhysicsObject> ships = getManager().getPhysObjectsInAABB(aabb);
        for (PhysicsObject wrapper : ships) {
            Polygon playerInLocal = new Polygon(aabb, wrapper.getShipTransformationManager().getCurrentTickTransform(), TransformType.GLOBAL_TO_SUBSPACE);
            AxisAlignedBB bb = playerInLocal.getEnclosedAABB();
            if ((bb.maxX - bb.minX) * (bb.maxZ - bb.minZ) > 9898989) {
                // This is too big, something went wrong here
                System.err.println("Why did transforming a players bounding box result in a giant bounding box?");
                System.err.println(bb + "\n" + wrapper.getShipData() + "\n" + entityIn.toString());
                new Exception().printStackTrace();
                return;
            }
            List<AxisAlignedBB> collidingBBs = getCollisionBoxes(null, bb);
            Polygon entityPoly = new Polygon(aabb.grow(-.2, 0, -.2));
            for (AxisAlignedBB inLocal : collidingBBs) {
                ShipPolygon poly = new ShipPolygon(inLocal, wrapper.getShipTransformationManager().getCurrentTickTransform(), TransformType.SUBSPACE_TO_GLOBAL, wrapper.getShipTransformationManager().normals, wrapper);
                EntityPolygonCollider collider = new EntityPolygonCollider(entityPoly, poly, poly.normals, new Vector3d());
                collider.processData();
                if (!collider.arePolygonsSeparated()) {
                    outList.add(inLocal);
                    // vanilla sneak code will work correctly.
                    return;
                }
            }
        }
    }
}
Also used : Vector3d(org.joml.Vector3d) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ShipPolygon(org.valkyrienskies.mod.common.collision.ShipPolygon) Polygon(org.valkyrienskies.mod.common.collision.Polygon) ShipPolygon(org.valkyrienskies.mod.common.collision.ShipPolygon) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) EntityPolygonCollider(org.valkyrienskies.mod.common.collision.EntityPolygonCollider) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 28 with Vector3d

use of org.joml.Vector3d in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class MixinEntityIntrinsic method onEntityPostMove.

/**
 * The goal of this injection is to correctly setup {@link IDraggable#getEntityShipMovementData()} for this Entity.
 * Specifically this code handles the last ship touched by the entity, as well as how many ticks ago that touch was.
 */
@Inject(method = "move", at = @At("RETURN"))
private void onEntityPostMove(CallbackInfo callbackInfo) {
    final EntityShipMovementData oldEntityShipMovementData = thisClassAsDraggable.getEntityShipMovementData();
    if (alteredMovement != null) {
        // If alteredMovement isn't null then we're touching a ship.
        final EntityShipMovementData newEntityShipMovementData = oldEntityShipMovementData.withLastTouchedShip(alteredMovement.shipTouched).withTicksSinceTouchedShip(0).withTicksPartOfGround(0);
        thisClassAsDraggable.setEntityShipMovementData(newEntityShipMovementData);
        EntityCollisionInjector.alterEntityMovementPost(thisClassAsAnEntity, alteredMovement);
    } else {
        if (this.collided) {
            // If we collided and alteredMovement is null, then we're touching the ground.
            final int newTicksPartOfGround = oldEntityShipMovementData.getTicksPartOfGround() + 1;
            final EntityShipMovementData newEntityShipMovementData = new EntityShipMovementData(null, 0, newTicksPartOfGround, new Vector3d(), 0);
            thisClassAsDraggable.setEntityShipMovementData(newEntityShipMovementData);
        } else {
            // If we're not collided and alteredMovement is null, then we're in the air.
            final int newTicksPartOfGround;
            if (oldEntityShipMovementData.getLastTouchedShip() != null) {
                newTicksPartOfGround = 0;
            } else {
                newTicksPartOfGround = oldEntityShipMovementData.getTicksPartOfGround() + 1;
            }
            final EntityShipMovementData newEntityShipMovementData = oldEntityShipMovementData.withTicksSinceTouchedShip(oldEntityShipMovementData.getTicksSinceTouchedShip() + 1).withTicksPartOfGround(newTicksPartOfGround);
            thisClassAsDraggable.setEntityShipMovementData(newEntityShipMovementData);
        }
    }
}
Also used : EntityShipMovementData(org.valkyrienskies.mod.common.entity.EntityShipMovementData) Vector3d(org.joml.Vector3d) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 29 with Vector3d

use of org.joml.Vector3d in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class MixinEntityMinecart method transformThis.

private void transformThis(Matrix4dc transform) {
    Vector3d pos = transform.transformPosition(JOML.convert(self.getPositionVector()));
    Vector3d lastPos = transform.transformPosition(new Vector3d(self.lastTickPosX, self.lastTickPosY, self.lastTickPosZ));
    self.setPosition(pos.x, pos.y, pos.z);
    self.lastTickPosX = lastPos.x;
    self.lastTickPosY = lastPos.y;
    self.lastTickPosZ = lastPos.z;
}
Also used : Vector3d(org.joml.Vector3d)

Example 30 with Vector3d

use of org.joml.Vector3d in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class MixinNetHandlerPlayServer method onSetPlayerLocation.

/**
 * Fixes things such that when mods try to teleport players into the ship space, VS will either
 * redirect the teleport or block it. Looking at you SimpleTeleporters mod >:/
 */
@Inject(method = "setPlayerLocation(DDDFFLjava/util/Set;)V", at = @At("HEAD"), cancellable = true)
public void onSetPlayerLocation(double x, double y, double z, float yaw, float pitch, Set<SPacketPlayerPosLook.EnumFlags> relativeSet, CallbackInfo callbackInfo) {
    if (!redirectingSetPlayerLocation) {
        BlockPos pos = new BlockPos(x, y, z);
        // If the player is being teleported to ship space then we have to stop it.
        if (ShipChunkAllocator.isBlockInShipyard(pos)) {
            callbackInfo.cancel();
            redirectingSetPlayerLocation = true;
            World world = player.getEntityWorld();
            Optional<ShipData> ship = ValkyrienUtils.getShipManagingBlock(world, pos);
            if (ship.isPresent()) {
                Vector3d tpPos = new Vector3d(x, y, z);
                ship.get().getShipTransform().transformPosition(tpPos, TransformType.SUBSPACE_TO_GLOBAL);
                // Now call this again with the transformed position.
                // player.sendMessage(new TextComponentString("Transformed the player tp from <"
                // + x + ":" + y + ":" + z + "> to" + tpPos));
                thisAsNetHandler.setPlayerLocation(tpPos.x, tpPos.y, tpPos.z, yaw, pitch, relativeSet);
                if (VSConfig.showAnnoyingDebugOutput) {
                    System.out.printf("Player was teleported to %.1f, %.1f, %.1f, redirected to %.1f, %.1f, %.1f\n", x, y, z, tpPos.x, tpPos.y, tpPos.z);
                }
            } else {
                if (VSConfig.showAnnoyingDebugOutput) {
                    System.out.printf("Player was teleported to %.1f, %.1f, %.1f, cancelling because no ship found\n", x, y, z);
                }
                player.sendMessage(new TextComponentString("Tried teleporting you to shipyard but there was no ship; teleportation canceled."));
            }
            redirectingSetPlayerLocation = false;
        }
    }
}
Also used : Vector3d(org.joml.Vector3d) QueryableShipData(org.valkyrienskies.mod.common.ships.QueryableShipData) ShipData(org.valkyrienskies.mod.common.ships.ShipData) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

Vector3d (org.joml.Vector3d)117 Vector3dc (org.joml.Vector3dc)33 PhysicsObject (org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)20 BlockPos (net.minecraft.util.math.BlockPos)19 ShipTransform (org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform)18 Location (io.xol.chunkstories.api.Location)12 Entity (io.xol.chunkstories.api.entity.Entity)11 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)9 World (net.minecraft.world.World)9 ShipData (org.valkyrienskies.mod.common.ships.ShipData)9 WorldClient (io.xol.chunkstories.api.world.WorldClient)8 WorldMaster (io.xol.chunkstories.api.world.WorldMaster)8 EntityPlayer (net.minecraft.entity.player.EntityPlayer)8 EntityShipMovementData (org.valkyrienskies.mod.common.entity.EntityShipMovementData)7 EntityControllable (io.xol.chunkstories.api.entity.interfaces.EntityControllable)6 IBlockState (net.minecraft.block.state.IBlockState)6 Vec3d (net.minecraft.util.math.Vec3d)6 Vector3f (org.joml.Vector3f)6 EntityLiving (io.xol.chunkstories.api.entity.EntityLiving)5 CellData (io.xol.chunkstories.api.world.cell.CellData)5