Skip to content

Commit

Permalink
Merge branch '1.20.1/new-api' into 1.20.1/main
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubydesic committed May 26, 2024
2 parents bcda04a + 70461ea commit c819c5c
Show file tree
Hide file tree
Showing 30 changed files with 407 additions and 283 deletions.
3 changes: 2 additions & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ dependencies {
exclude module: "netty-buffer"
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 @@ -4,8 +4,6 @@
import java.util.Collections;
import java.util.Set;
import java.util.WeakHashMap;
import org.valkyrienskies.core.impl.hooks.VSEvents.ShipUnloadEventClient;
import org.valkyrienskies.mod.mixinducks.MixinBlockEntityInstanceManagerDuck;

public class FlywheelEvents {
static {
Expand All @@ -18,11 +16,12 @@ public class FlywheelEvents {
);

private static synchronized void registerEvents() {
ShipUnloadEventClient.Companion.on(event -> {
for (final InstanceWorld instanceWorld : weakLoadedInstanceWorlds) {
((MixinBlockEntityInstanceManagerDuck) instanceWorld.getBlockEntityInstanceManager()).vs$removeShipManager(event.getShip());
}
});
// TODO api fix
// ShipUnloadEventClient.Companion.on(event -> {
// for (final InstanceWorld instanceWorld : weakLoadedInstanceWorlds) {
// ((MixinBlockEntityInstanceManagerDuck) instanceWorld.getBlockEntityInstanceManager()).vs$removeShipManager(event.getShip());
// }
// });
}

public static void onInstanceWorldLoad(final InstanceWorld instanceWorld) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,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 @@ -128,18 +136,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
@@ -1,7 +1,14 @@
package org.valkyrienskies.mod.api

import net.minecraft.core.Direction
import org.valkyrienskies.mod.common.entity.ShipMountingEntity

/**
* A utility class that is attached to ships and gives the inputs from a player
* mounted to a [ShipMountingEntity]
*/
@Deprecated("This API will be removed at a later date. " +
"Addons should make their own seat entities and handle their own inputs. ")
class SeatedControllingPlayer(val seatInDirection: Direction) {
var forwardImpulse: Float = 0.0f
var leftImpulse: Float = 0.0f
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@file:JvmName("ValkyrienSkies")
package org.valkyrienskies.mod.api

import net.minecraft.core.BlockPos
import net.minecraft.world.level.ChunkPos
import net.minecraft.world.level.Level
import org.valkyrienskies.core.api.ships.LoadedShip
import org.valkyrienskies.core.api.ships.Ship

val vsApi: VsApi @JvmName("getApi") get() = TODO()

fun Level?.getShipManagingBlock(pos: BlockPos?) = vsApi.getShipManagingBlock(this, pos)
fun Level?.getShipManagingBlock(x: Int, y: Int, z: Int) = getShipManagingChunk(x shr 4, z shr 4)

fun Level?.getLoadedShipManagingBlock(pos: BlockPos?): LoadedShip? = TODO()

fun Level?.getDeadShipManagingBlock(pos: BlockPos?): Ship? = TODO()

fun Level?.getShipManagingChunk(pos: ChunkPos?) = vsApi.getShipManagingChunk(this, pos)
fun Level?.getShipManagingChunk(chunkX: Int, chunkZ: Int) = vsApi.getShipManagingChunk(this, chunkX, chunkZ)
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 @@ -35,10 +35,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
Expand Up @@ -13,12 +13,6 @@ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ 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 @@ -197,7 +197,7 @@ fun Level?.transformToNearbyShipsAndWorld(
this?.transformToNearbyShipsAndWorld(x, y, z, aabbRadius, cb::accept)
}

inline fun Level?.transformToNearbyShipsAndWorld(
inline fun Level.transformToNearbyShipsAndWorld(
x: Double, y: Double, z: Double, aabbRadius: Double, cb: (Double, Double, Double) -> Unit
) {
val currentShip = getShipManagingPos(x, y, z)
Expand All @@ -212,7 +212,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, dimensionId)) {
if (nearbyShip == currentShip) continue
val posInShip = nearbyShip.worldToShip.transformPosition(posInWorld, temp0)
cb(posInShip.x(), posInShip.y(), posInShip.z())
Expand Down Expand Up @@ -285,12 +285,7 @@ fun ServerLevel?.getShipObjectManagingPos(pos: Vector3dc) =

private fun getShipManagingPosImpl(world: Level?, x: Int, z: Int): Ship? {
return if (world != null && world.isChunkInShipyard(x, z)) {
val ship = world.shipObjectWorld.allShips.getByChunkPos(x, z, world.dimensionId)
if (ship != null && ship.chunkClaimDimension == world.dimensionId) {
ship
} else {
null
}
world.shipObjectWorld.allShips.getByChunkPos(x, z, world.dimensionId)
} else {
null
}
Expand Down Expand Up @@ -397,7 +392,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
Expand All @@ -406,7 +401,7 @@ fun Level.transformAabbToWorld(aabb: AABBdc, dest: AABBd): AABBd {
val ship2 = getShipManagingPos(aabb.maxX(), aabb.maxY(), aabb.maxZ())

// if both endpoints of the aabb are in the same ship, do the transform
if (ship1 == ship2 && ship1 != null && ship1.chunkClaimDimension == dimensionId) {
if (ship1 == ship2 && ship1 != null) {
return aabb.transform(ship1.shipToWorld, dest)
}

Expand Down
Loading

0 comments on commit c819c5c

Please sign in to comment.