Make grid search history static and remove network from grid interface
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package com.raoulvdberge.refinedstorage.api.network.grid;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IFluidGridHandler;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IItemGridHandler;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageCache;
|
||||
@@ -51,45 +50,27 @@ public interface IGrid {
|
||||
GridType getType();
|
||||
|
||||
/**
|
||||
* @return the network of this grid, or null if the network is unavailable
|
||||
*/
|
||||
@Nullable
|
||||
INetwork getNetwork();
|
||||
|
||||
/**
|
||||
* @return a listener for this grid
|
||||
* @return a listener for this grid, will be attached to the storage cache in {@link #getStorageCache()}
|
||||
*/
|
||||
IStorageCacheListener createListener(EntityPlayerMP player);
|
||||
|
||||
/**
|
||||
* @return the storage cache for this grid
|
||||
* @return the storage cache for this grid, or null if this grid is unavailable
|
||||
*/
|
||||
@Nullable
|
||||
default IStorageCache getStorageCache() {
|
||||
INetwork network = getNetwork();
|
||||
|
||||
if (network == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return getType() == GridType.FLUID ? network.getFluidStorageCache() : network.getItemStorageCache();
|
||||
}
|
||||
IStorageCache getStorageCache();
|
||||
|
||||
/**
|
||||
* @return the item grid handler of the network of the grid, or null if the network is unavailable
|
||||
* @return the item grid handler, or null if there is no handler available
|
||||
*/
|
||||
@Nullable
|
||||
default IItemGridHandler getItemHandler() {
|
||||
return getNetwork() != null ? getNetwork().getItemGridHandler() : null;
|
||||
}
|
||||
IItemGridHandler getItemHandler();
|
||||
|
||||
/**
|
||||
* @return the fluid grid handler of the network of the grid, or null if the network is unavailable
|
||||
* @return the fluid grid handler, or null if there is no handler available
|
||||
*/
|
||||
@Nullable
|
||||
default IFluidGridHandler getFluidHandler() {
|
||||
return getNetwork() != null ? getNetwork().getFluidGridHandler() : null;
|
||||
}
|
||||
IFluidGridHandler getFluidHandler();
|
||||
|
||||
/**
|
||||
* @return an unlocalized gui title
|
||||
|
@@ -0,0 +1,16 @@
|
||||
package com.raoulvdberge.refinedstorage.api.network.grid;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* A grid that knows about a network.
|
||||
*/
|
||||
public interface IGridNetworkAware extends IGrid {
|
||||
/**
|
||||
* @return the network, or null if no network is available
|
||||
*/
|
||||
@Nullable
|
||||
INetwork getNetwork();
|
||||
}
|
@@ -6,14 +6,19 @@ import com.raoulvdberge.refinedstorage.RSItems;
|
||||
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.GridType;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGridNetworkAware;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGridTab;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IFluidGridHandler;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IItemGridHandler;
|
||||
import com.raoulvdberge.refinedstorage.api.network.item.INetworkItem;
|
||||
import com.raoulvdberge.refinedstorage.api.network.item.NetworkItemAction;
|
||||
import com.raoulvdberge.refinedstorage.api.network.security.Permission;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageCache;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageCacheListener;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IFilter;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageCacheListenerGridFluid;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageCacheListenerGridItem;
|
||||
import com.raoulvdberge.refinedstorage.block.BlockGrid;
|
||||
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase;
|
||||
@@ -41,10 +46,11 @@ import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import net.minecraftforge.items.wrapper.CombinedInvWrapper;
|
||||
import net.minecraftforge.items.wrapper.InvWrapper;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class NetworkNodeGrid extends NetworkNode implements IGrid {
|
||||
public class NetworkNodeGrid extends NetworkNode implements IGridNetworkAware {
|
||||
public static final String ID = "grid";
|
||||
|
||||
public static final String NBT_VIEW_TYPE = "ViewType";
|
||||
@@ -192,7 +198,25 @@ public class NetworkNodeGrid extends NetworkNode implements IGrid {
|
||||
|
||||
@Override
|
||||
public IStorageCacheListener createListener(EntityPlayerMP player) {
|
||||
return new StorageCacheListenerGridItem(player, network);
|
||||
return getType() == GridType.FLUID ? new StorageCacheListenerGridFluid(player, network) : new StorageCacheListenerGridItem(player, network);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IStorageCache getStorageCache() {
|
||||
return network != null ? (getType() == GridType.FLUID ? network.getFluidStorageCache() : network.getItemStorageCache()) : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IItemGridHandler getItemHandler() {
|
||||
return network != null ? network.getItemGridHandler() : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IFluidGridHandler getFluidHandler() {
|
||||
return network != null ? network.getFluidGridHandler() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -264,7 +288,7 @@ public class NetworkNodeGrid extends NetworkNode implements IGrid {
|
||||
onRecipeTransfer(this, player, recipe);
|
||||
}
|
||||
|
||||
public static void onRecipeTransfer(IGrid grid, EntityPlayer player, ItemStack[][] recipe) {
|
||||
public static void onRecipeTransfer(IGridNetworkAware grid, EntityPlayer player, ItemStack[][] recipe) {
|
||||
INetwork network = grid.getNetwork();
|
||||
|
||||
if (network != null && grid.getType() == GridType.CRAFTING && !network.getSecurityManager().hasPermission(Permission.EXTRACT, player)) {
|
||||
@@ -369,7 +393,7 @@ public class NetworkNodeGrid extends NetworkNode implements IGrid {
|
||||
onCrafted(this, world, player);
|
||||
}
|
||||
|
||||
public static void onCrafted(IGrid grid, World world, EntityPlayer player) {
|
||||
public static void onCrafted(IGridNetworkAware grid, World world, EntityPlayer player) {
|
||||
NonNullList<ItemStack> remainder = CraftingManager.getRemainingItems(grid.getCraftingMatrix(), world);
|
||||
|
||||
INetwork network = grid.getNetwork();
|
||||
@@ -419,7 +443,7 @@ public class NetworkNodeGrid extends NetworkNode implements IGrid {
|
||||
onCraftedShift(this, player);
|
||||
}
|
||||
|
||||
public static void onCraftedShift(IGrid grid, EntityPlayer player) {
|
||||
public static void onCraftedShift(IGridNetworkAware grid, EntityPlayer player) {
|
||||
List<ItemStack> craftedItemsList = new ArrayList<>();
|
||||
int craftedItems = 0;
|
||||
ItemStack crafted = grid.getCraftingResult().getStackInSlot(0);
|
||||
|
@@ -52,6 +52,8 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class GuiGrid extends GuiBase implements IGridDisplay {
|
||||
private static final List<String> SEARCH_HISTORY = new ArrayList<>();
|
||||
|
||||
private IGridView view;
|
||||
|
||||
private GuiTextField searchField;
|
||||
@@ -70,7 +72,6 @@ public class GuiGrid extends GuiBase implements IGridDisplay {
|
||||
|
||||
private int slotNumber;
|
||||
|
||||
private List<String> searchHistory = new ArrayList<>();
|
||||
private int searchHistoryIndex = -1;
|
||||
|
||||
public GuiGrid(ContainerGrid container, IGrid grid) {
|
||||
@@ -742,20 +743,20 @@ public class GuiGrid extends GuiBase implements IGridDisplay {
|
||||
}
|
||||
|
||||
private void updateSearchHistory(int delta) {
|
||||
if (searchHistory.isEmpty()) {
|
||||
if (SEARCH_HISTORY.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (searchHistoryIndex == -1) {
|
||||
searchHistoryIndex = searchHistory.size();
|
||||
searchHistoryIndex = SEARCH_HISTORY.size();
|
||||
}
|
||||
|
||||
searchHistoryIndex += delta;
|
||||
|
||||
if (searchHistoryIndex < 0) {
|
||||
searchHistoryIndex = 0;
|
||||
} else if (searchHistoryIndex > searchHistory.size() - 1) {
|
||||
searchHistoryIndex = searchHistory.size() - 1;
|
||||
} else if (searchHistoryIndex > SEARCH_HISTORY.size() - 1) {
|
||||
searchHistoryIndex = SEARCH_HISTORY.size() - 1;
|
||||
|
||||
if (delta == 1) {
|
||||
searchField.setText("");
|
||||
@@ -768,7 +769,7 @@ public class GuiGrid extends GuiBase implements IGridDisplay {
|
||||
}
|
||||
}
|
||||
|
||||
searchField.setText(searchHistory.get(searchHistoryIndex));
|
||||
searchField.setText(SEARCH_HISTORY.get(searchHistoryIndex));
|
||||
|
||||
view.sort();
|
||||
|
||||
@@ -776,12 +777,12 @@ public class GuiGrid extends GuiBase implements IGridDisplay {
|
||||
}
|
||||
|
||||
private void saveHistory() {
|
||||
if (!searchHistory.isEmpty() && searchHistory.get(searchHistory.size() - 1).equals(searchField.getText())) {
|
||||
if (!SEARCH_HISTORY.isEmpty() && SEARCH_HISTORY.get(SEARCH_HISTORY.size() - 1).equals(searchField.getText())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!searchField.getText().trim().isEmpty()) {
|
||||
searchHistory.add(searchField.getText());
|
||||
SEARCH_HISTORY.add(searchField.getText());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package com.raoulvdberge.refinedstorage.network;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.GridType;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGridNetworkAware;
|
||||
import com.raoulvdberge.refinedstorage.api.network.security.Permission;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeGrid;
|
||||
import com.raoulvdberge.refinedstorage.container.ContainerGrid;
|
||||
@@ -31,8 +31,8 @@ public class MessageGridClear extends MessageHandlerPlayerToServer<MessageGridCl
|
||||
public void handle(MessageGridClear message, EntityPlayerMP player) {
|
||||
Container container = player.openContainer;
|
||||
|
||||
if (container instanceof ContainerGrid) {
|
||||
IGrid grid = ((ContainerGrid) container).getGrid();
|
||||
if (container instanceof ContainerGrid && ((ContainerGrid) container).getGrid() instanceof IGridNetworkAware) {
|
||||
IGridNetworkAware grid = (IGridNetworkAware) ((ContainerGrid) container).getGrid();
|
||||
|
||||
InventoryCrafting matrix = grid.getCraftingMatrix();
|
||||
|
||||
|
@@ -3,8 +3,11 @@ package com.raoulvdberge.refinedstorage.tile.grid;
|
||||
import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.GridType;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGridNetworkAware;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGridTab;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IFluidGridHandler;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IItemGridHandler;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageCache;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageCacheListener;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IFilter;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageCacheListenerGridFluid;
|
||||
@@ -28,7 +31,7 @@ import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class WirelessFluidGrid implements IGrid {
|
||||
public class WirelessFluidGrid implements IGridNetworkAware {
|
||||
public static int ID;
|
||||
|
||||
private ItemStack stack;
|
||||
@@ -81,6 +84,28 @@ public class WirelessFluidGrid implements IGrid {
|
||||
return new StorageCacheListenerGridFluid(player, getNetwork());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IStorageCache getStorageCache() {
|
||||
INetwork network = getNetwork();
|
||||
|
||||
return network != null ? network.getFluidStorageCache() : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IItemGridHandler getItemHandler() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IFluidGridHandler getFluidHandler() {
|
||||
INetwork network = getNetwork();
|
||||
|
||||
return network != null ? network.getFluidGridHandler() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGuiTitle() {
|
||||
return "gui.refinedstorage:fluid_grid";
|
||||
|
@@ -4,7 +4,11 @@ import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.GridType;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGridNetworkAware;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGridTab;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IFluidGridHandler;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IItemGridHandler;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageCache;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageCacheListener;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IFilter;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageCacheListenerGridItem;
|
||||
@@ -31,7 +35,7 @@ import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WirelessGrid implements IGrid {
|
||||
public class WirelessGrid implements IGridNetworkAware {
|
||||
public static int ID;
|
||||
|
||||
private ItemStack stack;
|
||||
@@ -109,6 +113,28 @@ public class WirelessGrid implements IGrid {
|
||||
return new StorageCacheListenerGridItem(player, getNetwork());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IStorageCache getStorageCache() {
|
||||
INetwork network = getNetwork();
|
||||
|
||||
return network != null ? network.getItemStorageCache() : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IItemGridHandler getItemHandler() {
|
||||
INetwork network = getNetwork();
|
||||
|
||||
return network != null ? network.getItemGridHandler() : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IFluidGridHandler getFluidHandler() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGuiTitle() {
|
||||
return "gui.refinedstorage:grid";
|
||||
|
@@ -1,10 +1,10 @@
|
||||
package com.raoulvdberge.refinedstorage.tile.grid.portable;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.GridType;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGridTab;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IFluidGridHandler;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IItemGridHandler;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.*;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IFilter;
|
||||
@@ -200,12 +200,6 @@ public class PortableGrid implements IGrid, IPortableGrid {
|
||||
return GridType.NORMAL;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public INetwork getNetwork() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IStorageCache getStorageCache() {
|
||||
@@ -223,6 +217,12 @@ public class PortableGrid implements IGrid, IPortableGrid {
|
||||
return handler;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IFluidGridHandler getFluidHandler() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGuiTitle() {
|
||||
return "gui.refinedstorage:portable_grid";
|
||||
|
@@ -2,10 +2,10 @@ package com.raoulvdberge.refinedstorage.tile.grid.portable;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.RSBlocks;
|
||||
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.GridType;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGridTab;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IFluidGridHandler;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IItemGridHandler;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.*;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IFilter;
|
||||
@@ -277,12 +277,6 @@ public class TilePortableGrid extends TileBase implements IGrid, IPortableGrid,
|
||||
return GridType.NORMAL;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public INetwork getNetwork() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IStorageCache getStorageCache() {
|
||||
@@ -300,6 +294,12 @@ public class TilePortableGrid extends TileBase implements IGrid, IPortableGrid,
|
||||
return handler;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IFluidGridHandler getFluidHandler() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGuiTitle() {
|
||||
return "gui.refinedstorage:portable_grid";
|
||||
|
Reference in New Issue
Block a user