use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class EventsClient method onRenderWorldLastEvent.
@SubscribeEvent
public void onRenderWorldLastEvent(RenderWorldLastEvent event) {
Minecraft mc = Minecraft.getMinecraft();
World world = Minecraft.getMinecraft().world;
if (mc.getRenderManager().isDebugBoundingBox() && !mc.isReducedDebug() && world != null) {
float partialTicks = event.getPartialTicks();
Vector3dc offset = VSRenderUtils.getEntityPartialPosition(mc.getRenderViewEntity(), partialTicks).negate();
for (PhysicsObject physo : ValkyrienUtils.getPhysosLoadedInWorld(world)) {
physo.getShipRenderer().renderDebugInfo(offset);
}
}
}
use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class EventsClient method onChunkLoadEvent.
/**
* Used to handle when a chunk in a ship gets updated. This allows us to create ships on the client without
* requiring all the chunks are present at the time of ship creation.
*/
@SubscribeEvent
public void onChunkLoadEvent(ChunkEvent.Load event) {
if (!event.getWorld().isRemote) {
return;
}
Chunk chunk = event.getChunk();
QueryableShipData queryableShipData = QueryableShipData.get(event.getWorld());
Optional<ShipData> shipClaimingOptional = queryableShipData.getShipFromChunk(chunk.x, chunk.z);
if (shipClaimingOptional.isPresent()) {
ShipData shipData = shipClaimingOptional.get();
IPhysObjectWorld physObjectWorld = ValkyrienUtils.getPhysObjWorld(event.getWorld());
PhysicsObject physicsObject = physObjectWorld.getPhysObjectFromUUID(shipData.getUuid());
if (physicsObject != null) {
physicsObject.updateChunk(chunk);
}
}
}
use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject 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.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class EventsClient method onPlaySoundEvent.
@SubscribeEvent
public void onPlaySoundEvent(PlaySoundEvent event) {
if (Minecraft.getMinecraft().world != null) {
ISound sound = event.getSound();
BlockPos pos = new BlockPos(sound.getXPosF(), sound.getYPosF(), sound.getZPosF());
Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(Minecraft.getMinecraft().world, pos);
if (physicsObject.isPresent()) {
Vector3d newSoundLocation = new Vector3d(sound.getXPosF(), sound.getYPosF(), sound.getZPosF());
physicsObject.get().getShipTransformationManager().getCurrentTickTransform().transformPosition(newSoundLocation, TransformType.SUBSPACE_TO_GLOBAL);
SoundFixWrapper soundFix = new SoundFixWrapper(sound, newSoundLocation);
event.setResultSound(soundFix);
}
}
}
use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class EventsClient method onRenderTickEvent.
@SubscribeEvent
public void onRenderTickEvent(RenderTickEvent event) {
final World world = Minecraft.getMinecraft().world;
if (world == null) {
// No ships to worry about.
return;
}
double partialTicks = event.renderTickTime;
if (Minecraft.getMinecraft().isGamePaused()) {
partialTicks = Minecraft.getMinecraft().renderPartialTicksPaused;
}
if (event.phase == Phase.START) {
lastPositionsMap.clear();
for (PhysicsObject wrapper : ValkyrienUtils.getPhysosLoadedInWorld(world)) {
wrapper.getShipTransformationManager().updateRenderTransform(partialTicks);
}
// variables so that Minecraft's interpolation code computes the correct value.
for (final Entity entity : world.getLoadedEntityList()) {
final EntityShipMovementData entityShipMovementData = ValkyrienUtils.getEntityShipMovementDataFor(entity);
if (entityShipMovementData.getLastTouchedShip() != null && entityShipMovementData.getTicksSinceTouchedShip() < VSConfig.ticksToStickToShip) {
final PhysicsObject shipPhysicsObject = ValkyrienUtils.getPhysObjWorld(world).getPhysObjectFromUUID(entityShipMovementData.getLastTouchedShip().getUuid());
if (shipPhysicsObject == null) {
// This ship doesn't exist anymore, just remove it.
IDraggable.class.cast(entity).setEntityShipMovementData(entityShipMovementData.withLastTouchedShip(null));
continue;
}
final ShipTransform prevTickTransform = shipPhysicsObject.getPrevTickShipTransform();
final ShipTransform shipRenderTransform = shipPhysicsObject.getShipTransformationManager().getRenderTransform();
final Vector3dc entityAddedVelocity = entityShipMovementData.getAddedLinearVelocity();
// The velocity the entity was moving without the added velocity from the ship
final double entityMovementX = entity.posX - entityAddedVelocity.x() - entity.lastTickPosX;
final double entityMovementY = entity.posY - entityAddedVelocity.y() - entity.lastTickPosY;
final double entityMovementZ = entity.posZ - entityAddedVelocity.z() - entity.lastTickPosZ;
// Compute the position the entity should be rendered at this frame
final Vector3d entityShouldBeHere = new Vector3d(entity.lastTickPosX, entity.lastTickPosY, entity.lastTickPosZ);
entityShouldBeHere.add(entityMovementX * partialTicks, entityMovementY * partialTicks, entityMovementZ * partialTicks);
prevTickTransform.transformPosition(entityShouldBeHere, TransformType.GLOBAL_TO_SUBSPACE);
shipRenderTransform.transformPosition(entityShouldBeHere, TransformType.SUBSPACE_TO_GLOBAL);
// Save the entity lastTickPos in the map
lastPositionsMap.put(entity, new Vector3d(entity.lastTickPosX, entity.lastTickPosY, entity.lastTickPosZ));
// Then update lastTickPos such that Minecraft's interpolation code will render entity at entityShouldBeHere.
entity.lastTickPosX = (entityShouldBeHere.x() - (entity.posX * partialTicks)) / (1 - partialTicks);
entity.lastTickPosY = (entityShouldBeHere.y() - (entity.posY * partialTicks)) / (1 - partialTicks);
entity.lastTickPosZ = (entityShouldBeHere.z() - (entity.posZ * partialTicks)) / (1 - partialTicks);
}
}
// endregion
} else {
// Once the rendering code has finished we restore the lastTickPos variables to their old values.
for (final Entity entity : world.getLoadedEntityList()) {
if (lastPositionsMap.containsKey(entity)) {
final Vector3dc entityLastPosition = lastPositionsMap.get(entity);
entity.lastTickPosX = entityLastPosition.x();
entity.lastTickPosY = entityLastPosition.y();
entity.lastTickPosZ = entityLastPosition.z();
}
}
}
}
Aggregations