Search in sources :

Example 11 with PhysicsObject

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

the class MixinWorld method rayTraceBlocksForGetBlockDensity.

/**
 * Use Bresenham's tracing algorithm instead of raytracing for getBlockDensity, makes it way faster
 */
@Redirect(method = "getBlockDensity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;rayTraceBlocks(Lnet/minecraft/util/math/Vec3d;Lnet/minecraft/util/math/Vec3d;)Lnet/minecraft/util/math/RayTraceResult;"))
private RayTraceResult rayTraceBlocksForGetBlockDensity(World world, Vec3d start, Vec3d end) {
    if (VSConfig.explosionMode == ExplosionMode.VANILLA) {
        // Vanilla raytrace, ignore ships and perform the function like normal
        this.shouldInterceptRayTrace = false;
        RayTraceResult result = rayTraceBlocks(start, end);
        this.shouldInterceptRayTrace = true;
        return result;
    } else if (VSConfig.explosionMode == ExplosionMode.SLOW_VANILLA) {
        // Vanilla raytrace, include ships and perform the function like normal
        return rayTraceBlocks(start, end);
    }
    java.util.function.Predicate<BlockPos> canCollide = pos -> {
        IBlockState blockState = world.getBlockState(pos);
        return blockState.getBlock().canCollideCheck(blockState, false);
    };
    // Get all the blocks between start and end
    List<BlockPos> blocks = VSMath.generateLineBetween(start, end, BlockPos::new);
    // Whether or not this ray trace hit a block that was collidable.
    boolean collided = blocks.stream().anyMatch(canCollide);
    IPhysObjectWorld physObjectWorld = ((IHasShipManager) (this)).getManager();
    if (physObjectWorld != null) {
        List<PhysicsObject> nearbyShips = physObjectWorld.getPhysObjectsInAABB(new AxisAlignedBB(start.x, start.y, start.z, end.x, end.y, end.z));
        for (PhysicsObject obj : nearbyShips) {
            Vec3d transformedStart = obj.transformVector(start, TransformType.GLOBAL_TO_SUBSPACE);
            Vec3d transformedEnd = obj.transformVector(end, TransformType.GLOBAL_TO_SUBSPACE);
            // Transform the raytrace into ship space and check whether or not it hit a block
            List<BlockPos> physoBlocks = VSMath.generateLineBetween(transformedStart, transformedEnd, BlockPos::new);
            collided |= physoBlocks.stream().anyMatch(canCollide);
        }
    }
    // important information in the ray trace result.
    return collided ? DUMMY_RAYTRACE_RESULT : null;
}
Also used : Polygon(org.valkyrienskies.mod.common.collision.Polygon) Inject(org.spongepowered.asm.mixin.injection.Inject) IHasShipManager(org.valkyrienskies.mod.common.ships.ship_world.IHasShipManager) IWorldEventListener(net.minecraft.world.IWorldEventListener) ShipPolygon(org.valkyrienskies.mod.common.collision.ShipPolygon) MixinWorldIntrinsicMethods(org.valkyrienskies.mod.fixes.MixinWorldIntrinsicMethods) Function(java.util.function.Function) CallbackInfoReturnable(org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable) IPhysObjectWorld(org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld) ArrayList(java.util.ArrayList) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) Lists(com.google.common.collect.Lists) EntityPolygonCollider(org.valkyrienskies.mod.common.collision.EntityPolygonCollider) ExplosionMode(org.valkyrienskies.mod.common.config.VSConfig.ExplosionMode) org.spongepowered.asm.mixin(org.spongepowered.asm.mixin) Vector3d(org.joml.Vector3d) Chunk(net.minecraft.world.chunk.Chunk) Nullable(javax.annotation.Nullable) At(org.spongepowered.asm.mixin.injection.At) Entity(net.minecraft.entity.Entity) Iterator(java.util.Iterator) VSMath(org.valkyrienskies.mod.common.util.VSMath) net.minecraft.util.math(net.minecraft.util.math) World(net.minecraft.world.World) Redirect(org.spongepowered.asm.mixin.injection.Redirect) TransformType(valkyrienwarfare.api.TransformType) EnumFacing(net.minecraft.util.EnumFacing) Remap(org.spongepowered.asm.mixin.Interface.Remap) Type(net.minecraft.util.math.RayTraceResult.Type) IBlockState(net.minecraft.block.state.IBlockState) ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) List(java.util.List) ValkyrienUtils(org.valkyrienskies.mod.common.util.ValkyrienUtils) VSConfig(org.valkyrienskies.mod.common.config.VSConfig) Predicate(com.google.common.base.Predicate) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IWorldVS(org.valkyrienskies.mod.common.ships.ship_world.IWorldVS) Optional(java.util.Optional) IBlockState(net.minecraft.block.state.IBlockState) IPhysObjectWorld(org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) IHasShipManager(org.valkyrienskies.mod.common.ships.ship_world.IHasShipManager) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 12 with PhysicsObject

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

the class MixinEntityMinecart method moveToSubspace.

private void moveToSubspace() {
    Vec3d position = self.getPositionVector();
    for (PhysicsObject ship : ValkyrienUtils.getPhysosLoadedInWorld(self.world)) {
        if (ship.getShipBB().contains(position)) {
            transform = ship.getShipTransform();
            transformThis(transform.getGlobalToSubspace());
            isInGlobal = false;
            return;
        }
    }
}
Also used : PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) Vec3d(net.minecraft.util.math.Vec3d)

Example 13 with PhysicsObject

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

the class MixinCPacketPlayerDigging method getPacketParent.

@Override
public ShipData getPacketParent(NetHandlerPlayServer server) {
    World world = server.player.getEntityWorld();
    Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(world, thisPacketTryUse.getPosition());
    if (physicsObject.isPresent()) {
        return physicsObject.get().getShipData();
    } else {
        return null;
    }
}
Also used : World(net.minecraft.world.World) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)

Example 14 with PhysicsObject

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

the class MixinCPacketUpdateSign method getPacketParent.

@Override
public ShipData getPacketParent(NetHandlerPlayServer server) {
    World world = server.player.getEntityWorld();
    Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(world, thisAsPacketSign.getPosition());
    if (physicsObject.isPresent()) {
        return physicsObject.get().getShipData();
    } else {
        return null;
    }
}
Also used : World(net.minecraft.world.World) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)

Example 15 with PhysicsObject

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

the class MixinCPacketPlayerTryUseItemOnBlock method getPacketParent.

@Override
public ShipData getPacketParent(NetHandlerPlayServer server) {
    World world = server.player.getEntityWorld();
    Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(world, thisPacketTryUse.getPos());
    if (physicsObject.isPresent()) {
        return physicsObject.get().getShipData();
    } else {
        return null;
    }
}
Also used : World(net.minecraft.world.World) 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