aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNotNite <hi@notnite.com>2024-02-15 22:09:15 -0500
committerNotNite <hi@notnite.com>2024-02-15 22:09:15 -0500
commit40c0e869ad1edd5524b409d50d8733003c4d0c31 (patch)
tree74af1fded8b56fad2a6243af12d2d676732b1002
parent4cbe83614ad0d035c1d0ce11385335cec63a0ed8 (diff)
downloadgloppers-40c0e869ad1edd5524b409d50d8733003c4d0c31.tar.gz
gloppers-40c0e869ad1edd5524b409d50d8733003c4d0c31.tar.bz2
gloppers-40c0e869ad1edd5524b409d50d8733003c4d0c31.zip
1.0.2
-rw-r--r--build.gradle19
-rw-r--r--gradle.properties13
-rw-r--r--src/main/java/com/notnite/gloppers/mixin/HopperBlockEntityMixin.java57
-rw-r--r--src/main/kotlin/com/notnite/gloppers/Gloppers.kt38
-rw-r--r--src/main/resources/fabric.mod.json4
5 files changed, 58 insertions, 73 deletions
diff --git a/build.gradle b/build.gradle
index 6d1f37a..7445bac 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,6 +1,5 @@
plugins {
id "fabric-loom" version "1.2-SNAPSHOT"
- id "org.jetbrains.kotlin.jvm" version "1.8.22"
id "com.modrinth.minotaur" version "2.+"
}
@@ -19,12 +18,6 @@ dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
-
- modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
- modImplementation "net.fabricmc:fabric-language-kotlin:${project.fabric_kotlin_version}"
-
- implementation "com.github.LlamaLad7:MixinExtras:${project.mixinextras_version}"
- annotationProcessor "com.github.LlamaLad7:MixinExtras:${project.mixinextras_version}"
}
processResources {
@@ -39,12 +32,6 @@ tasks.withType(JavaCompile).configureEach {
it.options.release = 17
}
-tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
- kotlinOptions {
- jvmTarget = 17
- }
-}
-
java {
withSourcesJar()
@@ -64,10 +51,6 @@ modrinth {
projectId = "gloppers"
versionType = "release"
uploadFile = remapJar
- gameVersions = ["1.20", "1.20.1"]
+ gameVersions = ["1.20.4"]
loaders = ["fabric", "quilt"]
- dependencies {
- required.project "fabric-api"
- required.project "fabric-language-kotlin"
- }
}
diff --git a/gradle.properties b/gradle.properties
index 28ae9c8..5b540a0 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,15 +1,10 @@
org.gradle.jvmargs=-Xmx1G
org.gradle.parallel=true
-minecraft_version=1.20
-yarn_mappings=1.20+build.1
-# While we build off of 0.14.21, the dependency is set as 0.14.19 to work with Quilt
-loader_version=0.14.21
-fabric_kotlin_version=1.9.5+kotlin.1.8.22
+minecraft_version=1.20.4
+yarn_mappings=1.20.4+build.3
+loader_version=0.15.6
-mod_version=1.0.1
+mod_version=1.0.2
maven_group=com.notnite
archives_base_name=gloppers
-
-fabric_version=0.83.0+1.20
-mixinextras_version=0.1.1
diff --git a/src/main/java/com/notnite/gloppers/mixin/HopperBlockEntityMixin.java b/src/main/java/com/notnite/gloppers/mixin/HopperBlockEntityMixin.java
index ce463a3..7637cc8 100644
--- a/src/main/java/com/notnite/gloppers/mixin/HopperBlockEntityMixin.java
+++ b/src/main/java/com/notnite/gloppers/mixin/HopperBlockEntityMixin.java
@@ -1,21 +1,57 @@
package com.notnite.gloppers.mixin;
-import com.notnite.gloppers.Gloppers;
import net.minecraft.block.entity.Hopper;
import net.minecraft.block.entity.HopperBlockEntity;
+import net.minecraft.entity.ItemEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
+import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.Direction;
import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(HopperBlockEntity.class)
-public class HopperBlockEntityMixin {
+public abstract class HopperBlockEntityMixin {
+ @Unique
private static int dirtySlotState = 0;
+ @Shadow
+ private DefaultedList<ItemStack> inventory;
+
+ @Unique
+ private static boolean canTransfer(Inventory to, ItemStack stack) {
+ try {
+ if (to instanceof HopperBlockEntity) {
+ var hopperName = ((HopperBlockEntity) to).getName().copyContentOnly().getString();
+ var itemRegistryEntry = stack.getRegistryEntry().getKey();
+ if (itemRegistryEntry.isEmpty()) return false;
+ var itemName = itemRegistryEntry.get().getValue().getPath();
+
+ if (hopperName.startsWith("!")) {
+ var globs = hopperName.substring(1).split(",");
+ for (var glob : globs) {
+ var strippedGlob = glob.replaceAll("[^a-zA-Z0-9_*?]", "");
+ var regex = strippedGlob.replace(".", "\\.").replace("*", ".*").replace("?", ".");
+ if (itemName.matches(regex)) return true;
+ }
+
+ // No globs matched, so don't transfer
+ return false;
+ }
+ }
+ } catch (Exception e) {
+ // ignored
+ }
+
+ // Doesn't have a glob (or exception), so transfer
+ return true;
+ }
+
// We can't decrement the item stack before it gets passed to transfer, because we may not be allowed to transfer,
// eating an item. We know removeStack will get called immediately before transfer, so while it's messy, we can use
// a static variable to keep track of what slot we're removing from.
@@ -38,7 +74,7 @@ public class HopperBlockEntityMixin {
private static ItemStack insert$gloppersTransfer(
Inventory from, Inventory to, ItemStack stack, Direction side
) {
- if (!Gloppers.INSTANCE.canTransfer(to, stack)) {
+ if (!canTransfer(to, stack)) {
// The return value of this is only used to check if it's empty, and if so, returns that it succeeded.
// We can just return the item stack we were given, as we didn't remove from it.
return stack;
@@ -55,8 +91,19 @@ public class HopperBlockEntityMixin {
at = @At("HEAD"),
cancellable = true
)
- private static void extract(Hopper hopper, Inventory inventory, int slot, Direction side, CallbackInfoReturnable<Boolean> cir) {
+ private static void extract(Hopper hopper, Inventory inventory, int slot, Direction
+ side, CallbackInfoReturnable<Boolean> cir) {
var item = inventory.getStack(slot);
- if (!Gloppers.INSTANCE.canTransfer(hopper, item)) cir.setReturnValue(false);
+ if (!canTransfer(hopper, item)) cir.setReturnValue(false);
+ }
+
+ // This handles the case where an item entity is dropped onto the hopper from above.
+ @Inject(
+ method = "extract(Lnet/minecraft/inventory/Inventory;Lnet/minecraft/entity/ItemEntity;)Z",
+ at = @At("HEAD"),
+ cancellable = true
+ )
+ private static void extract(Inventory inventory, ItemEntity itemEntity, CallbackInfoReturnable<Boolean> cir) {
+ if (!canTransfer(inventory, itemEntity.getStack())) cir.setReturnValue(false);
}
}
diff --git a/src/main/kotlin/com/notnite/gloppers/Gloppers.kt b/src/main/kotlin/com/notnite/gloppers/Gloppers.kt
deleted file mode 100644
index 95596c0..0000000
--- a/src/main/kotlin/com/notnite/gloppers/Gloppers.kt
+++ /dev/null
@@ -1,38 +0,0 @@
-package com.notnite.gloppers
-
-import net.minecraft.block.entity.HopperBlockEntity
-import net.minecraft.inventory.Inventory
-import net.minecraft.item.ItemStack
-
-object Gloppers {
- 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
- }
-}
diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json
index eebc2a7..b75428f 100644
--- a/src/main/resources/fabric.mod.json
+++ b/src/main/resources/fabric.mod.json
@@ -19,8 +19,6 @@
"depends": {
"fabricloader": ">=0.14.19",
"minecraft": "~1.20",
- "java": ">=17",
- "fabric-api": "*",
- "fabric-language-kotlin": ">=1.8.22"
+ "java": ">=17"
}
}