Skip to content

Commit

Permalink
refactor: revert change from datapack to packet-listener
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Aug 3, 2024
1 parent e5a99c4 commit 95e0dbb
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 34 deletions.
51 changes: 51 additions & 0 deletions src/main/kotlin/com/mineinabyss/blocky/BlockyDatapacks.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.mineinabyss.blocky

import kotlinx.serialization.json.*
import net.minecraft.core.registries.BuiltInRegistries
import net.minecraft.tags.BlockTags
import org.bukkit.Bukkit

object BlockyDatapacks {

private val defaultWorld = Bukkit.getWorlds().first()
private val blockyDatapack = defaultWorld.worldFolder.resolve("datapacks/blocky")

fun generateDatapack() {
blockyDatapack.resolve("data").mkdirs()
writeMcMeta()
generateMineableTag()

Bukkit.getDatapackManager().packs.firstOrNull { it.name == "file/blocky" }?.isEnabled = true
}

private fun writeMcMeta() {
runCatching {
val packMeta = blockyDatapack.resolve("pack.mcmeta")
packMeta.writeText(buildJsonObject {
putJsonObject("pack") {
put("description", "Datapack for Blocky")
put("pack_format", 26)
}
}.toString())
}.onFailure { it.printStackTrace() }
}

private fun generateMineableTag() {
runCatching {
val tagFile = blockyDatapack.resolve("data/minecraft/tags/block/mineable/axe.json")
tagFile.parentFile.mkdirs()
tagFile.createNewFile()

val tagObject = buildJsonObject {
put("replace", true)
putJsonArray("values") {
BuiltInRegistries.BLOCK.tags.toList().find { it.first == BlockTags.MINEABLE_WITH_AXE }?.second?.forEach {
if (it.registeredName != "minecraft:note_block") add(it.registeredName)
}
}
}

tagFile.writeText(tagObject.toString())
}.onFailure { it.printStackTrace() }
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/com/mineinabyss/blocky/BlockyPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class BlockyPlugin : JavaPlugin() {
override fun onEnable() {
createBlockyContext()

BlockyTags.interceptConfigPhaseTagPacket()
BlockyDatapacks.generateDatapack()

if (Plugins.isEnabled("WorldEdit")) {
WorldEdit.getInstance().blockFactory.register(WorldEditSupport.BlockyInputParser())
Expand Down
33 changes: 0 additions & 33 deletions src/main/kotlin/com/mineinabyss/blocky/BlockyTags.kt

This file was deleted.

0 comments on commit 95e0dbb

Please sign in to comment.