-
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.
- Loading branch information
1 parent
18e0411
commit 5d4c736
Showing
190 changed files
with
2,558 additions
and
1 deletion.
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
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
43 changes: 43 additions & 0 deletions
43
src/main/java/com/github/mori01231/lifecore/data/DataLoader.kt
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,43 @@ | ||
package com.github.mori01231.lifecore.data | ||
|
||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.json.Json | ||
import org.slf4j.Logger | ||
import java.nio.file.Files | ||
import java.nio.file.Path | ||
import kotlin.io.path.isDirectory | ||
import kotlin.io.path.readText | ||
import kotlin.io.path.relativeTo | ||
|
||
class DataLoader(private val logger: Logger, private val dataFolder: Path) { | ||
val tags: List<Tag> by lazy { loadTags() } | ||
|
||
fun findTag(name: String): Tag? = tags.firstOrNull { it.name == name } | ||
|
||
fun loadTags(): List<Tag> { | ||
val tags = mutableListOf<Tag>() | ||
val tagsPath = dataFolder.resolve("tags") | ||
Files.walk(tagsPath).forEach { path -> | ||
if (path.isDirectory()) return@forEach | ||
val tagName = | ||
path.relativeTo(tagsPath) | ||
.toString() | ||
.let { it.substring(0, it.length - ".json".length) } | ||
.let { it.substring(it.indexOf('/') + 1) } | ||
logger.info("Loading tag $tagName") | ||
val values = mutableListOf<TagValue>() | ||
Json.decodeFromString<RawTag>(path.readText()).values.forEach { tagValue -> | ||
if (tagValue.startsWith("#")) { | ||
values.add(TagReference(this, tagValue.substring(1))) | ||
} else { | ||
values.add(StringTagValue(tagValue)) | ||
} | ||
} | ||
tags.add(Tag("minecraft:$tagName", values)) | ||
} | ||
return tags | ||
} | ||
|
||
@Serializable | ||
data class RawTag(val values: List<String>) | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/github/mori01231/lifecore/data/StringTagValue.kt
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,5 @@ | ||
package com.github.mori01231.lifecore.data | ||
|
||
data class StringTagValue(val value: String) : TagValue { | ||
override fun resolve(): Set<String> = setOf(value) | ||
} |
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,5 @@ | ||
package com.github.mori01231.lifecore.data | ||
|
||
data class Tag(val name: String, val values: List<TagValue>) : TagValue { | ||
override fun resolve(): Set<String> = values.flatMap(TagValue::resolve).toSet() | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/github/mori01231/lifecore/data/TagReference.kt
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,10 @@ | ||
package com.github.mori01231.lifecore.data | ||
|
||
class TagReference(private val dataLoader: DataLoader, val name: String) : TagValue { | ||
val values by lazy { | ||
val tag = dataLoader.findTag(name) ?: error("missing tag $name") | ||
tag.values.flatMap(TagValue::resolve).toSet() | ||
} | ||
|
||
override fun resolve(): Set<String> = values | ||
} |
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,5 @@ | ||
package com.github.mori01231.lifecore.data | ||
|
||
interface TagValue { | ||
fun resolve(): Set<String> | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/github/mori01231/lifecore/listener/item/PicksawItemListener.kt
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,39 @@ | ||
package com.github.mori01231.lifecore.listener.item | ||
|
||
import com.github.mori01231.lifecore.data.DataLoader | ||
import com.github.mori01231.lifecore.util.ItemUtil | ||
import org.bukkit.Material | ||
import org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData | ||
import org.bukkit.event.EventHandler | ||
import org.bukkit.event.Listener | ||
import org.bukkit.event.block.Action | ||
import org.bukkit.event.player.PlayerInteractEvent | ||
import org.bukkit.inventory.EquipmentSlot | ||
|
||
class PicksawItemListener(private val dataLoader: DataLoader) : Listener { | ||
companion object { | ||
const val ITEM_ID = "2dd646f1-70a1-4613-92c3-431de7c0126f" | ||
} | ||
|
||
@EventHandler | ||
fun onPlayerInteract(e: PlayerInteractEvent) { | ||
if (e.hand != EquipmentSlot.HAND) return | ||
if (e.action != Action.LEFT_CLICK_BLOCK) return | ||
val item = e.player.inventory.itemInMainHand | ||
if (ItemUtil.getStringTag(item, "LifeItemId") != ITEM_ID) return | ||
val minecraftName = "minecraft:" + ((e.clickedBlock ?: return).blockData as CraftBlockData).state.block.item.toString() | ||
if (dataLoader.findTag("minecraft:mineable/axe")?.resolve()?.contains(minecraftName) == true) { | ||
item.type = Material.valueOf(item.type.name.substring(0, item.type.name.lastIndexOf('_')) + "_AXE") | ||
e.player.inventory.setItemInMainHand(item) | ||
} else if (dataLoader.findTag("minecraft:mineable/pickaxe")?.resolve()?.contains(minecraftName) == true) { | ||
item.type = Material.valueOf(item.type.name.substring(0, item.type.name.lastIndexOf('_')) + "_PICKAXE") | ||
e.player.inventory.setItemInMainHand(item) | ||
} else if (dataLoader.findTag("minecraft:mineable/shovel")?.resolve()?.contains(minecraftName) == true) { | ||
item.type = Material.valueOf(item.type.name.substring(0, item.type.name.lastIndexOf('_')) + "_SHOVEL") | ||
e.player.inventory.setItemInMainHand(item) | ||
} else if (dataLoader.findTag("minecraft:mineable/hoe")?.resolve()?.contains(minecraftName) == true) { | ||
item.type = Material.valueOf(item.type.name.substring(0, item.type.name.lastIndexOf('_')) + "_HOE") | ||
e.player.inventory.setItemInMainHand(item) | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/github/mori01231/lifecore/util/FileSystemUtil.kt
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,16 @@ | ||
package com.github.mori01231.lifecore.util | ||
|
||
import java.io.File | ||
import java.nio.file.FileSystem | ||
import java.nio.file.FileSystems | ||
import java.nio.file.Path | ||
|
||
object FileSystemUtil { | ||
@JvmStatic | ||
fun openFileAsFileSystem(file: File): FileSystem = | ||
FileSystems.newFileSystem(file.toPath(), null as ClassLoader?) | ||
|
||
@JvmStatic | ||
fun getPathInFile(file: File, path: String): Path = | ||
openFileAsFileSystem(file).getPath(path) | ||
} |
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,8 @@ | ||
{ | ||
"values": [ | ||
"minecraft:acacia_log", | ||
"minecraft:acacia_wood", | ||
"minecraft:stripped_acacia_log", | ||
"minecraft:stripped_acacia_wood" | ||
] | ||
} |
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,6 @@ | ||
{ | ||
"values": [ | ||
"#minecraft:ceiling_hanging_signs", | ||
"#minecraft:wall_hanging_signs" | ||
] | ||
} |
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,6 @@ | ||
{ | ||
"values": [ | ||
"#minecraft:signs", | ||
"#minecraft:all_hanging_signs" | ||
] | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/resources/data/tags/blocks/ancient_city_replaceable.json
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,16 @@ | ||
{ | ||
"values": [ | ||
"minecraft:deepslate", | ||
"minecraft:deepslate_bricks", | ||
"minecraft:deepslate_tiles", | ||
"minecraft:deepslate_brick_slab", | ||
"minecraft:deepslate_tile_slab", | ||
"minecraft:deepslate_brick_stairs", | ||
"minecraft:deepslate_tile_wall", | ||
"minecraft:deepslate_brick_wall", | ||
"minecraft:cobbled_deepslate", | ||
"minecraft:cracked_deepslate_bricks", | ||
"minecraft:cracked_deepslate_tiles", | ||
"minecraft:gray_wool" | ||
] | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/resources/data/tags/blocks/animals_spawnable_on.json
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,5 @@ | ||
{ | ||
"values": [ | ||
"minecraft:grass_block" | ||
] | ||
} |
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,7 @@ | ||
{ | ||
"values": [ | ||
"minecraft:anvil", | ||
"minecraft:chipped_anvil", | ||
"minecraft:damaged_anvil" | ||
] | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/resources/data/tags/blocks/armadillo_spawnable_on.json
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,8 @@ | ||
{ | ||
"values": [ | ||
"#minecraft:animals_spawnable_on", | ||
"#minecraft:badlands_terracotta", | ||
"minecraft:red_sand", | ||
"minecraft:coarse_dirt" | ||
] | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/resources/data/tags/blocks/axolotls_spawnable_on.json
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,5 @@ | ||
{ | ||
"values": [ | ||
"minecraft:clay" | ||
] | ||
} |
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,9 @@ | ||
{ | ||
"values": [ | ||
"#minecraft:dirt", | ||
"#minecraft:sand", | ||
"#minecraft:terracotta", | ||
"minecraft:snow_block", | ||
"minecraft:powder_snow" | ||
] | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/resources/data/tags/blocks/azalea_root_replaceable.json
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,13 @@ | ||
{ | ||
"values": [ | ||
"#minecraft:base_stone_overworld", | ||
"#minecraft:dirt", | ||
"#minecraft:terracotta", | ||
"minecraft:red_sand", | ||
"minecraft:clay", | ||
"minecraft:gravel", | ||
"minecraft:sand", | ||
"minecraft:snow_block", | ||
"minecraft:powder_snow" | ||
] | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/resources/data/tags/blocks/badlands_terracotta.json
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,11 @@ | ||
{ | ||
"values": [ | ||
"minecraft:terracotta", | ||
"minecraft:white_terracotta", | ||
"minecraft:yellow_terracotta", | ||
"minecraft:orange_terracotta", | ||
"minecraft:red_terracotta", | ||
"minecraft:brown_terracotta", | ||
"minecraft:light_gray_terracotta" | ||
] | ||
} |
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,6 @@ | ||
{ | ||
"values": [ | ||
"minecraft:bamboo_block", | ||
"minecraft:stripped_bamboo_block" | ||
] | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/resources/data/tags/blocks/bamboo_plantable_on.json
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,10 @@ | ||
{ | ||
"values": [ | ||
"#minecraft:sand", | ||
"#minecraft:dirt", | ||
"minecraft:bamboo", | ||
"minecraft:bamboo_sapling", | ||
"minecraft:gravel", | ||
"minecraft:suspicious_gravel" | ||
] | ||
} |
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,36 @@ | ||
{ | ||
"values": [ | ||
"minecraft:white_banner", | ||
"minecraft:orange_banner", | ||
"minecraft:magenta_banner", | ||
"minecraft:light_blue_banner", | ||
"minecraft:yellow_banner", | ||
"minecraft:lime_banner", | ||
"minecraft:pink_banner", | ||
"minecraft:gray_banner", | ||
"minecraft:light_gray_banner", | ||
"minecraft:cyan_banner", | ||
"minecraft:purple_banner", | ||
"minecraft:blue_banner", | ||
"minecraft:brown_banner", | ||
"minecraft:green_banner", | ||
"minecraft:red_banner", | ||
"minecraft:black_banner", | ||
"minecraft:white_wall_banner", | ||
"minecraft:orange_wall_banner", | ||
"minecraft:magenta_wall_banner", | ||
"minecraft:light_blue_wall_banner", | ||
"minecraft:yellow_wall_banner", | ||
"minecraft:lime_wall_banner", | ||
"minecraft:pink_wall_banner", | ||
"minecraft:gray_wall_banner", | ||
"minecraft:light_gray_wall_banner", | ||
"minecraft:cyan_wall_banner", | ||
"minecraft:purple_wall_banner", | ||
"minecraft:blue_wall_banner", | ||
"minecraft:brown_wall_banner", | ||
"minecraft:green_wall_banner", | ||
"minecraft:red_wall_banner", | ||
"minecraft:black_wall_banner" | ||
] | ||
} |
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,7 @@ | ||
{ | ||
"values": [ | ||
"minecraft:netherrack", | ||
"minecraft:basalt", | ||
"minecraft:blackstone" | ||
] | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/resources/data/tags/blocks/base_stone_overworld.json
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,10 @@ | ||
{ | ||
"values": [ | ||
"minecraft:stone", | ||
"minecraft:granite", | ||
"minecraft:diorite", | ||
"minecraft:andesite", | ||
"minecraft:tuff", | ||
"minecraft:deepslate" | ||
] | ||
} |
Oops, something went wrong.