use of org.joml.Vector3d 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.joml.Vector3d 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();
}
}
}
}
use of org.joml.Vector3d in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class PhysObjectRenderManager method applyRenderTransform.
private void applyRenderTransform(double partialTicks, boolean inverse) {
Vector3dc centerOfRotation = parent.getCenterCoord();
Entity player = Objects.requireNonNull(Minecraft.getMinecraft().getRenderViewEntity());
double p0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks;
double p1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks;
double p2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks;
ShipTransform renderTransform = parent.getShipTransformationManager().getRenderTransform();
Vector3d renderPos = renderTransform.getSubspaceToGlobal().transformPosition(centerOfRotation, new Vector3d());
// Offset pos is used to prevent floating point errors when rendering stuff thats very far away.
double offsetX = offsetPos.getX() - centerOfRotation.x();
double offsetY = offsetPos.getY() - centerOfRotation.y();
double offsetZ = offsetPos.getZ() - centerOfRotation.z();
if (inverse) {
AxisAngle4d rotation = new AxisAngle4d().set(renderTransform.getGlobalToSubspace());
GL11.glTranslated(-offsetX, -offsetY, -offsetZ);
GL11.glRotated(Math.toDegrees(rotation.angle), rotation.x, rotation.y, rotation.z);
GL11.glTranslated(p0 - renderPos.x, p1 - renderPos.y, p2 - renderPos.z);
} else {
AxisAngle4d rotation = new AxisAngle4d().set(renderTransform.getSubspaceToGlobal());
GL11.glTranslated(-p0 + renderPos.x, -p1 + renderPos.y, -p2 + renderPos.z);
GL11.glRotated(Math.toDegrees(rotation.angle), rotation.x, rotation.y, rotation.z);
GL11.glTranslated(offsetX, offsetY, offsetZ);
}
}
use of org.joml.Vector3d in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class EventsCommon method onExplosionStart.
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void onExplosionStart(ExplosionEvent.Start event) {
// Only run on server side
if (!event.getWorld().isRemote) {
Explosion explosion = event.getExplosion();
Vector3dc center = new Vector3d(explosion.x, explosion.y, explosion.z);
Optional<PhysicsObject> optionalPhysicsObject = ValkyrienUtils.getPhysoManagingBlock(event.getWorld(), new BlockPos(event.getExplosion().getPosition()));
if (optionalPhysicsObject.isPresent()) {
return;
}
// Explosion radius
float radius = explosion.size;
AxisAlignedBB toCheck = new AxisAlignedBB(center.x() - radius, center.y() - radius, center.z() - radius, center.x() + radius, center.y() + radius, center.z() + radius);
// Find nearby ships, we will check if the explosion effects them
List<PhysicsObject> shipsNear = ((IHasShipManager) event.getWorld()).getManager().getPhysObjectsInAABB(toCheck);
// Process the explosion on the nearby ships
for (PhysicsObject ship : shipsNear) {
Vector3d inLocal = new Vector3d(center);
inLocal.mulPosition(ship.getShipTransform().getGlobalToSubspace());
Explosion expl = new Explosion(event.getWorld(), explosion.exploder, inLocal.x, inLocal.y, inLocal.z, radius, explosion.causesFire, explosion.damagesTerrain);
double waterRange = .6D;
for (int x = (int) Math.floor(expl.x - waterRange); x <= Math.ceil(expl.x + waterRange); x++) {
for (int y = (int) Math.floor(expl.y - waterRange); y <= Math.ceil(expl.y + waterRange); y++) {
for (int z = (int) Math.floor(expl.z - waterRange); z <= Math.ceil(expl.z + waterRange); z++) {
IBlockState state = event.getWorld().getBlockState(new BlockPos(x, y, z));
if (state.getBlock() instanceof BlockLiquid) {
return;
}
}
}
}
expl.doExplosionA();
event.getExplosion().affectedBlockPositions.addAll(expl.affectedBlockPositions);
}
}
}
use of org.joml.Vector3d in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class BlockCaptainsChair method onBlockActivated.
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (!worldIn.isRemote) {
Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(worldIn, pos);
if (physicsObject.isPresent()) {
TileEntity tileEntity = worldIn.getTileEntity(pos);
if (tileEntity instanceof TileEntityCaptainsChair) {
Vector3d playerPos = new Vector3d(playerIn.posX, playerIn.posY, playerIn.posZ);
physicsObject.get().getShipTransformationManager().getCurrentTickTransform().transformPosition(playerPos, TransformType.SUBSPACE_TO_GLOBAL);
playerIn.posX = playerPos.x;
playerIn.posY = playerPos.y;
playerIn.posZ = playerPos.z;
// Only mount the player if they're standing on the ship.
final EntityShipMovementData entityShipMovementData = ValkyrienUtils.getEntityShipMovementDataFor(playerIn);
if (entityShipMovementData.getTicksSinceTouchedShip() == 0 && (entityShipMovementData.getLastTouchedShip() == physicsObject.get().getShipData())) {
Vector3dc localMountPos = getPlayerMountOffset(state, pos);
ValkyrienUtils.fixEntityToShip(playerIn, localMountPos, physicsObject.get());
}
((TileEntityCaptainsChair) tileEntity).setPilotEntity(playerIn);
physicsObject.get().getShipTransformationManager().getCurrentTickTransform().transformPosition(playerPos, TransformType.GLOBAL_TO_SUBSPACE);
playerIn.posX = playerPos.x;
playerIn.posY = playerPos.y;
playerIn.posZ = playerPos.z;
}
}
}
return true;
}
Aggregations