Search in sources :

Example 46 with PhysicsObject

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

the class MainCommand method deletePhyso.

private static void deletePhyso(ICommandSender sender, ShipData shipData, DeconstructState state) {
    final WorldServerShipManager world = ValkyrienUtils.getServerShipManager(sender.getEntityWorld());
    final PhysicsObject obj = world.getPhysObjectFromUUID(shipData.getUuid());
    if (obj != null) {
        obj.setDeconstructState(state);
        switch(state) {
            case DECONSTRUCT_NORMAL:
                sender.sendMessage(new TextComponentString("That ship is being deconstructed"));
                break;
            case DECONSTRUCT_IMMEDIATE_NO_COPY:
                sender.sendMessage(new TextComponentString("That ship will be deleted in the next tick."));
                break;
        }
    } else {
        sender.sendMessage(new TextComponentString("That ship is not loaded"));
    }
}
Also used : PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) WorldServerShipManager(org.valkyrienskies.mod.common.ships.ship_world.WorldServerShipManager) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 47 with PhysicsObject

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

the class PilotControlsMessageHandler method onMessage.

@Override
public IMessage onMessage(final PilotControlsMessage message, final MessageContext ctx) {
    IThreadListener mainThread = ctx.getServerHandler().server;
    mainThread.addScheduledTask(() -> {
        if (message.controlBlockPos != null) {
            World worldObj = ctx.getServerHandler().player.world;
            BlockPos posFor = message.controlBlockPos;
            TileEntity tile = worldObj.getTileEntity(posFor);
            if (tile instanceof ITileEntityPilotable) {
                ((ITileEntityPilotable) tile).onPilotControlsMessage(message, ctx.getServerHandler().player);
            }
        } else {
            final PhysicsObject physicsObject = ValkyrienUtils.getPhysObjWorld(ctx.getServerHandler().player.world).getPhysObjectFromUUID(message.shipFor);
            if (physicsObject != null && physicsObject.getShipPilot() != null && physicsObject.getShipPilot().getPilot().equals(ctx.getServerHandler().player.getUniqueID())) {
                physicsObject.getShipPilot().processControlMessage(message, ctx.getServerHandler().player);
            }
        }
    });
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IThreadListener(net.minecraft.util.IThreadListener) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)

Example 48 with PhysicsObject

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

the class QueryableShipData method addOrUpdateShipPreservingPhysObj.

/**
 * Adds the ShipData if it doesn't exist, or updates the values of the old ShipData to match the input.
 *
 * @return reference to the "real" ShipData object used by {@link IPhysObjectWorld} and {@link PhysicsObject}.
 */
public ShipData addOrUpdateShipPreservingPhysObj(ShipData ship, World world) {
    Optional<ShipData> old = getShip(ship.getUuid());
    if (old.isPresent()) {
        PhysicsObject physicsObject = ValkyrienUtils.getPhysObjWorld(world).getPhysObjectFromUUID(ship.getUuid());
        if (physicsObject != null) {
        // Ship transform updates are now done by ShipTransformUpdateMessageHandler
        // ITransformInterpolator interpolator = physicsObject.getTransformInterpolator();
        // interpolator.onNewTransformPacket(ship.getShipTransform(), ship.getShipBB());
        } else {
            old.get().setShipTransform(ship.getShipTransform());
            old.get().setPrevTickShipTransform(ship.getPrevTickShipTransform());
            old.get().setShipBB(ship.getShipBB());
        }
        // old.get().setName(ship.getName());
        old.get().setPhysicsEnabled(ship.isPhysicsEnabled());
        // Update inertia data
        old.get().getInertiaData().setGameMoITensor(ship.getInertiaData().getGameMoITensor());
        old.get().getInertiaData().setGameTickMass(ship.getInertiaData().getGameTickMass());
        old.get().getInertiaData().setGameTickCenterOfMass(ship.getInertiaData().getGameTickCenterOfMass());
        return old.get();
    } else {
        this.allShips.add(ship);
        return ship;
    }
}
Also used : PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)

Example 49 with PhysicsObject

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

the class VSNetwork method sendToAllNearExcept.

