Do some cleanup.
This commit is contained in:
@@ -21,9 +21,7 @@ public interface IStackList<T> {
|
|||||||
*
|
*
|
||||||
* @param stack the stack
|
* @param stack the stack
|
||||||
*/
|
*/
|
||||||
default void add(@Nonnull T stack) {
|
void add(@Nonnull T stack);
|
||||||
add(stack, getSizeFromStack(stack));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decrements the count of that stack in the list.
|
* Decrements the count of that stack in the list.
|
||||||
@@ -40,9 +38,7 @@ public interface IStackList<T> {
|
|||||||
* @param stack the stack
|
* @param stack the stack
|
||||||
* @return true if the remove was successful for the full amount, false otherwise
|
* @return true if the remove was successful for the full amount, false otherwise
|
||||||
*/
|
*/
|
||||||
default boolean remove(@Nonnull T stack) {
|
boolean remove(@Nonnull T stack);
|
||||||
return remove(stack, getSizeFromStack(stack));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a stack.
|
* Returns a stack.
|
||||||
@@ -84,12 +80,6 @@ public interface IStackList<T> {
|
|||||||
*/
|
*/
|
||||||
boolean isEmpty();
|
boolean isEmpty();
|
||||||
|
|
||||||
/**
|
|
||||||
* @param stack the stack
|
|
||||||
* @return the size of the stack
|
|
||||||
*/
|
|
||||||
int getSizeFromStack(T stack);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return a collection of stacks in this list
|
* @return a collection of stacks in this list
|
||||||
*/
|
*/
|
||||||
|
@@ -232,7 +232,7 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
|
|||||||
ItemStack extracted = null;
|
ItemStack extracted = null;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
if (IFilterable.isEmpty(itemFilters)) {
|
if (itemFilters.isEmpty()) {
|
||||||
ItemStack toExtract = null;
|
ItemStack toExtract = null;
|
||||||
ArrayList<ItemStack> networkItems = new ArrayList<>(network.getItemStorageCache().getList().getStacks());
|
ArrayList<ItemStack> networkItems = new ArrayList<>(network.getItemStorageCache().getList().getStacks());
|
||||||
|
|
||||||
@@ -331,7 +331,7 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
|
|||||||
FluidStack extracted = null;
|
FluidStack extracted = null;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
if (IFilterable.isEmpty(itemFilters)) {
|
if (fluidFilters.isEmpty()) {
|
||||||
FluidStack toExtract = null;
|
FluidStack toExtract = null;
|
||||||
ArrayList<FluidStack> networkFluids = new ArrayList<>(network.getFluidStorageCache().getList().getStacks());
|
ArrayList<FluidStack> networkFluids = new ArrayList<>(network.getFluidStorageCache().getList().getStacks());
|
||||||
|
|
||||||
|
@@ -10,6 +10,7 @@ import com.raoulvdberge.refinedstorage.apiimpl.network.node.storage.NetworkNodeF
|
|||||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.storage.NetworkNodeStorage;
|
import com.raoulvdberge.refinedstorage.apiimpl.network.node.storage.NetworkNodeStorage;
|
||||||
import com.raoulvdberge.refinedstorage.block.enums.FluidStorageType;
|
import com.raoulvdberge.refinedstorage.block.enums.FluidStorageType;
|
||||||
import com.raoulvdberge.refinedstorage.block.enums.ItemStorageType;
|
import com.raoulvdberge.refinedstorage.block.enums.ItemStorageType;
|
||||||
|
import com.raoulvdberge.refinedstorage.inventory.item.ItemHandlerBase;
|
||||||
import com.raoulvdberge.refinedstorage.item.ItemPattern;
|
import com.raoulvdberge.refinedstorage.item.ItemPattern;
|
||||||
import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
|
import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
@@ -205,10 +206,10 @@ public class OneSixMigrationHelper implements IOneSixMigrationHelper {
|
|||||||
public static void removalHook() {
|
public static void removalHook() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void migrateEmptyWhitelistToEmptyBlacklist(String version, IFilterable filterable, @Nullable IItemHandler itemFilterInv) {
|
public static void migrateEmptyWhitelistToEmptyBlacklist(String version, IFilterable filterable, @Nullable ItemHandlerBase itemFilterInv) {
|
||||||
// Only migrate if we come from a version where the RS version tag stuff in NetworkNode wasn't added yet.
|
// Only migrate if we come from a version where the RS version tag stuff in NetworkNode wasn't added yet.
|
||||||
// Otherwise, we would constantly migrate empty whitelists to empty blacklists...
|
// Otherwise, we would constantly migrate empty whitelists to empty blacklists...
|
||||||
if (version == null && filterable.getMode() == IFilterable.WHITELIST && IFilterable.isEmpty(itemFilterInv)) {
|
if (version == null && filterable.getMode() == IFilterable.WHITELIST && (itemFilterInv == null || itemFilterInv.isEmpty())) {
|
||||||
filterable.setMode(IFilter.MODE_BLACKLIST);
|
filterable.setMode(IFilter.MODE_BLACKLIST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -36,6 +36,11 @@ public class StackListFluid implements IStackList<FluidStack> {
|
|||||||
stacks.put(stack.getFluid(), newStack);
|
stacks.put(stack.getFluid(), newStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void add(@Nonnull FluidStack stack) {
|
||||||
|
add(stack, stack.amount);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean remove(@Nonnull FluidStack stack, int size) {
|
public boolean remove(@Nonnull FluidStack stack, int size) {
|
||||||
for (FluidStack otherStack : stacks.get(stack.getFluid())) {
|
for (FluidStack otherStack : stacks.get(stack.getFluid())) {
|
||||||
@@ -55,6 +60,11 @@ public class StackListFluid implements IStackList<FluidStack> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean remove(@Nonnull FluidStack stack) {
|
||||||
|
return remove(stack, stack.amount);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public FluidStack get(@Nonnull FluidStack stack, int flags) {
|
public FluidStack get(@Nonnull FluidStack stack, int flags) {
|
||||||
@@ -89,11 +99,6 @@ public class StackListFluid implements IStackList<FluidStack> {
|
|||||||
return stacks.isEmpty();
|
return stacks.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSizeFromStack(FluidStack stack) {
|
|
||||||
return stack.amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Collection<FluidStack> getStacks() {
|
public Collection<FluidStack> getStacks() {
|
||||||
|
@@ -35,6 +35,11 @@ public class StackListItem implements IStackList<ItemStack> {
|
|||||||
stacks.put(stack.getItem(), ItemHandlerHelper.copyStackWithSize(stack, size));
|
stacks.put(stack.getItem(), ItemHandlerHelper.copyStackWithSize(stack, size));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void add(@Nonnull ItemStack stack) {
|
||||||
|
add(stack, stack.getCount());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean remove(@Nonnull ItemStack stack, int size) {
|
public boolean remove(@Nonnull ItemStack stack, int size) {
|
||||||
for (ItemStack otherStack : stacks.get(stack.getItem())) {
|
for (ItemStack otherStack : stacks.get(stack.getItem())) {
|
||||||
@@ -54,6 +59,11 @@ public class StackListItem implements IStackList<ItemStack> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean remove(@Nonnull ItemStack stack) {
|
||||||
|
return remove(stack, stack.getCount());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public ItemStack get(@Nonnull ItemStack stack, int flags) {
|
public ItemStack get(@Nonnull ItemStack stack, int flags) {
|
||||||
@@ -88,11 +98,6 @@ public class StackListItem implements IStackList<ItemStack> {
|
|||||||
return stacks.isEmpty();
|
return stacks.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSizeFromStack(ItemStack stack) {
|
|
||||||
return stack.getCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Collection<ItemStack> getStacks() {
|
public Collection<ItemStack> getStacks() {
|
||||||
|
@@ -11,6 +11,7 @@ public class FluidInventory {
|
|||||||
|
|
||||||
private FluidStack[] fluids;
|
private FluidStack[] fluids;
|
||||||
private int maxAmount;
|
private int maxAmount;
|
||||||
|
private boolean empty = true;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private Consumer<Integer> listener;
|
private Consumer<Integer> listener;
|
||||||
@@ -56,6 +57,8 @@ public class FluidInventory {
|
|||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
listener.accept(slot);
|
listener.accept(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateEmptyState();
|
||||||
}
|
}
|
||||||
|
|
||||||
public NBTTagCompound writeToNbt() {
|
public NBTTagCompound writeToNbt() {
|
||||||
@@ -80,5 +83,23 @@ public class FluidInventory {
|
|||||||
fluids[i] = FluidStack.loadFluidStackFromNBT(tag.getCompoundTag(key));
|
fluids[i] = FluidStack.loadFluidStackFromNBT(tag.getCompoundTag(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateEmptyState();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateEmptyState() {
|
||||||
|
this.empty = true;
|
||||||
|
|
||||||
|
for (FluidStack fluid : fluids) {
|
||||||
|
if (fluid != null) {
|
||||||
|
this.empty = false;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package com.raoulvdberge.refinedstorage.inventory.item;
|
package com.raoulvdberge.refinedstorage.inventory.item;
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraftforge.items.ItemStackHandler;
|
import net.minecraftforge.items.ItemStackHandler;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@@ -27,15 +28,6 @@ public class ItemHandlerBase extends ItemStackHandler {
|
|||||||
this(size, null, validators);
|
this(size, null, validators);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setStackInSlot(int slot, @Nonnull ItemStack stack) {
|
|
||||||
validateSlotIndex(slot);
|
|
||||||
|
|
||||||
stacks.set(slot, stack);
|
|
||||||
|
|
||||||
onContentsChanged(slot);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
|
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
|
||||||
@@ -63,6 +55,13 @@ public class ItemHandlerBase extends ItemStackHandler {
|
|||||||
this.empty = stacks.stream().allMatch(ItemStack::isEmpty);
|
this.empty = stacks.stream().allMatch(ItemStack::isEmpty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deserializeNBT(NBTTagCompound tag) {
|
||||||
|
super.deserializeNBT(tag);
|
||||||
|
|
||||||
|
this.empty = stacks.stream().allMatch(ItemStack::isEmpty);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return empty;
|
return empty;
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
package com.raoulvdberge.refinedstorage.tile;
|
package com.raoulvdberge.refinedstorage.tile;
|
||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.tile.data.TileDataManager;
|
import com.raoulvdberge.refinedstorage.tile.data.TileDataManager;
|
||||||
|
import com.raoulvdberge.refinedstorage.tile.direction.DirectionHandlerTile;
|
||||||
|
import com.raoulvdberge.refinedstorage.tile.direction.IDirectionHandler;
|
||||||
import com.raoulvdberge.refinedstorage.util.WorldUtils;
|
import com.raoulvdberge.refinedstorage.util.WorldUtils;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
@@ -11,6 +11,7 @@ import com.raoulvdberge.refinedstorage.capability.CapabilityNetworkNodeProxy;
|
|||||||
import com.raoulvdberge.refinedstorage.tile.config.IRedstoneConfigurable;
|
import com.raoulvdberge.refinedstorage.tile.config.IRedstoneConfigurable;
|
||||||
import com.raoulvdberge.refinedstorage.tile.config.RedstoneMode;
|
import com.raoulvdberge.refinedstorage.tile.config.RedstoneMode;
|
||||||
import com.raoulvdberge.refinedstorage.tile.data.TileDataParameter;
|
import com.raoulvdberge.refinedstorage.tile.data.TileDataParameter;
|
||||||
|
import com.raoulvdberge.refinedstorage.tile.direction.DirectionHandlerNetworkNode;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
@@ -10,8 +10,6 @@ import net.minecraft.tileentity.TileEntity;
|
|||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
public interface IFilterable {
|
public interface IFilterable {
|
||||||
int WHITELIST = 0;
|
int WHITELIST = 0;
|
||||||
int BLACKLIST = 1;
|
int BLACKLIST = 1;
|
||||||
@@ -76,20 +74,6 @@ public interface IFilterable {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isEmpty(@Nullable IItemHandler filter) {
|
|
||||||
if (filter == null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < filter.getSlots(); i++) {
|
|
||||||
if (!filter.getStackInSlot(i).isEmpty()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setMode(int mode);
|
void setMode(int mode);
|
||||||
|
|
||||||
int getMode();
|
int getMode();
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
package com.raoulvdberge.refinedstorage.tile;
|
package com.raoulvdberge.refinedstorage.tile.direction;
|
||||||
|
|
||||||
|
import com.raoulvdberge.refinedstorage.tile.TileNode;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
|
|
@@ -1,4 +1,4 @@
|
|||||||
package com.raoulvdberge.refinedstorage.tile;
|
package com.raoulvdberge.refinedstorage.tile.direction;
|
||||||
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
@@ -1,4 +1,4 @@
|
|||||||
package com.raoulvdberge.refinedstorage.tile;
|
package com.raoulvdberge.refinedstorage.tile.direction;
|
||||||
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
Reference in New Issue
Block a user