-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: revert change from datapack to packet-listener
- Loading branch information
Showing
3 changed files
with
52 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.