Just wanted to push my initial crap to fix #145, doesn't even compile yet and is unfinished
This commit is contained in:
@@ -7,6 +7,7 @@ import net.minecraft.util.math.BlockPos;
|
||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||
import refinedstorage.api.autocrafting.ICraftingTask;
|
||||
import refinedstorage.api.storage.CompareFlags;
|
||||
import refinedstorage.api.storage.IItemList;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@@ -59,9 +60,9 @@ public interface INetworkMaster {
|
||||
IWirelessGridHandler getWirelessGridHandler();
|
||||
|
||||
/**
|
||||
* @return The items stored in this network, do NOT modify this list
|
||||
* @return A {@link IItemList} containing all network items.
|
||||
*/
|
||||
List<ItemStack> getItems();
|
||||
IItemList getItems();
|
||||
|
||||
/**
|
||||
* @return The crafting tasks in this network, do NOT modify this list
|
||||
@@ -143,21 +144,11 @@ public interface INetworkMaster {
|
||||
/**
|
||||
* Takes an item from this network.
|
||||
*
|
||||
* @param stack A prototype of the stack to takeFromNetwork, do NOT modify
|
||||
* @param stack A prototype of the stack to take, do NOT modify
|
||||
* @param size The amount of that prototype that has to be taken
|
||||
* @param flags The flags to compare on, see {@link CompareFlags}
|
||||
* @return null if we didn't takeFromNetwork anything, or a {@link ItemStack} with the result
|
||||
*/
|
||||
@Nullable
|
||||
ItemStack take(@Nonnull ItemStack stack, int size, int flags);
|
||||
|
||||
/**
|
||||
* Returns an item from storage, based on the given prototype.
|
||||
*
|
||||
* @param stack The stack prototype to search
|
||||
* @param flags The flags to compare on, see {@link CompareFlags}
|
||||
* @return The {@link ItemStack} we found, do NOT modify
|
||||
*/
|
||||
@Nullable
|
||||
ItemStack getItem(@Nonnull ItemStack stack, int flags);
|
||||
}
|
||||
|
15
src/main/java/refinedstorage/api/storage/IItemList.java
Executable file
15
src/main/java/refinedstorage/api/storage/IItemList.java
Executable file
@@ -0,0 +1,15 @@
|
||||
package refinedstorage.api.storage;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IItemList {
|
||||
void add(ItemStack stack);
|
||||
|
||||
void remove(ItemStack stack);
|
||||
|
||||
ItemStack get(ItemStack stack, int flags);
|
||||
|
||||
List<ItemStack> getStacks();
|
||||
}
|
@@ -12,12 +12,9 @@ import java.util.List;
|
||||
*/
|
||||
public interface IStorage {
|
||||
/**
|
||||
* Adds the items in this storage to the storage network.
|
||||
* This is called every 20 ticks or when the storage changes, so don't make this method too resource intensive.
|
||||
*
|
||||
* @param items A list of previously added items
|
||||
* @return Items stored in this storage
|
||||
*/
|
||||
void addItems(List<ItemStack> items);
|
||||
List<ItemStack> getItems();
|
||||
|
||||
/**
|
||||
* Pushes an item to this storage.
|
||||
|
@@ -1,13 +1,11 @@
|
||||
package refinedstorage.api.storage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Implement this interface on the tile that has a {@link refinedstorage.api.RefinedStorageCapabilities#NETWORK_SLAVE_CAPABILITY} capability.
|
||||
*/
|
||||
public interface IStorageProvider {
|
||||
/**
|
||||
* @param storages A list containing previously added storages
|
||||
* @return The storages that this tile provides.
|
||||
*/
|
||||
void provide(List<IStorage> storages);
|
||||
IStorage[] getStorages();
|
||||
}
|
||||
|
61
src/main/java/refinedstorage/apiimpl/storage/ItemList.java
Executable file
61
src/main/java/refinedstorage/apiimpl/storage/ItemList.java
Executable file
@@ -0,0 +1,61 @@
|
||||
package refinedstorage.apiimpl.storage;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import refinedstorage.RefinedStorageUtils;
|
||||
import refinedstorage.api.storage.IItemList;
|
||||
import refinedstorage.api.storage.IStorageProvider;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ItemList implements IItemList {
|
||||
private List<ItemStack> stacks;
|
||||
|
||||
@Override
|
||||
public void rebuild(List<IStorageProvider> providers) {
|
||||
stacks.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(ItemStack stack) {
|
||||
for (ItemStack otherStack : stacks) {
|
||||
if (RefinedStorageUtils.compareStackNoQuantity(otherStack, stack)) {
|
||||
otherStack.stackSize += stack.stackSize;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
stacks.add(stack.copy());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(ItemStack stack) {
|
||||
for (ItemStack otherStack : stacks) {
|
||||
if (RefinedStorageUtils.compareStackNoQuantity(otherStack, stack)) {
|
||||
otherStack.stackSize -= stack.stackSize;
|
||||
|
||||
if (otherStack.stackSize == 0) {
|
||||
stacks.remove(otherStack);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack get(ItemStack stack, int flags) {
|
||||
for (ItemStack otherStack : stacks) {
|
||||
if (RefinedStorageUtils.compareStack(otherStack, stack, flags)) {
|
||||
return otherStack;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getStacks() {
|
||||
return stacks;
|
||||
}
|
||||
}
|
@@ -53,7 +53,7 @@ public class TileDetector extends TileSlave implements ICompareConfig {
|
||||
boolean wasPowered = powered;
|
||||
|
||||
if (slot != null) {
|
||||
ItemStack stack = network.getItem(slot, compare);
|
||||
ItemStack stack = network.getItems().get(slot, compare);
|
||||
|
||||
if (stack != null) {
|
||||
switch (mode) {
|
||||
|
@@ -25,6 +25,7 @@ import refinedstorage.api.network.INetworkMaster;
|
||||
import refinedstorage.api.network.INetworkSlave;
|
||||
import refinedstorage.api.network.IWirelessGridHandler;
|
||||
import refinedstorage.api.storage.CompareFlags;
|
||||
import refinedstorage.api.storage.IItemList;
|
||||
import refinedstorage.api.storage.IStorage;
|
||||
import refinedstorage.api.storage.IStorageProvider;
|
||||
import refinedstorage.apiimpl.autocrafting.BasicCraftingTask;
|
||||
@@ -32,6 +33,7 @@ import refinedstorage.apiimpl.autocrafting.CraftingPattern;
|
||||
import refinedstorage.apiimpl.autocrafting.ProcessingCraftingTask;
|
||||
import refinedstorage.apiimpl.network.GridHandler;
|
||||
import refinedstorage.apiimpl.network.WirelessGridHandler;
|
||||
import refinedstorage.apiimpl.storage.ItemList;
|
||||
import refinedstorage.block.BlockController;
|
||||
import refinedstorage.block.EnumControllerType;
|
||||
import refinedstorage.container.ContainerController;
|
||||
@@ -56,11 +58,8 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
||||
private GridHandler gridHandler = new GridHandler(this);
|
||||
private WirelessGridHandler wirelessGridHandler = new WirelessGridHandler(this);
|
||||
|
||||
private List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
private List<ItemStack> combinedItems = new ArrayList<ItemStack>();
|
||||
private Set<Integer> combinedItemsIndices = new HashSet<Integer>();
|
||||
|
||||
private List<IStorage> storages = new ArrayList<IStorage>();
|
||||
private IItemList items = new ItemList();
|
||||
|
||||
private List<INetworkSlave> slaves = new ArrayList<INetworkSlave>();
|
||||
private List<INetworkSlave> slavesToAdd = new ArrayList<INetworkSlave>();
|
||||
@@ -108,6 +107,14 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
||||
boolean forceUpdate = !slavesToAdd.isEmpty() || !slavesToRemove.isEmpty();
|
||||
|
||||
for (INetworkSlave newSlave : slavesToAdd) {
|
||||
if (newSlave instanceof IStorageProvider) {
|
||||
for (IStorage storage : ((IStorageProvider) newSlave).getStorages()) {
|
||||
for (ItemStack item : storage.getItems()) {
|
||||
items.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean found = false;
|
||||
|
||||
for (int i = 0; i < slaves.size(); ++i) {
|
||||
@@ -250,7 +257,7 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getItems() {
|
||||
public IItemList getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
@@ -326,7 +333,7 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
||||
int score = 0;
|
||||
|
||||
for (ItemStack input : patterns.get(i).getInputs()) {
|
||||
ItemStack stored = getItem(input, CompareFlags.COMPARE_DAMAGE | CompareFlags.COMPARE_NBT);
|
||||
ItemStack stored = items.get(input, CompareFlags.COMPARE_DAMAGE | CompareFlags.COMPARE_NBT);
|
||||
|
||||
score += stored != null ? stored.stackSize : 0;
|
||||
}
|
||||
@@ -342,7 +349,6 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
||||
|
||||
private void updateSlaves() {
|
||||
this.energyUsage = 0;
|
||||
this.storages.clear();
|
||||
this.patterns.clear();
|
||||
|
||||
int range = 0;
|
||||
@@ -356,10 +362,6 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
||||
range += ((TileWirelessTransmitter) slave).getRange();
|
||||
}
|
||||
|
||||
if (slave instanceof IStorageProvider) {
|
||||
((IStorageProvider) slave).provide(storages);
|
||||
}
|
||||
|
||||
if (slave instanceof TileCrafter) {
|
||||
TileCrafter crafter = (TileCrafter) slave;
|
||||
|
||||
@@ -401,57 +403,6 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
||||
return (left.getPriority() > right.getPriority()) ? -1 : 1;
|
||||
}
|
||||
});
|
||||
|
||||
updateItems();
|
||||
updateItemsWithClient();
|
||||
}
|
||||
|
||||
private void updateItems() {
|
||||
items.clear();
|
||||
|
||||
for (IStorage storage : storages) {
|
||||
storage.addItems(items);
|
||||
}
|
||||
|
||||
for (ICraftingPattern pattern : patterns) {
|
||||
for (ItemStack output : pattern.getOutputs()) {
|
||||
ItemStack patternStack = output.copy();
|
||||
patternStack.stackSize = 0;
|
||||
items.add(patternStack);
|
||||
}
|
||||
}
|
||||
|
||||
/*combinedItems.clear();
|
||||
combinedItemsIndices.clear();
|
||||
|
||||
for (int i = 0; i < items.size(); ++i) {
|
||||
if (combinedItemsIndices.contains(i)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack stack = items.get(i);
|
||||
|
||||
for (int j = i + 1; j < items.size(); ++j) {
|
||||
if (combinedItemsIndices.contains(j)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack otherStack = items.get(j);
|
||||
|
||||
if (RefinedStorageUtils.compareStackNoQuantity(stack, otherStack)) {
|
||||
// We copy here so we don't modify the quantity of the ItemStack IStorage uses.
|
||||
// We re-get the ItemStack because the stack may change from a previous iteration in this loop
|
||||
ItemStack newStack = items.get(i).copy();
|
||||
newStack.stackSize += otherStack.stackSize;
|
||||
items.set(i, newStack);
|
||||
|
||||
combinedItems.add(otherStack);
|
||||
combinedItemsIndices.add(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
items.removeAll(combinedItems);*/
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -470,11 +421,7 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
||||
|
||||
@Override
|
||||
public ItemStack push(ItemStack stack, int size, boolean simulate) {
|
||||
if (stack == null || stack.getItem() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (storages.isEmpty()) {
|
||||
if (stack == null || stack.getItem() == null || storages.isEmpty()) {
|
||||
return ItemHandlerHelper.copyStackWithSize(stack, size);
|
||||
}
|
||||
|
||||
@@ -505,8 +452,7 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
||||
}
|
||||
}
|
||||
|
||||
updateItems();
|
||||
updateItemsWithClient();
|
||||
items.add(ItemHandlerHelper.copyStackWithSize(stack, sizePushed));
|
||||
}
|
||||
|
||||
return remainder;
|
||||
@@ -538,24 +484,12 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
||||
}
|
||||
|
||||
if (newStack != null) {
|
||||
updateItems();
|
||||
updateItemsWithClient();
|
||||
items.remove(newStack);
|
||||
}
|
||||
|
||||
return newStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(ItemStack stack, int flags) {
|
||||
for (ItemStack otherStack : items) {
|
||||
if (RefinedStorageUtils.compareStack(otherStack, stack, flags)) {
|
||||
return otherStack;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag) {
|
||||
super.readFromNBT(tag);
|
||||
|
Reference in New Issue
Block a user