Search in sources :

Example 6 with PhysicsObject

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

the class EventsClient method onDrawBlockHighlightEventFirst.

@SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true)
public void onDrawBlockHighlightEventFirst(DrawBlockHighlightEvent event) {
    GL11.glPushMatrix();
    BlockPos pos = Minecraft.getMinecraft().objectMouseOver.getBlockPos();
    Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(Minecraft.getMinecraft().world, pos);
    if (physicsObject.isPresent()) {
        RayTraceResult objectOver = Minecraft.getMinecraft().objectMouseOver;
        if (objectOver != null && objectOver.hitVec != null) {
            BufferBuilder buffer = Tessellator.getInstance().getBuffer();
            oldXOff = buffer.xOffset;
            oldYOff = buffer.yOffset;
            oldZOff = buffer.zOffset;
            buffer.setTranslation(-physicsObject.get().getShipRenderer().offsetPos.getX(), -physicsObject.get().getShipRenderer().offsetPos.getY(), -physicsObject.get().getShipRenderer().offsetPos.getZ());
            physicsObject.get().getShipRenderer().applyRenderTransform(event.getPartialTicks());
        }
    }
}
Also used : BufferBuilder(net.minecraft.client.renderer.BufferBuilder) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockPos(net.minecraft.util.math.BlockPos) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 7 with PhysicsObject

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

the class BlockCaptainsChair method onBlockActivated.

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (!worldIn.isRemote) {
        Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(worldIn, pos);
        if (physicsObject.isPresent()) {
            TileEntity tileEntity = worldIn.getTileEntity(pos);
            if (tileEntity instanceof TileEntityCaptainsChair) {
                Vector3d playerPos = new Vector3d(playerIn.posX, playerIn.posY, playerIn.posZ);
                physicsObject.get().getShipTransformationManager().getCurrentTickTransform().transformPosition(playerPos, TransformType.SUBSPACE_TO_GLOBAL);
                playerIn.posX = playerPos.x;
                playerIn.posY = playerPos.y;
                playerIn.posZ = playerPos.z;
                // Only mount the player if they're standing on the ship.
                final EntityShipMovementData entityShipMovementData = ValkyrienUtils.getEntityShipMovementDataFor(playerIn);
                if (entityShipMovementData.getTicksSinceTouchedShip() == 0 && (entityShipMovementData.getLastTouchedShip() == physicsObject.get().getShipData())) {
                    Vector3dc localMountPos = getPlayerMountOffset(state, pos);
                    ValkyrienUtils.fixEntityToShip(playerIn, localMountPos, physicsObject.get());
                }
                ((TileEntityCaptainsChair) tileEntity).setPilotEntity(playerIn);
                physicsObject.get().getShipTransformationManager().getCurrentTickTransform().transformPosition(playerPos, TransformType.GLOBAL_TO_SUBSPACE);
                playerIn.posX = playerPos.x;
                playerIn.posY = playerPos.y;
                playerIn.posZ = playerPos.z;
            }
        }
    }
    return true;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EntityShipMovementData(org.valkyrienskies.mod.common.entity.EntityShipMovementData) Vector3dc(org.joml.Vector3dc) Vector3d(org.joml.Vector3d) TileEntityCaptainsChair(org.valkyrienskies.mod.common.tileentity.TileEntityCaptainsChair) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)

Example 8 with PhysicsObject

use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject 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 9 with PhysicsObject

use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject 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 10 with PhysicsObject

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

the class MixinWorld method getEntitiesInAABBexcluding.

/**
 * aa
 *
 * @author xd
 */
@Overwrite
public List<Entity> getEntitiesInAABBexcluding(@Nullable Entity entityIn, AxisAlignedBB boundingBox, @Nullable Predicate<? super Entity> predicate) {
    if (isBoundingBoxTooLarge(boundingBox)) {
        new Exception("Tried getting entities from giant bounding box of " + boundingBox).printStackTrace();
        return new ArrayList<>();
    }
    List<Entity> toReturn = this.getEntitiesInAABBexcludingOriginal(entityIn, boundingBox, predicate);
    BlockPos pos = new BlockPos((boundingBox.minX + boundingBox.maxX) / 2D, (boundingBox.minY + boundingBox.maxY) / 2D, (boundingBox.minZ + boundingBox.maxZ) / 2D);
    Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(World.class.cast(this), pos);
    if (physicsObject.isPresent()) {
        Polygon poly = new Polygon(boundingBox, physicsObject.get().getShipTransformationManager().getCurrentTickTransform(), TransformType.SUBSPACE_TO_GLOBAL);
        boundingBox = poly.getEnclosedAABB().shrink(.3D);
        if (isBoundingBoxTooLarge(boundingBox)) {
            new Exception("Tried getting entities from giant bounding box of " + boundingBox).printStackTrace();
            return new ArrayList<>();
        }
        toReturn.addAll(this.getEntitiesInAABBexcludingOriginal(entityIn, boundingBox, predicate));
    }
    return toReturn;
}
Also used : Entity(net.minecraft.entity.Entity) ArrayList(java.util.ArrayList) IPhysObjectWorld(org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld) World(net.minecraft.world.World) Polygon(org.valkyrienskies.mod.common.collision.Polygon) ShipPolygon(org.valkyrienskies.mod.common.collision.ShipPolygon) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)

Aggregations

PhysicsObject (org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)54 World (net.minecraft.world.World)21 Vector3d (org.joml.Vector3d)21 BlockPos (net.minecraft.util.math.BlockPos)20 ShipTransform (org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform)10 IPhysObjectWorld (org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld)10 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)9 Vector3dc (org.joml.Vector3dc)9 TileEntity (net.minecraft.tileentity.TileEntity)8 Inject (org.spongepowered.asm.mixin.injection.Inject)8 Polygon (org.valkyrienskies.mod.common.collision.Polygon)8 ShipPolygon (org.valkyrienskies.mod.common.collision.ShipPolygon)8 Entity (net.minecraft.entity.Entity)7 EntityPlayer (net.minecraft.entity.player.EntityPlayer)7 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)7 IBlockState (net.minecraft.block.state.IBlockState)5 Overwrite (org.spongepowered.asm.mixin.Overwrite)5 ArrayList (java.util.ArrayList)4 IThreadListener (net.minecraft.util.IThreadListener)4 Vec3d (net.minecraft.util.math.Vec3d)4