use of org.valkyrienskies.mod.common.ships.ShipData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class ShipIndexDataMessage method fromBytes.
@Override
public void fromBytes(ByteBuf buf) {
PacketBuffer packetBuffer = new PacketBuffer(buf);
int numberOfIndices = packetBuffer.readInt();
int numberOfUUIDLoad = packetBuffer.readInt();
int numberOfUUIDUnload = packetBuffer.readInt();
for (int i = 0; i < numberOfIndices; i++) {
// Read index data from the byte buffer.
int bytesSize = packetBuffer.readInt();
byte[] bytes = new byte[bytesSize];
packetBuffer.readBytes(bytes);
try {
ShipData data = serializer.readValue(bytes, ShipData.class);
this.indexedData.add(data);
} catch (IOException e) {
e.printStackTrace();
}
}
for (int i = 0; i < numberOfUUIDLoad; i++) {
shipsToLoad.add(packetBuffer.readUniqueId());
}
for (int i = 0; i < numberOfUUIDUnload; i++) {
shipsToUnload.add(packetBuffer.readUniqueId());
}
dimensionID = packetBuffer.readInt();
}
use of org.valkyrienskies.mod.common.ships.ShipData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class WorldClientShipManager method loadAndUnloadShips.
private void loadAndUnloadShips() {
QueryableShipData queryableShipData = QueryableShipData.get(world);
// Load ships queued for loading
for (final UUID toLoadID : loadQueue) {
if (loadedShips.containsKey(toLoadID)) {
logger.error("Tried loading a for ship that was already loaded? UUID is\n" + toLoadID);
continue;
}
Optional<ShipData> toLoadOptional = queryableShipData.getShip(toLoadID);
if (!toLoadOptional.isPresent()) {
logger.error("No ship found for UUID:\n" + toLoadID);
continue;
}
ShipData shipData = toLoadOptional.get();
PhysicsObject physicsObject = new PhysicsObject(world, shipData);
for (final Chunk chunk : physicsObject.getClaimedChunkCache()) {
chunk.loaded = true;
}
loadedShips.put(toLoadID, physicsObject);
if (VSConfig.showAnnoyingDebugOutput) {
System.out.println("Successfully loaded " + shipData);
}
}
loadQueue.clear();
// Unload ships queued for unloading
for (final UUID toUnloadID : unloadQueue) {
if (!loadedShips.containsKey(toUnloadID)) {
logger.error("Tried unloading that isn't loaded? ID is\n" + toUnloadID);
continue;
}
PhysicsObject removedShip = loadedShips.get(toUnloadID);
removedShip.unload();
loadedShips.remove(toUnloadID);
if (VSConfig.showAnnoyingDebugOutput) {
System.out.println("Successfully unloaded " + removedShip.getShipData());
}
}
unloadQueue.clear();
}
use of org.valkyrienskies.mod.common.ships.ShipData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class WorldShipLoadingController method sendUpdatesPackets.
/**
* Send load/unload/update packets accordingly.
*/
private void sendUpdatesPackets(Map<ShipData, Set<EntityPlayerMP>> oldWatching, Map<ShipData, Set<EntityPlayerMP>> newWatching) {
// First send the update packets
// Create a map for every player to the ship data updates it will receive
Map<EntityPlayerMP, List<ShipData>> updatesMap = new HashMap<>();
shipManager.getWorld().playerEntities.forEach((player) -> updatesMap.put((EntityPlayerMP) player, new ArrayList<>()));
for (PhysicsObject ship : shipManager.getAllLoadedPhysObj()) {
ShipData shipData = ship.getShipData();
Set<EntityPlayerMP> currentWatchers = newWatching.get(shipData);
currentWatchers.forEach((player) -> updatesMap.get(player).add(shipData));
}
Map<EntityPlayerMP, ShipIndexDataMessage> playerPacketMap = new HashMap<>();
// Then send those updates
updatesMap.forEach((player, updates) -> {
ShipIndexDataMessage indexDataMessage = new ShipIndexDataMessage();
indexDataMessage.setDimensionID(shipManager.getWorld().provider.getDimension());
if (!updates.isEmpty()) {
indexDataMessage.addData(updates);
}
playerPacketMap.put(player, indexDataMessage);
});
// Then send ship loads to the packets
for (PhysicsObject ship : shipManager.getAllLoadedPhysObj()) {
ShipData shipData = ship.getShipData();
Set<EntityPlayerMP> newWatchers = new HashSet<>(newWatching.get(shipData));
if (oldWatching.containsKey(shipData)) {
newWatchers.removeAll(oldWatching.get(shipData));
}
if (!newWatchers.isEmpty()) {
// First send the ship chunks to the new watchers
for (Chunk chunk : ship.getClaimedChunkCache()) {
SPacketChunkData data = new SPacketChunkData(chunk, 65535);
for (EntityPlayerMP player : newWatchers) {
player.connection.sendPacket(data);
shipManager.getWorld().getEntityTracker().sendLeashedEntitiesInChunk(player, chunk);
}
}
newWatchers.forEach(player -> playerPacketMap.get(player).addLoadUUID(shipData.getUuid()));
}
}
// Then add ship unloads to the packets
for (ShipData shipData : oldWatching.keySet()) {
Set<EntityPlayerMP> removedWatchers = new HashSet<>(oldWatching.get(shipData));
if (newWatching.containsKey(shipData)) {
removedWatchers.removeAll(newWatching.get(shipData));
}
for (EntityPlayerMP player : removedWatchers) {
// BetterPortals.
if (!playerPacketMap.containsKey(player)) {
playerPacketMap.put(player, new ShipIndexDataMessage());
playerPacketMap.get(player).setDimensionID(shipManager.getWorld().provider.getDimension());
}
playerPacketMap.get(player).addUnloadUUID(shipData.getUuid());
}
}
// Finally, send each player their update packet
playerPacketMap.forEach((player, packet) -> {
if (!player.hasDisconnected()) {
ValkyrienSkiesMod.physWrapperNetwork.sendTo(packet, player);
}
});
}
use of org.valkyrienskies.mod.common.ships.ShipData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinEntityPlayer method preGetBedSpawnLocation.
@Inject(method = "getBedSpawnLocation", at = @At("HEAD"), cancellable = true)
private static void preGetBedSpawnLocation(World worldIn, BlockPos bedLocation, boolean forceSpawn, CallbackInfoReturnable<BlockPos> callbackInfo) {
Optional<ShipData> shipData = ValkyrienUtils.getQueryableData(worldIn).getShipFromBlock(bedLocation);
if (shipData.isPresent()) {
ShipTransform positionData = shipData.get().getShipTransform();
if (positionData != null) {
Vector3d bedLocationD = JOML.castDouble(JOML.convert(bedLocation)).add(0.5, 0.5, 0.5);
positionData.getSubspaceToGlobal().transformPosition(bedLocationD);
bedLocationD.y += 1D;
bedLocation = JOML.toMinecraft(JOML.castInt(bedLocationD));
callbackInfo.setReturnValue(bedLocation);
} else {
System.err.println("A ship just had chunks claimed persistent, but not any position data persistent");
}
}
}
use of org.valkyrienskies.mod.common.ships.ShipData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinMinecraft method rightClickBlockProxy.
/**
* This mixin fixes slabs not placing correctly on ships.
*/
@Redirect(method = "rightClickMouse", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/PlayerControllerMP;processRightClickBlock(Lnet/minecraft/client/entity/EntityPlayerSP;Lnet/minecraft/client/multiplayer/WorldClient;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/EnumFacing;Lnet/minecraft/util/math/Vec3d;Lnet/minecraft/util/EnumHand;)Lnet/minecraft/util/EnumActionResult;"))
private EnumActionResult rightClickBlockProxy(PlayerControllerMP playerControllerMP, EntityPlayerSP player, WorldClient worldIn, BlockPos pos, EnumFacing direction, Vec3d vec, EnumHand hand) {
// Check if this is for a ship
final Optional<ShipData> shipDataOptional = ValkyrienUtils.getShipManagingBlock(worldIn, pos);
if (shipDataOptional.isPresent()) {
// This ray trace was in the ship, we're going to have to mess with the hit vector
final ShipData shipData = shipDataOptional.get();
final ShipTransform shipTransform = shipData.getShipTransform();
// Put the hit vector in ship coordinates
final Vector3d hitVecInLocal = JOML.convert(vec);
shipTransform.transformPosition(hitVecInLocal, TransformType.GLOBAL_TO_SUBSPACE);
final Vec3d moddedHitVec = JOML.toMinecraft(hitVecInLocal);
return playerControllerMP.processRightClickBlock(player, worldIn, pos, direction, moddedHitVec, hand);
}
return playerControllerMP.processRightClickBlock(player, worldIn, pos, direction, vec, hand);
}
Aggregations