Search in sources :

Example 41 with PhysicsObject

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

the class MixinTileEntityRendererDispatcher method preRender.

@Inject(method = "render(Lnet/minecraft/tileentity/TileEntity;FI)V", at = @At("HEAD"), cancellable = true)
private void preRender(TileEntity tileentityIn, float partialTicks, int destroyStage, CallbackInfo callbackInfo) {
    if (!hasChanged) {
        BlockPos pos = tileentityIn.getPos();
        Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(tileentityIn.getWorld(), tileentityIn.getPos());
        if (physicsObject.isPresent()) {
            try {
                GlStateManager.resetColor();
                if (drawingBatch) {
                    this.drawBatch(MinecraftForgeClient.getRenderPass());
                    this.preDrawBatch();
                }
                physicsObject.get().getShipRenderer().applyRenderTransform(partialTicks);
                double playerX = TileEntityRendererDispatcher.staticPlayerX;
                double playerY = TileEntityRendererDispatcher.staticPlayerY;
                double playerZ = TileEntityRendererDispatcher.staticPlayerZ;
                TileEntityRendererDispatcher.staticPlayerX = physicsObject.get().getShipRenderer().offsetPos.getX();
                TileEntityRendererDispatcher.staticPlayerY = physicsObject.get().getShipRenderer().offsetPos.getY();
                TileEntityRendererDispatcher.staticPlayerZ = physicsObject.get().getShipRenderer().offsetPos.getZ();
                hasChanged = true;
                if (drawingBatch) {
                    this.render(tileentityIn, partialTicks, destroyStage);
                    this.drawBatch(MinecraftForgeClient.getRenderPass());
                    this.preDrawBatch();
                } else {
                    this.render(tileentityIn, partialTicks, destroyStage);
                }
                hasChanged = false;
                TileEntityRendererDispatcher.staticPlayerX = playerX;
                TileEntityRendererDispatcher.staticPlayerY = playerY;
                TileEntityRendererDispatcher.staticPlayerZ = playerZ;
                physicsObject.get().getShipRenderer().applyInverseTransform(partialTicks);
            } catch (Exception e) {
                e.printStackTrace();
            }
            callbackInfo.cancel();
        }
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 42 with PhysicsObject

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

the class MixinNetHandlerPlayServer method preProcessPlayer.

/**
 * This mixin fixes "Player Moved Wrongly" errors.
 *
 * @param packetPlayer The packet the player sent us
 * @param info We can use this to cancel the invocation
 */
@Inject(method = "processPlayer", at = @At("HEAD"))
private void preProcessPlayer(final CPacketPlayer packetPlayer, final CallbackInfo info) {
    // Don't run any of this code on the network thread!
    if (this.player.getServerWorld().isCallingFromMinecraftThread()) {
        // This fixes players dying of fall damage when changing dimensions
        if (this.player.isInvulnerableDimensionChange()) {
            return;
        }
        final PlayerMovementData addedPlayerMovementData = IHasPlayerMovementData.class.cast(packetPlayer).getPlayerMovementData();
        final World world = player.world;
        final UUID lastTouchedShipId = addedPlayerMovementData.getLastTouchedShipId();
        final int ticksSinceTouchedLastShip = addedPlayerMovementData.getTicksSinceTouchedLastShip();
        if (ticksSinceTouchedLastShip > 40) {
            // If the player hasn't touched the ship in over 40 ticks, then ignore its coordinates relative to that ship.
            final IDraggable playerAsDraggable = IDraggable.class.cast(this.player);
            playerAsDraggable.setEntityShipMovementData(playerAsDraggable.getEntityShipMovementData().withLastTouchedShip(null).withAddedLinearVelocity(new Vector3d()).withAddedYawVelocity(0).withTicksPartOfGround(addedPlayerMovementData.getTicksPartOfGround()).withTicksSinceTouchedShip(ticksSinceTouchedLastShip));
            return;
        }
        final int ticksPartOfGround = addedPlayerMovementData.getTicksPartOfGround();
        final Vector3d playerPosInShip = new Vector3d(addedPlayerMovementData.getPlayerPosInShip());
        final Vector3d playerLookInShip = new Vector3d(addedPlayerMovementData.getPlayerLookInShip());
        ShipData lastTouchedShip = null;
        if (lastTouchedShipId != null) {
            final QueryableShipData queryableShipData = QueryableShipData.get(world);
            final Optional<ShipData> shipDataOptional = queryableShipData.getShip(lastTouchedShipId);
            if (shipDataOptional.isPresent()) {
                lastTouchedShip = shipDataOptional.get();
                final PhysicsObject shipObject = ValkyrienUtils.getServerShipManager(world).getPhysObjectFromUUID(lastTouchedShip.getUuid());
                if (shipObject != null) {
                    if (shipObject.getTicksSinceShipTeleport() > PhysicsObject.TICKS_SINCE_TELEPORT_TO_START_DRAGGING) {
                        final ShipTransform shipTransform = lastTouchedShip.getShipTransform();
                        shipTransform.transformPosition(playerPosInShip, TransformType.SUBSPACE_TO_GLOBAL);
                        shipTransform.transformDirection(playerLookInShip, TransformType.SUBSPACE_TO_GLOBAL);
                    } else {
                        // Don't move the player relative to the ship until the TicksSinceShipTeleport timer expires.
                        playerPosInShip.set(player.posX, player.posY, player.posZ);
                    }
                }
            } else {
                // info.cancel();
                return;
            }
        }
        // Get the player pitch/yaw from the look vector
        final Tuple<Double, Double> pitchYawTuple = VSMath.getPitchYawFromVector(playerLookInShip);
        final double playerPitchInGlobal = pitchYawTuple.getFirst();
        final double playerYawInGlobal = pitchYawTuple.getSecond();
        // Idk if this is needed, but I'm too bothered to change it
        packetPlayer.moving = true;
        // Then update the packet values to match the ones above.
        packetPlayer.x = playerPosInShip.x();
        packetPlayer.y = playerPosInShip.y();
        packetPlayer.z = playerPosInShip.z();
        packetPlayer.yaw = (float) playerYawInGlobal;
        packetPlayer.pitch = (float) playerPitchInGlobal;
        // Set the player motion values to tell the NetHandlerPlayServer that the player is allowed to move this fast.
        this.player.motionX = packetPlayer.x - this.firstGoodX;
        this.player.motionY = packetPlayer.y - this.firstGoodY;
        this.player.motionZ = packetPlayer.z - this.firstGoodZ;
        // Update the player draggable
        final IDraggable playerAsDraggable = IDraggable.class.cast(this.player);
        playerAsDraggable.setEntityShipMovementData(playerAsDraggable.getEntityShipMovementData().withLastTouchedShip(lastTouchedShip).withAddedLinearVelocity(new Vector3d()).withAddedYawVelocity(0).withTicksPartOfGround(ticksPartOfGround).withTicksSinceTouchedShip(ticksSinceTouchedLastShip));
    }
}
Also used : QueryableShipData(org.valkyrienskies.mod.common.ships.QueryableShipData) ShipData(org.valkyrienskies.mod.common.ships.ShipData) IHasPlayerMovementData(org.valkyrienskies.mod.common.network.IHasPlayerMovementData) PlayerMovementData(org.valkyrienskies.mod.common.network.PlayerMovementData) World(net.minecraft.world.World) QueryableShipData(org.valkyrienskies.mod.common.ships.QueryableShipData) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) Vector3d(org.joml.Vector3d) ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) IDraggable(org.valkyrienskies.mod.common.ships.entity_interaction.IDraggable) IHasPlayerMovementData(org.valkyrienskies.mod.common.network.IHasPlayerMovementData)

