wip
This commit is contained in:
@@ -0,0 +1,590 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.client.gui.implementations;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import appeng.api.config.ActionItems;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.client.gui.widgets.GuiImgButton;
|
||||
import appeng.container.implementations.ContainerConfiguringTerminal;
|
||||
import appeng.core.worlddata.IWorldPlayerMapping;
|
||||
import appeng.helpers.DualityInterface;
|
||||
import appeng.parts.misc.PartInterface;
|
||||
import appeng.parts.reporting.PartConfiguringTerminal;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.misc.TileInterface;
|
||||
import appeng.util.BlockPosUtils;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.client.gui.AEBaseGui;
|
||||
import appeng.client.gui.widgets.GuiScrollbar;
|
||||
import appeng.client.gui.widgets.MEGuiTextField;
|
||||
import appeng.client.me.ClientDCInternalInv;
|
||||
import appeng.client.me.SlotDisconnected;
|
||||
import appeng.container.implementations.ContainerInterfaceTerminal;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.parts.reporting.PartInterfaceTerminal;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
|
||||
import static appeng.client.render.BlockPosHighlighter.hilightBlock;
|
||||
|
||||
|
||||
public class GuiConfiguringTerminal extends AEBaseGui
|
||||
{
|
||||
|
||||
private static final int LINES_ON_PAGE = 6;
|
||||
|
||||
// TODO: copied from GuiMEMonitorable. It looks not changed, maybe unneeded?
|
||||
private final int offsetX = 21;
|
||||
|
||||
private final HashMap<Long, ClientDCInternalInv> byId = new HashMap<>();
|
||||
private final HashMultimap<String, ClientDCInternalInv> byName = HashMultimap.create();
|
||||
private final HashMap<ClientDCInternalInv, BlockPos> blockPosHashMap = new HashMap<>();
|
||||
private final HashMap<GuiButton, ClientDCInternalInv> guiButtonHashMap = new HashMap<>();
|
||||
private final Map<ClientDCInternalInv, Integer> numUpgradesMap = new HashMap<>();
|
||||
private final ArrayList<String> names = new ArrayList<>();
|
||||
private final ArrayList<Object> lines = new ArrayList<>();
|
||||
private final Set<Object> matchedStacks = new HashSet<>();
|
||||
|
||||
private final Map<String, Set<Object>> cachedSearches = new WeakHashMap<>();
|
||||
|
||||
private boolean refreshList = false;
|
||||
private MEGuiTextField searchFieldOutputs;
|
||||
private MEGuiTextField searchFieldInputs;
|
||||
private PartConfiguringTerminal partInterfaceTerminal;
|
||||
private GuiButton guiButtonHide;
|
||||
private GuiButton guiButtonNextAssembler;
|
||||
private HashMap<ClientDCInternalInv, Integer> dimHashMap = new HashMap<>();
|
||||
|
||||
public GuiConfiguringTerminal( final InventoryPlayer inventoryPlayer, final PartConfiguringTerminal te )
|
||||
{
|
||||
super( new ContainerConfiguringTerminal( inventoryPlayer, te ) );
|
||||
|
||||
this.partInterfaceTerminal = te;
|
||||
final GuiScrollbar scrollbar = new GuiScrollbar();
|
||||
this.setScrollBar( scrollbar );
|
||||
this.xSize = 208;
|
||||
this.ySize = 255;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
super.initGui();
|
||||
|
||||
this.getScrollBar().setLeft( 189 );
|
||||
this.getScrollBar().setHeight( 106 );
|
||||
this.getScrollBar().setTop( 51 );
|
||||
|
||||
this.searchFieldInputs = new MEGuiTextField( this.fontRenderer, this.guiLeft + Math.max( 32, this.offsetX ), this.guiTop + 25, 65, 12 );
|
||||
this.searchFieldInputs.setEnableBackgroundDrawing( false );
|
||||
this.searchFieldInputs.setMaxStringLength( 25 );
|
||||
this.searchFieldInputs.setTextColor( 0xFFFFFF );
|
||||
this.searchFieldInputs.setVisible( true );
|
||||
this.searchFieldInputs.setFocused( false );
|
||||
|
||||
this.searchFieldOutputs = new MEGuiTextField( this.fontRenderer, this.guiLeft + Math.max( 32, this.offsetX ), this.guiTop + 38, 65, 12 );
|
||||
this.searchFieldOutputs.setEnableBackgroundDrawing( false );
|
||||
this.searchFieldOutputs.setMaxStringLength( 25 );
|
||||
this.searchFieldOutputs.setTextColor( 0xFFFFFF );
|
||||
this.searchFieldOutputs.setVisible( true );
|
||||
this.searchFieldOutputs.setFocused( true );
|
||||
|
||||
this.searchFieldInputs.setText( partInterfaceTerminal.in );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuiClosed()
|
||||
{
|
||||
partInterfaceTerminal.saveSearchStrings( this.searchFieldInputs.getText().toLowerCase() );
|
||||
super.onGuiClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawFG( final int offsetX, final int offsetY, final int mouseX, final int mouseY )
|
||||
{
|
||||
this.buttonList.clear();
|
||||
|
||||
this.fontRenderer.drawString( this.getGuiDisplayName( GuiText.InterfaceTerminal.getLocal() ), 8, 6, 4210752 );
|
||||
this.fontRenderer.drawString( GuiText.inventory.getLocal(), this.offsetX + 2, this.ySize - 96 + 3, 4210752 );
|
||||
|
||||
final int currentScroll = this.getScrollBar().getCurrentScroll();
|
||||
|
||||
this.inventorySlots.inventorySlots.removeIf( slot -> slot instanceof SlotDisconnected );
|
||||
|
||||
int offset = 52;
|
||||
int linesDraw = 0;
|
||||
for( int x = 0; x < LINES_ON_PAGE && linesDraw < LINES_ON_PAGE && currentScroll + x < this.lines.size(); x++ )
|
||||
{
|
||||
final Object lineObj = this.lines.get( currentScroll + x );
|
||||
if( lineObj instanceof ClientDCInternalInv )
|
||||
{
|
||||
final ClientDCInternalInv inv = (ClientDCInternalInv) lineObj;
|
||||
|
||||
GuiButton guiButton = new GuiImgButton( guiLeft + 4, guiTop + offset, Settings.ACTIONS, ActionItems.HIGHLIGHT_INTERFACE );
|
||||
guiButtonHashMap.put( guiButton, inv );
|
||||
this.buttonList.add( guiButton );
|
||||
int extraLines = numUpgradesMap.get( inv );
|
||||
|
||||
for( int row = 0; row < 1 + extraLines && linesDraw < LINES_ON_PAGE; ++row )
|
||||
{
|
||||
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 ) ) ) )
|
||||
{
|
||||
drawRect( z * 18 + 22, offset, z * 18 + 22 + 16, offset + 16, 0x2A00FF00 );
|
||||
}
|
||||
}
|
||||
linesDraw++;
|
||||
offset += 18;
|
||||
}
|
||||
}
|
||||
else if( lineObj instanceof String )
|
||||
{
|
||||
String name = (String) lineObj;
|
||||
final int rows = this.byName.get( name ).size();
|
||||
if( rows > 1 )
|
||||
{
|
||||
name = name + " (" + rows + ')';
|
||||
}
|
||||
|
||||
while ( name.length() > 2 && this.fontRenderer.getStringWidth( name ) > 155 )
|
||||
{
|
||||
name = name.substring( 0, name.length() - 1 );
|
||||
}
|
||||
this.fontRenderer.drawString( name, this.offsetX + 2, 5 + offset, 4210752 );
|
||||
linesDraw++;
|
||||
offset += 18;
|
||||
}
|
||||
}
|
||||
|
||||
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" );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked( final int xCoord, final int yCoord, final int btn ) throws IOException
|
||||
{
|
||||
this.searchFieldInputs.mouseClicked( xCoord, yCoord, btn );
|
||||
|
||||
if( btn == 1 && this.searchFieldInputs.isMouseIn( xCoord, yCoord ) )
|
||||
{
|
||||
this.searchFieldInputs.setText( "" );
|
||||
this.refreshList();
|
||||
}
|
||||
|
||||
this.searchFieldOutputs.mouseClicked( xCoord, yCoord, btn );
|
||||
|
||||
if( btn == 1 && this.searchFieldOutputs.isMouseIn( xCoord, yCoord ) )
|
||||
{
|
||||
this.searchFieldOutputs.setText( "" );
|
||||
this.refreshList();
|
||||
}
|
||||
|
||||
super.mouseClicked( xCoord, yCoord, btn );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed( final GuiButton btn ) throws IOException
|
||||
{
|
||||
if( guiButtonHashMap.containsKey( btn ) )
|
||||
{
|
||||
BlockPos blockPos = blockPosHashMap.get( guiButtonHashMap.get( this.selectedButton ) );
|
||||
BlockPos blockPos2 = mc.player.getPosition();
|
||||
int playerDim = mc.world.provider.getDimension();
|
||||
int interfaceDim = dimHashMap.get( guiButtonHashMap.get( this.selectedButton ) );
|
||||
if( playerDim != interfaceDim )
|
||||
{
|
||||
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 )
|
||||
{
|
||||
mc.player.sendStatusMessage( new TextComponentString( "Interface is located in another dimension and cannot be highlighted" ), false );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hilightBlock( blockPos, System.currentTimeMillis() + 500 * BlockPosUtils.getDistance( blockPos, blockPos2 ), playerDim );
|
||||
mc.player.sendStatusMessage( new TextComponentString( "The interface is now highlighted at " + "X: " + blockPos.getX() + " Y: " + blockPos.getY() + " Z: " + blockPos.getZ() ), false );
|
||||
}
|
||||
mc.player.closeScreen();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY )
|
||||
{
|
||||
this.bindTexture( "guis/newinterfaceterminal.png" );
|
||||
this.drawTexturedModalRect( offsetX, offsetY, 0, 0, this.xSize, this.ySize );
|
||||
|
||||
int offset = 51;
|
||||
final int ex = this.getScrollBar().getCurrentScroll();
|
||||
int linesDraw = 0;
|
||||
for( int x = 0; x < LINES_ON_PAGE && linesDraw < LINES_ON_PAGE && ex + x < this.lines.size(); x++ )
|
||||
{
|
||||
final Object lineObj = this.lines.get( ex + x );
|
||||
if( lineObj instanceof ClientDCInternalInv )
|
||||
{
|
||||
GlStateManager.color( 1, 1, 1, 1 );
|
||||
final int width = 9 * 18;
|
||||
|
||||
int extraLines = numUpgradesMap.get( lineObj );
|
||||
|
||||
for( int row = 0; row < 1 + extraLines && linesDraw < LINES_ON_PAGE; ++row )
|
||||
{
|
||||
this.drawTexturedModalRect( offsetX + 20, offsetY + offset, 20, 173, width, 18 );
|
||||
offset += 18;
|
||||
linesDraw++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
offset += 18;
|
||||
linesDraw++;
|
||||
}
|
||||
}
|
||||
|
||||
if( this.searchFieldInputs != null )
|
||||
{
|
||||
this.searchFieldInputs.drawTextBox();
|
||||
}
|
||||
|
||||
if( this.searchFieldOutputs != null )
|
||||
{
|
||||
this.searchFieldOutputs.drawTextBox();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped( final char character, final int key ) throws IOException
|
||||
{
|
||||
if( !this.checkHotbarKeys( key ) )
|
||||
{
|
||||
if( character == ' ' && this.searchFieldInputs.getText().isEmpty() && this.searchFieldInputs.isFocused() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if( character == ' ' && this.searchFieldOutputs.getText().isEmpty() && this.searchFieldOutputs.isFocused() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if( this.searchFieldInputs.textboxKeyTyped( character, key ) || this.searchFieldOutputs.textboxKeyTyped( character, key ) )
|
||||
{
|
||||
this.refreshList();
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
super.keyTyped( character, key );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void postUpdate( final NBTTagCompound in )
|
||||
{
|
||||
if( in.getBoolean( "clear" ) )
|
||||
{
|
||||
this.byId.clear();
|
||||
this.refreshList = true;
|
||||
}
|
||||
|
||||
for( final Object oKey : in.getKeySet() )
|
||||
{
|
||||
final String key = (String) oKey;
|
||||
if( key.startsWith( "=" ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
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" ) );
|
||||
|
||||
for( int x = 0; x < current.getInventory().getSlots(); x++ )
|
||||
{
|
||||
final String which = Integer.toString( x );
|
||||
if( invData.hasKey( which ) )
|
||||
{
|
||||
current.getInventory().setStackInSlot( x, new ItemStack( invData.getCompoundTag( which ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( final NumberFormatException ignored )
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( this.refreshList )
|
||||
{
|
||||
this.refreshList = false;
|
||||
// invalid caches on refresh
|
||||
this.cachedSearches.clear();
|
||||
this.refreshList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuilds the list of interfaces.
|
||||
* <p>
|
||||
* Respects a search term if present (ignores case) and adding only matching patterns.
|
||||
*/
|
||||
private void refreshList()
|
||||
{
|
||||
this.byName.clear();
|
||||
this.buttonList.clear();
|
||||
this.matchedStacks.clear();
|
||||
|
||||
final String searchFieldInputs = this.searchFieldInputs.getText().toLowerCase();
|
||||
final String searchFieldOutputs = this.searchFieldOutputs.getText().toLowerCase();
|
||||
|
||||
final Set<Object> cachedSearch = this.getCacheForSearchTerm( searchFieldInputs );
|
||||
final boolean rebuild = cachedSearch.isEmpty();
|
||||
|
||||
for( final ClientDCInternalInv entry : this.byId.values() )
|
||||
{
|
||||
// ignore inventory if not doing a full rebuild and cache already marks it as miss.
|
||||
if( !rebuild && !cachedSearch.contains( entry ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Shortcut to skip any filter if search term is ""/empty
|
||||
|
||||
boolean found = ( searchFieldInputs.isEmpty() && searchFieldOutputs.isEmpty() );
|
||||
boolean interfaceHasFreeSlots = false;
|
||||
|
||||
// Search if the current inventory holds a pattern containing the search term.
|
||||
if( !found )
|
||||
{
|
||||
int slot = 0;
|
||||
for( final ItemStack itemStack : entry.getInventory() )
|
||||
{
|
||||
if( slot > 8 + numUpgradesMap.get( entry ) * 9 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
if( !searchFieldInputs.isEmpty() && !searchFieldOutputs.isEmpty() )
|
||||
{
|
||||
if( this.itemStackMatchesSearchTerm( itemStack, searchFieldInputs, 0 ) || this.itemStackMatchesSearchTerm( itemStack, searchFieldOutputs, 1 ) )
|
||||
{
|
||||
found = true;
|
||||
matchedStacks.add( itemStack );
|
||||
}
|
||||
}
|
||||
else if( !searchFieldInputs.isEmpty() )
|
||||
{
|
||||
if( this.itemStackMatchesSearchTerm( itemStack, searchFieldInputs, 0 ) )
|
||||
{
|
||||
found = true;
|
||||
matchedStacks.add( itemStack );
|
||||
}
|
||||
}
|
||||
else if( !searchFieldOutputs.isEmpty() )
|
||||
{
|
||||
if( this.itemStackMatchesSearchTerm( itemStack, searchFieldOutputs, 1 ) )
|
||||
{
|
||||
found = true;
|
||||
matchedStacks.add( itemStack );
|
||||
}
|
||||
}
|
||||
// If only Interfaces with empty slots should be shown, check that here
|
||||
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( interfaceHasFreeSlots )
|
||||
{
|
||||
this.byName.put( entry.getName(), entry );
|
||||
cachedSearch.add( entry );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cachedSearch.remove( entry );
|
||||
}
|
||||
}
|
||||
|
||||
this.names.clear();
|
||||
this.names.addAll( this.byName.keySet() );
|
||||
|
||||
Collections.sort( this.names );
|
||||
|
||||
this.lines.clear();
|
||||
this.lines.ensureCapacity( this.getMaxRows() );
|
||||
|
||||
for( final String n : this.names )
|
||||
{
|
||||
this.lines.add( n );
|
||||
|
||||
final ArrayList<ClientDCInternalInv> clientInventories = new ArrayList<>();
|
||||
clientInventories.addAll( this.byName.get( n ) );
|
||||
|
||||
Collections.sort( clientInventories );
|
||||
this.lines.addAll( clientInventories );
|
||||
}
|
||||
|
||||
this.getScrollBar().setRange( 0, this.lines.size() - 1, 1 );
|
||||
}
|
||||
|
||||
private boolean itemStackMatchesSearchTerm( final ItemStack itemStack, final String searchTerm, int pass )
|
||||
{
|
||||
if( itemStack.isEmpty() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
final NBTTagCompound encodedValue = itemStack.getTagCompound();
|
||||
|
||||
if( encodedValue == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
NBTTagList tag = new NBTTagList();
|
||||
|
||||
if( pass == 0 )
|
||||
{
|
||||
tag = encodedValue.getTagList( "in", 10 );
|
||||
}
|
||||
else
|
||||
{
|
||||
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();
|
||||
|
||||
for( String term : searchTerm.split( " " ) )
|
||||
{
|
||||
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 foundMatchingItemStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to retrieve a cache for a with search term as keyword.
|
||||
* <p>
|
||||
* 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<Object> getCacheForSearchTerm( final String searchTerm )
|
||||
{
|
||||
if( !this.cachedSearches.containsKey( searchTerm ) )
|
||||
{
|
||||
this.cachedSearches.put( searchTerm, new HashSet<>() );
|
||||
}
|
||||
|
||||
final Set<Object> cache = this.cachedSearches.get( searchTerm );
|
||||
|
||||
if( cache.isEmpty() && searchTerm.length() > 1 )
|
||||
{
|
||||
cache.addAll( this.getCacheForSearchTerm( searchTerm.substring( 0, searchTerm.length() - 1 ) ) );
|
||||
return cache;
|
||||
}
|
||||
|
||||
return cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* The max amount of unique names and each inv row. Not affected by the filtering.
|
||||
*
|
||||
* @return max amount of unique names and each inv row
|
||||
*/
|
||||
private int getMaxRows()
|
||||
{
|
||||
return this.names.size() + this.byId.size();
|
||||
}
|
||||
|
||||
private ClientDCInternalInv getById( final long id, final long sortBy, final String string )
|
||||
{
|
||||
ClientDCInternalInv o = this.byId.get( id );
|
||||
|
||||
if( o == null )
|
||||
{
|
||||
this.byId.put( id, o = new ClientDCInternalInv( DualityInterface.NUMBER_OF_PATTERN_SLOTS, id, sortBy, string ) );
|
||||
this.refreshList = true;
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,471 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.container.implementations;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.parts.reporting.PartConfiguringTerminal;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.YesNo;
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.security.IActionHost;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketCompressedNBT;
|
||||
import appeng.helpers.DualityInterface;
|
||||
import appeng.helpers.IInterfaceHost;
|
||||
import appeng.helpers.InventoryAction;
|
||||
import appeng.items.misc.ItemEncodedPattern;
|
||||
import appeng.parts.misc.PartInterface;
|
||||
import appeng.parts.reporting.PartInterfaceTerminal;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.misc.TileInterface;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
import appeng.util.inv.AdaptorItemHandler;
|
||||
import appeng.util.inv.WrapperCursorItemHandler;
|
||||
import appeng.util.inv.WrapperFilteredItemHandler;
|
||||
import appeng.util.inv.WrapperRangeItemHandler;
|
||||
import appeng.util.inv.filter.IAEItemFilter;
|
||||
|
||||
|
||||
public final class ContainerConfiguringTerminal extends AEBaseContainer
|
||||
{
|
||||
|
||||
/**
|
||||
* this stuff is all server side..
|
||||
*/
|
||||
|
||||
private static long autoBase = Long.MIN_VALUE;
|
||||
private final Map<IInterfaceHost, ConfigTracker> diList = new HashMap<>();
|
||||
private final Map<Long, ConfigTracker> byId = new HashMap<>();
|
||||
private IGrid grid;
|
||||
private NBTTagCompound data = new NBTTagCompound();
|
||||
|
||||
public ContainerConfiguringTerminal( final InventoryPlayer ip, final PartConfiguringTerminal anchor )
|
||||
{
|
||||
super( ip, anchor );
|
||||
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
this.grid = anchor.getActionableNode().getGrid();
|
||||
}
|
||||
|
||||
this.bindPlayerInventory( ip, 14, 256 - /* height of player inventory */82 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges()
|
||||
{
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
super.detectAndSendChanges();
|
||||
|
||||
if( this.grid == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int total = 0;
|
||||
boolean missing = false;
|
||||
|
||||
final IActionHost host = this.getActionHost();
|
||||
if( host != null )
|
||||
{
|
||||
final IGridNode agn = host.getActionableNode();
|
||||
if( agn != null && agn.isActive() )
|
||||
{
|
||||
for( final IGridNode gn : this.grid.getMachines( TileInterface.class ) )
|
||||
{
|
||||
if( gn.isActive() )
|
||||
{
|
||||
final IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
|
||||
if( ih.getInterfaceDuality().getConfigManager().getSetting( Settings.INTERFACE_TERMINAL ) == YesNo.NO )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
final ConfigTracker t = this.diList.get( ih );
|
||||
|
||||
if( t == null )
|
||||
{
|
||||
missing = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
final DualityInterface dual = ih.getInterfaceDuality();
|
||||
if( !t.unlocalizedName.equals( dual.getTermName() ) )
|
||||
{
|
||||
missing = true;
|
||||
}
|
||||
}
|
||||
|
||||
total++;
|
||||
}
|
||||
}
|
||||
|
||||
for( final IGridNode gn : this.grid.getMachines( PartInterface.class ) )
|
||||
{
|
||||
if( gn.isActive() )
|
||||
{
|
||||
final IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
|
||||
if( ih.getInterfaceDuality().getConfigManager().getSetting( Settings.INTERFACE_TERMINAL ) == YesNo.NO )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
final ConfigTracker t = this.diList.get( ih );
|
||||
|
||||
if( t == null )
|
||||
{
|
||||
missing = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
final DualityInterface dual = ih.getInterfaceDuality();
|
||||
if( !t.unlocalizedName.equals( dual.getTermName() ) )
|
||||
{
|
||||
missing = true;
|
||||
}
|
||||
}
|
||||
|
||||
total++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( total != this.diList.size() || missing )
|
||||
{
|
||||
this.regenList( this.data );
|
||||
}
|
||||
else
|
||||
{
|
||||
for( final Entry<IInterfaceHost, ConfigTracker> en : this.diList.entrySet() )
|
||||
{
|
||||
final ConfigTracker inv = en.getValue();
|
||||
for( int x = 0; x < inv.server.getSlots(); x++ )
|
||||
{
|
||||
if( this.isDifferent( inv.server.getStackInSlot( x ), inv.client.getStackInSlot( x ) ) )
|
||||
{
|
||||
this.addItems( this.data, inv, x, 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !this.data.hasNoTags() )
|
||||
{
|
||||
try
|
||||
{
|
||||
NetworkHandler.instance().sendTo( new PacketCompressedNBT( this.data ), (EntityPlayerMP) this.getPlayerInv().player );
|
||||
}
|
||||
catch( final IOException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
this.data = new NBTTagCompound();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAction( final EntityPlayerMP player, final InventoryAction action, final int slot, final long id )
|
||||
{
|
||||
final ConfigTracker inv = this.byId.get( id );
|
||||
if( inv != null )
|
||||
{
|
||||
final ItemStack is = inv.server.getStackInSlot( slot );
|
||||
final boolean hasItemInHand = !player.inventory.getItemStack().isEmpty();
|
||||
|
||||
final InventoryAdaptor playerHand = new AdaptorItemHandler( new WrapperCursorItemHandler( player.inventory ) );
|
||||
|
||||
final IItemHandler theSlot = new WrapperFilteredItemHandler( new WrapperRangeItemHandler( inv.server, slot, slot + 1 ), new PatternSlotFilter() );
|
||||
final InventoryAdaptor interfaceSlot = new AdaptorItemHandler( theSlot );
|
||||
|
||||
IItemHandler interfaceHandler = inv.server;
|
||||
boolean canInsert = true;
|
||||
|
||||
switch ( action )
|
||||
{
|
||||
case PICKUP_OR_SET_DOWN:
|
||||
if( hasItemInHand )
|
||||
{
|
||||
for( int s = 0; s < interfaceHandler.getSlots(); s++ )
|
||||
{
|
||||
if( Platform.itemComparisons().isSameItem( interfaceHandler.getStackInSlot( s ), player.inventory.getItemStack() ) )
|
||||
{
|
||||
canInsert = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( canInsert )
|
||||
{
|
||||
ItemStack inSlot = theSlot.getStackInSlot( 0 );
|
||||
if( inSlot.isEmpty() )
|
||||
{
|
||||
player.inventory.setItemStack( interfaceSlot.addItems( player.inventory.getItemStack() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
inSlot = inSlot.copy();
|
||||
final ItemStack inHand = player.inventory.getItemStack().copy();
|
||||
|
||||
ItemHandlerUtil.setStackInSlot( theSlot, 0, ItemStack.EMPTY );
|
||||
player.inventory.setItemStack( ItemStack.EMPTY );
|
||||
|
||||
player.inventory.setItemStack( interfaceSlot.addItems( inHand.copy() ) );
|
||||
|
||||
if( player.inventory.getItemStack().isEmpty() )
|
||||
{
|
||||
player.inventory.setItemStack( inSlot );
|
||||
}
|
||||
else
|
||||
{
|
||||
player.inventory.setItemStack( inHand );
|
||||
ItemHandlerUtil.setStackInSlot( theSlot, 0, inSlot );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemHandlerUtil.setStackInSlot( theSlot, 0, playerHand.addItems( theSlot.getStackInSlot( 0 ) ) );
|
||||
}
|
||||
|
||||
break;
|
||||
case SPLIT_OR_PLACE_SINGLE:
|
||||
if( hasItemInHand )
|
||||
{
|
||||
for( int s = 0; s < interfaceHandler.getSlots(); s++ )
|
||||
{
|
||||
if( Platform.itemComparisons().isSameItem( interfaceHandler.getStackInSlot( s ), player.inventory.getItemStack() ) )
|
||||
{
|
||||
canInsert = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( canInsert )
|
||||
{
|
||||
ItemStack extra = playerHand.removeItems( 1, ItemStack.EMPTY, null );
|
||||
if( !extra.isEmpty() && !interfaceSlot.containsItems() )
|
||||
{
|
||||
extra = interfaceSlot.addItems( extra );
|
||||
}
|
||||
if( !extra.isEmpty() )
|
||||
{
|
||||
playerHand.addItems( extra );
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( !is.isEmpty() )
|
||||
{
|
||||
ItemStack extra = interfaceSlot.removeItems( ( is.getCount() + 1 ) / 2, ItemStack.EMPTY, null );
|
||||
if( !extra.isEmpty() )
|
||||
{
|
||||
extra = playerHand.addItems( extra );
|
||||
}
|
||||
if( !extra.isEmpty() )
|
||||
{
|
||||
interfaceSlot.addItems( extra );
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case SHIFT_CLICK:
|
||||
|
||||
final InventoryAdaptor playerInv = InventoryAdaptor.getAdaptor( player );
|
||||
|
||||
ItemHandlerUtil.setStackInSlot( theSlot, 0, playerInv.addItems( theSlot.getStackInSlot( 0 ) ) );
|
||||
|
||||
break;
|
||||
case MOVE_REGION:
|
||||
|
||||
final InventoryAdaptor playerInvAd = InventoryAdaptor.getAdaptor( player );
|
||||
for( int x = 0; x < inv.server.getSlots(); x++ )
|
||||
{
|
||||
ItemHandlerUtil.setStackInSlot( inv.server, x, playerInvAd.addItems( inv.server.getStackInSlot( x ) ) );
|
||||
}
|
||||
|
||||
break;
|
||||
case CREATIVE_DUPLICATE:
|
||||
|
||||
if( player.capabilities.isCreativeMode && !hasItemInHand )
|
||||
{
|
||||
player.inventory.setItemStack( is.isEmpty() ? ItemStack.EMPTY : is.copy() );
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
this.updateHeld( player );
|
||||
}
|
||||
}
|
||||
|
||||
private void regenList( final NBTTagCompound data )
|
||||
{
|
||||
this.byId.clear();
|
||||
this.diList.clear();
|
||||
|
||||
final IActionHost host = this.getActionHost();
|
||||
if( host != null )
|
||||
{
|
||||
final IGridNode agn = host.getActionableNode();
|
||||
if( agn != null && agn.isActive() )
|
||||
{
|
||||
for( final IGridNode gn : this.grid.getMachines( TileInterface.class ) )
|
||||
{
|
||||
final IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
|
||||
final DualityInterface dual = ih.getInterfaceDuality();
|
||||
if( gn.isActive() && dual.getConfigManager().getSetting( Settings.INTERFACE_TERMINAL ) == YesNo.YES )
|
||||
{
|
||||
this.diList.put( ih, new ConfigTracker( dual, dual.getPatterns(), dual.getTermName() ) );
|
||||
}
|
||||
}
|
||||
|
||||
for( final IGridNode gn : this.grid.getMachines( PartInterface.class ) )
|
||||
{
|
||||
final IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
|
||||
final DualityInterface dual = ih.getInterfaceDuality();
|
||||
if( gn.isActive() && dual.getConfigManager().getSetting( Settings.INTERFACE_TERMINAL ) == YesNo.YES )
|
||||
{
|
||||
this.diList.put( ih, new ConfigTracker( dual, dual.getPatterns(), dual.getTermName() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data.setBoolean( "clear", true );
|
||||
|
||||
for( final Entry<IInterfaceHost, ConfigTracker> en : this.diList.entrySet() )
|
||||
{
|
||||
final ConfigTracker inv = en.getValue();
|
||||
this.byId.put( inv.which, inv );
|
||||
this.addItems( data, inv, 0, inv.server.getSlots() );
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isDifferent( final ItemStack a, final ItemStack b )
|
||||
{
|
||||
if( a.isEmpty() && b.isEmpty() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if( a.isEmpty() || b.isEmpty() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return !ItemStack.areItemStacksEqual( a, b );
|
||||
}
|
||||
|
||||
private void addItems( final NBTTagCompound data, final ConfigTracker inv, final int offset, final int length )
|
||||
{
|
||||
final String name = '=' + Long.toString( inv.which, Character.MAX_RADIX );
|
||||
final NBTTagCompound tag = data.getCompoundTag( name );
|
||||
|
||||
if( tag.hasNoTags() )
|
||||
{
|
||||
tag.setLong( "sortBy", inv.sortBy );
|
||||
tag.setString( "un", inv.unlocalizedName );
|
||||
tag.setTag( "pos", NBTUtil.createPosTag( inv.pos ) );
|
||||
tag.setInteger( "dim", inv.dim );
|
||||
tag.setInteger( "numUpgrades", inv.numUpgrades );
|
||||
}
|
||||
|
||||
for( int x = 0; x < length; x++ )
|
||||
{
|
||||
final NBTTagCompound itemNBT = new NBTTagCompound();
|
||||
|
||||
final ItemStack is = inv.server.getStackInSlot( x + offset );
|
||||
|
||||
// "update" client side.
|
||||
ItemHandlerUtil.setStackInSlot( inv.client, x + offset, is.isEmpty() ? ItemStack.EMPTY : is.copy() );
|
||||
|
||||
if( !is.isEmpty() )
|
||||
{
|
||||
is.writeToNBT( itemNBT );
|
||||
}
|
||||
|
||||
tag.setTag( Integer.toString( x + offset ), itemNBT );
|
||||
}
|
||||
|
||||
data.setTag( name, tag );
|
||||
}
|
||||
|
||||
private static class ConfigTracker
|
||||
{
|
||||
|
||||
private final long sortBy;
|
||||
private final long which = autoBase++;
|
||||
private final String unlocalizedName;
|
||||
private final IItemHandler client;
|
||||
private final IItemHandler server;
|
||||
private final BlockPos pos;
|
||||
private final int dim;
|
||||
private final int numUpgrades;
|
||||
|
||||
public ConfigTracker( final DualityInterface dual, final IItemHandler patterns, final String unlocalizedName )
|
||||
{
|
||||
this.server = patterns;
|
||||
this.client = new AppEngInternalInventory( null, this.server.getSlots() );
|
||||
this.unlocalizedName = unlocalizedName;
|
||||
this.sortBy = dual.getSortValue();
|
||||
this.pos = dual.getLocation().getPos();
|
||||
this.dim = dual.getLocation().getWorld().provider.getDimension();
|
||||
this.numUpgrades = dual.getInstalledUpgrades( Upgrades.PATTERN_EXPANSION );
|
||||
}
|
||||
}
|
||||
|
||||
private static class PatternSlotFilter implements IAEItemFilter
|
||||
{
|
||||
@Override
|
||||
public boolean allowExtract( IItemHandler inv, int slot, int amount )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowInsert( IItemHandler inv, int slot, ItemStack stack )
|
||||
{
|
||||
return !stack.isEmpty() && stack.getItem() instanceof ItemEncodedPattern;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,6 +80,7 @@ public final class ApiParts implements IParts
|
||||
private final IItemDefinition interfaceTerminal;
|
||||
private final IItemDefinition patternTerminal;
|
||||
private final IItemDefinition expandedProcessingPatternTerminal;
|
||||
private final IItemDefinition configuringInterfaceTerminal;
|
||||
private final IItemDefinition craftingTerminal;
|
||||
private final IItemDefinition terminal;
|
||||
private final IItemDefinition storageMonitor;
|
||||
@@ -142,6 +143,7 @@ public final class ApiParts implements IParts
|
||||
this.interfaceTerminal = new DamagedItemDefinition( "part.terminal.interface", itemPart.createPart( PartType.INTERFACE_TERMINAL ) );
|
||||
this.patternTerminal = new DamagedItemDefinition( "part.terminal.pattern", itemPart.createPart( PartType.PATTERN_TERMINAL ) );
|
||||
this.expandedProcessingPatternTerminal = new DamagedItemDefinition( "part.terminal.expanded_processing_pattern", itemPart.createPart( PartType.EXPANDED_PROCESSING_PATTERN_TERMINAL ) );
|
||||
this.configuringInterfaceTerminal = new DamagedItemDefinition( "part.terminal.configuring_interface_terminal", itemPart.createPart( PartType.CONFIGURING_INTERFACE_TERMINAL ) );
|
||||
this.craftingTerminal = new DamagedItemDefinition( "part.terminal.crafting", itemPart.createPart( PartType.CRAFTING_TERMINAL ) );
|
||||
this.terminal = new DamagedItemDefinition( "part.terminal", itemPart.createPart( PartType.TERMINAL ) );
|
||||
this.storageMonitor = new DamagedItemDefinition( "part.monitor.storage", itemPart.createPart( PartType.STORAGE_MONITOR ) );
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.lang.reflect.Constructor;
|
||||
|
||||
import appeng.container.implementations.*;
|
||||
import appeng.parts.misc.PartOreDicStorageBus;
|
||||
import appeng.parts.reporting.PartExpandedProcessingPatternTerminal;
|
||||
import appeng.parts.reporting.*;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -74,9 +74,6 @@ import appeng.items.contents.QuartzKnifeObj;
|
||||
import appeng.parts.automation.PartFormationPlane;
|
||||
import appeng.parts.automation.PartLevelEmitter;
|
||||
import appeng.parts.misc.PartStorageBus;
|
||||
import appeng.parts.reporting.PartCraftingTerminal;
|
||||
import appeng.parts.reporting.PartInterfaceTerminal;
|
||||
import appeng.parts.reporting.PartPatternTerminal;
|
||||
import appeng.tile.crafting.TileCraftingTile;
|
||||
import appeng.tile.crafting.TileMolecularAssembler;
|
||||
import appeng.tile.grindstone.TileGrinder;
|
||||
@@ -180,7 +177,9 @@ public enum GuiBridge implements IGuiHandler
|
||||
|
||||
GUI_INTERFACE_TERMINAL( ContainerInterfaceTerminal.class, PartInterfaceTerminal.class, GuiHostType.WORLD, SecurityPermissions.BUILD ),
|
||||
|
||||
GUI_CRAFTING_STATUS( ContainerCraftingStatus.class, ITerminalHost.class, GuiHostType.ITEM_OR_WORLD, SecurityPermissions.CRAFT );
|
||||
GUI_CRAFTING_STATUS( ContainerCraftingStatus.class, ITerminalHost.class, GuiHostType.ITEM_OR_WORLD, SecurityPermissions.CRAFT ),
|
||||
|
||||
GUI_CONFIG_INTERFACE_TERMINAL( ContainerConfiguringTerminal.class, PartConfiguringTerminal.class, GuiHostType.WORLD, SecurityPermissions.BUILD );
|
||||
|
||||
private final Class tileClass;
|
||||
private final Class containerClass;
|
||||
@@ -343,7 +342,7 @@ public enum GuiBridge implements IGuiHandler
|
||||
if( target == null )
|
||||
{
|
||||
throw new IllegalStateException( "Cannot find " + this.containerClass.getName() + "( " + this.typeName( inventory ) + ", " + this
|
||||
.typeName( tE ) + " )" );
|
||||
.typeName( tE ) + " )" );
|
||||
}
|
||||
|
||||
return target.newInstance( inventory, tE );
|
||||
@@ -441,7 +440,7 @@ public enum GuiBridge implements IGuiHandler
|
||||
if( target == null )
|
||||
{
|
||||
throw new IllegalStateException( "Cannot find " + this.containerClass.getName() + "( " + this.typeName( inventory ) + ", " + this
|
||||
.typeName( tE ) + " )" );
|
||||
.typeName( tE ) + " )" );
|
||||
}
|
||||
|
||||
return target.newInstance( inventory, tE );
|
||||
|
||||
@@ -284,7 +284,8 @@ public enum PartType
|
||||
|
||||
INTERFACE_TERMINAL( 480, "interface_terminal", EnumSet.of( AEFeature.INTERFACE_TERMINAL ), EnumSet.noneOf( IntegrationType.class ), PartInterfaceTerminal.class ),
|
||||
|
||||
FLUID_TERMINAL( 520, "fluid_terminal", EnumSet.of( AEFeature.FLUID_TERMINAL ), EnumSet.noneOf( IntegrationType.class ), PartFluidTerminal.class );
|
||||
FLUID_TERMINAL( 520, "fluid_terminal", EnumSet.of( AEFeature.FLUID_TERMINAL ), EnumSet.noneOf( IntegrationType.class ), PartFluidTerminal.class ),
|
||||
CONFIGURING_INTERFACE_TERMINAL( 521, "configuring_interface_terminal", EnumSet.of( AEFeature.INTERFACE_TERMINAL ), EnumSet.noneOf( IntegrationType.class ), PartConfiguringTerminal.class );
|
||||
|
||||
private final int baseDamage;
|
||||
private final Set<AEFeature> features;
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.parts.reporting;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.parts.PartModel;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
public class PartConfiguringTerminal extends AbstractPartDisplay
|
||||
{
|
||||
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_OFF = new ResourceLocation( AppEng.MOD_ID, "part/interface_terminal_off" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_ON = new ResourceLocation( AppEng.MOD_ID, "part/interface_terminal_on" );
|
||||
|
||||
public static final IPartModel MODELS_OFF = new PartModel( MODEL_BASE, MODEL_OFF, MODEL_STATUS_OFF );
|
||||
public static final IPartModel MODELS_ON = new PartModel( MODEL_BASE, MODEL_ON, MODEL_STATUS_ON );
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, MODEL_ON, MODEL_STATUS_HAS_CHANNEL );
|
||||
public String in = "";
|
||||
|
||||
public PartConfiguringTerminal( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos )
|
||||
{
|
||||
if( !super.onPartActivate( player, hand, pos ) )
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_CONFIG_INTERFACE_TERMINAL );
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
return this.selectModel( MODELS_OFF, MODELS_ON, MODELS_HAS_CHANNEL );
|
||||
}
|
||||
|
||||
public void saveSearchStrings( String in )
|
||||
{
|
||||
this.in = in;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user