diff --git a/src/main/java/appeng/client/gui/implementations/GuiInterfaceTerminal.java b/src/main/java/appeng/client/gui/implementations/GuiInterfaceTerminal.java index 1fc29b9f3..d9f2ad6f5 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiInterfaceTerminal.java +++ b/src/main/java/appeng/client/gui/implementations/GuiInterfaceTerminal.java @@ -72,9 +72,9 @@ public class GuiInterfaceTerminal extends AEBaseGui private final HashMap byId = new HashMap<>(); private final HashMultimap byName = HashMultimap.create(); - private final HashMap blockPosHashMap = new HashMap<>(); - private final HashMap guiButtonHashMap = new HashMap<>(); - private final Map numUpgradesMap = new HashMap<>(); + private final HashMap blockPosHashMap = new HashMap<>(); + private final HashMap guiButtonHashMap = new HashMap<>(); + private final Map numUpgradesMap = new HashMap<>(); private final ArrayList names = new ArrayList<>(); private final ArrayList lines = new ArrayList<>(); private final Set matchedStacks = new HashSet<>(); @@ -87,7 +87,7 @@ public class GuiInterfaceTerminal extends AEBaseGui private PartInterfaceTerminal partInterfaceTerminal; private GuiButton guiButtonHide; private GuiButton guiButtonNextAssembler; - private HashMap dimHashMap = new HashMap<>(); + private HashMap dimHashMap = new HashMap<>(); public GuiInterfaceTerminal( final InventoryPlayer inventoryPlayer, final PartInterfaceTerminal te ) { @@ -166,9 +166,9 @@ public class GuiInterfaceTerminal extends AEBaseGui this.buttonList.add( guiButton ); int extraLines = numUpgradesMap.get( inv ); - for( int row = 0; row < 1 + extraLines && linesDraw < LINES_ON_PAGE ; ++row ) + for( int row = 0; row < 1 + extraLines && linesDraw < LINES_ON_PAGE; ++row ) { - for( int z = 0; z < 9 ; z++ ) + for( int z = 0; z < 9; z++ ) { this.inventorySlots.inventorySlots.add( new SlotDisconnected( inv, z + ( row * 9 ), ( z * 18 + 22 ), offset ) ); if( this.matchedStacks.contains( inv.getInventory().getStackInSlot( z + ( row * 9 ) ) ) ) @@ -199,8 +199,14 @@ public class GuiInterfaceTerminal extends AEBaseGui } } - if( searchFieldInputs.isMouseIn( mouseX, mouseY ) ) drawTooltip( Mouse.getEventX() * this.width / this.mc.displayWidth - offsetX, mouseY - guiTop, "Inputs OR names" ); - else if( searchFieldOutputs.isMouseIn( mouseX, mouseY ) ) drawTooltip( Mouse.getEventX() * this.width / this.mc.displayWidth - offsetX, mouseY - guiTop, "Outputs OR names" ); + if( searchFieldInputs.isMouseIn( mouseX, mouseY ) ) + { + drawTooltip( Mouse.getEventX() * this.width / this.mc.displayWidth - offsetX, mouseY - guiTop, "Inputs OR names" ); + } + else if( searchFieldOutputs.isMouseIn( mouseX, mouseY ) ) + { + drawTooltip( Mouse.getEventX() * this.width / this.mc.displayWidth - offsetX, mouseY - guiTop, "Outputs OR names" ); + } } @@ -237,9 +243,12 @@ public class GuiInterfaceTerminal extends AEBaseGui int interfaceDim = dimHashMap.get( guiButtonHashMap.get( this.selectedButton ) ); if( playerDim != interfaceDim ) { - try { + try + { mc.player.sendStatusMessage( new TextComponentString( "Interface located at dimension: " + interfaceDim + " [" + DimensionManager.getWorld( interfaceDim ).provider.getDimensionType().getName() + "] and cant be highlighted" ), false ); - } catch(Exception e){ + } + catch( Exception e ) + { mc.player.sendStatusMessage( new TextComponentString( "Interface is located in another dimension and cannot be highlighted" ), false ); } } @@ -251,25 +260,25 @@ public class GuiInterfaceTerminal extends AEBaseGui mc.player.closeScreen(); } - if (btn == guiButtonHide) + if( btn == guiButtonHide ) { partInterfaceTerminal.onlyInterfacesWithFreeSlots = !partInterfaceTerminal.onlyInterfacesWithFreeSlots; this.refreshList(); } - if (btn == guiButtonNextAssembler) + if( btn == guiButtonNextAssembler ) { // Set Search to "Molecular Assembler" and set "Only Free Interface" boolean currentOnlyInterfacesWithFreeSlots = this.partInterfaceTerminal.onlyInterfacesWithFreeSlots; String currentSearchText = this.searchFieldOutputs.getText(); this.partInterfaceTerminal.onlyInterfacesWithFreeSlots = true; - this.searchFieldOutputs.setText("Molecular Assembler"); + this.searchFieldOutputs.setText( "Molecular Assembler" ); this.refreshList(); this.partInterfaceTerminal.onlyInterfacesWithFreeSlots = currentOnlyInterfacesWithFreeSlots; - this.searchFieldOutputs.setText(currentSearchText); + this.searchFieldOutputs.setText( currentSearchText ); } } @@ -294,12 +303,13 @@ public class GuiInterfaceTerminal extends AEBaseGui for( int row = 0; row < 1 + extraLines && linesDraw < LINES_ON_PAGE; ++row ) { - this.drawTexturedModalRect( offsetX + 20, offsetY + offset , 20, 173, width, 18 ); + this.drawTexturedModalRect( offsetX + 20, offsetY + offset, 20, 173, width, 18 ); offset += 18; linesDraw++; } } - else { + else + { offset += 18; linesDraw++; } @@ -326,12 +336,12 @@ public class GuiInterfaceTerminal extends AEBaseGui return; } - if( character == ' ' && this.searchFieldOutputs.getText().isEmpty() && this.searchFieldOutputs.isFocused()) + if( character == ' ' && this.searchFieldOutputs.getText().isEmpty() && this.searchFieldOutputs.isFocused() ) { return; } - if( this.searchFieldInputs.textboxKeyTyped( character, key ) || this.searchFieldOutputs.textboxKeyTyped( character, key )) + if( this.searchFieldInputs.textboxKeyTyped( character, key ) || this.searchFieldOutputs.textboxKeyTyped( character, key ) ) { this.refreshList(); } @@ -361,9 +371,9 @@ public class GuiInterfaceTerminal extends AEBaseGui final long id = Long.parseLong( key.substring( 1 ), Character.MAX_RADIX ); final NBTTagCompound invData = in.getCompoundTag( key ); final ClientDCInternalInv current = this.getById( id, invData.getLong( "sortBy" ), invData.getString( "un" ) ); - blockPosHashMap.put( current, NBTUtil.getPosFromTag( invData.getCompoundTag( "pos" )) ); - dimHashMap.put( current, invData.getInteger( "dim" )); - numUpgradesMap.put( current, invData.getInteger("numUpgrades")); + blockPosHashMap.put( current, NBTUtil.getPosFromTag( invData.getCompoundTag( "pos" ) ) ); + dimHashMap.put( current, invData.getInteger( "dim" ) ); + numUpgradesMap.put( current, invData.getInteger( "numUpgrades" ) ); for( int x = 0; x < current.getInventory().getSlots(); x++ ) { @@ -391,7 +401,7 @@ public class GuiInterfaceTerminal extends AEBaseGui /** * Rebuilds the list of interfaces. - * + *

* Respects a search term if present (ignores case) and adding only matching patterns. */ private void refreshList() @@ -403,7 +413,7 @@ public class GuiInterfaceTerminal extends AEBaseGui final String searchFieldInputs = this.searchFieldInputs.getText().toLowerCase(); final String searchFieldOutputs = this.searchFieldOutputs.getText().toLowerCase(); - final Set cachedSearch = this.getCacheForSearchTerm( "IN:" + searchFieldInputs + " OUT:" + searchFieldOutputs + partInterfaceTerminal.onlyInterfacesWithFreeSlots); + final Set cachedSearch = this.getCacheForSearchTerm( "IN:" + searchFieldInputs + " OUT:" + searchFieldOutputs + partInterfaceTerminal.onlyInterfacesWithFreeSlots ); final boolean rebuild = cachedSearch.isEmpty(); for( final ClientDCInternalInv entry : this.byId.values() ) @@ -416,7 +426,7 @@ public class GuiInterfaceTerminal extends AEBaseGui // Shortcut to skip any filter if search term is ""/empty - boolean found = (searchFieldInputs.isEmpty() && searchFieldOutputs.isEmpty() && !partInterfaceTerminal.onlyInterfacesWithFreeSlots); + boolean found = ( searchFieldInputs.isEmpty() && searchFieldOutputs.isEmpty() && !partInterfaceTerminal.onlyInterfacesWithFreeSlots ); boolean interfaceHasFreeSlots = false; // Search if the current inventory holds a pattern containing the search term. @@ -425,42 +435,52 @@ public class GuiInterfaceTerminal extends AEBaseGui int slot = 0; for( final ItemStack itemStack : entry.getInventory() ) { - if (slot > 8 + numUpgradesMap.get(entry) * 9) { + if( slot > 8 + numUpgradesMap.get( entry ) * 9 ) + { break; } - if( !searchFieldInputs.isEmpty() && !searchFieldOutputs.isEmpty() ) { - if (this.itemStackMatchesSearchTerm(itemStack, searchFieldInputs, 0) || this.itemStackMatchesSearchTerm(itemStack, searchFieldOutputs, 1)) { + if( !searchFieldInputs.isEmpty() && !searchFieldOutputs.isEmpty() ) + { + if( this.itemStackMatchesSearchTerm( itemStack, searchFieldInputs, 0 ) || this.itemStackMatchesSearchTerm( itemStack, searchFieldOutputs, 1 ) ) + { found = true; - matchedStacks.add(itemStack); + matchedStacks.add( itemStack ); } } - else if( !searchFieldInputs.isEmpty() ) { - if (this.itemStackMatchesSearchTerm(itemStack, searchFieldInputs, 0)) { + else if( !searchFieldInputs.isEmpty() ) + { + if( this.itemStackMatchesSearchTerm( itemStack, searchFieldInputs, 0 ) ) + { found = true; - matchedStacks.add(itemStack); + matchedStacks.add( itemStack ); } } - else if( !searchFieldOutputs.isEmpty() ) { - if (this.itemStackMatchesSearchTerm(itemStack, searchFieldOutputs, 1)) { + else if( !searchFieldOutputs.isEmpty() ) + { + if( this.itemStackMatchesSearchTerm( itemStack, searchFieldOutputs, 1 ) ) + { found = true; - matchedStacks.add(itemStack); + matchedStacks.add( itemStack ); } } // If only Interfaces with empty slots should be shown, check that here - if(itemStack.isEmpty()) + if( itemStack.isEmpty() ) + { interfaceHasFreeSlots = true; + } slot++; } } // if found, filter skipped or machine name matching the search term, add it - if( found || (entry.getName().toLowerCase().contains( searchFieldInputs ) && entry.getName().toLowerCase().contains( searchFieldOutputs ))) + if( found || ( entry.getName().toLowerCase().contains( searchFieldInputs ) && entry.getName().toLowerCase().contains( searchFieldOutputs ) ) ) { - if (!partInterfaceTerminal.onlyInterfacesWithFreeSlots) + if( !partInterfaceTerminal.onlyInterfacesWithFreeSlots ) { this.byName.put( entry.getName(), entry ); cachedSearch.add( entry ); } - else if ( interfaceHasFreeSlots ){ + else if( interfaceHasFreeSlots ) + { this.byName.put( entry.getName(), entry ); cachedSearch.add( entry ); } @@ -493,7 +513,7 @@ public class GuiInterfaceTerminal extends AEBaseGui this.getScrollBar().setRange( 0, this.lines.size() - 1, 1 ); } - private boolean itemStackMatchesSearchTerm( final ItemStack itemStack, final String searchTerm,int pass ) + private boolean itemStackMatchesSearchTerm( final ItemStack itemStack, final String searchTerm, int pass ) { if( itemStack.isEmpty() ) { @@ -509,7 +529,7 @@ public class GuiInterfaceTerminal extends AEBaseGui NBTTagList tag = new NBTTagList(); - if (pass == 0) + if( pass == 0 ) { tag = encodedValue.getTagList( "in", 10 ); } @@ -518,32 +538,44 @@ public class GuiInterfaceTerminal extends AEBaseGui tag = encodedValue.getTagList( "out", 10 ); } + boolean foundMatchingItemStack = false; + for( int i = 0; i < tag.tagCount(); i++ ) { - final ItemStack parsedItemStack = new ItemStack( tag.getCompoundTagAt( i ) ); if( !parsedItemStack.isEmpty() ) { final String displayName = Platform .getItemDisplayName( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createStack( parsedItemStack ) ) .toLowerCase(); - if( displayName.contains( searchTerm ) ) + + for( String term : searchTerm.split( " " ) ) { - return true; + if( term.length() > 1 && ( term.startsWith( "-" ) || term.startsWith( "!" ) ) ) + { + term = term.substring( 1 ); + if( displayName.contains( term ) ) + { + return false; + } + } + else if( displayName.contains( term ) ) + { + foundMatchingItemStack = true; + } } } } - return false; + return foundMatchingItemStack; } /** * Tries to retrieve a cache for a with search term as keyword. - * + *

* If this cache should be empty, it will populate it with an earlier cache if available or at least the cache for * the empty string. * * @param searchTerm the corresponding search - * * @return a Set matching a superset of the search term */ private Set getCacheForSearchTerm( final String searchTerm ) diff --git a/src/main/java/appeng/client/me/ItemRepo.java b/src/main/java/appeng/client/me/ItemRepo.java index c357f2d73..c667e5c58 100644 --- a/src/main/java/appeng/client/me/ItemRepo.java +++ b/src/main/java/appeng/client/me/ItemRepo.java @@ -120,10 +120,11 @@ public class ItemRepo this.updateJEI( this.searchString ); } - this.innerSearch = this.searchString; final boolean terminalSearchToolTips = AEConfig.instance().getConfigManager().getSetting( Settings.SEARCH_TOOLTIPS ) != YesNo.NO; boolean searchMod = false; + + this.innerSearch = searchString.toLowerCase(); if( this.innerSearch.startsWith( "@" ) ) { searchMod = true; @@ -133,13 +134,13 @@ public class ItemRepo Pattern m = null; try { - m = Pattern.compile( this.innerSearch.toLowerCase(), Pattern.CASE_INSENSITIVE ); + m = Pattern.compile( this.innerSearch, Pattern.CASE_INSENSITIVE ); } catch( final Throwable ignore ) { try { - m = Pattern.compile( Pattern.quote( this.innerSearch.toLowerCase() ), Pattern.CASE_INSENSITIVE ); + m = Pattern.compile( Pattern.quote( this.innerSearch ), Pattern.CASE_INSENSITIVE ); } catch( final Throwable __ ) { @@ -168,26 +169,35 @@ public class ItemRepo continue; } - final String dspName = searchMod ? Platform.getModId( is ) : Platform.getItemDisplayName( is ); - boolean foundMatchingItemStack = false; - notDone = true; + final String dspName = ( searchMod ? Platform.getModId( is ) : Platform.getItemDisplayName( is ) ).toLowerCase(); + boolean foundMatchingItemStack = true; - if( m.matcher( dspName.toLowerCase() ).find() ) + for( String term : innerSearch.split( " " ) ) { - notDone = false; - foundMatchingItemStack = true; + if( term.length() > 1 && ( term.startsWith( "-" ) || term.startsWith( "!" ) ) ) + { + term = term.substring( 1 ); + if( dspName.contains( term ) ) + { + foundMatchingItemStack = false; + break; + } + } + else if( !dspName.contains( term ) ) + { + foundMatchingItemStack = false; + break; + } } - if( terminalSearchToolTips && notDone && !searchMod ) + if( terminalSearchToolTips && !foundMatchingItemStack ) { final List tooltip = Platform.getTooltip( is ); - for( final String line : tooltip ) { if( m.matcher( line ).find() ) { foundMatchingItemStack = true; - notDone = false; break; } } diff --git a/src/main/java/appeng/container/implementations/ContainerCondenser.java b/src/main/java/appeng/container/implementations/ContainerCondenser.java index 44c19eee9..519f2ea93 100644 --- a/src/main/java/appeng/container/implementations/ContainerCondenser.java +++ b/src/main/java/appeng/container/implementations/ContainerCondenser.java @@ -20,6 +20,8 @@ package appeng.container.implementations; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.IContainerListener; +import net.minecraft.item.ItemStack; import net.minecraftforge.items.IItemHandler; import appeng.api.config.CondenserOutput; @@ -43,6 +45,7 @@ public class ContainerCondenser extends AEBaseContainer implements IProgressProv public long storedPower = 0; @GuiSync( 2 ) public CondenserOutput output = CondenserOutput.TRASH; + private ItemStack prevStack = ItemStack.EMPTY; public ContainerCondenser( final InventoryPlayer ip, final TileCondenser condenser ) { @@ -62,6 +65,7 @@ public class ContainerCondenser extends AEBaseContainer implements IProgressProv @Override public void detectAndSendChanges() { + final ItemStack is = this.condenser.getInternalInventory().getStackInSlot( 1 ); if( Platform.isServer() ) { final double maxStorage = this.condenser.getStorage(); @@ -70,6 +74,14 @@ public class ContainerCondenser extends AEBaseContainer implements IProgressProv this.requiredEnergy = requiredEnergy == 0 ? (int) maxStorage : (int) Math.min( requiredEnergy, maxStorage ); this.storedPower = (int) this.condenser.getStoredPower(); this.setOutput( (CondenserOutput) this.condenser.getConfigManager().getSetting( Settings.CONDENSER_OUTPUT ) ); + + for( final IContainerListener listener : this.listeners ) + { + if( !ItemStack.areItemsEqual( is, prevStack ) ) + { + listener.sendSlotContents( this, 1, is ); + } + } } super.detectAndSendChanges(); diff --git a/src/main/java/appeng/tile/misc/TileCondenser.java b/src/main/java/appeng/tile/misc/TileCondenser.java index 2a0561a2c..f02fce023 100644 --- a/src/main/java/appeng/tile/misc/TileCondenser.java +++ b/src/main/java/appeng/tile/misc/TileCondenser.java @@ -125,7 +125,7 @@ public class TileCondenser extends AEBaseInvTile implements IConfigManagerHost, final double requiredPower = this.getRequiredPower(); final ItemStack output = this.getOutput(); - while( requiredPower <= this.getStoredPower() && !output.isEmpty() && requiredPower > 0 ) + while ( requiredPower <= this.getStoredPower() && !output.isEmpty() && requiredPower > 0 ) { if( this.canAddOutput( output ) ) { @@ -163,7 +163,7 @@ public class TileCondenser extends AEBaseInvTile implements IConfigManagerHost, { final IMaterials materials = AEApi.instance().definitions().materials(); - switch( (CondenserOutput) this.cm.getSetting( Settings.CONDENSER_OUTPUT ) ) + switch ( (CondenserOutput) this.cm.getSetting( Settings.CONDENSER_OUTPUT ) ) { case MATTER_BALLS: return materials.matterBall().maybeStack( 1 ).orElse( ItemStack.EMPTY ); @@ -193,6 +193,24 @@ public class TileCondenser extends AEBaseInvTile implements IConfigManagerHost, { if( inv == this.outputSlot ) { + if( !removed.isEmpty() ) + { + final double requiredPower = this.getRequiredPower(); + final ItemStack output = this.getOutput(); + while ( requiredPower <= this.getStoredPower() && !output.isEmpty() && requiredPower > 0 ) + { + if( this.canAddOutput( output ) ) + { + this.setStoredPower( this.getStoredPower() - requiredPower ); + this.addOutput( output ); + } + else + { + break; + } + removed.shrink( output.getCount() ); + } + } this.meHandler.outputChanged( added, removed ); } } @@ -296,7 +314,7 @@ public class TileCondenser extends AEBaseInvTile implements IConfigManagerHost, } } - private static final IFluidTankProperties[] EMPTY = { new FluidTankProperties( null, Fluid.BUCKET_VOLUME, true, false ) }; + private static final IFluidTankProperties[] EMPTY = {new FluidTankProperties( null, Fluid.BUCKET_VOLUME, true, false )}; /** * A fluid handler that exposes a 1 bucket tank that can only be filled, and - when filled - will add power