Skip to content

Commit

Permalink
Merge pull request #1038 from ValkyrienSkies/1.18.x/feature/fast-physics
Browse files Browse the repository at this point in the history
1.18.x/feature/fast physics
  • Loading branch information
ThePlasticPotato authored Dec 27, 2024
2 parents c41d894 + 83dfca2 commit 6958099
Show file tree
Hide file tree
Showing 40 changed files with 457 additions and 129 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {
id "dev.architectury.loom" version "1.3.355" apply false
id 'io.github.juuxel.loom-vineflower' version '1.11.0' apply false
// Kotlin
id "org.jetbrains.kotlin.jvm" version "1.9.10" apply false
id "org.jetbrains.kotlin.jvm" version "2.1.0" apply false
id 'com.matthewprenger.cursegradle' version '1.4.0' apply false
id "com.modrinth.minotaur" version "2.4.3" apply false
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.valkyrienskies.mod.mixin.feature.debug_sparse_voxel_rendering;

import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.debug.DebugRenderer;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.valkyrienskies.mod.client.SparseVoxelRenderer;

@Mixin(DebugRenderer.class)
public class MixinDebugRenderer {
@Unique
@Final
SparseVoxelRenderer sparseVoxelRenderer = new SparseVoxelRenderer();

@Inject(method = "render", at = @At("HEAD"))
void render(PoseStack poseStack, MultiBufferSource.BufferSource bufferSource, double d, double e, double f, final CallbackInfo ci) {
//sparseVoxelRenderer.render(poseStack, bufferSource, d, e, f);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.valkyrienskies.mod.mixin.feature.sealed_air_sync;

public class MixinBlockUpdatePacket {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.valkyrienskies.mod.mixin.feature.sealed_air_sync;

import net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;

@Mixin(ClientboundSectionBlocksUpdatePacket.class)
public class MixinSectionBlocksUpdatePacket {
@Unique
private boolean[] sealed;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.valkyrienskies.core.api.ships.LoadedServerShip;
import org.valkyrienskies.mod.common.VSGameUtilsKt;
import org.valkyrienskies.mod.common.util.SplitHandler;
import org.valkyrienskies.mod.common.util.SplittingDisablerAttachment;

@Mixin(Contraption.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.valkyrienskies.core.api.ships.properties.IShipActiveChunksSet;
import org.valkyrienskies.core.apigame.GameServer;
import org.valkyrienskies.core.apigame.ShipTeleportData;
import org.valkyrienskies.core.apigame.ships.LoadedServerShipCore;
import org.valkyrienskies.core.apigame.world.IPlayer;
import org.valkyrienskies.core.apigame.world.ServerShipWorldCore;
import org.valkyrienskies.core.apigame.world.VSPipeline;
Expand Down Expand Up @@ -256,7 +257,7 @@ private void handleShipPortals() {
final BlockPos blockPos2 = new BlockPos(shipPos.x() + bbRadius, shipPos.y() + bbRadius, shipPos.z() + bbRadius);
// Only run this code if the chunks between blockPos and blockPos2 are loaded
if (level.hasChunksAt(blockPos, blockPos2)) {
shipObject.decayPortalCoolDown();
((LoadedServerShipCore) shipObject).decayPortalCoolDown();

final BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
for (int i = blockPos.getX(); i <= blockPos2.getX(); ++i) {
Expand All @@ -266,7 +267,7 @@ private void handleShipPortals() {
final BlockState blockState = level.getBlockState(mutableBlockPos);
if (blockState.getBlock() == Blocks.NETHER_PORTAL) {
// Handle nether portal teleport
if (!shipObject.isOnPortalCoolDown()) {
if (!((LoadedServerShipCore) shipObject).isOnPortalCoolDown()) {
// Move the ship between dimensions
final ServerLevel destLevel = getLevel(level.dimension() == Level.NETHER ? Level.OVERWORLD : Level.NETHER);
// TODO: Do we want portal time?
Expand All @@ -276,7 +277,7 @@ private void handleShipPortals() {
level.getProfiler().pop();
}
}
shipObject.handleInsidePortal();
((LoadedServerShipCore) shipObject).handleInsidePortal();
} else if (blockState.getBlock() == Blocks.END_PORTAL) {
// Handle end portal teleport
final ServerLevel destLevel = level.getServer().getLevel(level.dimension() == Level.END ? Level.OVERWORLD : Level.END);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.valkyrienskies.core.apigame.world.chunks.TerrainUpdate;
import org.valkyrienskies.mod.common.IShipObjectWorldServerProvider;
import org.valkyrienskies.mod.common.VSGameUtilsKt;
import org.valkyrienskies.mod.common.ValkyrienSkiesMod;
import org.valkyrienskies.mod.common.block.WingBlock;
import org.valkyrienskies.mod.common.util.VSServerLevel;
import org.valkyrienskies.mod.common.util.VectorConversionsMCKt;
Expand Down Expand Up @@ -248,6 +249,10 @@ private void postTick(final BooleanSupplier shouldKeepTicking, final CallbackInf
voxelShapeUpdates
);

if (ValkyrienSkiesMod.getVsCore().getHooks().getEnableSplitting()) {
ValkyrienSkiesMod.splitHandler.tick(ServerLevel.class.cast(this));
}

}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.valkyrienskies.mod.mixinducks.mod_compat.bluemap;

import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.Level;

public interface WorldDuck {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.valkyrienskies.mod.mixinducks.world;

import net.minecraft.core.BlockPos;

public interface WithSealedPositions {
public void setSealed(BlockPos pos, boolean sealed);

public boolean[] getSealed();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ import net.minecraft.core.BlockPos
import net.minecraft.world.entity.Entity
import net.minecraft.world.level.ChunkPos
import net.minecraft.world.level.Level
import org.valkyrienskies.core.api.VsBeta
import org.valkyrienskies.core.api.attachment.AttachmentRegistration
import org.valkyrienskies.core.api.attachment.AttachmentRegistration.Builder
import org.valkyrienskies.core.api.bodies.properties.BodyTransform.Factory
import org.valkyrienskies.core.api.ships.Ship
import org.valkyrienskies.core.impl.bodies.properties.BodyTransformFactory
import org.valkyrienskies.core.util.events.EventEmitterImpl
import org.valkyrienskies.mod.api.VsApi
import org.valkyrienskies.mod.api.events.PostRenderShipEvent
import org.valkyrienskies.mod.api.events.PreRenderShipEvent
import org.valkyrienskies.mod.api.events.RegisterBlockStateEvent
import org.valkyrienskies.mod.common.ValkyrienSkiesMod
import org.valkyrienskies.mod.common.entity.ShipMountingEntity
import org.valkyrienskies.mod.common.getShipManagingPos
import org.valkyrienskies.mod.compat.clothconfig.VSClothConfig
Expand All @@ -25,6 +31,9 @@ class VsApiImpl : VsApi {
return entity is ShipMountingEntity
}

@Deprecated(
"The legacy VS config system will be replaced soon. Migrate to another config library, or the new system when it's released. "
)
override fun createConfigScreenLegacy(parent: Screen, vararg configs: Class<*>): Screen {
return VSClothConfig.createConfigScreenFor(parent, *configs)
}
Expand All @@ -41,4 +50,23 @@ class VsApiImpl : VsApi {
override fun getShipManagingChunk(level: Level?, chunkX: Int, chunkZ: Int): Ship? {
return level?.getShipManagingPos(chunkX, chunkZ)
}

@VsBeta
override val transformFactory: Factory = BodyTransformFactory

override fun <T> newAttachmentRegistrationBuilder(attachmentClass: Class<T>): Builder<T> {
return ValkyrienSkiesMod.vsCore.newAttachmentRegistrationBuilder(attachmentClass)
}

override fun <T> registerAttachment(attachmentClass: Class<T>, registrationBuilder: Builder<T>.() -> Unit) {
ValkyrienSkiesMod.vsCore.registerAttachment(attachmentClass, registrationBuilder)
}

override fun <T> registerAttachment(registration: AttachmentRegistration<T>) {
ValkyrienSkiesMod.vsCore.registerAttachment(registration)
}

override fun registerAttachmentForRemoval(attachmentKey: String) {
ValkyrienSkiesMod.vsCore.registerAttachmentForRemoval(attachmentKey)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.valkyrienskies.mod.client

import com.mojang.blaze3d.vertex.PoseStack
import com.mojang.blaze3d.vertex.Tesselator
import net.minecraft.client.Minecraft
import net.minecraft.client.renderer.MultiBufferSource.BufferSource
import net.minecraft.client.renderer.RenderType
import net.minecraft.client.renderer.debug.DebugRenderer
import net.minecraft.world.phys.AABB
import org.valkyrienskies.core.util.datastructures.SparseVoxelPosition

class SparseVoxelRenderer() {
val voxels = HashSet<SparseVoxelPosition>()

init {
voxels.add(SparseVoxelPosition(0, 128, 0, 2))
}

fun render(ms: PoseStack, buffer: BufferSource, camX: Double, camY: Double, camZ: Double) {
for (voxel in voxels) {
drawVoxel(voxel, ms, buffer, camX, camY, camZ)
}
}

fun drawVoxel(voxel: SparseVoxelPosition, poseStack: PoseStack, buffer: BufferSource, camX: Double, camY: Double, camZ: Double) {
poseStack.pushPose()

// Draw the voxel
val random = Minecraft.getInstance().level?.random ?: return
DebugRenderer.renderFilledBox(voxel.toAABB(-camX, -camY, -camZ), 1.0f, 1.0f, 0.5f, 0.5f)
//Tesselator.getInstance().end()

poseStack.popPose()
}

private fun SparseVoxelPosition.toAABB(offsetX: Double = 0.0, offsetY: Double = 0.0, offsetZ: Double = 0.0): AABB {
return AABB(x.toDouble() + offsetX, y.toDouble() + offsetY, z.toDouble() + offsetZ,
x.toDouble() + extent.toDouble() + offsetX, y.toDouble() + extent.toDouble() + offsetY, z.toDouble() + extent.toDouble() + offsetZ)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ object BlockStateInfo {
newBlockMass
)

if (ValkyrienSkiesMod.vsCore.hooks.enableConnectivity) {
ValkyrienSkiesMod.splitHandler.split(level, x, y, z, prevBlockState, newBlockState)
if (ValkyrienSkiesMod.vsCore.hooks.enableSplitting) {
ValkyrienSkiesMod.splitHandler.queueSplit(level, x, y, z)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ import org.joml.Vector3ic
import org.joml.primitives.AABBd
import org.joml.primitives.AABBdc
import org.valkyrienskies.core.api.ships.ClientShip
import org.valkyrienskies.core.api.ships.LoadedServerShip
import org.valkyrienskies.core.api.ships.LoadedShip
import org.valkyrienskies.core.api.ships.ServerShip
import org.valkyrienskies.core.api.ships.Ship
import org.valkyrienskies.core.api.util.functions.DoubleTernaryConsumer
import org.valkyrienskies.core.api.world.LevelYRange
import org.valkyrienskies.core.api.world.properties.DimensionId
import org.valkyrienskies.core.apigame.world.IPlayer
import org.valkyrienskies.core.apigame.world.ServerShipWorldCore
import org.valkyrienskies.core.apigame.world.ShipWorldCore
import org.valkyrienskies.core.apigame.world.chunks.TerrainUpdate
import org.valkyrienskies.core.apigame.world.properties.DimensionId
import org.valkyrienskies.core.game.ships.ShipObjectServer
import org.valkyrienskies.core.impl.hooks.VSEvents.TickEndEvent
import org.valkyrienskies.core.util.expand
Expand Down Expand Up @@ -266,7 +267,7 @@ fun ClientLevel?.getShipObjectManagingPos(chunkPos: ChunkPos) =

// ServerWorld
fun ServerLevel?.getShipObjectManagingPos(chunkX: Int, chunkZ: Int) =
getShipObjectManagingPosImpl(this, chunkX, chunkZ) as ShipObjectServer?
getShipObjectManagingPosImpl(this, chunkX, chunkZ) as LoadedServerShip?

fun ServerLevel?.getShipObjectManagingPos(blockPos: Vec3i) =
getShipObjectManagingPos(blockPos.x shr 4, blockPos.z shr 4)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import net.minecraft.world.entity.EntityType
import net.minecraft.world.item.Item
import net.minecraft.world.level.block.Block
import net.minecraft.world.level.block.entity.BlockEntityType
import org.valkyrienskies.core.api.ships.setAttachment
import org.valkyrienskies.core.apigame.VSCore
import org.valkyrienskies.core.apigame.VSCoreClient
import org.valkyrienskies.core.impl.hooks.VSEvents
Expand All @@ -15,6 +14,7 @@ import org.valkyrienskies.mod.common.entity.ShipMountingEntity
import org.valkyrienskies.mod.common.entity.VSPhysicsEntity
import org.valkyrienskies.mod.common.networking.VSGamePackets
import org.valkyrienskies.mod.common.util.GameTickForceApplier
import org.valkyrienskies.mod.common.util.ShipSettings
import org.valkyrienskies.mod.common.util.SplitHandler
import org.valkyrienskies.mod.common.util.SplittingDisablerAttachment

Expand Down Expand Up @@ -59,6 +59,10 @@ object ValkyrienSkiesMod {

splitHandler = SplitHandler(this.vsCore.hooks.enableBlockEdgeConnectivity, this.vsCore.hooks.enableBlockCornerConnectivity)

vsCore.registerAttachment(ShipSettings::class.java)
vsCore.registerAttachment(GameTickForceApplier::class.java)
vsCore.registerAttachment(SplittingDisablerAttachment::class.java)

VSEvents.ShipLoadEvent.on { event ->
event.ship.setAttachment(GameTickForceApplier())
event.ship.setAttachment(SplittingDisablerAttachment(true))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import net.minecraft.world.level.block.state.BlockState
import org.joml.Vector3d
import org.joml.Vector3i
import org.joml.Vector3ic
import org.valkyrienskies.core.api.attachment.getAttachment
import org.valkyrienskies.core.api.ships.ServerShip
import org.valkyrienskies.core.api.ships.Ship
import org.valkyrienskies.core.api.ships.getAttachment
import org.valkyrienskies.core.impl.game.ShipTeleportDataImpl
import org.valkyrienskies.mod.common.BlockStateInfo.onSetBlock
import org.valkyrienskies.mod.common.dimensionId
Expand Down Expand Up @@ -111,7 +111,7 @@ object ShipAssembler {
AssemblyUtil.updateBlock(level,itPos,shipPos,level.getBlockState(shipPos))
}

val shipCenterPos = ((newShip as ServerShip).inertiaData.centerOfMassInShip).add(0.5, 0.5, 0.5, Vector3d())
val shipCenterPos = ((newShip as ServerShip).inertiaData.centerOfMass).add(0.5, 0.5, 0.5, Vector3d())
// This is giga sus, but whatever
val shipPos = Vector3d(shipOGPos).add(0.5, 0.5, 0.5)
if (existingShip != null) {
Expand Down
Loading

0 comments on commit 6958099

Please sign in to comment.