Search in sources :

Example 1 with PhysicsObject

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

the class EventsClient method onRenderWorldLastEvent.

@SubscribeEvent
public void onRenderWorldLastEvent(RenderWorldLastEvent event) {
    Minecraft mc = Minecraft.getMinecraft();
    World world = Minecraft.getMinecraft().world;
    if (mc.getRenderManager().isDebugBoundingBox() && !mc.isReducedDebug() && world != null) {
        float partialTicks = event.getPartialTicks();
        Vector3dc offset = VSRenderUtils.getEntityPartialPosition(mc.getRenderViewEntity(), partialTicks).negate();
        for (PhysicsObject physo : ValkyrienUtils.getPhysosLoadedInWorld(world)) {
            physo.getShipRenderer().renderDebugInfo(offset);
        }
    }
}
Also used : Vector3dc(org.joml.Vector3dc) IPhysObjectWorld(org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld) World(net.minecraft.world.World) Minecraft(net.minecraft.client.Minecraft) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with PhysicsObject

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

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

the class EventsClient method onClientTick.

@SubscribeEvent
public void onClientTick(ClientTickEvent event) {
    final World world = Minecraft.getMinecraft().world;
    if (world == null) {
        // There's no world, so there's nothing to run.
        return;
    }
    // Pretend this is the world tick, because diesieben07 doesn't want WorldClient to make world tick events.
    switch(event.phase) {
        case START:
            for (PhysicsObject wrapper : ((IHasShipManager) world).getManager().getAllLoadedPhysObj()) {
                // This is necessary because Minecraft will run a raytrace right after this
                // event to determine what the player is looking at for interaction purposes.
                // That raytrace will use the render transform, so we must have the render
                // transform set to a partialTick of 1.0.
                wrapper.getShipTransformationManager().updateRenderTransform(1.0);
            }
            // Reset the air pocket status of all entities
            for (final Entity entity : world.loadedEntityList) {
                final IDraggable draggable = (IDraggable) entity;
                draggable.decrementTicksAirPocket();
            }
            break;
        case END:
            if (!Minecraft.getMinecraft().isGamePaused()) {
                // Tick the IShipManager on the world client.
                IHasShipManager shipManager = (IHasShipManager) world;
                shipManager.getManager().tick();
                EntityDraggable.tickAddedVelocityForWorld(world);
            }
            break;
    }
}
Also used : Entity(net.minecraft.entity.Entity) IHasShipManager(org.valkyrienskies.mod.common.ships.ship_world.IHasShipManager) IDraggable(org.valkyrienskies.mod.common.ships.entity_interaction.IDraggable) IPhysObjectWorld(org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld) World(net.minecraft.world.World) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with PhysicsObject

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

the class EventsClient method onPlaySoundEvent.

@SubscribeEvent
public void onPlaySoundEvent(PlaySoundEvent event) {
    if (Minecraft.getMinecraft().world != null) {
        ISound sound = event.getSound();
        BlockPos pos = new BlockPos(sound.getXPosF(), sound.getYPosF(), sound.getZPosF());
        Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(Minecraft.getMinecraft().world, pos);
        if (physicsObject.isPresent()) {
            Vector3d newSoundLocation = new Vector3d(sound.getXPosF(), sound.getYPosF(), sound.getZPosF());
            physicsObject.get().getShipTransformationManager().getCurrentTickTransform().transformPosition(newSoundLocation, TransformType.SUBSPACE_TO_GLOBAL);
            SoundFixWrapper soundFix = new SoundFixWrapper(sound, newSoundLocation);
            event.setResultSound(soundFix);
        }
    }
}
Also used : ISound(net.minecraft.client.audio.ISound) Vector3d(org.joml.Vector3d) BlockPos(net.minecraft.util.math.BlockPos) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) SoundFixWrapper(org.valkyrienskies.mod.fixes.SoundFixWrapper) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 5 with PhysicsObject

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

the class EventsClient method onRenderTickEvent.

