forked from BRNSystems/RegexingHoppers
Fix cooldowns
This commit is contained in:
parent
d1f812ed8b
commit
67c25b8477
@ -1,10 +1,12 @@
|
|||||||
package systems.brn.regexinghoppers;
|
package systems.brn.regexinghoppers;
|
||||||
|
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
|
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 org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import systems.brn.regexinghoppers.mixin.HopperBlockEntityAccessor;
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@ -37,6 +39,12 @@ public class RegexingHoppers implements ModInitializer {
|
|||||||
LOGGER.info("Custom regex pattern from hopper: {}", customName);
|
LOGGER.info("Custom regex pattern from hopper: {}", customName);
|
||||||
|
|
||||||
if (customName != null && !customName.isEmpty()) {
|
if (customName != null && !customName.isEmpty()) {
|
||||||
|
if (hopper instanceof HopperBlockEntity) {
|
||||||
|
HopperBlockEntityAccessor hopperAccessor = (HopperBlockEntityAccessor) hopper;
|
||||||
|
if (hopperAccessor.getTransferCooldown() > 1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
Pattern pattern = Pattern.compile(customName);
|
Pattern pattern = Pattern.compile(customName);
|
||||||
Matcher matcher = pattern.matcher(itemName);
|
Matcher matcher = pattern.matcher(itemName);
|
||||||
@ -45,6 +53,12 @@ public class RegexingHoppers implements ModInitializer {
|
|||||||
boolean matches = matcher.matches();
|
boolean matches = matcher.matches();
|
||||||
LOGGER.info("Regex matching result: {}", matches);
|
LOGGER.info("Regex matching result: {}", matches);
|
||||||
|
|
||||||
|
if (!matches) {
|
||||||
|
if (hopper instanceof HopperBlockEntity) {
|
||||||
|
HopperBlockEntityAccessor hopperAccessor = (HopperBlockEntityAccessor) hopper;
|
||||||
|
hopperAccessor.setTransferCooldown(8);
|
||||||
|
}
|
||||||
|
}
|
||||||
return !matches;
|
return !matches;
|
||||||
} catch (PatternSyntaxException e) {
|
} catch (PatternSyntaxException e) {
|
||||||
// Log exception if regex pattern is invalid
|
// 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;
|
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||||
|
|
||||||
@Mixin(HopperBlockEntity.class)
|
@Mixin(HopperBlockEntity.class)
|
||||||
interface HopperBlockEntityAccessor {
|
public interface HopperBlockEntityAccessor {
|
||||||
@Accessor("transferCooldown")
|
@Accessor("transferCooldown")
|
||||||
int getTransferCooldown();
|
int getTransferCooldown();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user