use of org.valkyrienskies.mod.common.ships.ShipData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinChunk method pre_setBlockState.
/**
* If this chunk is part of a ship, then tell that ship about the IBlockState update.
*
* Note that we're assuming that a Chunk cannot deny the setBlockState request. Therefore its safe to assume that
* the parameter "state" will be the final IBlockState of BlockPos "pos".
*/
@Inject(method = "setBlockState", at = @At("HEAD"))
private void pre_setBlockState(BlockPos pos, IBlockState state, CallbackInfoReturnable<IBlockState> cir) {
if (!world.isRemote) {
IBlockState oldState = getBlockState(pos);
QueryableShipData queryableShipData = QueryableShipData.get(world);
Optional<ShipData> shipDataOptional = queryableShipData.getShipFromChunk(pos.getX() >> 4, pos.getZ() >> 4);
shipDataOptional.ifPresent(shipData -> ShipDataMethods.onSetBlockState(shipData, pos, oldState, state));
}
}
use of org.valkyrienskies.mod.common.ships.ShipData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinEntity method runningParticlesFirstFloor.
@Redirect(method = "createRunningParticles", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;floor(D)I", ordinal = 0))
private int runningParticlesFirstFloor(double d) {
final ShipData lastTouchedShip = ValkyrienUtils.getLastShipTouchedByEntity(thisAsEntity);
if (lastTouchedShip == null) {
searchVector = null;
return MathHelper.floor(d);
} else {
searchVector = new Vector3d(this.posX, this.posY - 0.20000000298023224D, this.posZ);
lastTouchedShip.getShipTransform().transformPosition(searchVector, TransformType.GLOBAL_TO_SUBSPACE);
return MathHelper.floor(searchVector.x);
}
}
use of org.valkyrienskies.mod.common.ships.ShipData 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));
}
}
use of org.valkyrienskies.mod.common.ships.ShipData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinChunkSponge method onPreSpongeBridgeSetBlockState.
@Inject(method = "bridge$setBlockState", at = @At("HEAD"), remap = false)
private void onPreSpongeBridgeSetBlockState(BlockPos pos, IBlockState newState, IBlockState currentState, BlockChangeFlag flag, CallbackInfoReturnable<IBlockState> cir) {
if (!world.isRemote) {
QueryableShipData queryableShipData = QueryableShipData.get(world);
Optional<ShipData> shipDataOptional = queryableShipData.getShipFromChunk(pos.getX() >> 4, pos.getZ() >> 4);
shipDataOptional.ifPresent(shipData -> ShipDataMethods.onSetBlockState(shipData, pos, currentState, newState));
}
}
use of org.valkyrienskies.mod.common.ships.ShipData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class ShipIndexDataMessage method toBytes.
@Override
public void toBytes(ByteBuf buf) {
PacketBuffer packetBuffer = new PacketBuffer(buf);
packetBuffer.writeInt(indexedData.size());
packetBuffer.writeInt(shipsToLoad.size());
packetBuffer.writeInt(shipsToUnload.size());
for (ShipData data : indexedData) {
// Write index data to the byte buffer.
try {
byte[] dataBytes = serializer.writeValueAsBytes(data);
int bytesSize = dataBytes.length;
packetBuffer.writeInt(bytesSize);
packetBuffer.writeBytes(dataBytes);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}
for (UUID toLoad : shipsToLoad) {
packetBuffer.writeUniqueId(toLoad);
}
for (UUID toUnload : shipsToUnload) {
packetBuffer.writeUniqueId(toUnload);
}
packetBuffer.writeInt(dimensionID);
}
Aggregations