@SubscribeEvent
public void onRenderTickEvent(RenderTickEvent event) {
    final World world = Minecraft.getMinecraft().world;
    if (world == null) {
        // No ships to worry about.
        return;
    }
    double partialTicks = event.renderTickTime;
    if (Minecraft.getMinecraft().isGamePaused()) {
        partialTicks = Minecraft.getMinecraft().renderPartialTicksPaused;
    }
    if (event.phase == Phase.START) {
        lastPositionsMap.clear();
        for (PhysicsObject wrapper : ValkyrienUtils.getPhysosLoadedInWorld(world)) {
            wrapper.getShipTransformationManager().updateRenderTransform(partialTicks);
        }
        // variables so that Minecraft's interpolation code computes the correct value.
        for (final Entity entity : world.getLoadedEntityList()) {
            final EntityShipMovementData entityShipMovementData = ValkyrienUtils.getEntityShipMovementDataFor(entity);
            if (entityShipMovementData.getLastTouchedShip() != null && entityShipMovementData.getTicksSinceTouchedShip() < VSConfig.ticksToStickToShip) {
                final PhysicsObject shipPhysicsObject = ValkyrienUtils.getPhysObjWorld(world).getPhysObjectFromUUID(entityShipMovementData.getLastTouchedShip().getUuid());
                if (shipPhysicsObject == null) {
                    // This ship doesn't exist anymore, just remove it.
                    IDraggable.class.cast(entity).setEntityShipMovementData(entityShipMovementData.withLastTouchedShip(null));
                    continue;
                }
                final ShipTransform prevTickTransform = shipPhysicsObject.getPrevTickShipTransform();
                final ShipTransform shipRenderTransform = shipPhysicsObject.getShipTransformationManager().getRenderTransform();
                final Vector3dc entityAddedVelocity = entityShipMovementData.getAddedLinearVelocity();
                // The velocity the entity was moving without the added velocity from the ship
                final double entityMovementX = entity.posX - entityAddedVelocity.x() - entity.lastTickPosX;
                final double entityMovementY = entity.posY - entityAddedVelocity.y() - entity.lastTickPosY;
                final double entityMovementZ = entity.posZ - entityAddedVelocity.z() - entity.lastTickPosZ;
                // Compute the position the entity should be rendered at this frame
                final Vector3d entityShouldBeHere = new Vector3d(entity.lastTickPosX, entity.lastTickPosY, entity.lastTickPosZ);
                entityShouldBeHere.add(entityMovementX * partialTicks, entityMovementY * partialTicks, entityMovementZ * partialTicks);
                prevTickTransform.transformPosition(entityShouldBeHere, TransformType.GLOBAL_TO_SUBSPACE);
                shipRenderTransform.transformPosition(entityShouldBeHere, TransformType.SUBSPACE_TO_GLOBAL);
                // Save the entity lastTickPos in the map
                lastPositionsMap.put(entity, new Vector3d(entity.lastTickPosX, entity.lastTickPosY, entity.lastTickPosZ));
                // Then update lastTickPos such that Minecraft's interpolation code will render entity at entityShouldBeHere.
                entity.lastTickPosX = (entityShouldBeHere.x() - (entity.posX * partialTicks)) / (1 - partialTicks);
                entity.lastTickPosY = (entityShouldBeHere.y() - (entity.posY * partialTicks)) / (1 - partialTicks);
                entity.lastTickPosZ = (entityShouldBeHere.z() - (entity.posZ * partialTicks)) / (1 - partialTicks);
            }
        }
    // endregion
    } else {
        // Once the rendering code has finished we restore the lastTickPos variables to their old values.
        for (final Entity entity : world.getLoadedEntityList()) {
            if (lastPositionsMap.containsKey(entity)) {
                final Vector3dc entityLastPosition = lastPositionsMap.get(entity);
                entity.lastTickPosX = entityLastPosition.x();
                entity.lastTickPosY = entityLastPosition.y();
                entity.lastTickPosZ = entityLastPosition.z();
            }
        }
    }
}
Also used : EntityShipMovementData(org.valkyrienskies.mod.common.entity.EntityShipMovementData) Vector3dc(org.joml.Vector3dc) Entity(net.minecraft.entity.Entity) ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) Vector3d(org.joml.Vector3d) IDraggable(org.valkyrienskies.mod.common.ships.entity_interaction.IDraggable) IPhysObjectWorld(org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld) World(net.minecraft.world.World) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

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