Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

guess this is an API Backport:tm: now #878

Merged
merged 8 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ dependencies {
exclude module: "fastutil"
}

implementation("org.valkyrienskies.core:api:${rootProject.vs_core_version}")
implementation("org.valkyrienskies.core:api-game:${rootProject.vs_core_version}")
implementation("org.valkyrienskies.core:util:${rootProject.vs_core_version}")

// FTB Stuffs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.valkyrienskies.core.api.ships.LoadedShip;
import org.valkyrienskies.core.api.ships.Ship;
import org.valkyrienskies.core.api.ships.properties.ShipTransform;
import org.valkyrienskies.core.impl.game.ships.ShipObjectClient;
import org.valkyrienskies.mod.common.entity.ShipMountedToData;
import org.valkyrienskies.mod.common.VSGameUtilsKt;
import org.valkyrienskies.mod.common.util.EntityDraggingInformation;
Expand Down Expand Up @@ -112,8 +111,8 @@ private void preGetEyePosition(final float partialTicks, final CallbackInfoRetur
final LoadedShip shipMountedTo = shipMountedToData.getShipMountedTo();

final ShipTransform shipTransform;
if (shipMountedTo instanceof ShipObjectClient) {
shipTransform = ((ShipObjectClient) shipMountedTo).getRenderTransform();
if (shipMountedTo instanceof ClientShip) {
shipTransform = ((ClientShip) shipMountedTo).getRenderTransform();
} else {
shipTransform = shipMountedTo.getShipTransform();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ public VSPipeline getVsPipeline() {
)
)
private void postCreateLevels(final CallbackInfo ci) {
// Register blocks
if (!MassDatapackResolver.INSTANCE.getRegisteredBlocks()) {
final List<BlockState> blockStateList = new ArrayList<>(Block.BLOCK_STATE_REGISTRY.size());
Block.BLOCK_STATE_REGISTRY.forEach((blockStateList::add));
MassDatapackResolver.INSTANCE.registerAllBlockStates(blockStateList);
ValkyrienSkiesMod.getVsCore().registerBlockStates(MassDatapackResolver.INSTANCE.getBlockStateData());
}

// Load ship data from the world storage
final ShipSavedData shipSavedData = overworld().getDataStorage()
.computeIfAbsent(ShipSavedData::load, ShipSavedData.Companion::createEmpty, ShipSavedData.SAVED_DATA_ID);
Expand All @@ -140,18 +148,6 @@ private void postCreateLevels(final CallbackInfo ci) {
// Create ship world and VS Pipeline
vsPipeline = shipSavedData.getPipeline();

// Register blocks
if (!MassDatapackResolver.INSTANCE.getRegisteredBlocks()) {
final List<BlockState> blockStateList = new ArrayList<>(Block.BLOCK_STATE_REGISTRY.size());
Block.BLOCK_STATE_REGISTRY.forEach((blockStateList::add));
MassDatapackResolver.INSTANCE.registerAllBlockStates(blockStateList);
}
vsPipeline.registerBlocks(
MassDatapackResolver.INSTANCE.getSolidBlockStates(),
MassDatapackResolver.INSTANCE.getLiquidBlockStates(),
MassDatapackResolver.INSTANCE.getBlockStateData()
);

KrunchSupport.INSTANCE.setKrunchSupported(!vsPipeline.isUsingDummyPhysics());

shipWorld = vsPipeline.getShipWorld();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import it.unimi.dsi.fastutil.longs.Long2LongOpenHashMap;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -48,13 +47,10 @@
import org.valkyrienskies.core.api.ships.LoadedServerShip;
import org.valkyrienskies.core.api.ships.Wing;
import org.valkyrienskies.core.api.ships.WingManager;
import org.valkyrienskies.core.api.ships.datastructures.ShipConnDataAttachment;
import org.valkyrienskies.core.apigame.world.ServerShipWorldCore;
import org.valkyrienskies.core.apigame.world.chunks.TerrainUpdate;
import org.valkyrienskies.core.util.datastructures.Breakage;
import org.valkyrienskies.mod.common.IShipObjectWorldServerProvider;
import org.valkyrienskies.mod.common.VSGameUtilsKt;
import org.valkyrienskies.mod.common.assembly.SubShipAssemblyKt;
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,23 +244,6 @@ private void postTick(final BooleanSupplier shouldKeepTicking, final CallbackInf
voxelShapeUpdates
);

// Process pending ship breakages
for (final LoadedServerShip loadedShip : shipObjectWorld.getLoadedShips()) {
if (loadedShip.getAttachment(ShipConnDataAttachment.class) instanceof ShipConnDataAttachment) {
ShipConnDataAttachment connData = loadedShip.getAttachment(ShipConnDataAttachment.class);
assert connData != null;
HashSet<Object> shipBreakages = (HashSet<Object>) connData.getBreakages();
Iterator<Object> breakageIterator = shipBreakages.iterator();

while (breakageIterator.hasNext()) {
Object breakage = breakageIterator.next();
if (breakage instanceof Breakage breaking) {
SubShipAssemblyKt.splitShip(VectorConversionsMCKt.toBlockPos(breaking.component1()), breaking.component2(), self, loadedShip);
breakageIterator.remove();
}
}
}
}
}

@Override
Expand Down
56 changes: 56 additions & 0 deletions common/src/main/kotlin/org/valkyrienskies/mod/api/VsAPI.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.valkyrienskies.mod.api

import net.minecraft.client.gui.screens.Screen
import net.minecraft.client.multiplayer.ClientLevel
import net.minecraft.core.BlockPos
import net.minecraft.world.level.ChunkPos
import net.minecraft.world.level.Level
import net.minecraft.server.level.ServerLevel
import net.minecraft.world.entity.Entity

import org.jetbrains.annotations.ApiStatus.*
import org.valkyrienskies.core.api.VsCoreApi
import org.valkyrienskies.core.api.event.ListenableEvent
import org.valkyrienskies.core.api.ships.*
import org.valkyrienskies.mod.api.events.PostRenderShipEvent
import org.valkyrienskies.mod.api.events.PreRenderShipEvent
import org.valkyrienskies.mod.api.events.RegisterBlockStateEvent

@NonExtendable
interface VsApi : VsCoreApi {

/**
* This event gets called when it's time to register physics block states for Minecraft block states.
*/
@get:Experimental
val registerBlockStateEvent: ListenableEvent<RegisterBlockStateEvent>

@get:Experimental
val preRenderShipEvent: ListenableEvent<PreRenderShipEvent>

@get:Experimental
val postRenderShipEvent: ListenableEvent<PostRenderShipEvent>

fun isShipMountingEntity(entity: Entity): Boolean

@Deprecated(message = "The legacy VS config system will be replaced soon. " +
"Migrate to another config library, or the new system when it's released. ")
fun createConfigScreenLegacy(parent: Screen, vararg configs: Class<*>): Screen

/**
* Get the ship with the chunk claim that contains [pos], if it exists.
*
* If either parameter is null, this will return null.
*
* @param level The [Level] to look for the ship in. If [level] is a
* [ServerLevel], this will return a [ServerShip]. If [level] is a
* [ClientLevel], this will return a [ClientShip].
*
* @param pos A block position in the Shipyard
*/
fun getShipManagingBlock(level: Level?, pos: BlockPos?): Ship?

fun getShipManagingChunk(level: Level?, pos: ChunkPos?): Ship?

fun getShipManagingChunk(level: Level?, chunkX: Int, chunkZ: Int): Ship?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.valkyrienskies.mod.api.events

import org.jetbrains.annotations.ApiStatus.Experimental

@Experimental
interface PostRenderShipEvent
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.valkyrienskies.mod.api.events

import org.jetbrains.annotations.ApiStatus.Experimental

@Experimental
interface PreRenderShipEvent
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.valkyrienskies.mod.api.events

import net.minecraft.world.level.block.state.BlockState
import org.jetbrains.annotations.ApiStatus.Experimental
import org.valkyrienskies.core.api.physics.blockstates.LiquidState
import org.valkyrienskies.core.api.physics.blockstates.SolidState

@Experimental
interface RegisterBlockStateEvent {

fun newLiquidStateBuilder(): LiquidState.Builder
fun buildLiquidState(block: LiquidState.Builder.() -> Unit): LiquidState
fun newSolidStateBuilder(): SolidState.Builder
fun buildSolidState(block: SolidState.Builder.() -> Unit): SolidState

fun register(state: BlockState, solidState: SolidState)
fun register(state: BlockState, liquidState: LiquidState)

/**
* Registers the Minecraft [state] to be represented by [LiquidState] and [SolidState] in the same block.
* This is useful for e.g., a waterlogged chest, where the [liquidState] would be water and the [solidState] would
* be the chest shape.
*/
fun register(state: BlockState, liquidState: LiquidState, solidState: SolidState)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.valkyrienskies.mod.api_impl.events

import net.minecraft.world.level.block.state.BlockState
import org.valkyrienskies.core.api.physics.blockstates.LiquidState
import org.valkyrienskies.core.api.physics.blockstates.SolidState
import org.valkyrienskies.core.apigame.physics.blockstates.VsBlockState
import org.valkyrienskies.mod.api.events.RegisterBlockStateEvent
import org.valkyrienskies.mod.common.ValkyrienSkiesMod.vsCore

class RegisterBlockStateEventImpl : RegisterBlockStateEvent {
val toRegister = mutableListOf<Pair<BlockState, VsBlockState>>()

override fun newLiquidStateBuilder(): LiquidState.Builder =
vsCore.newLiquidStateBuilder()

override fun buildLiquidState(block: LiquidState.Builder.() -> Unit): LiquidState =
vsCore.newLiquidStateBuilder().apply(block).build()

override fun newSolidStateBuilder(): SolidState.Builder =
vsCore.newSolidStateBuilder()

override fun buildSolidState(block: SolidState.Builder.() -> Unit): SolidState =
vsCore.newSolidStateBuilder().apply(block).build()

override fun register(state: BlockState, solidState: SolidState) {
toRegister.add(Pair(state, VsBlockState(solidState, null)))
}

override fun register(state: BlockState, liquidState: LiquidState) {
toRegister.add(Pair(state, VsBlockState(null, liquidState)))
}

override fun register(state: BlockState, liquidState: LiquidState, solidState: SolidState) {
toRegister.add(Pair(state, VsBlockState(solidState, liquidState)))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.valkyrienskies.mod.api_impl.events

import net.minecraft.client.gui.screens.Screen
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.ships.Ship
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.entity.ShipMountingEntity
import org.valkyrienskies.mod.common.getShipManagingPos
import org.valkyrienskies.mod.compat.clothconfig.VSClothConfig

class VsApiImpl : VsApi {

override val registerBlockStateEvent = EventEmitterImpl<RegisterBlockStateEvent>()
override val preRenderShipEvent = EventEmitterImpl<PreRenderShipEvent>()
override val postRenderShipEvent = EventEmitterImpl<PostRenderShipEvent>()

override fun isShipMountingEntity(entity: Entity): Boolean {
return entity is ShipMountingEntity
}

override fun createConfigScreenLegacy(parent: Screen, vararg configs: Class<*>): Screen {
return VSClothConfig.createConfigScreenFor(parent, *configs)
}


override fun getShipManagingBlock(level: Level?, pos: BlockPos?): Ship? {
return pos?.let { level?.getShipManagingPos(it) }
}

override fun getShipManagingChunk(level: Level?, pos: ChunkPos?): Ship? {
return pos?.let { level?.getShipManagingPos(it) }
}

override fun getShipManagingChunk(level: Level?, chunkX: Int, chunkZ: Int): Ship? {
return level?.getShipManagingPos(chunkX, chunkZ)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ import org.valkyrienskies.core.apigame.world.chunks.BlockType
import org.valkyrienskies.mod.common.block.WingBlock
import org.valkyrienskies.mod.common.config.MassDatapackResolver
import org.valkyrienskies.mod.common.hooks.VSGameEvents
import org.valkyrienskies.physics_api.Lod1BlockStateId
import org.valkyrienskies.physics_api.Lod1LiquidBlockStateId
import org.valkyrienskies.physics_api.Lod1SolidBlockStateId
import org.valkyrienskies.physics_api.voxel.Lod1LiquidBlockState
import org.valkyrienskies.physics_api.voxel.Lod1SolidBlockState
import java.util.function.IntFunction

// Other mods can then provide weights and types based on their added content
Expand All @@ -35,10 +30,6 @@ interface BlockStateInfoProvider {

// Get the id of the block state
fun getBlockStateType(blockState: BlockState): BlockType?

val solidBlockStates: List<Lod1SolidBlockState>
val liquidBlockStates: List<Lod1LiquidBlockState>
val blockStateData: List<Triple<Lod1SolidBlockStateId, Lod1LiquidBlockStateId, Lod1BlockStateId>>
}

object BlockStateInfo {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,26 @@
package org.valkyrienskies.mod.common

import net.minecraft.world.level.block.Blocks
import net.minecraft.world.level.block.LiquidBlock
import net.minecraft.world.level.block.state.BlockState
import net.minecraft.world.level.material.Material
import org.valkyrienskies.core.apigame.world.chunks.BlockType
import org.valkyrienskies.physics_api.Lod1BlockStateId
import org.valkyrienskies.physics_api.Lod1LiquidBlockStateId
import org.valkyrienskies.physics_api.Lod1SolidBlockStateId
import org.valkyrienskies.physics_api.voxel.Lod1LiquidBlockState
import org.valkyrienskies.physics_api.voxel.Lod1SolidBlockState

object DefaultBlockStateInfoProvider : BlockStateInfoProvider {
override val priority: Int
get() = Int.MIN_VALUE
override val solidBlockStates: List<Lod1SolidBlockState>
get() = TODO()
override val liquidBlockStates: List<Lod1LiquidBlockState>
get() = TODO()
override val blockStateData: List<Triple<Lod1SolidBlockStateId, Lod1LiquidBlockStateId, Lod1BlockStateId>>
get() = TODO()

override fun getBlockStateMass(blockState: BlockState): Double {
if (blockState.isAir) return 0.0
// By default make blocks weight 100 kg
return 100.0
// By default make blocks weight 1000 kg
return 1000.0
}

override fun getBlockStateType(blockState: BlockState): BlockType {
if (blockState.isAir) return vsCore.blockTypes.air

val blockMaterial = blockState.material
if (blockMaterial.isLiquid)
return if (blockMaterial == Material.LAVA) vsCore.blockTypes.lava else vsCore.blockTypes.water
return if (blockMaterial.isSolid) vsCore.blockTypes.solid else vsCore.blockTypes.noCollision
val block = blockState.block
if (block is LiquidBlock)
return if (block == Blocks.LAVA) vsCore.blockTypes.lava else vsCore.blockTypes.water
return if (blockState.material.isSolid) vsCore.blockTypes.solid else vsCore.blockTypes.air
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ inline fun Level?.transformToNearbyShipsAndWorld(
cb(posInWorld.x(), posInWorld.y(), posInWorld.z())
}

for (nearbyShip in shipObjectWorld.allShips.getIntersecting(aabb)) {
for (nearbyShip in shipObjectWorld.allShips.getIntersecting(aabb, this!!.dimensionId)) {
if (nearbyShip == currentShip) continue
val posInShip = nearbyShip.worldToShip.transformPosition(posInWorld, temp0)
cb(posInShip.x(), posInShip.y(), posInShip.z())
Expand Down Expand Up @@ -393,8 +393,7 @@ fun Level?.getWorldCoordinates(blockPos: BlockPos, pos: Vector3d): Vector3d {
}

fun Level.getShipsIntersecting(aabb: AABB): Iterable<Ship> = getShipsIntersecting(aabb.toJOML())
fun Level.getShipsIntersecting(aabb: AABBdc): Iterable<Ship> = allShips.getIntersecting(aabb).filter { it.chunkClaimDimension == dimensionId }

fun Level.getShipsIntersecting(aabb: AABBdc): Iterable<Ship> = allShips.getIntersecting(aabb, dimensionId)
fun Level?.transformAabbToWorld(aabb: AABB): AABB = transformAabbToWorld(aabb.toJOML()).toMinecraft()
fun Level?.transformAabbToWorld(aabb: AABBd) = this?.transformAabbToWorld(aabb, aabb) ?: aabb
fun Level.transformAabbToWorld(aabb: AABBdc, dest: AABBd): AABBd {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ 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.config.VSConfigClass
import org.valkyrienskies.core.impl.config.VSCoreConfig
import org.valkyrienskies.core.impl.hooks.VSEvents
import org.valkyrienskies.mod.common.blockentity.TestHingeBlockEntity
import org.valkyrienskies.mod.common.config.VSGameConfig
Expand Down Expand Up @@ -50,8 +48,7 @@ object ValkyrienSkiesMod {
VSGamePackets.register()
VSGamePackets.registerHandlers()

VSConfigClass.registerConfig("vs_core", VSCoreConfig::class.java)
VSConfigClass.registerConfig("vs", VSGameConfig::class.java)
core.registerConfigLegacy("vs", VSGameConfig::class.java)
VSEvents.ShipLoadEvent.on { event ->
event.ship.setAttachment(GameTickForceApplier())
}
Expand Down
Loading
Loading