Example 43 with PhysicsObject

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

the class BlockBoatChair 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 TileEntityBoatChair) {
                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());
                }
                ((TileEntityBoatChair) 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) TileEntityBoatChair(org.valkyrienskies.mod.common.tileentity.TileEntityBoatChair) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)

Example 44 with PhysicsObject

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

the class EventsClient method onDrawBlockHighlightEventLast.

@SubscribeEvent(priority = EventPriority.LOWEST, receiveCanceled = true)
public void onDrawBlockHighlightEventLast(DrawBlockHighlightEvent event) {
    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();
            buffer.xOffset = oldXOff;
            buffer.yOffset = oldYOff;
            buffer.zOffset = oldZOff;
        // wrapper.wrapping.renderer.inverseTransform(event.getPartialTicks());
        // objectOver.hitVec = RotationMatrices.applyTransform(wrapper.wrapping.coordTransform.lToWTransform, objectOver.hitVec);
        }
    }
    GL11.glPopMatrix();
}
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 45 with PhysicsObject

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

the class MainCommand method teleportShipToPosition.

private static void teleportShipToPosition(final ShipData ship, final Vec3d position, final ICommandSender sender) {
    try {
        final World world = sender.getEntityWorld();
        final WorldServerShipManager shipManager = ValkyrienUtils.getServerShipManager(world);
        final PhysicsObject shipObject = shipManager.getPhysObjectFromUUID(ship.getUuid());
        // Create the new ship transform that moves the ship to this position
        final ShipTransform shipTransform = ship.getShipTransform();
        final ShipTransform newTransform = new ShipTransform(JOML.convert(position), shipTransform.getCenterCoord());
        if (shipObject != null) {
            // The ship already exists in the world, so we need to update the physics transform as well
            final PhysicsCalculations physicsCalculations = shipObject.getPhysicsCalculations();
            physicsCalculations.setForceToUseGameTransform(true);
            // Also update the transform in the ShipTransformationManager
            shipObject.setForceToUseShipDataTransform(true);
            shipObject.setTicksSinceShipTeleport(0);
        }
        // Update the ship transform of the ship data.
        ship.setPhysicsEnabled(false);
        ship.setPrevTickShipTransform(newTransform);
        ship.setShipTransform(newTransform);
        System.out.println(String.format("Teleporting ship %s to %s", ship.getName(), position.toString()));
    } catch (final Exception e) {
        e.printStackTrace();
    }
}
Also used : ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) World(net.minecraft.world.World) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) PhysicsCalculations(org.valkyrienskies.mod.common.physics.PhysicsCalculations) WorldServerShipManager(org.valkyrienskies.mod.common.ships.ship_world.WorldServerShipManager)

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