use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class ValkyrienUtils method getMountedShipAndPos.
public EntityShipMountData getMountedShipAndPos(Entity entity) {
Entity ridingEntity = entity.ridingEntity;
if (ridingEntity instanceof EntityMountable) {
EntityMountable mountable = (EntityMountable) ridingEntity;
Optional<PhysicsObject> mountedShip = mountable.getMountedShip();
if (mountedShip.isPresent()) {
return new EntityShipMountData(mountedShip.get(), mountable.getMountPos());
}
}
return new EntityShipMountData();
}
use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class VSWorldPhysicsLoop method tickThePhysicsAndCollision.
/**
* Ticks physics and collision for the List of PhysicsWrapperEntity passed in.
*/
private void tickThePhysicsAndCollision(List<PhysicsObject> shipsWithPhysics, double timeStep) {
final List<ShipCollisionTask> collisionTasks = new ArrayList<>(shipsWithPhysics.size() * 2);
final List<WaterForcesTask> waterForcesTasks = new ArrayList<>();
for (PhysicsObject wrapper : shipsWithPhysics) {
// Update the physics simulation
try {
wrapper.getPhysicsCalculations().rawPhysTickPreCol(timeStep);
// Do water collision and buoyancy
wrapper.getPhysicsCalculations().getWorldWaterCollider().tickUpdatingTheCollisionCache();
// Add water forces tasks to be processed in parallel
waterForcesTasks.addAll(wrapper.getPhysicsCalculations().getWorldWaterCollider().generateWaterForceTasks());
// Update the collision task if necessary
wrapper.getPhysicsCalculations().getWorldCollision().tickUpdatingTheCollisionCache();
// Take the big collision and split into tiny ones
wrapper.getPhysicsCalculations().getWorldCollision().splitIntoCollisionTasks(collisionTasks);
} catch (Exception e) {
e.printStackTrace();
}
}
final List<Callable<Void>> allTasks = new ArrayList<>();
allTasks.addAll(collisionTasks);
allTasks.addAll(waterForcesTasks);
try {
// Run all the block collision and water physics tasks
ValkyrienSkiesMod.getPhysicsThreadPool().invokeAll(allTasks);
} catch (Exception e) {
e.printStackTrace();
}
// Handle the results of water force tasks
for (final WaterForcesTask waterForcesTask : waterForcesTasks) {
waterForcesTask.addForcesToShip();
}
// this thread. Thankfully this step is not cpu intensive.
for (ShipCollisionTask task : collisionTasks) {
task.getToTask().processCollisionTask(task);
}
for (PhysicsObject wrapper : shipsWithPhysics) {
try {
wrapper.getPhysicsCalculations().rawPhysTickPostCol();
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinRenderGlobal method drawBlockDamageTexture.
/**
* aa
*
* @author xd
*/
@Overwrite
public void drawBlockDamageTexture(Tessellator tessellatorIn, BufferBuilder worldRendererIn, Entity entityIn, float partialTicks) {
double d0 = entityIn.lastTickPosX + (entityIn.posX - entityIn.lastTickPosX) * partialTicks;
double d1 = entityIn.lastTickPosY + (entityIn.posY - entityIn.lastTickPosY) * partialTicks;
double d2 = entityIn.lastTickPosZ + (entityIn.posZ - entityIn.lastTickPosZ) * partialTicks;
if (!this.damagedBlocks.isEmpty()) {
this.renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
this.preRenderDamagedBlocks();
worldRendererIn.begin(7, DefaultVertexFormats.BLOCK);
worldRendererIn.setTranslation(-d0, -d1, -d2);
worldRendererIn.noColor();
Iterator<DestroyBlockProgress> iterator = this.damagedBlocks.values().iterator();
while (iterator.hasNext()) {
DestroyBlockProgress destroyblockprogress = iterator.next();
BlockPos blockpos = destroyblockprogress.getPosition();
double d3 = blockpos.getX() - d0;
double d4 = blockpos.getY() - d1;
double d5 = blockpos.getZ() - d2;
Block block = this.world.getBlockState(blockpos).getBlock();
TileEntity te = this.world.getTileEntity(blockpos);
boolean hasBreak = block instanceof BlockChest || block instanceof BlockEnderChest || block instanceof BlockSign || block instanceof BlockSkull;
if (!hasBreak) {
hasBreak = te != null && te.canRenderBreaking();
}
if (!hasBreak) {
Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(world, blockpos);
if (!physicsObject.isPresent() && (d3 * d3 + d4 * d4 + d5 * d5 > 1024.0D)) {
iterator.remove();
} else {
IBlockState iblockstate = this.world.getBlockState(blockpos);
if (physicsObject.isPresent()) {
physicsObject.get().getShipRenderer().applyRenderTransform(partialTicks);
worldRendererIn.setTranslation(-physicsObject.get().getShipRenderer().offsetPos.getX(), -physicsObject.get().getShipRenderer().offsetPos.getY(), -physicsObject.get().getShipRenderer().offsetPos.getZ());
}
if (iblockstate.getMaterial() != Material.AIR) {
int i = destroyblockprogress.getPartialBlockDamage();
TextureAtlasSprite textureatlassprite = this.destroyBlockIcons[i];
BlockRendererDispatcher blockrendererdispatcher = this.mc.getBlockRendererDispatcher();
try {
blockrendererdispatcher.renderBlockDamage(iblockstate, blockpos, textureatlassprite, this.world);
} catch (Exception e) {
e.printStackTrace();
}
}
worldRendererIn.setTranslation(-d0, -d1, -d2);
// TODO: Reverse the Matrix Transforms here
if (physicsObject.isPresent()) {
tessellatorIn.draw();
worldRendererIn.begin(7, DefaultVertexFormats.BLOCK);
physicsObject.get().getShipRenderer().applyInverseTransform(partialTicks);
}
}
}
}
tessellatorIn.draw();
worldRendererIn.setTranslation(0.0D, 0.0D, 0.0D);
this.postRenderDamagedBlocks();
}
}
use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinWorldClient method vs_showBarrierParticles.
private void vs_showBarrierParticles(int x, int y, int z, int offset, Random random, boolean holdingBarrier, BlockPos.MutableBlockPos pos, final List<PhysicsObject> nearbyShipObjects, final Vector3d temp0) {
final int i = x + random.nextInt(offset) - random.nextInt(offset);
final int j = y + random.nextInt(offset) - random.nextInt(offset);
final int k = z + random.nextInt(offset) - random.nextInt(offset);
pos.setPos(i, j, k);
vs_displayTickPos(pos, holdingBarrier, random);
for (final PhysicsObject physicsObject : nearbyShipObjects) {
if (!aabbContains(physicsObject.getShipBB(), i, j, k)) {
continue;
}
final Vector3dc posInShip = physicsObject.getShipTransformationManager().getRenderTransform().transformPositionNew(temp0.set(i + .5, j + .5, k + .5), TransformType.GLOBAL_TO_SUBSPACE);
final double randomXOffset = random.nextDouble();
final double randomYOffset = random.nextDouble();
final double randomZOffset = random.nextDouble();
pos.setPos(posInShip.x() + randomXOffset, posInShip.y() + randomYOffset, posInShip.z() + randomZOffset);
vs_displayTickPos(pos, holdingBarrier, random);
}
}
use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinWorldClient method doVoidFogParticles.
/**
* Adds torch particles to ships.
* @author Tri0de
*/
@Overwrite
public void doVoidFogParticles(int posX, int posY, int posZ) {
final int i = 32;
final Random random = ThreadLocalRandom.current();
ItemStack itemstack = this.mc.player.getHeldItemMainhand();
boolean flag = this.mc.playerController.getCurrentGameType() == GameType.CREATIVE && !itemstack.isEmpty() && itemstack.getItem() == Item.getItemFromBlock(Blocks.BARRIER);
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
final AxisAlignedBB shipDetectionBB = new AxisAlignedBB(posX - i, posY - i, posZ - i, posX + i, posY + i, posZ + i);
final List<PhysicsObject> nearbyShipObjects = ValkyrienUtils.getPhysObjWorld(thisAsWorldClient).getPhysObjectsInAABB(shipDetectionBB);
final Vector3d temp0 = new Vector3d();
for (int j = 0; j < 667; ++j) {
this.vs_showBarrierParticles(posX, posY, posZ, 16, random, flag, blockpos$mutableblockpos, nearbyShipObjects, temp0);
this.vs_showBarrierParticles(posX, posY, posZ, 32, random, flag, blockpos$mutableblockpos, nearbyShipObjects, temp0);
}
}
Aggregations