Fix cooldowns

This commit is contained in:
Bruno Rybársky 2024-05-05 12:27:09 +02:00
parent d1f812ed8b
commit 67c25b8477
2 changed files with 15 additions and 1 deletions

@ -1,10 +1,12 @@
package systems.brn.regexinghoppers;
import net.fabricmc.api.ModInitializer;
import net.minecraft.block.entity.HopperBlockEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.screen.NamedScreenHandlerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import systems.brn.regexinghoppers.mixin.HopperBlockEntityAccessor;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -37,6 +39,12 @@ public class RegexingHoppers implements ModInitializer {
LOGGER.info("Custom regex pattern from hopper: {}", customName);
if (customName != null && !customName.isEmpty()) {
if (hopper instanceof HopperBlockEntity) {
HopperBlockEntityAccessor hopperAccessor = (HopperBlockEntityAccessor) hopper;
if (hopperAccessor.getTransferCooldown() > 1) {
return true;
}
}
try {
Pattern pattern = Pattern.compile(customName);
Matcher matcher = pattern.matcher(itemName);
@ -45,6 +53,12 @@ public class RegexingHoppers implements ModInitializer {
boolean matches = matcher.matches();
LOGGER.info("Regex matching result: {}", matches);
if (!matches) {
if (hopper instanceof HopperBlockEntity) {
HopperBlockEntityAccessor hopperAccessor = (HopperBlockEntityAccessor) hopper;
hopperAccessor.setTransferCooldown(8);
}
}
return !matches;
} catch (PatternSyntaxException e) {
// Log exception if regex pattern is invalid

@ -6,7 +6,7 @@ import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.gen.Invoker;
@Mixin(HopperBlockEntity.class)
interface HopperBlockEntityAccessor {
public interface HopperBlockEntityAccessor {
@Accessor("transferCooldown")
int getTransferCooldown();