Search in sources :

Example 36 with PhysicsObject

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

the class MixinWorld method postCheckBlockCollision.

/**
 * This mixin fixes players getting kicked for flying when they're standing on the ground.
 */
@Inject(method = "checkBlockCollision", at = @At("HEAD"), cancellable = true)
public void postCheckBlockCollision(final AxisAlignedBB axisAlignedBB, final CallbackInfoReturnable<Boolean> callbackInfoReturnable) {
    // If there wasn't a collision in the world, then check if there is a collision in ships
    final List<PhysicsObject> physObjectsInAABB = getManager().getPhysObjectsInAABB(axisAlignedBB);
    for (final PhysicsObject physicsObject : physObjectsInAABB) {
        final ShipTransform shipTransform = physicsObject.getShipTransform();
        final AxisAlignedBB aabbInShipSpace = new Polygon(axisAlignedBB, shipTransform.getGlobalToSubspace()).getEnclosedAABB();
        final boolean collisionInShip = this.checkBlockCollision(aabbInShipSpace);
        if (collisionInShip) {
            callbackInfoReturnable.setReturnValue(true);
            return;
        }
    }
}
Also used : ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) Polygon(org.valkyrienskies.mod.common.collision.Polygon) ShipPolygon(org.valkyrienskies.mod.common.collision.ShipPolygon) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 37 with PhysicsObject

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

the class MixinEntity method getDistanceSq.

/**
 * This is easier to have as an overwrite because there's less laggy hackery to be done then :P
 *
 * @author DaPorkchop_
 */
@Overwrite
public double getDistanceSq(BlockPos pos) {
    double vanilla = pos.getDistance((int) posX, (int) posY, (int) posZ);
    if (vanilla < 64.0D) {
        return vanilla;
    } else {
        Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(world, pos);
        if (physicsObject.isPresent()) {
            Vector3d posVec = new Vector3d(pos.getX() + .5D, pos.getY() + .5D, pos.getZ() + .5D);
            physicsObject.get().getShipTransformationManager().getCurrentTickTransform().transformPosition(posVec, TransformType.SUBSPACE_TO_GLOBAL);
            posVec.x -= this.posX;
            posVec.y -= this.posY;
            posVec.z -= this.posZ;
            if (vanilla > posVec.lengthSquared()) {
                return posVec.lengthSquared();
            }
        }
    }
    return vanilla;
}
Also used : Vector3d(org.joml.Vector3d) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 38 with PhysicsObject

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

the class MixinEntity method getDistanceSq.

/**
 * This is easier to have as an overwrite because there's less laggy hackery to be done then :P
 *
 * @author DaPorkchop_
 */
@Overwrite
public double getDistanceSq(double x, double y, double z) {
    double d0 = this.posX - x;
    double d1 = this.posY - y;
    double d2 = this.posZ - z;
    double vanilla = d0 * d0 + d1 * d1 + d2 * d2;
    if (vanilla < 64.0D) {
        return vanilla;
    } else {
        Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(world, new BlockPos(x, y, z));
        if (physicsObject.isPresent()) {
            Vector3d posVec = new Vector3d(x, y, z);
            physicsObject.get().getShipTransformationManager().getCurrentTickTransform().transformPosition(posVec, TransformType.SUBSPACE_TO_GLOBAL);
            posVec.x -= this.posX;
            posVec.y -= this.posY;
            posVec.z -= this.posZ;
            if (vanilla > posVec.lengthSquared()) {
                return posVec.lengthSquared();
            }
        }
    }
    return vanilla;
}
Also used : Vector3d(org.joml.Vector3d) BlockPos(net.minecraft.util.math.BlockPos) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 39 with PhysicsObject

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

the class MixinRenderGlobal method preRenderBlockLayer.

@Inject(method = "renderBlockLayer(Lnet/minecraft/util/BlockRenderLayer;DILnet/minecraft/entity/Entity;)I", at = @At("HEAD"))
private void preRenderBlockLayer(BlockRenderLayer blockLayerIn, double partialTicks, int pass, Entity entityIn, CallbackInfoReturnable callbackInfo) {
    RenderHelper.disableStandardItemLighting();
    // This probably won't work with strange mods, but I'm too lazy to do it better
    ICamera icamera = new Frustum();
    Entity entity = this.mc.getRenderViewEntity();
    double d0 = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * (double) partialTicks;
    double d1 = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * (double) partialTicks;
    double d2 = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * (double) partialTicks;
    icamera.setPosition(d0, d1, d2);
    for (PhysicsObject physicsObject : ValkyrienUtils.getPhysObjWorld(world).getAllLoadedPhysObj()) {
        GL11.glPushMatrix();
        if (physicsObject.getShipRenderer().shouldRender(icamera)) {
            physicsObject.getShipRenderer().renderBlockLayer(blockLayerIn, partialTicks, pass, icamera);
        }
        GL11.glPopMatrix();
    }
    GlStateManager.resetColor();
}
Also used : Frustum(net.minecraft.client.renderer.culling.Frustum) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) ICamera(net.minecraft.client.renderer.culling.ICamera) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 40 with PhysicsObject

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

the class MixinRenderGlobal method preMarkBlocksForUpdate.

@Inject(method = "markBlocksForUpdate", at = @At("HEAD"))
private void preMarkBlocksForUpdate(int minX, int minY, int minZ, int maxX, int maxY, int maxZ, boolean updateImmediately, CallbackInfo ci) {
    Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(world, new BlockPos(minX, minY, minZ));
    if (!physicsObject.isPresent()) {
        // Try again
        physicsObject = ValkyrienUtils.getPhysoManagingBlock(world, new BlockPos(minX, maxY, maxZ));
    }
    if (!physicsObject.isPresent()) {
        // Try again
        physicsObject = ValkyrienUtils.getPhysoManagingBlock(world, new BlockPos(maxX, maxY, minZ));
    }
    if (!physicsObject.isPresent()) {
        // Try again
        physicsObject = ValkyrienUtils.getPhysoManagingBlock(world, new BlockPos(maxX, maxY, maxZ));
    }
    physicsObject.ifPresent(p -> p.getShipRenderer().updateRange(minX, minY, minZ, maxX, maxY, maxZ, updateImmediately));
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) Inject(org.spongepowered.asm.mixin.injection.Inject)

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