aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/notnite/gloppers/Gloppers.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/com/notnite/gloppers/Gloppers.kt')
-rw-r--r--src/main/kotlin/com/notnite/gloppers/Gloppers.kt41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/main/kotlin/com/notnite/gloppers/Gloppers.kt b/src/main/kotlin/com/notnite/gloppers/Gloppers.kt
new file mode 100644
index 0000000..bdea779
--- /dev/null
+++ b/src/main/kotlin/com/notnite/gloppers/Gloppers.kt
@@ -0,0 +1,41 @@
+package com.notnite.gloppers
+
+import net.fabricmc.api.DedicatedServerModInitializer
+import net.minecraft.block.entity.HopperBlockEntity
+import net.minecraft.inventory.Inventory
+import net.minecraft.item.ItemStack
+
+object Gloppers : DedicatedServerModInitializer {
+ override fun onInitializeServer() {}
+
+ private fun matchesGlob(glob: String, str: String): Boolean {
+ val regex = glob
+ .replace(".", "\\.")
+ .replace("*", ".*")
+ .replace("?", ".")
+ return str.matches(regex.toRegex())
+ }
+
+ fun canTransfer(to: Inventory, stack: ItemStack): Boolean {
+ if (to is HopperBlockEntity) {
+ val hopperName = to.name.copyContentOnly().string
+ val itemName = stack.registryEntry.key.get().value.path
+
+ if (hopperName.startsWith("!")) {
+ val globs = hopperName.substring(1).split(",")
+ for (glob in globs) {
+ if (matchesGlob(glob, itemName)) {
+ // Glob matched, transfer
+ return true
+ }
+ }
+
+ // No globs matched, so don't transfer
+ return false
+ }
+ }
+
+ // Doesn't have a glob, so transfer
+ return true
+ }
+}