use of org.valkyrienskies.mod.common.ships.ship_world.IHasShipManager 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.IHasShipManager in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinWorld method rayTraceBlocksForGetBlockDensity.
/**
* Use Bresenham's tracing algorithm instead of raytracing for getBlockDensity, makes it way faster
*/
@Redirect(method = "getBlockDensity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;rayTraceBlocks(Lnet/minecraft/util/math/Vec3d;Lnet/minecraft/util/math/Vec3d;)Lnet/minecraft/util/math/RayTraceResult;"))
private RayTraceResult rayTraceBlocksForGetBlockDensity(World world, Vec3d start, Vec3d end) {
if (VSConfig.explosionMode == ExplosionMode.VANILLA) {
// Vanilla raytrace, ignore ships and perform the function like normal
this.shouldInterceptRayTrace = false;
RayTraceResult result = rayTraceBlocks(start, end);
this.shouldInterceptRayTrace = true;
return result;
} else if (VSConfig.explosionMode == ExplosionMode.SLOW_VANILLA) {
// Vanilla raytrace, include ships and perform the function like normal
return rayTraceBlocks(start, end);
}
java.util.function.Predicate<BlockPos> canCollide = pos -> {
IBlockState blockState = world.getBlockState(pos);
return blockState.getBlock().canCollideCheck(blockState, false);
};
// Get all the blocks between start and end
List<BlockPos> blocks = VSMath.generateLineBetween(start, end, BlockPos::new);
// Whether or not this ray trace hit a block that was collidable.
boolean collided = blocks.stream().anyMatch(canCollide);
IPhysObjectWorld physObjectWorld = ((IHasShipManager) (this)).getManager();
if (physObjectWorld != null) {
List<PhysicsObject> nearbyShips = physObjectWorld.getPhysObjectsInAABB(new AxisAlignedBB(start.x, start.y, start.z, end.x, end.y, end.z));
for (PhysicsObject obj : nearbyShips) {
Vec3d transformedStart = obj.transformVector(start, TransformType.GLOBAL_TO_SUBSPACE);
Vec3d transformedEnd = obj.transformVector(end, TransformType.GLOBAL_TO_SUBSPACE);
// Transform the raytrace into ship space and check whether or not it hit a block
List<BlockPos> physoBlocks = VSMath.generateLineBetween(transformedStart, transformedEnd, BlockPos::new);
collided |= physoBlocks.stream().anyMatch(canCollide);
}
}
// important information in the ray trace result.
return collided ? DUMMY_RAYTRACE_RESULT : null;
}
use of org.valkyrienskies.mod.common.ships.ship_world.IHasShipManager in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinWorld method rayTraceBlocksIgnoreShip.
@Override
public RayTraceResult rayTraceBlocksIgnoreShip(Vec3d vec31, Vec3d vec32, boolean stopOnLiquid, boolean ignoreBlockWithoutBoundingBox, boolean returnLastUncollidableBlock, PhysicsObject toIgnore) {
this.shouldInterceptRayTrace = false;
RayTraceResult vanillaTrace = World.class.cast(this).rayTraceBlocks(vec31, vec32, stopOnLiquid, ignoreBlockWithoutBoundingBox, returnLastUncollidableBlock);
IPhysObjectWorld physObjectWorld = ((IHasShipManager) (this)).getManager();
if (physObjectWorld == null) {
return vanillaTrace;
}
Vec3d playerReachVector = vec32.subtract(vec31);
AxisAlignedBB playerRangeBB = new AxisAlignedBB(vec31.x, vec31.y, vec31.z, vec32.x, vec32.y, vec32.z);
List<PhysicsObject> nearbyShips = physObjectWorld.getPhysObjectsInAABB(playerRangeBB);
// Get rid of the Ship that we're not supposed to be RayTracing for
nearbyShips.remove(toIgnore);
double reachDistance = playerReachVector.length();
double worldResultDistFromPlayer = 420000000D;
if (vanillaTrace != null && vanillaTrace.hitVec != null) {
worldResultDistFromPlayer = vanillaTrace.hitVec.distanceTo(vec31);
}
for (PhysicsObject wrapper : nearbyShips) {
Vec3d playerEyesPos = vec31;
playerReachVector = vec32.subtract(vec31);
ShipTransform shipTransform = wrapper.getShipTransformationManager().getRenderTransform();
playerEyesPos = shipTransform.transform(playerEyesPos, TransformType.GLOBAL_TO_SUBSPACE);
playerReachVector = shipTransform.rotate(playerReachVector, TransformType.GLOBAL_TO_SUBSPACE);
Vec3d playerEyesReachAdded = playerEyesPos.add(playerReachVector.x * reachDistance, playerReachVector.y * reachDistance, playerReachVector.z * reachDistance);
RayTraceResult resultInShip = World.class.cast(this).rayTraceBlocks(playerEyesPos, playerEyesReachAdded, stopOnLiquid, ignoreBlockWithoutBoundingBox, returnLastUncollidableBlock);
if (resultInShip != null && resultInShip.hitVec != null && resultInShip.typeOfHit == Type.BLOCK) {
double shipResultDistFromPlayer = resultInShip.hitVec.distanceTo(playerEyesPos);
if (shipResultDistFromPlayer < worldResultDistFromPlayer) {
worldResultDistFromPlayer = shipResultDistFromPlayer;
// The hitVec must ALWAYS be in global coordinates.
resultInShip.hitVec = shipTransform.transform(resultInShip.hitVec, TransformType.SUBSPACE_TO_GLOBAL);
vanillaTrace = resultInShip;
}
}
}
this.shouldInterceptRayTrace = true;
return vanillaTrace;
}
use of org.valkyrienskies.mod.common.ships.ship_world.IHasShipManager in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class VSWorldPhysicsLoop method physicsTick.
private void physicsTick(double delta) {
// Update the immutable ship list.
immutableShipsList = ((IHasShipManager) hostWorld).getManager().getAllLoadedThreadSafe();
// Run tasks queued to run on physics thread
recurringTasks.forEach(t -> t.runTask(delta));
taskQueue.forEach(Runnable::run);
taskQueue.clear();
// Make a sublist of physics objects to process physics on.
List<PhysicsObject> physicsEntitiesToDoPhysics = new ArrayList<>();
for (PhysicsObject physicsObject : immutableShipsList) {
if (physicsObject.isPhysicsReady() && physicsObject.isPhysicsEnabled() && physicsObject.getCachedSurroundingChunks() != null) {
physicsEntitiesToDoPhysics.add(physicsObject);
}
}
// Finally, actually process the physics tick
tickThePhysicsAndCollision(physicsEntitiesToDoPhysics, delta);
// Send ship position update packets around 20 times a second
final long currentTimeMillis = System.currentTimeMillis();
final double secondsSinceLastPacket = (currentTimeMillis - lastPacketSendTime) / 1000.0;
// Use .04 to guarantee we're always sending at least 20 packets per second
if (secondsSinceLastPacket > .04) {
// Update the last update time
lastPacketSendTime = currentTimeMillis;
try {
// At the end, send the transform update packets
final ShipTransformUpdateMessage shipTransformUpdateMessage = new ShipTransformUpdateMessage();
final int dimensionID = hostWorld.provider.getDimension();
shipTransformUpdateMessage.setDimensionID(dimensionID);
for (final PhysicsObject physicsObject : immutableShipsList) {
final UUID shipUUID = physicsObject.getUuid();
final ShipTransform shipTransform = physicsObject.getShipTransformationManager().getCurrentPhysicsTransform();
final AxisAlignedBB shipBB = physicsObject.getPhysicsTransformAABB();
shipTransformUpdateMessage.addData(shipUUID, shipTransform, shipBB);
}
ValkyrienSkiesMod.physWrapperTransformUpdateNetwork.sendToDimension(shipTransformUpdateMessage, shipTransformUpdateMessage.getDimensionID());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Aggregations