forked from BRNSystems/RegexingHoppers
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
998f7e2ba6
|
|||
73aa86a862
|
|||
67212bed62
|
|||
93a58282c5
|
@@ -1,5 +1,5 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'fabric-loom' version '1.6-SNAPSHOT'
|
id 'fabric-loom' version '1.11-SNAPSHOT'
|
||||||
id 'maven-publish'
|
id 'maven-publish'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
# Done to increase the memory available to gradle.
|
# Done to increase the memory available to gradle.
|
||||||
org.gradle.jvmargs=-Xmx1G
|
org.gradle.jvmargs=-Xmx1G
|
||||||
minecraft_version=1.21.1
|
minecraft_version=1.21.8
|
||||||
yarn_mappings=1.21.1+build.3
|
yarn_mappings=1.21.8+build.1
|
||||||
loader_version=0.16.0
|
loader_version=0.16.14
|
||||||
# Fabric API
|
# Fabric API
|
||||||
fabric_version=0.102.1+1.21.1
|
fabric_version=0.129.0+1.21.8
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version=1.6
|
mod_version=1.6.4
|
||||||
maven_group=systems.brn
|
maven_group=systems.brn
|
||||||
archives_base_name=RegexingHoppers
|
archives_base_name=RegexingHoppers
|
||||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
validateDistributionUrl=true
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
@@ -1,12 +1,19 @@
|
|||||||
package systems.brn.regexinghoppers;
|
package systems.brn.regexinghoppers;
|
||||||
|
|
||||||
|
import com.mojang.datafixers.types.Type;
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
import net.minecraft.block.entity.HopperBlockEntity;
|
import net.minecraft.block.entity.HopperBlockEntity;
|
||||||
import net.minecraft.inventory.Inventory;
|
import net.minecraft.inventory.Inventory;
|
||||||
import net.minecraft.screen.NamedScreenHandlerFactory;
|
import net.minecraft.screen.NamedScreenHandlerFactory;
|
||||||
|
import net.minecraft.text.MutableText;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.text.TextContent;
|
||||||
|
import net.minecraft.text.TranslatableTextContent;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import systems.brn.regexinghoppers.mixin.HopperBlockEntityAccessor;
|
import systems.brn.regexinghoppers.mixin.HopperBlockEntityAccessor;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.regex.PatternSyntaxException;
|
import java.util.regex.PatternSyntaxException;
|
||||||
@@ -22,20 +29,27 @@ public class RegexingHoppers implements ModInitializer {
|
|||||||
// This code runs as soon as Minecraft is in a mod-load-ready state.
|
// This code runs as soon as Minecraft is in a mod-load-ready state.
|
||||||
// However, some things (like resources) may still be uninitialized.
|
// However, some things (like resources) may still be uninitialized.
|
||||||
// Proceed with mild caution.
|
// Proceed with mild caution.
|
||||||
LOGGER.debug("RegexingHoppers initialized!");
|
LOGGER.info("RegexingHoppers initialized!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean shouldNotMove(Inventory hopper, String itemName) {
|
public static boolean shouldNotMove(Inventory hopper, String itemName) {
|
||||||
// Log entering the method with given parameters
|
// Log entering the method with given parameters
|
||||||
LOGGER.debug("Entering shouldNotMove with itemName: {}", itemName);
|
|
||||||
|
|
||||||
|
|
||||||
|
boolean isDefaultName = false;
|
||||||
if (hopper instanceof NamedScreenHandlerFactory factory) {
|
if (hopper instanceof NamedScreenHandlerFactory factory) {
|
||||||
String customName = factory.getDisplayName().getLiteralString();
|
Text name = factory.getDisplayName();
|
||||||
|
if (name instanceof MutableText mutableText) {
|
||||||
|
if (mutableText.getContent() instanceof TranslatableTextContent textContent) {
|
||||||
|
isDefaultName = textContent.getKey().startsWith("container.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String customName = name.getString();
|
||||||
|
|
||||||
// Log the custom name used for matching
|
// Log the custom name used for matching
|
||||||
LOGGER.debug("Custom regex pattern from hopper: {}", customName);
|
|
||||||
|
|
||||||
if (customName != null && !customName.isEmpty()) {
|
if (customName != null && !customName.isEmpty() && !isDefaultName) {
|
||||||
if (hopper instanceof HopperBlockEntity) {
|
if (hopper instanceof HopperBlockEntity) {
|
||||||
HopperBlockEntityAccessor hopperAccessor = (HopperBlockEntityAccessor) hopper;
|
HopperBlockEntityAccessor hopperAccessor = (HopperBlockEntityAccessor) hopper;
|
||||||
if (hopperAccessor.getTransferCooldown() > 1) {
|
if (hopperAccessor.getTransferCooldown() > 1) {
|
||||||
@@ -43,12 +57,13 @@ public class RegexingHoppers implements ModInitializer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
LOGGER.info("Entering shouldNotMove with itemName: {}, pattern: {}", itemName, customName);
|
||||||
Pattern pattern = Pattern.compile(customName);
|
Pattern pattern = Pattern.compile(customName);
|
||||||
Matcher matcher = pattern.matcher(itemName);
|
Matcher matcher = pattern.matcher(itemName);
|
||||||
|
|
||||||
// Log the result of the regex matching
|
// Log the result of the regex matching
|
||||||
boolean matches = matcher.matches();
|
boolean matches = matcher.matches();
|
||||||
LOGGER.debug("Regex matching result: {}", matches);
|
LOGGER.info("Regex matching result: {}", matches);
|
||||||
|
|
||||||
if (!matches) {
|
if (!matches) {
|
||||||
if (hopper instanceof HopperBlockEntity) {
|
if (hopper instanceof HopperBlockEntity) {
|
||||||
@@ -59,15 +74,14 @@ public class RegexingHoppers implements ModInitializer {
|
|||||||
return !matches;
|
return !matches;
|
||||||
} catch (PatternSyntaxException e) {
|
} catch (PatternSyntaxException e) {
|
||||||
// Log exception if regex pattern is invalid
|
// Log exception if regex pattern is invalid
|
||||||
LOGGER.debug("Invalid regex pattern: {}", customName, e);
|
LOGGER.info("Invalid regex pattern: {}", customName, e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Log case when custom name is null or empty
|
// Log case when custom name is null or empty
|
||||||
LOGGER.debug("Custom name is null or empty, not performing regex matching.");
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Log if hopper is not an instance of NamedScreenHandlerFactory
|
// Log if hopper is not an instance of NamedScreenHandlerFactory
|
||||||
LOGGER.debug("Hopper is not an instance of NamedScreenHandlerFactory.");
|
LOGGER.info("Hopper is not an instance of NamedScreenHandlerFactory.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default return value in case no conditions are met
|
// Default return value in case no conditions are met
|
||||||
|
Reference in New Issue
Block a user