use of org.valkyrienskies.mod.common.ships.entity_interaction.IDraggable 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;
}
}
use of org.valkyrienskies.mod.common.ships.entity_interaction.IDraggable in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class EventsCommon method onWorldTickEvent.
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void onWorldTickEvent(WorldTickEvent event) {
// change their mind, this exception will crash the game to notify us of the change.
if (event.side == Side.CLIENT) {
throw new IllegalStateException("This event should never get called client side");
}
World world = event.world;
IPhysObjectWorld physObjectWorld = ValkyrienUtils.getPhysObjWorld(world);
switch(event.phase) {
case START:
// Reset the air pocket status of all entities
for (final Entity entity : world.loadedEntityList) {
final IDraggable draggable = (IDraggable) entity;
draggable.decrementTicksAirPocket();
}
break;
case END:
physObjectWorld.tick();
EntityDraggable.tickAddedVelocityForWorld(world);
break;
}
}
use of org.valkyrienskies.mod.common.ships.entity_interaction.IDraggable in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinEntityLivingBase method onPreCanBreatheUnderwater.
/**
* This mixin allows players to breathe underwater when they're in an air pocket.
*/
@Inject(method = "canBreatheUnderwater", at = @At("HEAD"), cancellable = true)
private void onPreCanBreatheUnderwater(CallbackInfoReturnable<Boolean> cir) {
final IDraggable draggable = (IDraggable) this;
final boolean isInAirPocket = draggable.getInAirPocket();
if (isInAirPocket) {
cir.setReturnValue(true);
}
}
use of org.valkyrienskies.mod.common.ships.entity_interaction.IDraggable 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.entity_interaction.IDraggable in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class TileEntityWaterPump method update.
@Override
public void update() {
final AxisAlignedBB pumpRangeBB = new AxisAlignedBB(pos, pos).grow(pumpRadius);
final List<Entity> entitiesInPumpRadius = world.getEntitiesWithinAABBExcludingEntity(null, pumpRangeBB);
for (final Entity entity : entitiesInPumpRadius) {
final IDraggable draggable = (IDraggable) entity;
draggable.setTicksAirPocket(2);
entity.setAir(300);
}
}
Aggregations