Search in sources :

Example 1 with IPhysObjectWorld

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

the class EventsClient method onChunkLoadEvent.

/**
 * Used to handle when a chunk in a ship gets updated. This allows us to create ships on the client without
 * requiring all the chunks are present at the time of ship creation.
 */
@SubscribeEvent
public void onChunkLoadEvent(ChunkEvent.Load event) {
    if (!event.getWorld().isRemote) {
        return;
    }
    Chunk chunk = event.getChunk();
    QueryableShipData queryableShipData = QueryableShipData.get(event.getWorld());
    Optional<ShipData> shipClaimingOptional = queryableShipData.getShipFromChunk(chunk.x, chunk.z);
    if (shipClaimingOptional.isPresent()) {
        ShipData shipData = shipClaimingOptional.get();
        IPhysObjectWorld physObjectWorld = ValkyrienUtils.getPhysObjWorld(event.getWorld());
        PhysicsObject physicsObject = physObjectWorld.getPhysObjectFromUUID(shipData.getUuid());
        if (physicsObject != null) {
            physicsObject.updateChunk(chunk);
        }
    }
}
Also used : QueryableShipData(org.valkyrienskies.mod.common.ships.QueryableShipData) ShipData(org.valkyrienskies.mod.common.ships.ShipData) Chunk(net.minecraft.world.chunk.Chunk) QueryableShipData(org.valkyrienskies.mod.common.ships.QueryableShipData) IPhysObjectWorld(org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with IPhysObjectWorld

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

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

the class ShipIndexDataMessageHandler method onMessage.

@Override
@SuppressWarnings("Convert2Lambda")
public // errors. DON'T USE A LAMBDA
IMessage onMessage(ShipIndexDataMessage message, MessageContext ctx) {
    IThreadListener mainThread = Minecraft.getMinecraft();
    mainThread.addScheduledTask(new Runnable() {

        @Override
        public void run() {
            World world = Minecraft.getMinecraft().world;
            IPhysObjectWorld physObjectWorld = ValkyrienUtils.getPhysObjWorld(world);
            QueryableShipData worldData = QueryableShipData.get(world);
            for (ShipData shipData : message.indexedData) {
                worldData.addOrUpdateShipPreservingPhysObj(shipData, world);
            }
            for (UUID loadID : message.shipsToLoad) {
                physObjectWorld.queueShipLoad(loadID);
            }
            for (UUID unloadID : message.shipsToUnload) {
                physObjectWorld.queueShipUnload(unloadID);
            }
        }
    });
    return null;
}
Also used : ShipData(org.valkyrienskies.mod.common.ships.ShipData) QueryableShipData(org.valkyrienskies.mod.common.ships.QueryableShipData) IThreadListener(net.minecraft.util.IThreadListener) World(net.minecraft.world.World) IPhysObjectWorld(org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld) UUID(java.util.UUID) IPhysObjectWorld(org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld) QueryableShipData(org.valkyrienskies.mod.common.ships.QueryableShipData)

Example 4 with IPhysObjectWorld

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

the class ShipTransformUpdateMessageHandler method onMessage.

@Override
@SuppressWarnings("Convert2Lambda")
public // errors. DON'T USE A LAMBDA
IMessage onMessage(final ShipTransformUpdateMessage message, final MessageContext ctx) {
    IThreadListener mainThread = Minecraft.getMinecraft();
    mainThread.addScheduledTask(new Runnable() {

        @Override
        public void run() {
            World world = Minecraft.getMinecraft().world;
            IPhysObjectWorld physObjectWorld = ValkyrienUtils.getPhysObjWorld(world);
            QueryableShipData worldData = QueryableShipData.get(world);
            for (Map.Entry<UUID, Tuple<ShipTransform, AxisAlignedBB>> transformUpdate : message.shipTransforms.entrySet()) {
                final UUID shipID = transformUpdate.getKey();
                final ShipTransform shipTransform = transformUpdate.getValue().getFirst();
                final AxisAlignedBB shipBB = transformUpdate.getValue().getSecond();
                final PhysicsObject physicsObject = ValkyrienUtils.getPhysObjWorld(world).getPhysObjectFromUUID(shipID);
                if (physicsObject != null) {
                    // Do not update the transform in ShipData, that will be done by PhysicsObject.tick()
                    ITransformInterpolator interpolator = physicsObject.getTransformInterpolator();
                    interpolator.onNewTransformPacket(shipTransform, shipBB);
                }
            }
        }
    });
    return null;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) ITransformInterpolator(org.valkyrienskies.mod.common.ships.interpolation.ITransformInterpolator) IThreadListener(net.minecraft.util.IThreadListener) World(net.minecraft.world.World) IPhysObjectWorld(org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld) UUID(java.util.UUID) IPhysObjectWorld(org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld) QueryableShipData(org.valkyrienskies.mod.common.ships.QueryableShipData) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)

