Skip to content

Commit

Permalink
New World Format & Model Generation
Browse files Browse the repository at this point in the history
This commit introduces the first iteration of the new world format, along with model generation, some refactoring and a bunch of minor changes. Both of these features are partially unfinished, and some other things (such as tile-entity networks) are non-functional right now.
  • Loading branch information
NichtStudioCode committed Mar 26, 2024
1 parent 15d2bd7 commit 5976329
Show file tree
Hide file tree
Showing 1,655 changed files with 13,539 additions and 13,353 deletions.
6 changes: 6 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ subprojects {

freeCompilerArgs.addAll(
"-Xjvm-default=all", // Emit JVM default methods for interface declarations with bodies

// experimental features
"-opt-in=kotlin.io.path.ExperimentalPathApi",
"-opt-in=kotlin.time.ExperimentalTime"
)
Expand All @@ -58,6 +60,10 @@ subprojects {
"-Xno-receiver-assertions", // Don't generate not-null assertion for extension receiver arguments of platform types
"-Xno-param-assertions", // Don't generate not-null assertions on parameters of methods accessible from Java
)
} else {
freeCompilerArgs.addAll(
"-Xdebug" // https://kotlinlang.org/docs/debug-coroutines-with-idea.html#optimized-out-variables
)
}
}
}
Expand Down
13 changes: 8 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
format.version = "1.1"

[versions]
cbf = "0.7"
cbf = "0.8"
configurate = "4.2.0-SNAPSHOT"
invui = "1.24"
kotlin = "1.9.20"
invui = "1.25"
kotlin = "1.9.22"
kotlinx-coroutines = "1.7.3"
ktor = "2.3.7"
paper = "1.20.4-R0.1-SNAPSHOT"
paperweight = "1.5.5"
stringremapper = "1.6"
xenondevs-commons = "1.7"
xenondevs-commons = "1.9"