public static void sendToAllNearExcept(@Nullable EntityPlayer except, double x, double y, double z, double radius, int dimension, Packet<?> packetIn) {
    BlockPos pos = new BlockPos(x, y, z);
    World worldIn;
    if (except == null) {
        worldIn = DimensionManager.getWorld(dimension);
    } else {
        worldIn = except.world;
    }
    Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(worldIn, pos);
    Vector3d packetPosition = new Vector3d(x, y, z);
    if (physicsObject.isPresent()) {
        physicsObject.get().getShipTransformationManager().getCurrentTickTransform().transformPosition(packetPosition, TransformType.SUBSPACE_TO_GLOBAL);
        // Special treatment for certain packets.
        if (packetIn instanceof SPacketSoundEffect) {
            SPacketSoundEffect soundEffect = (SPacketSoundEffect) packetIn;
            packetIn = new SPacketSoundEffect(soundEffect.sound, soundEffect.category, packetPosition.x, packetPosition.y, packetPosition.z, soundEffect.soundVolume, soundEffect.soundPitch);
        }
        if (packetIn instanceof SPacketEffect) {
            SPacketEffect effect = (SPacketEffect) packetIn;
            BlockPos blockpos = new BlockPos(packetPosition.x, packetPosition.y, packetPosition.z);
            packetIn = new SPacketEffect(effect.soundType, blockpos, effect.soundData, effect.serverWide);
        }
    }
    List<EntityPlayer> playerEntityList = ((WorldServer) worldIn).playerEntities;
    // Original method here.
    for (int i = 0; i < playerEntityList.size(); ++i) {
        EntityPlayerMP entityplayermp = (EntityPlayerMP) playerEntityList.get(i);
        if (entityplayermp != except && entityplayermp.dimension == dimension) {
            double d0 = x - entityplayermp.posX;
            double d1 = y - entityplayermp.posY;
            double d2 = z - entityplayermp.posZ;
            double d3 = packetPosition.x - entityplayermp.posX;
            double d4 = packetPosition.y - entityplayermp.posY;
            double d5 = packetPosition.z - entityplayermp.posZ;
            // Cover both cases; if player is in ship space or if player is in world space.
            if ((d0 * d0 + d1 * d1 + d2 * d2 < radius * radius) || (d3 * d3 + d4 * d4 + d5 * d5 < radius * radius)) {
                entityplayermp.connection.sendPacket(packetIn);
            }
        }
    }
}
Also used : SPacketSoundEffect(net.minecraft.network.play.server.SPacketSoundEffect) WorldServer(net.minecraft.world.WorldServer) World(net.minecraft.world.World) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) SPacketEffect(net.minecraft.network.play.server.SPacketEffect) Vector3d(org.joml.Vector3d) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Example 50 with PhysicsObject

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

the class EntityCollisionInjector method getLadderCollisions.

/**
 * Returns all the possible ladders that the entity could potentially climb with
 */
public static Iterable<Triple<PhysicsObject, BlockPos, IBlockState>> getLadderCollisions(final EntityLivingBase entity, final List<PhysicsObject> collidingShips) {
    final boolean isSpectator = entity instanceof EntityPlayer && ((EntityPlayer) entity).isSpectator();
    final World world = entity.getEntityWorld();
    final List<Triple<PhysicsObject, BlockPos, IBlockState>> ladderCollisions = new ArrayList<>();
    if (!isSpectator) {
        final AxisAlignedBB bb = entity.getEntityBoundingBox();
        for (PhysicsObject physicsObject : collidingShips) {
            final Polygon playerPolyInShip = new Polygon(bb, physicsObject.getShipTransform(), TransformType.GLOBAL_TO_SUBSPACE);
            final AxisAlignedBB playerPolyInShipBB = playerPolyInShip.getEnclosedAABB();
            int mX = MathHelper.floor(playerPolyInShipBB.minX);
            int mY = MathHelper.floor(playerPolyInShipBB.minY);
            int mZ = MathHelper.floor(playerPolyInShipBB.minZ);
            for (int y2 = mY; (double) y2 < playerPolyInShipBB.maxY; ++y2) {
                for (int x2 = mX; (double) x2 < playerPolyInShipBB.maxX; ++x2) {
                    for (int z2 = mZ; (double) z2 < playerPolyInShipBB.maxZ; ++z2) {
                        BlockPos tmp = new BlockPos(x2, y2, z2);
                        IBlockState state = world.getBlockState(tmp);
                        if (state.getBlock().isLadder(state, world, tmp, entity)) {
                            ladderCollisions.add(Triple.of(physicsObject, tmp, state));
                        }
                    }
                }
            }
        }
    }
    return ladderCollisions;
}
Also used : Triple(org.apache.commons.lang3.tuple.Triple) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IBlockState(net.minecraft.block.state.IBlockState) ArrayList(java.util.ArrayList) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) Polygon(org.valkyrienskies.mod.common.collision.Polygon) ShipPolygon(org.valkyrienskies.mod.common.collision.ShipPolygon) 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