cache oredict filter list

This commit is contained in:
PrototypeTrousers
2022-01-03 10:47:35 -03:00
parent 9eef9d3840
commit 41796449ed
5 changed files with 38 additions and 10 deletions
@@ -1,12 +1,16 @@
package appeng.client.gui.implementations;
import appeng.client.gui.AEBaseGui;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.client.gui.widgets.MEGuiTextField;
import appeng.container.implementations.ContainerPartOreDictStorageBus;
import appeng.core.localization.GuiText;
import appeng.core.sync.GuiBridge;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketSwitchGuis;
import appeng.core.sync.packets.PacketValueConfig;
import appeng.parts.misc.PartOreDicStorageBus;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import java.io.IOException;
@@ -16,8 +20,9 @@ import java.util.regex.Pattern;
public class GuiPartOreDictStorageBus extends AEBaseGui
{
PartOreDicStorageBus part;
private GuiTabButton priority;
private static final Pattern ORE_DICTIONARY_FILTER = Pattern.compile( "\\*?[a-zA-Z0-9_]*\\*?" );
private static final Pattern ORE_DICTIONARY_FILTER = Pattern.compile( "\\*?[a-zA-Z0-9_|\\\\+(){,}?!=\\-\\[:\\]&^$]*\\*?" );
private MEGuiTextField searchFieldInputs;
public GuiPartOreDictStorageBus( final InventoryPlayer inventoryPlayer, final PartOreDicStorageBus te )
@@ -32,7 +37,7 @@ public class GuiPartOreDictStorageBus extends AEBaseGui
{
super.initGui();
this.searchFieldInputs = new MEGuiTextField( this.fontRenderer, this.guiLeft + 3, this.guiTop + 18, 170, 36 );
this.searchFieldInputs = new MEGuiTextField( this.fontRenderer, this.guiLeft + 3, this.guiTop + 22, 170, 12 );
this.searchFieldInputs.setEnableBackgroundDrawing( false );
this.searchFieldInputs.setMaxStringLength( 512 );
this.searchFieldInputs.setTextColor( 0xFFFFFF );
@@ -40,6 +45,8 @@ public class GuiPartOreDictStorageBus extends AEBaseGui
this.searchFieldInputs.setFocused( false );
this.searchFieldInputs.setValidator( str -> ORE_DICTIONARY_FILTER.matcher( str ).matches() );
this.buttonList.add( this.priority = new GuiTabButton( this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRender ) );
try
{
NetworkHandler.instance().sendToServer( new PacketValueConfig( "OreDictStorageBus.getRegex", "1" ) );
@@ -56,6 +63,16 @@ public class GuiPartOreDictStorageBus extends AEBaseGui
this.searchFieldInputs.setText( regex );
}
@Override
protected void actionPerformed( final GuiButton btn ) throws IOException
{
super.actionPerformed( btn );
if( btn == this.priority )
{
NetworkHandler.instance().sendToServer( new PacketSwitchGuis( GuiBridge.GUI_PRIORITY ) );
}
}
@Override
protected void mouseClicked( final int xCoord, final int yCoord, final int btn ) throws IOException
{
@@ -90,15 +107,15 @@ public class GuiPartOreDictStorageBus extends AEBaseGui
@Override
public void drawFG( int offsetX, int offsetY, int mouseX, int mouseY )
{
this.fontRenderer.drawString( this.getGuiDisplayName( GuiText.StorageBus.getLocal() ), 8, 6, 4210752 );
this.fontRenderer.drawString( this.getGuiDisplayName( GuiText.OreDictStorageBus.getLocal() ), 8, 6, 4210752 );
this.fontRenderer.drawString( this.searchFieldInputs.getText().length() + " / " + this.searchFieldInputs.getMaxStringLength(), 8, 36, 4210752 );
this.fontRenderer.drawSplitString( "Supports regex. Or use * as a wildcard", 6, 48, 174, 4210752 );
}
@Override
public void drawBG( int offsetX, int offsetY, int mouseX, int mouseY )
{
this.bindTexture( "guis/oredictstoragebus.png" );
this.drawTexturedModalRect( offsetX, offsetY, 0, 0, 175, 85 );
if( this.searchFieldInputs != null )
@@ -38,7 +38,6 @@ public class ContainerPartOreDictStorageBus extends AEBaseContainer
public void saveOreMatch( String value )
{
part.saveOreMatch( value );
part.upgradesChanged();
}
public void sendRegex()
@@ -70,6 +70,7 @@ public enum GuiText
EnergyDrain,
StorageBus,
OreDictStorageBus,
StorageBusFluids,
Priority,
Security,
@@ -27,7 +27,8 @@ import net.minecraft.util.math.Vec3d;
public class PartOreDicStorageBus extends PartStorageBus
{
public String oreMatch = "";
public String oreMatch;
OreDictPriorityList<IAEItemStack> priorityList;
public PartOreDicStorageBus( ItemStack is )
{
@@ -96,7 +97,7 @@ public class PartOreDicStorageBus extends PartStorageBus
this.handler.setWhitelist( this.getInstalledUpgrades( Upgrades.INVERTER ) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST );
this.handler.setPriority( this.priority );
this.handler.setPartitionList( new OreDictPriorityList<>( OreHelper.INSTANCE.getMatchingOre( oreMatch ), oreMatch ) );
this.handler.setPartitionList( priorityList );
if( inv instanceof IBaseMonitor )
{
@@ -153,8 +154,16 @@ public class PartOreDicStorageBus extends PartStorageBus
public void saveOreMatch( String oreMatch )
{
this.oreMatch = oreMatch;
this.getHost().markForSave();
if( !this.oreMatch.equals( oreMatch ) )
{
this.oreMatch = oreMatch;
this.priorityList = new OreDictPriorityList<>( OreHelper.INSTANCE.getMatchingOre( oreMatch ), oreMatch );
if( this.handler != null )
{
handler.setPartitionList( this.priorityList );
}
this.getHost().markForSave();
}
}
@Override
@@ -162,6 +171,7 @@ public class PartOreDicStorageBus extends PartStorageBus
{
super.readFromNBT( data );
this.oreMatch = data.getString( "oreMatch" );
this.priorityList = new OreDictPriorityList<>( OreHelper.INSTANCE.getMatchingOre( oreMatch ), oreMatch );
}
@Override