[libraries]
adventure-api = { group = "net.kyori", name = "adventure-api", version = "4.12.0" }
Expand All @@ -34,10 +35,12 @@ gson = { group = "com.google.code.gson", name = "gson", version = "2.10.1" }
inventoryaccess = { group = "xyz.xenondevs.invui", name = "inventory-access-r18", version.ref = "invui" }
invui-kotlin = { group = "xyz.xenondevs.invui", name = "invui-kotlin", version.ref = "invui" }
jimfs = { group = "com.google.jimfs", name = "jimfs", version = "1.2" }
joml-primitives = { group = "org.joml", name = "joml-primitives", version = "1.10.0" }
junit-jupiter = { group = "org.junit.jupiter", name = "junit-jupiter", version = "5.9.0" }
kotlin-reflect = { group = "org.jetbrains.kotlin", name = "kotlin-reflect", version.ref = "kotlin" }
kotlin-stdlib = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib", version.ref = "kotlin" }
kotlin-test-junit = { group = "org.jetbrains.kotlin", name = "kotlin-test-junit", version.ref = "kotlin" }
kotlinx-coroutines-core-jvm = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core-jvm", version.ref = "kotlinx-coroutines" }
ktor-client-cio-jvm = { group = "io.ktor", name = "ktor-client-cio-jvm", version.ref = "ktor" }
ktor-client-content-negotiation = { group = "io.ktor", name = "ktor-client-content-negotiation", version.ref = "ktor" }
ktor-client-core-jvm = { group = "io.ktor", name = "ktor-client-core-jvm", version.ref = "ktor" }
Expand All @@ -59,7 +62,7 @@ zip4j = { group = "net.lingala.zip4j", name = "zip4j", version = "2.11.2" }
[bundles]
cbf = ["cosmic-binary-format", "cosmic-binary-format-netty-adapter"]
configurate = ["configurate-yaml", "configurate-extra-kotlin"]
kotlin = ["kotlin-stdlib", "kotlin-reflect"]
kotlin = ["kotlin-stdlib", "kotlin-reflect", "kotlinx-coroutines-core-jvm"]
ktor = ["ktor-server-core-jvm", "ktor-server-cio-jvm", "ktor-client-core-jvm", "ktor-client-cio-jvm", "ktor-client-content-negotiation", "ktor-serialization-gson-jvm"]
kyori-adventure = ["adventure-api", "adventure-text-serializer-gson", "adventure-text-serializer-plain", "adventure-platform-bukkit"]
maven-resolver = ["maven-resolver-provider", "maven-resolver-connector-basic", "maven-resolver-transport-http"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package xyz.xenondevs.nova.api.tileentity;

import org.bukkit.Location;
import org.bukkit.World;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public interface TileEntityManager {

/**
Expand All @@ -24,4 +27,17 @@ public interface TileEntityManager {
*/
@Nullable TileEntity getTileEntity(@NotNull Location location);

/**
* Gets all loaded {@link TileEntity TileEntities} in the specified {@link World}.
* @param world The {@link World} to get the {@link TileEntity TileEntities} from.
* @return All loaded {@link TileEntity TileEntities} in the specified {@link World}.
*/
@NotNull List<@NotNull TileEntity> getTileEntities(@NotNull World world);

/**
* Gets all loaded {@link TileEntity TileEntities}.
* @return All loaded {@link TileEntity TileEntities}.
*/
@NotNull List<@NotNull TileEntity> getTileEntities();

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ import com.sk89q.worldedit.util.eventbus.Subscribe
import com.sk89q.worldedit.world.block.BaseBlock
import com.sk89q.worldedit.world.block.BlockStateHolder
import com.sk89q.worldedit.world.block.BlockTypes
import xyz.xenondevs.nova.data.world.WorldDataManager
import xyz.xenondevs.nova.integration.Hook
import xyz.xenondevs.nova.registry.NovaRegistries
import xyz.xenondevs.nova.util.contains
import xyz.xenondevs.nova.util.get
import xyz.xenondevs.nova.util.runTask
import xyz.xenondevs.nova.world.BlockPos
import xyz.xenondevs.nova.world.format.WorldDataManager
import java.util.stream.Stream

private val BLOCK_STATE = BlockTypes.BARRIER!!.defaultState
Expand Down Expand Up @@ -64,7 +63,7 @@ internal class NovaBlockExtent(private val event: EditSessionEvent) : AbstractDe
override fun <T : BlockStateHolder<T>?> setBlock(x: Int, y: Int, z: Int, block: T): Boolean {
if (block is NovaBlock) {
val pos = BlockPos(BukkitAdapter.adapt(event.world), x, y, z)
runTask { WorldDataManager.addOrphanBlock(pos, NovaRegistries.BLOCK[block.novaId]!!) }
WorldDataManager.setBlockState(pos, NovaRegistries.BLOCK[block.novaId]!!.defaultBlockState)
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import xyz.xenondevs.nova.integration.customitems.CustomItemService
import xyz.xenondevs.nova.integration.customitems.CustomItemType
import xyz.xenondevs.nova.util.item.customModelData
import xyz.xenondevs.nova.util.item.playPlaceSoundEffect
import xyz.xenondevs.nova.util.playBreakEffects
import xyz.xenondevs.nova.util.broadcastBreakEvent

@Hook(plugins = ["ItemsAdder"], loadListener = ItemsAdderLoadListener::class)
internal object ItemsAdderHook : CustomItemService {
Expand All @@ -36,7 +36,7 @@ internal object ItemsAdderHook : CustomItemService {

val customCrop = CustomCrop.byAlreadyPlaced(block)
if (customCrop != null) {
if (breakEffects) block.playBreakEffects()
if (breakEffects) block.broadcastBreakEvent()
block.type = Material.AIR
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ import com.sk89q.worldedit.util.eventbus.Subscribe
import com.sk89q.worldedit.world.block.BaseBlock
import com.sk89q.worldedit.world.block.BlockStateHolder
import com.sk89q.worldedit.world.block.BlockTypes
import xyz.xenondevs.nova.data.world.WorldDataManager
import xyz.xenondevs.nova.integration.Hook
import xyz.xenondevs.nova.registry.NovaRegistries
import xyz.xenondevs.nova.util.contains
import xyz.xenondevs.nova.util.get
import xyz.xenondevs.nova.util.runTask
import xyz.xenondevs.nova.world.BlockPos
import xyz.xenondevs.nova.world.format.WorldDataManager
import java.util.stream.Stream

private val BLOCK_STATE = BlockTypes.BARRIER!!.defaultState
Expand Down Expand Up @@ -65,7 +64,7 @@ internal class NovaBlockExtent(private val event: EditSessionEvent) : AbstractDe
override fun <T : BlockStateHolder<T>?> setBlock(vec: BlockVector3, block: T): Boolean {
if (block is NovaBlock) {
val pos = BlockPos(BukkitAdapter.adapt(event.world), vec.x, vec.y, vec.z)
runTask { WorldDataManager.addOrphanBlock(pos, NovaRegistries.BLOCK[block.novaId]!!) }
WorldDataManager.setBlockState(pos, NovaRegistries.BLOCK[block.novaId]!!.defaultBlockState)
return true
}

Expand Down
5 changes: 5 additions & 0 deletions nova/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies {
novaLoaderApi(libs.bundles.cbf)
novaLoaderApi(libs.bundles.xenondevs.commons)
novaLoaderApi(libs.invui.kotlin)
novaLoaderApi(libs.joml.primitives)

// internal dependencies
compileOnly(project(":nova-loader"))
Expand Down Expand Up @@ -52,6 +53,10 @@ tasks {
expand(project.properties)
}
}

test {
useJUnitPlatform()
}
}

publishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import xyz.xenondevs.nova.addon.registry.NetworkTypeRegistry
import xyz.xenondevs.nova.addon.registry.RecipeTypeRegistry
import xyz.xenondevs.nova.addon.registry.ToolCategoryRegistry
import xyz.xenondevs.nova.addon.registry.ToolTierRegistry
import xyz.xenondevs.nova.addon.registry.UpgradeTypeRegistry
import xyz.xenondevs.nova.addon.registry.WailaInfoProviderRegistry
import xyz.xenondevs.nova.addon.registry.worldgen.BiomeRegistry
import xyz.xenondevs.nova.addon.registry.worldgen.CarverRegistry
Expand All @@ -23,6 +22,6 @@ import xyz.xenondevs.nova.addon.registry.worldgen.StructureRegistry
class AddonRegistryHolder internal constructor(
override val addon: Addon
) : AbilityTypeRegistry, AttachmentTypeRegistry, BlockRegistry, EnchantmentCategoryRegistry, EnchantmentRegistry,
ItemRegistry, NetworkTypeRegistry, RecipeTypeRegistry, ToolCategoryRegistry, ToolTierRegistry, UpgradeTypeRegistry,
ItemRegistry, NetworkTypeRegistry, RecipeTypeRegistry, ToolCategoryRegistry, ToolTierRegistry,
WailaInfoProviderRegistry, MinecraftUtilTypeRegistry, BiomeRegistry, CarverRegistry, DimensionRegistry,
FeatureRegistry, NoiseRegistry, StructureRegistry
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package xyz.xenondevs.nova.addon.registry

import xyz.xenondevs.nova.world.block.NovaBlock
import xyz.xenondevs.nova.world.block.NovaBlockBuilder
import xyz.xenondevs.nova.world.block.NovaTileEntityBlock
import xyz.xenondevs.nova.world.block.NovaTileEntityBlockBuilder
import xyz.xenondevs.nova.world.block.TileEntityConstructor
import xyz.xenondevs.nova.world.block.TileEntityNovaBlockBuilder

interface BlockRegistry : AddonGetter {

fun tileEntity(name: String, tileEntity: TileEntityConstructor) =
TileEntityNovaBlockBuilder(addon, name, tileEntity)
fun tileEntity(name: String, constructor: TileEntityConstructor, tileEntity: NovaTileEntityBlockBuilder.() -> Unit): NovaTileEntityBlock =
NovaTileEntityBlockBuilder(addon, name, constructor).apply(tileEntity).register()

fun block(name: String, block: NovaBlockBuilder.() -> Unit): NovaBlock =
NovaBlockBuilder(addon, name).apply(block).register()

fun block(name: String): NovaBlockBuilder =
NovaBlockBuilder(addon, name)
}
Original file line number Diff line number Diff line change
@@ -1,89 +1,40 @@
package xyz.xenondevs.nova.addon.registry

import net.kyori.adventure.text.Component
import net.kyori.adventure.text.format.Style
import xyz.xenondevs.nova.item.NovaItem
import xyz.xenondevs.nova.item.NovaItemBuilder
import xyz.xenondevs.nova.item.behavior.ItemBehaviorHolder
import xyz.xenondevs.nova.registry.NovaRegistries
import xyz.xenondevs.nova.util.ResourceLocation
import xyz.xenondevs.nova.util.set
import xyz.xenondevs.nova.world.block.NovaBlock

interface ItemRegistry : AddonGetter {

fun item(name: String): NovaItemBuilder =
NovaItemBuilder(addon, name)
fun item(name: String, init: NovaItemBuilder.() -> Unit): NovaItem =
NovaItemBuilder(addon, name).apply(init).register()

fun item(block: NovaBlock): NovaItemBuilder {
fun item(block: NovaBlock, init: NovaItemBuilder.() -> Unit): NovaItem {
require(block.id.namespace == addon.description.id) { "The block must be from the same addon (${block.id})!" }
return NovaItemBuilder.fromBlock(block)
return NovaItemBuilder.fromBlock(block).apply(init).register()
}

fun registerItem(
name: String,
vararg behaviors: ItemBehaviorHolder,
localizedName: String = "item.${addon.description.id}.$name",
localizedName: String? = null,
isHidden: Boolean = false
): NovaItem {
val item = NovaItem(
ResourceLocation(addon, name),
Component.translatable(localizedName),
Style.empty(),
behaviors.asList(),
isHidden = isHidden
)
NovaRegistries.ITEM[item.id] = item
return item
): NovaItem = item(name) {
behaviors(*behaviors)
localizedName?.let(::localizedName)
hidden(isHidden)
}

fun registerItem(
block: NovaBlock,
vararg behaviors: ItemBehaviorHolder,
localizedName: String? = null,
isHidden: Boolean = false
): NovaItem {
require(block.id.namespace == addon.description.id) { "The block must be from the same addon (${block.id})!" }
val item = NovaItem(
block.id,
localizedName?.let(Component::translatable) ?: block.name,
Style.empty(),
behaviors.asList(),
isHidden = isHidden,
block = block
)
block.item = item
NovaRegistries.ITEM[item.id] = item
return item
}

fun registerUnnamedItem(
name: String,
isHidden: Boolean = false
): NovaItem {
val item = NovaItem(
ResourceLocation(addon, name),
Component.empty(),
Style.empty(),
emptyList(),
isHidden = isHidden
)
NovaRegistries.ITEM[item.id] = item
return item
): NovaItem = item(block) {
behaviors(*behaviors)
localizedName?.let(::localizedName)
hidden(isHidden)
}

fun registerUnnamedHiddenItem(
name: String
): NovaItem {
val item = NovaItem(
ResourceLocation(addon, name),
Component.empty(),
Style.empty(),
emptyList(),
isHidden = true
)
NovaRegistries.ITEM[item.id] = item
return item
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package xyz.xenondevs.nova.addon.registry

import xyz.xenondevs.commons.provider.immutable.provider
import xyz.xenondevs.nova.data.config.Configs
import xyz.xenondevs.nova.data.config.entry
import xyz.xenondevs.nova.item.tool.ToolTier
import xyz.xenondevs.nova.registry.HardcodedProperties
import xyz.xenondevs.nova.registry.NovaRegistries
Expand Down
Loading

0 comments on commit 5976329

Please sign in to comment.