Example 5 with IPhysObjectWorld

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

the class MixinWorld method rayTraceBlocksIgnoreShip.

@Override
public RayTraceResult rayTraceBlocksIgnoreShip(Vec3d vec31, Vec3d vec32, boolean stopOnLiquid, boolean ignoreBlockWithoutBoundingBox, boolean returnLastUncollidableBlock, PhysicsObject toIgnore) {
    this.shouldInterceptRayTrace = false;
    RayTraceResult vanillaTrace = World.class.cast(this).rayTraceBlocks(vec31, vec32, stopOnLiquid, ignoreBlockWithoutBoundingBox, returnLastUncollidableBlock);
    IPhysObjectWorld physObjectWorld = ((IHasShipManager) (this)).getManager();
    if (physObjectWorld == null) {
        return vanillaTrace;
    }
    Vec3d playerReachVector = vec32.subtract(vec31);
    AxisAlignedBB playerRangeBB = new AxisAlignedBB(vec31.x, vec31.y, vec31.z, vec32.x, vec32.y, vec32.z);
    List<PhysicsObject> nearbyShips = physObjectWorld.getPhysObjectsInAABB(playerRangeBB);
    // Get rid of the Ship that we're not supposed to be RayTracing for
    nearbyShips.remove(toIgnore);
    double reachDistance = playerReachVector.length();
    double worldResultDistFromPlayer = 420000000D;
    if (vanillaTrace != null && vanillaTrace.hitVec != null) {
        worldResultDistFromPlayer = vanillaTrace.hitVec.distanceTo(vec31);
    }
    for (PhysicsObject wrapper : nearbyShips) {
        Vec3d playerEyesPos = vec31;
        playerReachVector = vec32.subtract(vec31);
        ShipTransform shipTransform = wrapper.getShipTransformationManager().getRenderTransform();
        playerEyesPos = shipTransform.transform(playerEyesPos, TransformType.GLOBAL_TO_SUBSPACE);
        playerReachVector = shipTransform.rotate(playerReachVector, TransformType.GLOBAL_TO_SUBSPACE);
        Vec3d playerEyesReachAdded = playerEyesPos.add(playerReachVector.x * reachDistance, playerReachVector.y * reachDistance, playerReachVector.z * reachDistance);
        RayTraceResult resultInShip = World.class.cast(this).rayTraceBlocks(playerEyesPos, playerEyesReachAdded, stopOnLiquid, ignoreBlockWithoutBoundingBox, returnLastUncollidableBlock);
        if (resultInShip != null && resultInShip.hitVec != null && resultInShip.typeOfHit == Type.BLOCK) {
            double shipResultDistFromPlayer = resultInShip.hitVec.distanceTo(playerEyesPos);
            if (shipResultDistFromPlayer < worldResultDistFromPlayer) {
                worldResultDistFromPlayer = shipResultDistFromPlayer;
                // The hitVec must ALWAYS be in global coordinates.
                resultInShip.hitVec = shipTransform.transform(resultInShip.hitVec, TransformType.SUBSPACE_TO_GLOBAL);
                vanillaTrace = resultInShip;
            }
        }
    }
    this.shouldInterceptRayTrace = true;
    return vanillaTrace;
}
Also used : ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) IHasShipManager(org.valkyrienskies.mod.common.ships.ship_world.IHasShipManager) IPhysObjectWorld(org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld) World(net.minecraft.world.World) IPhysObjectWorld(org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)

Aggregations

IPhysObjectWorld (org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld)5 World (net.minecraft.world.World)4 PhysicsObject (org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)4 QueryableShipData (org.valkyrienskies.mod.common.ships.QueryableShipData)3 ShipTransform (org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform)3 UUID (java.util.UUID)2 IThreadListener (net.minecraft.util.IThreadListener)2 Chunk (net.minecraft.world.chunk.Chunk)2 ShipData (org.valkyrienskies.mod.common.ships.ShipData)2 IHasShipManager (org.valkyrienskies.mod.common.ships.ship_world.IHasShipManager)2 Predicate (com.google.common.base.Predicate)1 Lists (com.google.common.collect.Lists)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Optional (java.util.Optional)1 Function (java.util.function.Function)1 Nullable (javax.annotation.Nullable)1 IBlockState (net.minecraft.block.state.IBlockState)1 Entity (net.minecraft.entity.Entity)1