Add API for adding storage disks
This commit is contained in:
@@ -2,10 +2,10 @@ package com.raoulvdberge.refinedstorage;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.network.INetworkMaster;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDisk;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDiskProvider;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IStackList;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageFluidNBT;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageItemNBT;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
@@ -115,23 +115,32 @@ public final class RSUtils {
|
||||
return Pair.of(buf.readInt(), new FluidStack(FluidRegistry.getFluid(ByteBufUtils.readUTF8String(buf)), buf.readInt(), ByteBufUtils.readTag(buf)));
|
||||
}
|
||||
|
||||
public static void createStorages(ItemStack disk, int slot, StorageItemNBT[] itemStorages, StorageFluidNBT[] fluidStorages, Function<ItemStack, StorageItemNBT> itemStorageSupplier, Function<ItemStack, StorageFluidNBT> fluidStorageNBTSupplier) {
|
||||
public static ItemStack getStack(@Nullable ItemStack stack) {
|
||||
return stack == null ? ItemStack.EMPTY : stack;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void createStorages(ItemStack disk, int slot, IStorageDisk<ItemStack>[] itemStorages, IStorageDisk<FluidStack>[] fluidStorages, Function<IStorageDisk, IStorageDisk> itemStorageWrapper, Function<IStorageDisk, IStorageDisk> fluidStorageWrapper) {
|
||||
if (disk.isEmpty()) {
|
||||
itemStorages[slot] = null;
|
||||
fluidStorages[slot] = null;
|
||||
} else {
|
||||
if (disk.getItem() == RSItems.STORAGE_DISK) {
|
||||
itemStorages[slot] = itemStorageSupplier.apply(disk);
|
||||
} else if (disk.getItem() == RSItems.FLUID_STORAGE_DISK) {
|
||||
fluidStorages[slot] = fluidStorageNBTSupplier.apply(disk);
|
||||
IStorageDiskProvider provider = (IStorageDiskProvider) disk.getItem();
|
||||
IStorageDisk storage = provider.create(disk);
|
||||
|
||||
storage.readFromNBT();
|
||||
|
||||
switch (storage.getType()) {
|
||||
case ITEMS:
|
||||
itemStorages[slot] = itemStorageWrapper.apply(storage);
|
||||
break;
|
||||
case FLUIDS:
|
||||
fluidStorages[slot] = fluidStorageWrapper.apply(storage);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack getStack(@Nullable ItemStack stack) {
|
||||
return stack == null ? ItemStack.EMPTY : stack;
|
||||
}
|
||||
|
||||
public static NonNullList<ItemStack> toNonNullList(List<ItemStack> list) {
|
||||
NonNullList<ItemStack> other = NonNullList.create();
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeRegistry;
|
||||
import com.raoulvdberge.refinedstorage.api.network.readerwriter.IReaderWriterChannel;
|
||||
import com.raoulvdberge.refinedstorage.api.network.readerwriter.IReaderWriterHandlerRegistry;
|
||||
import com.raoulvdberge.refinedstorage.api.solderer.ISoldererRegistry;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDiskBehavior;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IStackList;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -41,6 +42,11 @@ public interface IRSAPI {
|
||||
*/
|
||||
INetworkNodeManager getNetworkNodeManager(int dimension);
|
||||
|
||||
/**
|
||||
* @return the storage disk behavior
|
||||
*/
|
||||
IStorageDiskBehavior getStorageDiskBehavior();
|
||||
|
||||
/**
|
||||
* @return the solderer registry
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.raoulvdberge.refinedstorage.api.storage;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Represents a storage disk.
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public interface IStorageDisk<T> extends IStorage<T> {
|
||||
/**
|
||||
* @return the capacity of this storage disk
|
||||
*/
|
||||
int getCapacity();
|
||||
|
||||
boolean isVoiding();
|
||||
|
||||
/**
|
||||
* Returns whether the storage disk is valid.
|
||||
* Determines if it can be inserted in a disk drive.
|
||||
*
|
||||
* @param stack the disk
|
||||
* @return whether it's valid
|
||||
*/
|
||||
boolean isValid(ItemStack stack);
|
||||
|
||||
/**
|
||||
* Called when the storage changes.
|
||||
*/
|
||||
void onChanged();
|
||||
|
||||
/**
|
||||
* Reads the storage from NBT.
|
||||
*/
|
||||
void readFromNBT();
|
||||
|
||||
/**
|
||||
* Writes the storage to NBT.
|
||||
*/
|
||||
void writeToNBT();
|
||||
|
||||
/**
|
||||
* @return the storage type
|
||||
*/
|
||||
StorageDiskType getType();
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.raoulvdberge.refinedstorage.api.storage;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
/**
|
||||
* Helper class for creation and usage of basic storage disks.
|
||||
* For more advanced usage of storages, implement {@link IStorage} yourself.
|
||||
*/
|
||||
public interface IStorageDiskBehavior {
|
||||
/**
|
||||
* Creates an item storage for a disk.
|
||||
*
|
||||
* @param tag the tag of the disk
|
||||
* @param capacity the capacity of the disk
|
||||
* @return the storage
|
||||
*/
|
||||
IStorageDisk<ItemStack> createItemStorage(NBTTagCompound tag, int capacity);
|
||||
|
||||
/**
|
||||
* Creates a fluid storage for a disk.
|
||||
*
|
||||
* @param tag the tag of the disk
|
||||
* @param capacity the capacity of the disk
|
||||
* @return the storage
|
||||
*/
|
||||
IStorageDisk<FluidStack> createFluidStorage(NBTTagCompound tag, int capacity);
|
||||
|
||||
/**
|
||||
* Returns a NBT share tag for a disk.
|
||||
*
|
||||
* @param type the type of disk
|
||||
* @param stack the disk
|
||||
* @return the share tag
|
||||
*/
|
||||
NBTTagCompound getShareTag(StorageDiskType type, ItemStack stack);
|
||||
|
||||
/**
|
||||
* Returns a initial base NBT tag for a disk.
|
||||
*
|
||||
* @param type the disk type
|
||||
* @return the tag
|
||||
*/
|
||||
NBTTagCompound getTag(StorageDiskType type);
|
||||
|
||||
/**
|
||||
* Initializes a disk with the base NBT tag.
|
||||
*
|
||||
* @param type the disk type
|
||||
* @param stack the disk
|
||||
* @return the initialized disk
|
||||
*/
|
||||
default ItemStack initDisk(StorageDiskType type, ItemStack stack) {
|
||||
stack.setTagCompound(getTag(type));
|
||||
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.raoulvdberge.refinedstorage.api.storage;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Implement this on an item.
|
||||
*/
|
||||
public interface IStorageDiskProvider<T> {
|
||||
@Nonnull
|
||||
IStorageDisk<T> create(ItemStack disk);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.raoulvdberge.refinedstorage.api.storage;
|
||||
|
||||
public enum StorageDiskType {
|
||||
ITEMS,
|
||||
FLUIDS
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import com.raoulvdberge.refinedstorage.api.autocrafting.craftingmonitor.ICraftin
|
||||
import com.raoulvdberge.refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElementRegistry;
|
||||
import com.raoulvdberge.refinedstorage.api.autocrafting.preview.ICraftingPreviewElementRegistry;
|
||||
import com.raoulvdberge.refinedstorage.api.autocrafting.registry.ICraftingTaskRegistry;
|
||||
import com.raoulvdberge.refinedstorage.api.network.*;
|
||||
import com.raoulvdberge.refinedstorage.api.network.INetworkMaster;
|
||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
|
||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeManager;
|
||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeProxy;
|
||||
@@ -14,6 +14,7 @@ import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeRegistry;
|
||||
import com.raoulvdberge.refinedstorage.api.network.readerwriter.IReaderWriterChannel;
|
||||
import com.raoulvdberge.refinedstorage.api.network.readerwriter.IReaderWriterHandlerRegistry;
|
||||
import com.raoulvdberge.refinedstorage.api.solderer.ISoldererRegistry;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDiskBehavior;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IStackList;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementList;
|
||||
@@ -25,6 +26,7 @@ import com.raoulvdberge.refinedstorage.apiimpl.network.NetworkNodeRegistry;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.readerwriter.ReaderWriterChannel;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.readerwriter.ReaderWriterHandlerRegistry;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.solderer.SoldererRegistry;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskBehavior;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.util.Comparer;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.util.StackListFluid;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.util.StackListItem;
|
||||
@@ -54,6 +56,7 @@ public class API implements IRSAPI {
|
||||
private INetworkNodeRegistry networkNodeRegistry = new NetworkNodeRegistry();
|
||||
private Map<Integer, INetworkNodeManager> networkNodeProviderServer = new HashMap<>();
|
||||
private Map<Integer, INetworkNodeManager> networkNodeProviderClient = new HashMap<>();
|
||||
private IStorageDiskBehavior storageDiskBehavior = new StorageDiskBehavior();
|
||||
private ISoldererRegistry soldererRegistry = new SoldererRegistry();
|
||||
private ICraftingTaskRegistry craftingTaskRegistry = new CraftingTaskRegistry();
|
||||
private ICraftingMonitorElementRegistry craftingMonitorElementRegistry = new CraftingMonitorElementRegistry();
|
||||
@@ -102,6 +105,11 @@ public class API implements IRSAPI {
|
||||
return provider.computeIfAbsent(dimension, r -> new NetworkNodeManager());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStorageDiskBehavior getStorageDiskBehavior() {
|
||||
return storageDiskBehavior;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ISoldererRegistry getSoldererRegistry() {
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorage;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageProvider;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageFluidNBT;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskFluid;
|
||||
import com.raoulvdberge.refinedstorage.block.BlockFluidStorage;
|
||||
import com.raoulvdberge.refinedstorage.block.EnumFluidStorageType;
|
||||
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerFluid;
|
||||
@@ -28,9 +28,9 @@ import java.util.List;
|
||||
public class NetworkNodeFluidStorage extends NetworkNode implements IStorageGui, IStorageProvider, IComparable, IFilterable, IPrioritizable, IExcessVoidable, IAccessType {
|
||||
public static final String ID = "fluid_storage";
|
||||
|
||||
class StorageFluid extends StorageFluidNBT {
|
||||
class StorageFluid extends StorageDiskFluid {
|
||||
public StorageFluid() {
|
||||
super(NetworkNodeFluidStorage.this.getStorageTag(), NetworkNodeFluidStorage.this.getCapacity(), NetworkNodeFluidStorage.this);
|
||||
super(NetworkNodeFluidStorage.this.getStorageTag(), NetworkNodeFluidStorage.this.getCapacity());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,6 +57,13 @@ public class NetworkNodeFluidStorage extends NetworkNode implements IStorageGui,
|
||||
public boolean isVoiding() {
|
||||
return voidExcess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChanged() {
|
||||
super.onChanged();
|
||||
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
public static final String NBT_STORAGE = "Storage";
|
||||
@@ -68,7 +75,7 @@ public class NetworkNodeFluidStorage extends NetworkNode implements IStorageGui,
|
||||
|
||||
private ItemHandlerFluid filters = new ItemHandlerFluid(9, new ItemHandlerListenerNetworkNode(this));
|
||||
|
||||
private NBTTagCompound storageTag = StorageFluidNBT.createNBT();
|
||||
private NBTTagCompound storageTag = StorageDiskFluid.getTag();
|
||||
|
||||
private StorageFluid storage;
|
||||
|
||||
@@ -235,7 +242,7 @@ public class NetworkNodeFluidStorage extends NetworkNode implements IStorageGui,
|
||||
this.storageTag = storageTag;
|
||||
}
|
||||
|
||||
public StorageFluidNBT getStorage() {
|
||||
public StorageDiskFluid getStorage() {
|
||||
return storage;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorage;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageProvider;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageItemNBT;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskItem;
|
||||
import com.raoulvdberge.refinedstorage.block.BlockStorage;
|
||||
import com.raoulvdberge.refinedstorage.block.EnumItemStorageType;
|
||||
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBasic;
|
||||
@@ -28,9 +28,9 @@ import java.util.List;
|
||||
public class NetworkNodeStorage extends NetworkNode implements IStorageGui, IStorageProvider, IComparable, IFilterable, IPrioritizable, IExcessVoidable, IAccessType {
|
||||
public static final String ID = "storage";
|
||||
|
||||
class StorageItem extends StorageItemNBT {
|
||||
class StorageItem extends StorageDiskItem {
|
||||
public StorageItem() {
|
||||
super(NetworkNodeStorage.this.getStorageTag(), NetworkNodeStorage.this.getCapacity(), NetworkNodeStorage.this);
|
||||
super(NetworkNodeStorage.this.getStorageTag(), NetworkNodeStorage.this.getCapacity());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -56,6 +56,13 @@ public class NetworkNodeStorage extends NetworkNode implements IStorageGui, ISto
|
||||
public boolean isVoiding() {
|
||||
return voidExcess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChanged() {
|
||||
super.onChanged();
|
||||
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
public static final String NBT_STORAGE = "Storage";
|
||||
@@ -67,7 +74,7 @@ public class NetworkNodeStorage extends NetworkNode implements IStorageGui, ISto
|
||||
|
||||
private ItemHandlerBasic filters = new ItemHandlerBasic(9, new ItemHandlerListenerNetworkNode(this));
|
||||
|
||||
private NBTTagCompound storageTag = StorageItemNBT.createNBT();
|
||||
private NBTTagCompound storageTag = StorageDiskItem.getTag();
|
||||
|
||||
private StorageItem storage;
|
||||
|
||||
@@ -246,7 +253,7 @@ public class NetworkNodeStorage extends NetworkNode implements IStorageGui, ISto
|
||||
this.storageTag = storageTag;
|
||||
}
|
||||
|
||||
public StorageItemNBT getStorage() {
|
||||
public StorageDiskItem getStorage() {
|
||||
return storage;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.network.node;
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.network.node.diskdrive;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.RSItems;
|
||||
@@ -6,10 +6,13 @@ import com.raoulvdberge.refinedstorage.RSUtils;
|
||||
import com.raoulvdberge.refinedstorage.api.network.INetworkMaster;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorage;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDisk;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageProvider;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageFluidNBT;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageItemNBT;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.INetworkNodeHolder;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNode;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskFluid;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskItem;
|
||||
import com.raoulvdberge.refinedstorage.block.EnumFluidStorageType;
|
||||
import com.raoulvdberge.refinedstorage.block.EnumItemStorageType;
|
||||
import com.raoulvdberge.refinedstorage.inventory.IItemValidator;
|
||||
@@ -26,111 +29,12 @@ import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class NetworkNodeDiskDrive extends NetworkNode implements IStorageGui, IStorageProvider, IComparable, IFilterable, IPrioritizable, IType, IExcessVoidable, IAccessType {
|
||||
public static final String ID = "disk_drive";
|
||||
|
||||
public class StorageItem extends StorageItemNBT {
|
||||
private int lastState;
|
||||
|
||||
public StorageItem(ItemStack disk) {
|
||||
super(disk.getTagCompound(), EnumItemStorageType.getById(disk.getItemDamage()).getCapacity(), NetworkNodeDiskDrive.this);
|
||||
|
||||
lastState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ItemStack insert(@Nonnull ItemStack stack, int size, boolean simulate) {
|
||||
if (!IFilterable.canTake(itemFilters, mode, getCompare(), stack)) {
|
||||
return ItemHandlerHelper.copyStackWithSize(stack, size);
|
||||
}
|
||||
|
||||
return super.insert(stack, size, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccessType getAccessType() {
|
||||
return accessType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVoiding() {
|
||||
return voidExcess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStorageChanged() {
|
||||
super.onStorageChanged();
|
||||
|
||||
int currentState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||
|
||||
if (lastState != currentState) {
|
||||
lastState = currentState;
|
||||
|
||||
RSUtils.updateBlock(holder.world(), holder.pos());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class StorageFluid extends StorageFluidNBT {
|
||||
private int lastState;
|
||||
|
||||
public StorageFluid(ItemStack disk) {
|
||||
super(disk.getTagCompound(), EnumFluidStorageType.getById(disk.getItemDamage()).getCapacity(), NetworkNodeDiskDrive.this);
|
||||
|
||||
lastState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public FluidStack insert(@Nonnull FluidStack stack, int size, boolean simulate) {
|
||||
if (!IFilterable.canTakeFluids(fluidFilters, mode, getCompare(), stack)) {
|
||||
return RSUtils.copyStackWithSize(stack, size);
|
||||
}
|
||||
|
||||
return super.insert(stack, size, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccessType getAccessType() {
|
||||
return accessType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVoiding() {
|
||||
return voidExcess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStorageChanged() {
|
||||
super.onStorageChanged();
|
||||
|
||||
int currentState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||
|
||||
if (lastState != currentState) {
|
||||
lastState = currentState;
|
||||
|
||||
RSUtils.updateBlock(holder.world(), holder.pos());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final String NBT_PRIORITY = "Priority";
|
||||
private static final String NBT_COMPARE = "Compare";
|
||||
private static final String NBT_MODE = "Mode";
|
||||
@@ -143,7 +47,14 @@ public class NetworkNodeDiskDrive extends NetworkNode implements IStorageGui, IS
|
||||
super.onContentsChanged(slot);
|
||||
|
||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
|
||||
RSUtils.createStorages(getStackInSlot(slot), slot, itemStorages, fluidStorages, s -> new StorageItem(s), s -> new StorageFluid(s));
|
||||
RSUtils.createStorages(
|
||||
getStackInSlot(slot),
|
||||
slot,
|
||||
itemStorages,
|
||||
fluidStorages,
|
||||
s -> new StorageItemDiskDrive(NetworkNodeDiskDrive.this, s),
|
||||
s -> new StorageFluidDiskDrive(NetworkNodeDiskDrive.this, s)
|
||||
);
|
||||
|
||||
if (network != null) {
|
||||
network.getItemStorageCache().invalidate();
|
||||
@@ -171,8 +82,8 @@ public class NetworkNodeDiskDrive extends NetworkNode implements IStorageGui, IS
|
||||
private ItemHandlerBasic itemFilters = new ItemHandlerBasic(9, new ItemHandlerListenerNetworkNode(this));
|
||||
private ItemHandlerFluid fluidFilters = new ItemHandlerFluid(9, new ItemHandlerListenerNetworkNode(this));
|
||||
|
||||
private StorageItem itemStorages[] = new StorageItem[8];
|
||||
private StorageFluid fluidStorages[] = new StorageFluid[8];
|
||||
private IStorageDisk[] itemStorages = new IStorageDisk[8];
|
||||
private IStorageDisk[] fluidStorages = new IStorageDisk[8];
|
||||
|
||||
private AccessType accessType = AccessType.INSERT_EXTRACT;
|
||||
private int priority = 0;
|
||||
@@ -185,11 +96,11 @@ public class NetworkNodeDiskDrive extends NetworkNode implements IStorageGui, IS
|
||||
super(holder);
|
||||
}
|
||||
|
||||
public StorageItem[] getItemStorages() {
|
||||
public IStorageDisk[] getItemStorages() {
|
||||
return itemStorages;
|
||||
}
|
||||
|
||||
public StorageFluid[] getFluidStorages() {
|
||||
public IStorageDisk[] getFluidStorages() {
|
||||
return fluidStorages;
|
||||
}
|
||||
|
||||
@@ -207,13 +118,13 @@ public class NetworkNodeDiskDrive extends NetworkNode implements IStorageGui, IS
|
||||
}
|
||||
|
||||
public void onBreak() {
|
||||
for (StorageItem storage : this.itemStorages) {
|
||||
for (IStorageDisk storage : this.itemStorages) {
|
||||
if (storage != null) {
|
||||
storage.writeToNBT();
|
||||
}
|
||||
}
|
||||
|
||||
for (StorageFluid storage : this.fluidStorages) {
|
||||
for (IStorageDisk storage : this.fluidStorages) {
|
||||
if (storage != null) {
|
||||
storage.writeToNBT();
|
||||
}
|
||||
@@ -404,7 +315,7 @@ public class NetworkNodeDiskDrive extends NetworkNode implements IStorageGui, IS
|
||||
ItemStack disk = disks.getStackInSlot(i);
|
||||
|
||||
if (!disk.isEmpty()) {
|
||||
stored += disk.getItem() == RSItems.STORAGE_DISK ? StorageItemNBT.getStoredFromNBT(disk.getTagCompound()) : StorageFluidNBT.getStoredFromNBT(disk.getTagCompound());
|
||||
stored += disk.getItem() == RSItems.STORAGE_DISK ? StorageDiskItem.getStored(disk.getTagCompound()) : StorageDiskFluid.getStored(disk.getTagCompound());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -494,6 +405,14 @@ public class NetworkNodeDiskDrive extends NetworkNode implements IStorageGui, IS
|
||||
return getType() == IType.ITEMS ? itemFilters : fluidFilters;
|
||||
}
|
||||
|
||||
public ItemHandlerBasic getItemFilters() {
|
||||
return itemFilters;
|
||||
}
|
||||
|
||||
public ItemHandlerFluid getFluidFilters() {
|
||||
return fluidFilters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getDrops() {
|
||||
return disks;
|
||||
@@ -0,0 +1,112 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.network.node.diskdrive;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RSUtils;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDisk;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.StorageDiskType;
|
||||
import com.raoulvdberge.refinedstorage.tile.TileDiskDrive;
|
||||
import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class StorageFluidDiskDrive implements IStorageDisk<FluidStack> {
|
||||
private NetworkNodeDiskDrive diskDrive;
|
||||
private IStorageDisk<FluidStack> parent;
|
||||
private int lastState;
|
||||
|
||||
public StorageFluidDiskDrive(NetworkNodeDiskDrive diskDrive, IStorageDisk<FluidStack> parent) {
|
||||
this.diskDrive = diskDrive;
|
||||
this.parent = parent;
|
||||
this.lastState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return diskDrive.getPriority();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<FluidStack> getStacks() {
|
||||
return parent.getStacks();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public FluidStack insert(@Nonnull FluidStack stack, int size, boolean simulate) {
|
||||
if (!IFilterable.canTakeFluids(diskDrive.getFluidFilters(), diskDrive.getMode(), diskDrive.getCompare(), stack)) {
|
||||
return RSUtils.copyStackWithSize(stack, size);
|
||||
}
|
||||
|
||||
return parent.insert(stack, size, simulate);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public FluidStack extract(@Nonnull FluidStack stack, int size, int flags, boolean simulate) {
|
||||
return parent.extract(stack, size, flags, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStored() {
|
||||
return parent.getStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccessType getAccessType() {
|
||||
return diskDrive.getAccessType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCacheDelta(int storedPreInsertion, int size, @Nullable FluidStack remainder) {
|
||||
return parent.getCacheDelta(storedPreInsertion, size, remainder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity() {
|
||||
return parent.getCapacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVoiding() {
|
||||
return diskDrive.getVoidExcess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(ItemStack stack) {
|
||||
return parent.isValid(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChanged() {
|
||||
parent.onChanged();
|
||||
|
||||
diskDrive.markDirty();
|
||||
|
||||
int currentState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||
|
||||
if (lastState != currentState) {
|
||||
lastState = currentState;
|
||||
|
||||
RSUtils.updateBlock(diskDrive.getHolder().world(), diskDrive.getHolder().pos());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT() {
|
||||
parent.readFromNBT();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT() {
|
||||
parent.writeToNBT();
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageDiskType getType() {
|
||||
return parent.getType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.network.node.diskdrive;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RSUtils;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDisk;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.StorageDiskType;
|
||||
import com.raoulvdberge.refinedstorage.tile.TileDiskDrive;
|
||||
import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class StorageItemDiskDrive implements IStorageDisk<ItemStack> {
|
||||
private NetworkNodeDiskDrive diskDrive;
|
||||
private IStorageDisk<ItemStack> parent;
|
||||
private int lastState;
|
||||
|
||||
public StorageItemDiskDrive(NetworkNodeDiskDrive diskDrive, IStorageDisk<ItemStack> parent) {
|
||||
this.diskDrive = diskDrive;
|
||||
this.parent = parent;
|
||||
this.lastState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return diskDrive.getPriority();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> getStacks() {
|
||||
return parent.getStacks();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ItemStack insert(@Nonnull ItemStack stack, int size, boolean simulate) {
|
||||
if (!IFilterable.canTake(diskDrive.getItemFilters(), diskDrive.getMode(), diskDrive.getCompare(), stack)) {
|
||||
return ItemHandlerHelper.copyStackWithSize(stack, size);
|
||||
}
|
||||
|
||||
return parent.insert(stack, size, simulate);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ItemStack extract(@Nonnull ItemStack stack, int size, int flags, boolean simulate) {
|
||||
return parent.extract(stack, size, flags, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStored() {
|
||||
return parent.getStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccessType getAccessType() {
|
||||
return diskDrive.getAccessType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCacheDelta(int storedPreInsertion, int size, @Nullable ItemStack remainder) {
|
||||
return parent.getCacheDelta(storedPreInsertion, size, remainder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity() {
|
||||
return parent.getCapacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVoiding() {
|
||||
return diskDrive.getVoidExcess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(ItemStack stack) {
|
||||
return parent.isValid(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChanged() {
|
||||
parent.onChanged();
|
||||
|
||||
diskDrive.markDirty();
|
||||
|
||||
int currentState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||
|
||||
if (lastState != currentState) {
|
||||
lastState = currentState;
|
||||
|
||||
RSUtils.updateBlock(diskDrive.getHolder().world(), diskDrive.getHolder().pos());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT() {
|
||||
parent.readFromNBT();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT() {
|
||||
parent.writeToNBT();
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageDiskType getType() {
|
||||
return parent.getType();
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,13 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.network.node;
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.network.node.diskmanipulator;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.RSUtils;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDisk;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageFluidNBT;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageItemNBT;
|
||||
import com.raoulvdberge.refinedstorage.block.EnumFluidStorageType;
|
||||
import com.raoulvdberge.refinedstorage.block.EnumItemStorageType;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.INetworkNodeHolder;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNode;
|
||||
import com.raoulvdberge.refinedstorage.inventory.*;
|
||||
import com.raoulvdberge.refinedstorage.item.ItemUpgrade;
|
||||
import com.raoulvdberge.refinedstorage.tile.TileDiskDrive;
|
||||
import com.raoulvdberge.refinedstorage.tile.config.IComparable;
|
||||
import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
|
||||
import com.raoulvdberge.refinedstorage.tile.config.IType;
|
||||
@@ -19,11 +17,9 @@ import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import net.minecraftforge.items.wrapper.CombinedInvWrapper;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class NetworkNodeDiskManipulator extends NetworkNode implements IComparable, IFilterable, IType {
|
||||
@@ -42,8 +38,8 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
|
||||
private int type = IType.ITEMS;
|
||||
private int ioMode = IO_MODE_INSERT;
|
||||
|
||||
private StorageItem[] itemStorages = new StorageItem[6];
|
||||
private StorageFluid[] fluidStorages = new StorageFluid[6];
|
||||
private IStorageDisk[] itemStorages = new IStorageDisk[8];
|
||||
private IStorageDisk[] fluidStorages = new IStorageDisk[8];
|
||||
|
||||
private ItemHandlerUpgrade upgrades = new ItemHandlerUpgrade(4, new ItemHandlerListenerNetworkNode(this), ItemUpgrade.TYPE_SPEED, ItemUpgrade.TYPE_STACK);
|
||||
|
||||
@@ -53,7 +49,14 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
|
||||
super.onContentsChanged(slot);
|
||||
|
||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
|
||||
RSUtils.createStorages(getStackInSlot(slot), slot, itemStorages, fluidStorages, s -> new StorageItem(s), s -> new StorageFluid(s));
|
||||
RSUtils.createStorages(
|
||||
getStackInSlot(slot),
|
||||
slot,
|
||||
itemStorages,
|
||||
fluidStorages,
|
||||
s -> new StorageItemDiskManipulator(NetworkNodeDiskManipulator.this, s),
|
||||
s -> new StorageFluidDiskManipulator(NetworkNodeDiskManipulator.this, s)
|
||||
);
|
||||
|
||||
RSUtils.updateBlock(holder.world(), holder.pos());
|
||||
}
|
||||
@@ -80,7 +83,14 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
|
||||
super.onContentsChanged(slot);
|
||||
|
||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
|
||||
RSUtils.createStorages(getStackInSlot(slot), 3 + slot, itemStorages, fluidStorages, s -> new StorageItem(s), s -> new StorageFluid(s));
|
||||
RSUtils.createStorages(
|
||||
getStackInSlot(slot),
|
||||
slot,
|
||||
itemStorages,
|
||||
fluidStorages,
|
||||
s -> new StorageItemDiskManipulator(NetworkNodeDiskManipulator.this, s),
|
||||
s -> new StorageFluidDiskManipulator(NetworkNodeDiskManipulator.this, s)
|
||||
);
|
||||
|
||||
RSUtils.updateBlock(holder.world(), holder.pos());
|
||||
}
|
||||
@@ -91,110 +101,6 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
|
||||
super(holder);
|
||||
}
|
||||
|
||||
public class StorageItem extends StorageItemNBT {
|
||||
private int lastState;
|
||||
|
||||
public StorageItem(ItemStack disk) {
|
||||
super(disk.getTagCompound(), EnumItemStorageType.getById(disk.getItemDamage()).getCapacity(), NetworkNodeDiskManipulator.this);
|
||||
|
||||
lastState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVoiding() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack insert(@Nonnull ItemStack stack, int size, boolean simulate) {
|
||||
if (!IFilterable.canTake(itemFilters, mode, getCompare(), stack)) {
|
||||
return ItemHandlerHelper.copyStackWithSize(stack, size);
|
||||
}
|
||||
|
||||
return super.insert(stack, size, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack extract(@Nonnull ItemStack stack, int size, int flags, boolean simulate) {
|
||||
if (!IFilterable.canTake(itemFilters, mode, getCompare(), stack)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return super.extract(stack, size, flags, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStorageChanged() {
|
||||
super.onStorageChanged();
|
||||
|
||||
int currentState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||
|
||||
if (lastState != currentState) {
|
||||
lastState = currentState;
|
||||
|
||||
RSUtils.updateBlock(holder.world(), holder.pos());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class StorageFluid extends StorageFluidNBT {
|
||||
private int lastState;
|
||||
|
||||
public StorageFluid(ItemStack disk) {
|
||||
super(disk.getTagCompound(), EnumFluidStorageType.getById(disk.getItemDamage()).getCapacity(), NetworkNodeDiskManipulator.this);
|
||||
|
||||
lastState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVoiding() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public FluidStack insert(@Nonnull FluidStack stack, int size, boolean simulate) {
|
||||
if (!IFilterable.canTakeFluids(fluidFilters, mode, getCompare(), stack)) {
|
||||
return RSUtils.copyStackWithSize(stack, size);
|
||||
}
|
||||
|
||||
return super.insert(stack, size, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public FluidStack extract(@Nonnull FluidStack stack, int size, int flags, boolean simulate) {
|
||||
if (!IFilterable.canTakeFluids(fluidFilters, mode, getCompare(), stack)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return super.extract(stack, size, flags, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStorageChanged() {
|
||||
super.onStorageChanged();
|
||||
|
||||
int currentState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||
|
||||
if (lastState != currentState) {
|
||||
lastState = currentState;
|
||||
|
||||
RSUtils.updateBlock(holder.world(), holder.pos());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ItemHandlerBasic itemFilters = new ItemHandlerBasic(9, new ItemHandlerListenerNetworkNode(this));
|
||||
private ItemHandlerFluid fluidFilters = new ItemHandlerFluid(9, new ItemHandlerListenerNetworkNode(this));
|
||||
|
||||
@@ -226,12 +132,12 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
|
||||
return;
|
||||
}
|
||||
|
||||
StorageItem storage = itemStorages[slot];
|
||||
IStorageDisk storage = itemStorages[slot];
|
||||
|
||||
if (ioMode == IO_MODE_INSERT) {
|
||||
insertIntoNetwork(storage, slot);
|
||||
insertItemIntoNetwork(storage, slot);
|
||||
} else if (ioMode == IO_MODE_EXTRACT) {
|
||||
extractFromNetwork(storage, slot);
|
||||
extractItemFromNetwork(storage, slot);
|
||||
}
|
||||
} else if (type == IType.FLUIDS) {
|
||||
while (slot < 3 && fluidStorages[slot] == null) {
|
||||
@@ -242,17 +148,17 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
|
||||
return;
|
||||
}
|
||||
|
||||
StorageFluid storage = fluidStorages[slot];
|
||||
IStorageDisk storage = fluidStorages[slot];
|
||||
|
||||
if (ioMode == IO_MODE_INSERT) {
|
||||
insertIntoNetwork(storage, slot);
|
||||
insertFluidIntoNetwork(storage, slot);
|
||||
} else if (ioMode == IO_MODE_EXTRACT) {
|
||||
extractFromNetwork(storage, slot);
|
||||
extractFluidFromNetwork(storage, slot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void insertIntoNetwork(StorageItem storage, int slot) {
|
||||
private void insertItemIntoNetwork(IStorageDisk<ItemStack> storage, int slot) {
|
||||
if (storage.getStored() == 0) {
|
||||
moveDriveToOutput(slot);
|
||||
return;
|
||||
@@ -260,9 +166,6 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
|
||||
|
||||
for (int i = 0; i < storage.getStacks().size(); i++) {
|
||||
ItemStack stack = storage.getStacks().get(i);
|
||||
if (stack == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack extracted = storage.extract(stack, upgrades.getItemInteractCount(), compare, false);
|
||||
if (extracted == null) {
|
||||
@@ -283,7 +186,7 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
|
||||
}
|
||||
}
|
||||
|
||||
private void extractFromNetwork(StorageItem storage, int slot) {
|
||||
private void extractItemFromNetwork(IStorageDisk<ItemStack> storage, int slot) {
|
||||
if (storage.getStored() == storage.getCapacity()) {
|
||||
moveDriveToOutput(slot);
|
||||
return;
|
||||
@@ -331,7 +234,7 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
|
||||
}
|
||||
}
|
||||
|
||||
private void insertIntoNetwork(StorageFluid storage, int slot) {
|
||||
private void insertFluidIntoNetwork(IStorageDisk<FluidStack> storage, int slot) {
|
||||
if (storage.getStored() == 0) {
|
||||
moveDriveToOutput(slot);
|
||||
return;
|
||||
@@ -364,7 +267,7 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
|
||||
}
|
||||
}
|
||||
|
||||
private void extractFromNetwork(StorageFluid storage, int slot) {
|
||||
private void extractFluidFromNetwork(IStorageDisk<FluidStack> storage, int slot) {
|
||||
if (storage.getStored() == storage.getCapacity()) {
|
||||
moveDriveToOutput(slot);
|
||||
return;
|
||||
@@ -491,15 +394,23 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
|
||||
return outputDisks;
|
||||
}
|
||||
|
||||
public ItemHandlerBasic getItemFilters() {
|
||||
return itemFilters;
|
||||
}
|
||||
|
||||
public ItemHandlerFluid getFluidFilters() {
|
||||
return fluidFilters;
|
||||
}
|
||||
|
||||
public IItemHandler getUpgrades() {
|
||||
return upgrades;
|
||||
}
|
||||
|
||||
public StorageItem[] getItemStorages() {
|
||||
public IStorageDisk[] getItemStorages() {
|
||||
return itemStorages;
|
||||
}
|
||||
|
||||
public StorageFluid[] getFluidStorages() {
|
||||
public IStorageDisk[] getFluidStorages() {
|
||||
return fluidStorages;
|
||||
}
|
||||
|
||||
@@ -570,20 +481,19 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
|
||||
}
|
||||
|
||||
public void onBreak() {
|
||||
for (StorageItem storage : itemStorages) {
|
||||
for (IStorageDisk storage : itemStorages) {
|
||||
if (storage != null) {
|
||||
storage.writeToNBT();
|
||||
}
|
||||
}
|
||||
|
||||
for (StorageFluid storage : fluidStorages) {
|
||||
for (IStorageDisk storage : fluidStorages) {
|
||||
if (storage != null) {
|
||||
storage.writeToNBT();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IItemHandler getDrops() {
|
||||
return new CombinedInvWrapper(inputDisks, outputDisks, upgrades);
|
||||
@@ -0,0 +1,110 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.network.node.diskmanipulator;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RSUtils;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDisk;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.StorageDiskType;
|
||||
import com.raoulvdberge.refinedstorage.tile.TileDiskDrive;
|
||||
import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class StorageFluidDiskManipulator implements IStorageDisk<FluidStack> {
|
||||
private NetworkNodeDiskManipulator diskManipulator;
|
||||
private IStorageDisk<FluidStack> parent;
|
||||
private int lastState;
|
||||
|
||||
public StorageFluidDiskManipulator(NetworkNodeDiskManipulator diskManipulator, IStorageDisk<FluidStack> parent) {
|
||||
this.diskManipulator = diskManipulator;
|
||||
this.parent = parent;
|
||||
this.lastState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity() {
|
||||
return parent.getCapacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVoiding() {
|
||||
return parent.isVoiding();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(ItemStack stack) {
|
||||
return parent.isValid(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChanged() {
|
||||
parent.onChanged();
|
||||
|
||||
diskManipulator.markDirty();
|
||||
|
||||
int currentState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||
|
||||
if (lastState != currentState) {
|
||||
lastState = currentState;
|
||||
|
||||
RSUtils.updateBlock(diskManipulator.getHolder().world(), diskManipulator.getHolder().pos());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT() {
|
||||
parent.readFromNBT();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT() {
|
||||
parent.writeToNBT();
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageDiskType getType() {
|
||||
return parent.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<FluidStack> getStacks() {
|
||||
return parent.getStacks();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public FluidStack insert(@Nonnull FluidStack stack, int size, boolean simulate) {
|
||||
if (!IFilterable.canTakeFluids(diskManipulator.getFluidFilters(), diskManipulator.getMode(), diskManipulator.getCompare(), stack)) {
|
||||
return RSUtils.copyStackWithSize(stack, size);
|
||||
}
|
||||
|
||||
return parent.insert(stack, size, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public FluidStack extract(@Nonnull FluidStack stack, int size, int flags, boolean simulate) {
|
||||
if (!IFilterable.canTakeFluids(diskManipulator.getFluidFilters(), diskManipulator.getMode(), diskManipulator.getCompare(), stack)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return parent.extract(stack, size, flags, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStored() {
|
||||
return parent.getStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return parent.getPriority();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCacheDelta(int storedPreInsertion, int size, @Nullable FluidStack remainder) {
|
||||
return parent.getCacheDelta(storedPreInsertion, size, remainder);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.network.node.diskmanipulator;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RSUtils;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDisk;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.StorageDiskType;
|
||||
import com.raoulvdberge.refinedstorage.tile.TileDiskDrive;
|
||||
import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class StorageItemDiskManipulator implements IStorageDisk<ItemStack> {
|
||||
private NetworkNodeDiskManipulator diskManipulator;
|
||||
private IStorageDisk<ItemStack> parent;
|
||||
private int lastState;
|
||||
|
||||
public StorageItemDiskManipulator(NetworkNodeDiskManipulator diskManipulator, IStorageDisk<ItemStack> parent) {
|
||||
this.diskManipulator = diskManipulator;
|
||||
this.parent = parent;
|
||||
this.lastState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity() {
|
||||
return parent.getCapacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVoiding() {
|
||||
return parent.isVoiding();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(ItemStack stack) {
|
||||
return parent.isValid(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChanged() {
|
||||
parent.onChanged();
|
||||
|
||||
diskManipulator.markDirty();
|
||||
|
||||
int currentState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||
|
||||
if (lastState != currentState) {
|
||||
lastState = currentState;
|
||||
|
||||
RSUtils.updateBlock(diskManipulator.getHolder().world(), diskManipulator.getHolder().pos());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT() {
|
||||
parent.readFromNBT();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT() {
|
||||
parent.writeToNBT();
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageDiskType getType() {
|
||||
return StorageDiskType.ITEMS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> getStacks() {
|
||||
return parent.getStacks();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ItemStack insert(@Nonnull ItemStack stack, int size, boolean simulate) {
|
||||
if (!IFilterable.canTake(diskManipulator.getItemFilters(), diskManipulator.getMode(), diskManipulator.getCompare(), stack)) {
|
||||
return ItemHandlerHelper.copyStackWithSize(stack, size);
|
||||
}
|
||||
|
||||
return parent.insert(stack, size, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ItemStack extract(@Nonnull ItemStack stack, int size, int flags, boolean simulate) {
|
||||
if (!IFilterable.canTake(diskManipulator.getItemFilters(), diskManipulator.getMode(), diskManipulator.getCompare(), stack)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return parent.extract(stack, size, flags, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStored() {
|
||||
return parent.getStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return parent.getPriority();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCacheDelta(int storedPreInsertion, int size, @Nullable ItemStack remainder) {
|
||||
return parent.getCacheDelta(storedPreInsertion, size, remainder);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.storage;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDisk;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDiskBehavior;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.StorageDiskType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
public class StorageDiskBehavior implements IStorageDiskBehavior {
|
||||
@Override
|
||||
public IStorageDisk<ItemStack> createItemStorage(NBTTagCompound tag, int capacity) {
|
||||
return new StorageDiskItem(tag, capacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStorageDisk<FluidStack> createFluidStorage(NBTTagCompound tag, int capacity) {
|
||||
return new StorageDiskFluid(tag, capacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getShareTag(StorageDiskType type, ItemStack stack) {
|
||||
switch (type) {
|
||||
case ITEMS:
|
||||
return StorageDiskItem.getShareTag(stack.getTagCompound());
|
||||
case FLUIDS:
|
||||
return StorageDiskFluid.getShareTag(stack.getTagCompound());
|
||||
default:
|
||||
throw new IllegalArgumentException("Expected items or fluids!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getTag(StorageDiskType type) {
|
||||
switch (type) {
|
||||
case ITEMS:
|
||||
return StorageDiskItem.getTag();
|
||||
case FLUIDS:
|
||||
return StorageDiskFluid.getTag();
|
||||
default:
|
||||
throw new IllegalArgumentException("Expected items or fluids!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.storage;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RSUtils;
|
||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorage;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDisk;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.StorageDiskType;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -14,14 +14,7 @@ import net.minecraftforge.fluids.FluidStack;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* A implementation of {@link IStorage<FluidStack>} that stores storage fluids in NBT.
|
||||
*/
|
||||
public abstract class StorageFluidNBT implements IStorage<FluidStack> {
|
||||
/**
|
||||
* The current save protocol that is used. It's set to every {@link StorageFluidNBT} to allow for
|
||||
* safe backwards compatibility breaks.
|
||||
*/
|
||||
public class StorageDiskFluid implements IStorageDisk<FluidStack> {
|
||||
private static final int PROTOCOL = 1;
|
||||
|
||||
private static final String NBT_PROTOCOL = "Protocol";
|
||||
@@ -31,24 +24,16 @@ public abstract class StorageFluidNBT implements IStorage<FluidStack> {
|
||||
|
||||
private NBTTagCompound tag;
|
||||
private int capacity;
|
||||
private INetworkNode node;
|
||||
|
||||
private NonNullList<FluidStack> stacks = NonNullList.create();
|
||||
|
||||
/**
|
||||
* @param tag The NBT tag we are reading from and writing the amount stored to, has to be initialized with {@link StorageFluidNBT#createNBT()} if it doesn't exist yet
|
||||
* @param capacity The capacity of this storage, -1 for infinite capacity
|
||||
* @param node A {@link INetworkNode} that the NBT storage is in, will be marked dirty when the storage changes
|
||||
*/
|
||||
public StorageFluidNBT(NBTTagCompound tag, int capacity, @Nullable INetworkNode node) {
|
||||
public StorageDiskFluid(NBTTagCompound tag, int capacity) {
|
||||
this.tag = tag;
|
||||
this.capacity = capacity;
|
||||
this.node = node;
|
||||
|
||||
readFromNBT();
|
||||
}
|
||||
|
||||
private void readFromNBT() {
|
||||
@Override
|
||||
public void readFromNBT() {
|
||||
NBTTagList list = (NBTTagList) tag.getTag(NBT_FLUIDS);
|
||||
|
||||
for (int i = 0; i < list.tagCount(); ++i) {
|
||||
@@ -60,9 +45,7 @@ public abstract class StorageFluidNBT implements IStorage<FluidStack> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the items to the NBT tag.
|
||||
*/
|
||||
@Override
|
||||
public void writeToNBT() {
|
||||
NBTTagList list = new NBTTagList();
|
||||
|
||||
@@ -74,6 +57,11 @@ public abstract class StorageFluidNBT implements IStorage<FluidStack> {
|
||||
tag.setInteger(NBT_PROTOCOL, PROTOCOL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageDiskType getType() {
|
||||
return StorageDiskType.FLUIDS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<FluidStack> getStacks() {
|
||||
return stacks;
|
||||
@@ -100,7 +88,7 @@ public abstract class StorageFluidNBT implements IStorage<FluidStack> {
|
||||
|
||||
otherStack.amount += remainingSpace;
|
||||
|
||||
onStorageChanged();
|
||||
onChanged();
|
||||
}
|
||||
|
||||
return isVoiding() ? null : RSUtils.copyStackWithSize(otherStack, size - remainingSpace);
|
||||
@@ -110,7 +98,7 @@ public abstract class StorageFluidNBT implements IStorage<FluidStack> {
|
||||
|
||||
otherStack.amount += size;
|
||||
|
||||
onStorageChanged();
|
||||
onChanged();
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -134,7 +122,7 @@ public abstract class StorageFluidNBT implements IStorage<FluidStack> {
|
||||
|
||||
stacks.add(RSUtils.copyStackWithSize(stack, remainingSpace));
|
||||
|
||||
onStorageChanged();
|
||||
onChanged();
|
||||
}
|
||||
|
||||
return isVoiding() ? null : RSUtils.copyStackWithSize(stack, size - remainingSpace);
|
||||
@@ -144,7 +132,7 @@ public abstract class StorageFluidNBT implements IStorage<FluidStack> {
|
||||
|
||||
stacks.add(RSUtils.copyStackWithSize(stack, size));
|
||||
|
||||
onStorageChanged();
|
||||
onChanged();
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -169,7 +157,7 @@ public abstract class StorageFluidNBT implements IStorage<FluidStack> {
|
||||
|
||||
tag.setInteger(NBT_STORED, getStored() - size);
|
||||
|
||||
onStorageChanged();
|
||||
onChanged();
|
||||
}
|
||||
|
||||
return RSUtils.copyStackWithSize(otherStack, size);
|
||||
@@ -179,22 +167,28 @@ public abstract class StorageFluidNBT implements IStorage<FluidStack> {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void onStorageChanged() {
|
||||
if (node != null) {
|
||||
node.markDirty();
|
||||
}
|
||||
@Override
|
||||
public void onChanged() {
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStored() {
|
||||
return getStoredFromNBT(tag);
|
||||
return getStored(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity() {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
protected boolean isVoiding() {
|
||||
@Override
|
||||
public boolean isVoiding() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -213,28 +207,26 @@ public abstract class StorageFluidNBT implements IStorage<FluidStack> {
|
||||
return inserted;
|
||||
}
|
||||
|
||||
public NBTTagCompound getTag() {
|
||||
return tag;
|
||||
@Override
|
||||
public boolean isValid(ItemStack stack) {
|
||||
return stack.hasTagCompound() && stack.getTagCompound().hasKey(NBT_FLUIDS) && stack.getTagCompound().hasKey(NBT_STORED);
|
||||
}
|
||||
|
||||
public static int getStoredFromNBT(NBTTagCompound tag) {
|
||||
return tag.getInteger(NBT_STORED);
|
||||
}
|
||||
|
||||
public static NBTTagCompound getNBTShareTag(NBTTagCompound tag) {
|
||||
public static NBTTagCompound getShareTag(NBTTagCompound tag) {
|
||||
NBTTagCompound otherTag = new NBTTagCompound();
|
||||
|
||||
otherTag.setInteger(NBT_STORED, getStoredFromNBT(tag));
|
||||
otherTag.setInteger(NBT_STORED, getStored(tag));
|
||||
otherTag.setTag(NBT_FLUIDS, new NBTTagList()); // To circumvent not being able to insert disks in Disk Drives (see FluidStorageNBT#isValid(ItemStack)).
|
||||
otherTag.setInteger(NBT_PROTOCOL, PROTOCOL);
|
||||
|
||||
return otherTag;
|
||||
}
|
||||
|
||||
/*
|
||||
* @return A NBT tag initialized with the fields that {@link NBTStorage} uses
|
||||
*/
|
||||
public static NBTTagCompound createNBT() {
|
||||
public static int getStored(NBTTagCompound tag) {
|
||||
return tag.getInteger(NBT_STORED);
|
||||
}
|
||||
|
||||
public static NBTTagCompound getTag() {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
|
||||
tag.setTag(NBT_FLUIDS, new NBTTagList());
|
||||
@@ -244,16 +236,8 @@ public abstract class StorageFluidNBT implements IStorage<FluidStack> {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public static boolean isValid(ItemStack stack) {
|
||||
return stack.hasTagCompound() && stack.getTagCompound().hasKey(NBT_FLUIDS) && stack.getTagCompound().hasKey(NBT_STORED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param stack The {@link ItemStack} to populate with the NBT tags from {@link StorageFluidNBT#createNBT()}
|
||||
* @return The provided {@link ItemStack} with NBT tags from {@link StorageFluidNBT#createNBT()}
|
||||
*/
|
||||
public static ItemStack createStackWithNBT(ItemStack stack) {
|
||||
stack.setTagCompound(createNBT());
|
||||
public static ItemStack initDisk(ItemStack stack) {
|
||||
stack.setTagCompound(getTag());
|
||||
|
||||
return stack;
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.storage;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorage;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDisk;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.StorageDiskType;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -17,11 +18,7 @@ import javax.annotation.Nullable;
|
||||
/**
|
||||
* A implementation of {@link IStorage<ItemStack>} that stores storage items in NBT.
|
||||
*/
|
||||
public abstract class StorageItemNBT implements IStorage<ItemStack> {
|
||||
/**
|
||||
* The current save protocol that is used. It's set to every {@link StorageItemNBT} to allow for
|
||||
* safe backwards compatibility breaks.
|
||||
*/
|
||||
public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
||||
private static final int PROTOCOL = 1;
|
||||
|
||||
private static final String NBT_PROTOCOL = "Protocol";
|
||||
@@ -37,25 +34,20 @@ public abstract class StorageItemNBT implements IStorage<ItemStack> {
|
||||
|
||||
private NBTTagCompound tag;
|
||||
private int capacity;
|
||||
@Nullable
|
||||
private INetworkNode node;
|
||||
|
||||
private NonNullList<ItemStack> stacks = NonNullList.create();
|
||||
|
||||
/**
|
||||
* @param tag The NBT tag we are reading from and writing the amount stored to, has to be initialized with {@link StorageItemNBT#createNBT()} if it doesn't exist yet
|
||||
* @param tag The NBT tag we are reading from and writing the amount stored to, has to be initialized with {@link StorageDiskItem#getTag()} if it doesn't exist yet
|
||||
* @param capacity The capacity of this storage, -1 for infinite capacity
|
||||
* @param node A {@link INetworkNode} that the NBT storage is in, will be marked dirty when the storage changes
|
||||
*/
|
||||
public StorageItemNBT(NBTTagCompound tag, int capacity, @Nullable INetworkNode node) {
|
||||
public StorageDiskItem(NBTTagCompound tag, int capacity) {
|
||||
this.tag = tag;
|
||||
this.capacity = capacity;
|
||||
this.node = node;
|
||||
|
||||
readFromNBT();
|
||||
}
|
||||
|
||||
private void readFromNBT() {
|
||||
@Override
|
||||
public void readFromNBT() {
|
||||
NBTTagList list = (NBTTagList) tag.getTag(NBT_ITEMS);
|
||||
|
||||
for (int i = 0; i < list.tagCount(); ++i) {
|
||||
@@ -76,9 +68,7 @@ public abstract class StorageItemNBT implements IStorage<ItemStack> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the items to the NBT tag.
|
||||
*/
|
||||
@Override
|
||||
public void writeToNBT() {
|
||||
NBTTagList list = new NBTTagList();
|
||||
|
||||
@@ -111,6 +101,11 @@ public abstract class StorageItemNBT implements IStorage<ItemStack> {
|
||||
tag.setInteger(NBT_PROTOCOL, PROTOCOL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageDiskType getType() {
|
||||
return StorageDiskType.ITEMS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> getStacks() {
|
||||
return stacks;
|
||||
@@ -137,7 +132,7 @@ public abstract class StorageItemNBT implements IStorage<ItemStack> {
|
||||
|
||||
otherStack.grow(remainingSpace);
|
||||
|
||||
onStorageChanged();
|
||||
onChanged();
|
||||
}
|
||||
|
||||
return isVoiding() ? null : ItemHandlerHelper.copyStackWithSize(otherStack, size - remainingSpace);
|
||||
@@ -147,7 +142,7 @@ public abstract class StorageItemNBT implements IStorage<ItemStack> {
|
||||
|
||||
otherStack.grow(size);
|
||||
|
||||
onStorageChanged();
|
||||
onChanged();
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -171,7 +166,7 @@ public abstract class StorageItemNBT implements IStorage<ItemStack> {
|
||||
|
||||
stacks.add(ItemHandlerHelper.copyStackWithSize(stack, remainingSpace));
|
||||
|
||||
onStorageChanged();
|
||||
onChanged();
|
||||
}
|
||||
|
||||
return isVoiding() ? null : ItemHandlerHelper.copyStackWithSize(stack, size - remainingSpace);
|
||||
@@ -181,7 +176,7 @@ public abstract class StorageItemNBT implements IStorage<ItemStack> {
|
||||
|
||||
stacks.add(ItemHandlerHelper.copyStackWithSize(stack, size));
|
||||
|
||||
onStorageChanged();
|
||||
onChanged();
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -206,7 +201,7 @@ public abstract class StorageItemNBT implements IStorage<ItemStack> {
|
||||
|
||||
tag.setInteger(NBT_STORED, getStored() - size);
|
||||
|
||||
onStorageChanged();
|
||||
onChanged();
|
||||
}
|
||||
|
||||
return ItemHandlerHelper.copyStackWithSize(otherStack, size);
|
||||
@@ -216,25 +211,36 @@ public abstract class StorageItemNBT implements IStorage<ItemStack> {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void onStorageChanged() {
|
||||
if (node != null) {
|
||||
node.markDirty();
|
||||
}
|
||||
@Override
|
||||
public int getStored() {
|
||||
return getStored(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStored() {
|
||||
return getStoredFromNBT(tag);
|
||||
public int getPriority() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity() {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
protected boolean isVoiding() {
|
||||
@Override
|
||||
public boolean isVoiding() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChanged() {
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(ItemStack stack) {
|
||||
return stack.hasTagCompound() && stack.getTagCompound().hasKey(NBT_ITEMS) && stack.getTagCompound().hasKey(NBT_STORED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCacheDelta(int storedPreInsertion, int size, @Nullable ItemStack remainder) {
|
||||
if (getAccessType() == AccessType.INSERT) {
|
||||
@@ -250,28 +256,21 @@ public abstract class StorageItemNBT implements IStorage<ItemStack> {
|
||||
return inserted;
|
||||
}
|
||||
|
||||
public NBTTagCompound getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public static int getStoredFromNBT(NBTTagCompound tag) {
|
||||
return tag.getInteger(NBT_STORED);
|
||||
}
|
||||
|
||||
public static NBTTagCompound getNBTShareTag(NBTTagCompound tag) {
|
||||
public static NBTTagCompound getShareTag(NBTTagCompound tag) {
|
||||
NBTTagCompound otherTag = new NBTTagCompound();
|
||||
|
||||
otherTag.setInteger(NBT_STORED, getStoredFromNBT(tag));
|
||||
otherTag.setInteger(NBT_STORED, getStored(tag));
|
||||
otherTag.setTag(NBT_ITEMS, new NBTTagList()); // To circumvent not being able to insert disks in Disk Drives (see ItemStorageNBT#isValid(ItemStack)).
|
||||
otherTag.setInteger(NBT_PROTOCOL, PROTOCOL);
|
||||
|
||||
return otherTag;
|
||||
}
|
||||
|
||||
/*
|
||||
* @return A NBT tag initialized with the fields that {@link NBTStorage} uses
|
||||
*/
|
||||
public static NBTTagCompound createNBT() {
|
||||
public static int getStored(NBTTagCompound tag) {
|
||||
return tag.getInteger(NBT_STORED);
|
||||
}
|
||||
|
||||
public static NBTTagCompound getTag() {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
|
||||
tag.setTag(NBT_ITEMS, new NBTTagList());
|
||||
@@ -281,16 +280,8 @@ public abstract class StorageItemNBT implements IStorage<ItemStack> {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public static boolean isValid(ItemStack stack) {
|
||||
return stack.hasTagCompound() && stack.getTagCompound().hasKey(NBT_ITEMS) && stack.getTagCompound().hasKey(NBT_STORED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param stack The {@link ItemStack} to populate with the NBT tags from {@link StorageItemNBT#createNBT()}
|
||||
* @return The provided {@link ItemStack} with NBT tags from {@link StorageItemNBT#createNBT()}
|
||||
*/
|
||||
public static ItemStack createStackWithNBT(ItemStack stack) {
|
||||
stack.setTagCompound(createNBT());
|
||||
public static ItemStack initDisk(ItemStack stack) {
|
||||
stack.setTagCompound(getTag());
|
||||
|
||||
return stack;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.raoulvdberge.refinedstorage.gui.sidebutton;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeDiskManipulator;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.diskmanipulator.NetworkNodeDiskManipulator;
|
||||
import com.raoulvdberge.refinedstorage.gui.GuiBase;
|
||||
import com.raoulvdberge.refinedstorage.tile.TileDiskManipulator;
|
||||
import com.raoulvdberge.refinedstorage.tile.data.TileDataManager;
|
||||
|
||||
@@ -1,29 +1,10 @@
|
||||
package com.raoulvdberge.refinedstorage.inventory;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RSItems;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageFluidNBT;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageItemNBT;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDiskProvider;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IItemValidator {
|
||||
IItemValidator ITEM_STORAGE_DISK = new ItemValidatorBasic(RSItems.STORAGE_DISK) {
|
||||
@Override
|
||||
public boolean isValid(ItemStack disk) {
|
||||
return super.isValid(disk) && StorageItemNBT.isValid(disk);
|
||||
}
|
||||
};
|
||||
IItemValidator FLUID_STORAGE_DISK = new ItemValidatorBasic(RSItems.FLUID_STORAGE_DISK) {
|
||||
@Override
|
||||
public boolean isValid(ItemStack disk) {
|
||||
return super.isValid(disk) && StorageFluidNBT.isValid(disk);
|
||||
}
|
||||
};
|
||||
IItemValidator STORAGE_DISK = new IItemValidator() {
|
||||
@Override
|
||||
public boolean isValid(ItemStack stack) {
|
||||
return ITEM_STORAGE_DISK.isValid(stack) || FLUID_STORAGE_DISK.isValid(stack);
|
||||
}
|
||||
};
|
||||
IItemValidator STORAGE_DISK = s -> s.getItem() instanceof IStorageDiskProvider && ((IStorageDiskProvider) s.getItem()).create(s).isValid(s);
|
||||
|
||||
boolean isValid(ItemStack stack);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.raoulvdberge.refinedstorage.item;
|
||||
import com.raoulvdberge.refinedstorage.RSBlocks;
|
||||
import com.raoulvdberge.refinedstorage.RSItems;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeFluidStorage;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageFluidNBT;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskFluid;
|
||||
import com.raoulvdberge.refinedstorage.block.EnumFluidStorageType;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.Entity;
|
||||
@@ -31,9 +31,9 @@ public class ItemBlockFluidStorage extends ItemBlockBase {
|
||||
NBTTagCompound tag = stack.getTagCompound().getCompoundTag(NetworkNodeFluidStorage.NBT_STORAGE);
|
||||
|
||||
if (type == EnumFluidStorageType.TYPE_CREATIVE) {
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored", StorageFluidNBT.getStoredFromNBT(tag)));
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored", StorageDiskFluid.getStored(tag)));
|
||||
} else {
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored_capacity", StorageFluidNBT.getStoredFromNBT(tag), type.getCapacity()));
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored_capacity", StorageDiskFluid.getStored(tag), type.getCapacity()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public class ItemBlockFluidStorage extends ItemBlockBase {
|
||||
|
||||
EnumFluidStorageType type = EnumFluidStorageType.getById(stack.getMetadata());
|
||||
|
||||
if (type != null && stack.getCount() == 1 && isValid(stack) && StorageFluidNBT.getStoredFromNBT(stack.getTagCompound().getCompoundTag(NetworkNodeFluidStorage.NBT_STORAGE)) <= 0 && stack.getMetadata() != ItemFluidStorageDisk.TYPE_CREATIVE && !world.isRemote && player.isSneaking()) {
|
||||
if (type != null && stack.getCount() == 1 && isValid(stack) && StorageDiskFluid.getStored(stack.getTagCompound().getCompoundTag(NetworkNodeFluidStorage.NBT_STORAGE)) <= 0 && stack.getMetadata() != ItemFluidStorageDisk.TYPE_CREATIVE && !world.isRemote && player.isSneaking()) {
|
||||
ItemStack storagePart = new ItemStack(RSItems.FLUID_STORAGE_PART, 1, stack.getMetadata());
|
||||
|
||||
if (!player.inventory.addItemStackToInventory(storagePart.copy())) {
|
||||
@@ -94,14 +94,14 @@ public class ItemBlockFluidStorage extends ItemBlockBase {
|
||||
return super.getNBTShareTag(stack);
|
||||
} else {
|
||||
NBTTagCompound shareTag = new NBTTagCompound();
|
||||
shareTag.setTag(NetworkNodeFluidStorage.NBT_STORAGE, StorageFluidNBT.getNBTShareTag(stack.getTagCompound().getCompoundTag(NetworkNodeFluidStorage.NBT_STORAGE)));
|
||||
shareTag.setTag(NetworkNodeFluidStorage.NBT_STORAGE, StorageDiskFluid.getShareTag(stack.getTagCompound().getCompoundTag(NetworkNodeFluidStorage.NBT_STORAGE)));
|
||||
return shareTag;
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack initNBT(ItemStack stack) {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setTag(NetworkNodeFluidStorage.NBT_STORAGE, StorageFluidNBT.createNBT());
|
||||
tag.setTag(NetworkNodeFluidStorage.NBT_STORAGE, StorageDiskFluid.getTag());
|
||||
stack.setTagCompound(tag);
|
||||
return stack;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.raoulvdberge.refinedstorage.item;
|
||||
import com.raoulvdberge.refinedstorage.RSBlocks;
|
||||
import com.raoulvdberge.refinedstorage.RSItems;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeStorage;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageItemNBT;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskItem;
|
||||
import com.raoulvdberge.refinedstorage.block.EnumItemStorageType;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.Entity;
|
||||
@@ -31,9 +31,9 @@ public class ItemBlockStorage extends ItemBlockBase {
|
||||
NBTTagCompound tag = stack.getTagCompound().getCompoundTag(NetworkNodeStorage.NBT_STORAGE);
|
||||
|
||||
if (type == EnumItemStorageType.TYPE_CREATIVE) {
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored", StorageItemNBT.getStoredFromNBT(tag)));
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored", StorageDiskItem.getStored(tag)));
|
||||
} else {
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored_capacity", StorageItemNBT.getStoredFromNBT(tag), type.getCapacity()));
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored_capacity", StorageDiskItem.getStored(tag), type.getCapacity()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public class ItemBlockStorage extends ItemBlockBase {
|
||||
|
||||
EnumItemStorageType type = EnumItemStorageType.getById(stack.getMetadata());
|
||||
|
||||
if (type != null && stack.getCount() == 1 && isValid(stack) && StorageItemNBT.getStoredFromNBT(stack.getTagCompound().getCompoundTag(NetworkNodeStorage.NBT_STORAGE)) <= 0 && stack.getMetadata() != ItemStorageDisk.TYPE_CREATIVE && !world.isRemote && player.isSneaking()) {
|
||||
if (type != null && stack.getCount() == 1 && isValid(stack) && StorageDiskItem.getStored(stack.getTagCompound().getCompoundTag(NetworkNodeStorage.NBT_STORAGE)) <= 0 && stack.getMetadata() != ItemStorageDisk.TYPE_CREATIVE && !world.isRemote && player.isSneaking()) {
|
||||
ItemStack storagePart = new ItemStack(RSItems.STORAGE_PART, 1, stack.getMetadata());
|
||||
|
||||
if (!player.inventory.addItemStackToInventory(storagePart.copy())) {
|
||||
@@ -94,14 +94,14 @@ public class ItemBlockStorage extends ItemBlockBase {
|
||||
return super.getNBTShareTag(stack);
|
||||
} else {
|
||||
NBTTagCompound shareTag = new NBTTagCompound();
|
||||
shareTag.setTag(NetworkNodeStorage.NBT_STORAGE, StorageItemNBT.getNBTShareTag(stack.getTagCompound().getCompoundTag(NetworkNodeStorage.NBT_STORAGE)));
|
||||
shareTag.setTag(NetworkNodeStorage.NBT_STORAGE, StorageDiskItem.getShareTag(stack.getTagCompound().getCompoundTag(NetworkNodeStorage.NBT_STORAGE)));
|
||||
return shareTag;
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack initNBT(ItemStack stack) {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setTag(NetworkNodeStorage.NBT_STORAGE, StorageItemNBT.createNBT());
|
||||
tag.setTag(NetworkNodeStorage.NBT_STORAGE, StorageDiskItem.getTag());
|
||||
stack.setTagCompound(tag);
|
||||
return stack;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package com.raoulvdberge.refinedstorage.item;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RSItems;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageFluidNBT;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDisk;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDiskProvider;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.StorageDiskType;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskFluid;
|
||||
import com.raoulvdberge.refinedstorage.block.EnumFluidStorageType;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
@@ -20,9 +24,10 @@ import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
|
||||
public class ItemFluidStorageDisk extends ItemBase {
|
||||
public class ItemFluidStorageDisk extends ItemBase implements IStorageDiskProvider<FluidStack> {
|
||||
public static final int TYPE_64K = 0;
|
||||
public static final int TYPE_128K = 1;
|
||||
public static final int TYPE_256K = 2;
|
||||
@@ -43,25 +48,15 @@ public class ItemFluidStorageDisk extends ItemBase {
|
||||
@Override
|
||||
public void getSubItems(Item item, CreativeTabs tab, NonNullList<ItemStack> subItems) {
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
subItems.add(StorageFluidNBT.createStackWithNBT(new ItemStack(item, 1, i)));
|
||||
subItems.add(API.instance().getStorageDiskBehavior().initDisk(StorageDiskType.FLUIDS, new ItemStack(item, 1, i)));
|
||||
}
|
||||
}
|
||||
|
||||
private void applyDebugDiskData(ItemStack stack) {
|
||||
if (debugDiskTag == null) {
|
||||
debugDiskTag = StorageFluidNBT.createNBT();
|
||||
debugDiskTag = API.instance().getStorageDiskBehavior().getTag(StorageDiskType.FLUIDS);
|
||||
|
||||
StorageFluidNBT storage = new StorageFluidNBT(debugDiskTag, -1, null) {
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVoiding() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
StorageDiskFluid storage = new StorageDiskFluid(debugDiskTag, -1);
|
||||
|
||||
for (Fluid fluid : FluidRegistry.getRegisteredFluids().values()) {
|
||||
storage.insert(new FluidStack(fluid, 0), Fluid.BUCKET_VOLUME * 1000, false);
|
||||
@@ -81,7 +76,7 @@ public class ItemFluidStorageDisk extends ItemBase {
|
||||
if (stack.getMetadata() == TYPE_DEBUG) {
|
||||
applyDebugDiskData(stack);
|
||||
} else {
|
||||
StorageFluidNBT.createStackWithNBT(stack);
|
||||
API.instance().getStorageDiskBehavior().initDisk(StorageDiskType.FLUIDS, stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,7 +85,9 @@ public class ItemFluidStorageDisk extends ItemBase {
|
||||
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
|
||||
ItemStack disk = player.getHeldItem(hand);
|
||||
|
||||
if (!world.isRemote && player.isSneaking() && StorageFluidNBT.isValid(disk) && StorageFluidNBT.getStoredFromNBT(disk.getTagCompound()) <= 0 && disk.getMetadata() != TYPE_CREATIVE) {
|
||||
IStorageDisk storage = create(disk);
|
||||
|
||||
if (!world.isRemote && player.isSneaking() && storage.isValid(disk) && storage.getStored() <= 0 && disk.getMetadata() != TYPE_CREATIVE) {
|
||||
ItemStack storagePart = new ItemStack(RSItems.FLUID_STORAGE_PART, 1, disk.getMetadata());
|
||||
|
||||
if (!player.inventory.addItemStackToInventory(storagePart.copy())) {
|
||||
@@ -105,13 +102,13 @@ public class ItemFluidStorageDisk extends ItemBase {
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack disk, EntityPlayer player, List<String> tooltip, boolean advanced) {
|
||||
if (StorageFluidNBT.isValid(disk)) {
|
||||
int capacity = EnumFluidStorageType.getById(disk.getItemDamage()).getCapacity();
|
||||
IStorageDisk storage = create(disk);
|
||||
|
||||
if (capacity == -1) {
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored", StorageFluidNBT.getStoredFromNBT(disk.getTagCompound())));
|
||||
if (storage.isValid(disk)) {
|
||||
if (storage.getCapacity() == -1) {
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored", storage.getStored()));
|
||||
} else {
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored_capacity", StorageFluidNBT.getStoredFromNBT(disk.getTagCompound()), capacity));
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored_capacity", storage.getStored(), storage.getCapacity()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,7 +117,7 @@ public class ItemFluidStorageDisk extends ItemBase {
|
||||
public void onCreated(ItemStack stack, World world, EntityPlayer player) {
|
||||
super.onCreated(stack, world, player);
|
||||
|
||||
StorageFluidNBT.createStackWithNBT(stack);
|
||||
API.instance().getStorageDiskBehavior().initDisk(StorageDiskType.FLUIDS, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -130,6 +127,12 @@ public class ItemFluidStorageDisk extends ItemBase {
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getNBTShareTag(ItemStack stack) {
|
||||
return StorageFluidNBT.getNBTShareTag(stack.getTagCompound());
|
||||
return API.instance().getStorageDiskBehavior().getShareTag(StorageDiskType.FLUIDS, stack);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IStorageDisk<FluidStack> create(ItemStack disk) {
|
||||
return API.instance().getStorageDiskBehavior().createFluidStorage(disk.getTagCompound(), EnumFluidStorageType.getById(disk.getItemDamage()).getCapacity());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package com.raoulvdberge.refinedstorage.item;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RSItems;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageItemNBT;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDisk;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDiskProvider;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.StorageDiskType;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskItem;
|
||||
import com.raoulvdberge.refinedstorage.block.EnumItemStorageType;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
@@ -17,10 +21,11 @@ import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class ItemStorageDisk extends ItemBase {
|
||||
public class ItemStorageDisk extends ItemBase implements IStorageDiskProvider<ItemStack> {
|
||||
public static final int TYPE_1K = 0;
|
||||
public static final int TYPE_4K = 1;
|
||||
public static final int TYPE_16K = 2;
|
||||
@@ -41,7 +46,7 @@ public class ItemStorageDisk extends ItemBase {
|
||||
@Override
|
||||
public void getSubItems(Item item, CreativeTabs tab, NonNullList<ItemStack> subItems) {
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
subItems.add(StorageItemNBT.createStackWithNBT(new ItemStack(item, 1, i)));
|
||||
subItems.add(API.instance().getStorageDiskBehavior().initDisk(StorageDiskType.ITEMS, new ItemStack(item, 1, i)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,26 +58,16 @@ public class ItemStorageDisk extends ItemBase {
|
||||
if (stack.getItemDamage() == TYPE_DEBUG) {
|
||||
applyDebugDiskData(stack);
|
||||
} else {
|
||||
StorageItemNBT.createStackWithNBT(stack);
|
||||
API.instance().getStorageDiskBehavior().initDisk(StorageDiskType.ITEMS, stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void applyDebugDiskData(ItemStack stack) {
|
||||
if (debugDiskTag == null) {
|
||||
debugDiskTag = StorageItemNBT.createNBT();
|
||||
debugDiskTag = API.instance().getStorageDiskBehavior().getTag(StorageDiskType.ITEMS);
|
||||
|
||||
StorageItemNBT storage = new StorageItemNBT(debugDiskTag, -1, null) {
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVoiding() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
StorageDiskItem storage = new StorageDiskItem(debugDiskTag, -1);
|
||||
|
||||
Iterator<Item> it = REGISTRY.iterator();
|
||||
|
||||
@@ -98,13 +93,13 @@ public class ItemStorageDisk extends ItemBase {
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack disk, EntityPlayer player, List<String> tooltip, boolean advanced) {
|
||||
if (StorageItemNBT.isValid(disk)) {
|
||||
int capacity = EnumItemStorageType.getById(disk.getItemDamage()).getCapacity();
|
||||
IStorageDisk storage = create(disk);
|
||||
|
||||
if (capacity == -1) {
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored", StorageItemNBT.getStoredFromNBT(disk.getTagCompound())));
|
||||
if (storage.isValid(disk)) {
|
||||
if (storage.getCapacity() == -1) {
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored", storage.getStored()));
|
||||
} else {
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored_capacity", StorageItemNBT.getStoredFromNBT(disk.getTagCompound()), capacity));
|
||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored_capacity", storage.getStored(), storage.getCapacity()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -113,7 +108,9 @@ public class ItemStorageDisk extends ItemBase {
|
||||
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
|
||||
ItemStack disk = player.getHeldItem(hand);
|
||||
|
||||
if (!world.isRemote && player.isSneaking() && StorageItemNBT.isValid(disk) && StorageItemNBT.getStoredFromNBT(disk.getTagCompound()) <= 0 && disk.getMetadata() != TYPE_CREATIVE) {
|
||||
IStorageDisk storage = create(disk);
|
||||
|
||||
if (!world.isRemote && player.isSneaking() && storage.isValid(disk) && storage.getStored() <= 0 && disk.getMetadata() != TYPE_CREATIVE) {
|
||||
ItemStack storagePart = new ItemStack(RSItems.STORAGE_PART, 1, disk.getMetadata());
|
||||
|
||||
if (!player.inventory.addItemStackToInventory(storagePart.copy())) {
|
||||
@@ -130,7 +127,7 @@ public class ItemStorageDisk extends ItemBase {
|
||||
public void onCreated(ItemStack stack, World world, EntityPlayer player) {
|
||||
super.onCreated(stack, world, player);
|
||||
|
||||
StorageItemNBT.createStackWithNBT(stack);
|
||||
API.instance().getStorageDiskBehavior().initDisk(StorageDiskType.ITEMS, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -140,6 +137,12 @@ public class ItemStorageDisk extends ItemBase {
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getNBTShareTag(ItemStack stack) {
|
||||
return StorageItemNBT.getNBTShareTag(stack.getTagCompound());
|
||||
return API.instance().getStorageDiskBehavior().getShareTag(StorageDiskType.ITEMS, stack);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IStorageDisk<ItemStack> create(ItemStack disk) {
|
||||
return API.instance().getStorageDiskBehavior().createItemStorage(disk.getTagCompound(), EnumItemStorageType.getById(disk.getItemDamage()).getCapacity());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@ import com.raoulvdberge.refinedstorage.apiimpl.network.readerwriter.ReaderWriter
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.readerwriter.ReaderWriterHandlerItems;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.readerwriter.ReaderWriterHandlerRedstone;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.solderer.*;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageFluidNBT;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageItemNBT;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskFluid;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskItem;
|
||||
import com.raoulvdberge.refinedstorage.block.*;
|
||||
import com.raoulvdberge.refinedstorage.gui.GuiHandler;
|
||||
import com.raoulvdberge.refinedstorage.integration.craftingtweaks.IntegrationCraftingTweaks;
|
||||
@@ -565,7 +565,7 @@ public class ProxyCommon {
|
||||
|
||||
// Storage Disks
|
||||
for (int type = 0; type <= 3; ++type) {
|
||||
ItemStack disk = StorageItemNBT.createStackWithNBT(new ItemStack(RSItems.STORAGE_DISK, 1, type));
|
||||
ItemStack disk = StorageDiskItem.initDisk(new ItemStack(RSItems.STORAGE_DISK, 1, type));
|
||||
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(disk,
|
||||
"GRG",
|
||||
@@ -585,7 +585,7 @@ public class ProxyCommon {
|
||||
|
||||
// Fluid Storage Disks
|
||||
for (int type = 0; type <= 3; ++type) {
|
||||
ItemStack disk = StorageFluidNBT.createStackWithNBT(new ItemStack(RSItems.FLUID_STORAGE_DISK, 1, type));
|
||||
ItemStack disk = StorageDiskFluid.initDisk(new ItemStack(RSItems.FLUID_STORAGE_DISK, 1, type));
|
||||
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(disk,
|
||||
"GRG",
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package com.raoulvdberge.refinedstorage.tile;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeDiskDrive;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageFluidNBT;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageItemNBT;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDisk;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.diskdrive.NetworkNodeDiskDrive;
|
||||
import com.raoulvdberge.refinedstorage.tile.config.*;
|
||||
import com.raoulvdberge.refinedstorage.tile.data.TileDataParameter;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -63,7 +62,7 @@ public class TileDiskDrive extends TileNode<NetworkNodeDiskDrive> {
|
||||
return diskState;
|
||||
}
|
||||
|
||||
public static void writeDiskState(NBTTagCompound tag, int disks, boolean connected, StorageItemNBT[] itemStorages, StorageFluidNBT[] fluidStorages) {
|
||||
public static void writeDiskState(NBTTagCompound tag, int disks, boolean connected, IStorageDisk[] itemStorages, IStorageDisk[] fluidStorages) {
|
||||
for (int i = 0; i < disks; ++i) {
|
||||
int state = DISK_STATE_NONE;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.raoulvdberge.refinedstorage.tile;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeDiskManipulator;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.diskmanipulator.NetworkNodeDiskManipulator;
|
||||
import com.raoulvdberge.refinedstorage.tile.config.IComparable;
|
||||
import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
|
||||
import com.raoulvdberge.refinedstorage.tile.config.IType;
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.raoulvdberge.refinedstorage.tile;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeFluidStorage;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageFluidNBT;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskFluid;
|
||||
import com.raoulvdberge.refinedstorage.tile.config.*;
|
||||
import com.raoulvdberge.refinedstorage.tile.data.ITileDataProducer;
|
||||
import com.raoulvdberge.refinedstorage.tile.data.TileDataParameter;
|
||||
@@ -19,7 +19,7 @@ public class TileFluidStorage extends TileNode<NetworkNodeFluidStorage> {
|
||||
public static final TileDataParameter<Integer> STORED = new TileDataParameter<>(DataSerializers.VARINT, 0, new ITileDataProducer<Integer, TileFluidStorage>() {
|
||||
@Override
|
||||
public Integer getValue(TileFluidStorage tile) {
|
||||
return StorageFluidNBT.getStoredFromNBT(tile.getNode().getStorageTag());
|
||||
return StorageDiskFluid.getStored(tile.getNode().getStorageTag());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.raoulvdberge.refinedstorage.tile;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeStorage;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageItemNBT;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskItem;
|
||||
import com.raoulvdberge.refinedstorage.tile.config.*;
|
||||
import com.raoulvdberge.refinedstorage.tile.data.ITileDataProducer;
|
||||
import com.raoulvdberge.refinedstorage.tile.data.TileDataParameter;
|
||||
@@ -18,7 +18,7 @@ public class TileStorage extends TileNode<NetworkNodeStorage> {
|
||||
public static final TileDataParameter<Integer> STORED = new TileDataParameter<>(DataSerializers.VARINT, 0, new ITileDataProducer<Integer, TileStorage>() {
|
||||
@Override
|
||||
public Integer getValue(TileStorage tile) {
|
||||
return StorageItemNBT.getStoredFromNBT(tile.getNode().getStorageTag());
|
||||
return StorageDiskItem.getStored(tile.getNode().getStorageTag());
|
||||
}
|
||||
});
|
||||
public static final TileDataParameter<Boolean> VOID_EXCESS = IExcessVoidable.createParameter();
|
||||
|
||||
Reference in New Issue
Block a user