New storage disk system.
This commit is contained in:
@@ -13,7 +13,9 @@ import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeRegistry;
|
|||||||
import com.raoulvdberge.refinedstorage.api.network.readerwriter.IReaderWriterChannel;
|
import com.raoulvdberge.refinedstorage.api.network.readerwriter.IReaderWriterChannel;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.readerwriter.IReaderWriterHandlerRegistry;
|
import com.raoulvdberge.refinedstorage.api.network.readerwriter.IReaderWriterHandlerRegistry;
|
||||||
import com.raoulvdberge.refinedstorage.api.solderer.ISoldererRegistry;
|
import com.raoulvdberge.refinedstorage.api.solderer.ISoldererRegistry;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDiskBehavior;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskManager;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskRegistry;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskSync;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IQuantityFormatter;
|
import com.raoulvdberge.refinedstorage.api.util.IQuantityFormatter;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IStackList;
|
import com.raoulvdberge.refinedstorage.api.util.IStackList;
|
||||||
@@ -59,12 +61,6 @@ public interface IRSAPI {
|
|||||||
*/
|
*/
|
||||||
INetworkNodeManager getNetworkNodeManager(World world);
|
INetworkNodeManager getNetworkNodeManager(World world);
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the default storage disk behavior
|
|
||||||
*/
|
|
||||||
@Nonnull
|
|
||||||
IStorageDiskBehavior getDefaultStorageDiskBehavior();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the solderer registry
|
* @return the solderer registry
|
||||||
*/
|
*/
|
||||||
@@ -127,6 +123,12 @@ public interface IRSAPI {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
IWirelessGridRegistry getWirelessGridRegistry();
|
IWirelessGridRegistry getWirelessGridRegistry();
|
||||||
|
|
||||||
|
IStorageDiskRegistry getStorageDiskRegistry();
|
||||||
|
|
||||||
|
IStorageDiskManager getStorageDiskManager(World world);
|
||||||
|
|
||||||
|
IStorageDiskSync getStorageDiskSync();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens a wireless grid for the given player.
|
* Opens a wireless grid for the given player.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,51 +0,0 @@
|
|||||||
package com.raoulvdberge.refinedstorage.api.storage;
|
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a storage disk.
|
|
||||||
*
|
|
||||||
* @param <T> the storage
|
|
||||||
*/
|
|
||||||
public interface IStorageDisk<T> extends IStorage<T> {
|
|
||||||
/**
|
|
||||||
* @return the capacity of this storage disk
|
|
||||||
*/
|
|
||||||
int getCapacity();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether the storage disk is valid.
|
|
||||||
* Determines if it can be inserted in a disk drive.
|
|
||||||
*
|
|
||||||
* @param stack the disk
|
|
||||||
* @return true if the disk is valid, false otherwise
|
|
||||||
*/
|
|
||||||
boolean isValid(ItemStack stack);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* When this storage disk is inserted into a storage disk container, it has to adjust to the container's settings
|
|
||||||
* and use the following parameters instead.
|
|
||||||
*
|
|
||||||
* @param listener the listener to be called when the storage changes
|
|
||||||
* @param voidExcess a supplier whether this storage should void excess stacks
|
|
||||||
* @param accessType the access type of the container
|
|
||||||
*/
|
|
||||||
void onPassContainerContext(Runnable listener, Supplier<Boolean> voidExcess, Supplier<AccessType> accessType);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads the storage from NBT.
|
|
||||||
*/
|
|
||||||
void readFromNBT();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes the storage to NBT.
|
|
||||||
*/
|
|
||||||
void writeToNBT();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the storage type
|
|
||||||
*/
|
|
||||||
StorageDiskType getType();
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package com.raoulvdberge.refinedstorage.api.storage;
|
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implement this on an item that provides storage.
|
|
||||||
*/
|
|
||||||
public interface IStorageDiskProvider<T> {
|
|
||||||
/**
|
|
||||||
* @param disk the disk
|
|
||||||
* @return the storage that this disk provides
|
|
||||||
*/
|
|
||||||
@Nonnull
|
|
||||||
IStorageDisk<T> create(ItemStack disk);
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package com.raoulvdberge.refinedstorage.api.storage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The storage disk type.
|
|
||||||
*/
|
|
||||||
public enum StorageDiskType {
|
|
||||||
ITEMS,
|
|
||||||
FLUIDS
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.api.storage.disk;
|
||||||
|
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.IStorage;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a storage disk.
|
||||||
|
*
|
||||||
|
* @param <T> the storage
|
||||||
|
*/
|
||||||
|
public interface IStorageDisk<T> extends IStorage<T> {
|
||||||
|
/**
|
||||||
|
* @return the capacity of this storage disk
|
||||||
|
*/
|
||||||
|
int getCapacity();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When this storage disk is inserted into a storage disk container, it has to adjust to the container's settings
|
||||||
|
* and use the following parameters instead.
|
||||||
|
*
|
||||||
|
* @param listener the listener to be called when the storage changes, or null for no listener
|
||||||
|
* @param context the container context, containing some settings
|
||||||
|
*/
|
||||||
|
void setSettings(@Nullable IStorageDiskListener listener, IStorageDiskContainerContext context);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes the storage to NBT.
|
||||||
|
*/
|
||||||
|
NBTTagCompound writeToNbt();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the factory id as registered in {@link IStorageDiskRegistry}
|
||||||
|
*/
|
||||||
|
String getId();
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.api.storage.disk;
|
||||||
|
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores relevant information about the container where the {@link IStorageDisk} is in.
|
||||||
|
*/
|
||||||
|
public interface IStorageDiskContainerContext {
|
||||||
|
/**
|
||||||
|
* @return true if excess stacks can be voided, false otherwise
|
||||||
|
*/
|
||||||
|
boolean isVoidExcess();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the access type
|
||||||
|
*/
|
||||||
|
AccessType getAccessType();
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.api.storage.disk;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a storage disk from NBT or on-demand.
|
||||||
|
*
|
||||||
|
* @param <T>
|
||||||
|
*/
|
||||||
|
public interface IStorageDiskFactory<T> {
|
||||||
|
/**
|
||||||
|
* Creates a storage disk based on NBT.
|
||||||
|
*
|
||||||
|
* @param world the world
|
||||||
|
* @param tag the tag
|
||||||
|
* @return the storage disk
|
||||||
|
*/
|
||||||
|
IStorageDisk<T> createFromNbt(World world, NBTTagCompound tag);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a storage disk on-demand.
|
||||||
|
*
|
||||||
|
* @param world the world
|
||||||
|
* @param capacity the capacity
|
||||||
|
* @return the storage disk
|
||||||
|
*/
|
||||||
|
IStorageDisk<T> create(World world, int capacity);
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.api.storage.disk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listens to storage disk changes.
|
||||||
|
*/
|
||||||
|
public interface IStorageDiskListener {
|
||||||
|
/**
|
||||||
|
* Called when any change happens.
|
||||||
|
*/
|
||||||
|
void onChanged();
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.api.storage.disk;
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores storage disks.
|
||||||
|
*/
|
||||||
|
public interface IStorageDiskManager {
|
||||||
|
/**
|
||||||
|
* Gets a storage disk by id.
|
||||||
|
*
|
||||||
|
* @param id the id
|
||||||
|
* @return the storage disk, or null if no storage disk is found
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
IStorageDisk get(UUID id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a storage disk by disk stack (a {@link IStorageDiskProvider}).
|
||||||
|
*
|
||||||
|
* @param disk the disk stack
|
||||||
|
* @return the storage disk, or null if no storage disk is found
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
IStorageDisk getByStack(ItemStack disk);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a storage disk.
|
||||||
|
*
|
||||||
|
* @param id the id
|
||||||
|
* @param disk the disk
|
||||||
|
*/
|
||||||
|
void set(UUID id, IStorageDisk disk);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks this manager for saving.
|
||||||
|
*/
|
||||||
|
void markForSaving();
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.api.storage.disk;
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps disk items to an id.
|
||||||
|
* Implement this on a disk item.
|
||||||
|
*/
|
||||||
|
public interface IStorageDiskProvider {
|
||||||
|
/**
|
||||||
|
* @param disk the disk
|
||||||
|
* @return the id of the disk
|
||||||
|
*/
|
||||||
|
UUID getId(ItemStack disk);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param disk the disk
|
||||||
|
* @return true if the given disk has an id set, false otherwise
|
||||||
|
*/
|
||||||
|
boolean isValid(ItemStack disk);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the storage type
|
||||||
|
*/
|
||||||
|
StorageDiskType getType();
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.api.storage.disk;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores factories for reproducing storage disks from disk.
|
||||||
|
*/
|
||||||
|
public interface IStorageDiskRegistry {
|
||||||
|
/**
|
||||||
|
* Adds a factory.
|
||||||
|
*
|
||||||
|
* @param id the id of this factory
|
||||||
|
* @param factory the factory
|
||||||
|
*/
|
||||||
|
void add(String id, IStorageDiskFactory factory);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a factory.
|
||||||
|
*
|
||||||
|
* @param id the factory id
|
||||||
|
* @return the factory, or null if no factory was found
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
IStorageDiskFactory get(String id);
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.api.storage.disk;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to send requests to the server to get storage disk information ({@link IStorageDiskSyncData}).
|
||||||
|
*/
|
||||||
|
public interface IStorageDiskSync {
|
||||||
|
/**
|
||||||
|
* Gets disk data by disk id.
|
||||||
|
* Can return null if there is no response yet.
|
||||||
|
*
|
||||||
|
* @param id the disk id
|
||||||
|
* @return the disk data, or null if there was no response from the server yet
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
IStorageDiskSyncData getData(UUID id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a request to the server to get information from a storage disk.
|
||||||
|
* Can be called in a loop or in high frequency, the request is throttled.
|
||||||
|
*
|
||||||
|
* @param id the disk id
|
||||||
|
*/
|
||||||
|
void sendRequest(UUID id);
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.api.storage.disk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains storage disk data.
|
||||||
|
*/
|
||||||
|
public interface IStorageDiskSyncData {
|
||||||
|
/**
|
||||||
|
* @return the amount stored
|
||||||
|
*/
|
||||||
|
int getStored();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the capacity, or -1 if infinite capacity
|
||||||
|
*/
|
||||||
|
int getCapacity();
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.api.storage.disk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The storage disk type.
|
||||||
|
*/
|
||||||
|
public enum StorageDiskType {
|
||||||
|
ITEM,
|
||||||
|
FLUID
|
||||||
|
}
|
||||||
@@ -17,7 +17,9 @@ import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeRegistry;
|
|||||||
import com.raoulvdberge.refinedstorage.api.network.readerwriter.IReaderWriterChannel;
|
import com.raoulvdberge.refinedstorage.api.network.readerwriter.IReaderWriterChannel;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.readerwriter.IReaderWriterHandlerRegistry;
|
import com.raoulvdberge.refinedstorage.api.network.readerwriter.IReaderWriterHandlerRegistry;
|
||||||
import com.raoulvdberge.refinedstorage.api.solderer.ISoldererRegistry;
|
import com.raoulvdberge.refinedstorage.api.solderer.ISoldererRegistry;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDiskBehavior;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskManager;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskRegistry;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskSync;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IQuantityFormatter;
|
import com.raoulvdberge.refinedstorage.api.util.IQuantityFormatter;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IStackList;
|
import com.raoulvdberge.refinedstorage.api.util.IStackList;
|
||||||
@@ -31,7 +33,9 @@ import com.raoulvdberge.refinedstorage.apiimpl.network.grid.wireless.WirelessGri
|
|||||||
import com.raoulvdberge.refinedstorage.apiimpl.network.readerwriter.ReaderWriterChannel;
|
import com.raoulvdberge.refinedstorage.apiimpl.network.readerwriter.ReaderWriterChannel;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.network.readerwriter.ReaderWriterHandlerRegistry;
|
import com.raoulvdberge.refinedstorage.apiimpl.network.readerwriter.ReaderWriterHandlerRegistry;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.solderer.SoldererRegistry;
|
import com.raoulvdberge.refinedstorage.apiimpl.solderer.SoldererRegistry;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskBehavior;
|
import com.raoulvdberge.refinedstorage.apiimpl.storage.disk.StorageDiskManager;
|
||||||
|
import com.raoulvdberge.refinedstorage.apiimpl.storage.disk.StorageDiskRegistry;
|
||||||
|
import com.raoulvdberge.refinedstorage.apiimpl.storage.disk.StorageDiskSync;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.util.Comparer;
|
import com.raoulvdberge.refinedstorage.apiimpl.util.Comparer;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.util.QuantityFormatter;
|
import com.raoulvdberge.refinedstorage.apiimpl.util.QuantityFormatter;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.util.StackListFluid;
|
import com.raoulvdberge.refinedstorage.apiimpl.util.StackListFluid;
|
||||||
@@ -61,13 +65,14 @@ public class API implements IRSAPI {
|
|||||||
private IComparer comparer = new Comparer();
|
private IComparer comparer = new Comparer();
|
||||||
private IQuantityFormatter quantityFormatter = new QuantityFormatter();
|
private IQuantityFormatter quantityFormatter = new QuantityFormatter();
|
||||||
private INetworkNodeRegistry networkNodeRegistry = new NetworkNodeRegistry();
|
private INetworkNodeRegistry networkNodeRegistry = new NetworkNodeRegistry();
|
||||||
private IStorageDiskBehavior storageDiskBehavior = new StorageDiskBehavior();
|
|
||||||
private ISoldererRegistry soldererRegistry = new SoldererRegistry();
|
private ISoldererRegistry soldererRegistry = new SoldererRegistry();
|
||||||
private ICraftingTaskRegistry craftingTaskRegistry = new CraftingTaskRegistry();
|
private ICraftingTaskRegistry craftingTaskRegistry = new CraftingTaskRegistry();
|
||||||
private ICraftingMonitorElementRegistry craftingMonitorElementRegistry = new CraftingMonitorElementRegistry();
|
private ICraftingMonitorElementRegistry craftingMonitorElementRegistry = new CraftingMonitorElementRegistry();
|
||||||
private ICraftingPreviewElementRegistry craftingPreviewElementRegistry = new CraftingPreviewElementRegistry();
|
private ICraftingPreviewElementRegistry craftingPreviewElementRegistry = new CraftingPreviewElementRegistry();
|
||||||
private IReaderWriterHandlerRegistry readerWriterHandlerRegistry = new ReaderWriterHandlerRegistry();
|
private IReaderWriterHandlerRegistry readerWriterHandlerRegistry = new ReaderWriterHandlerRegistry();
|
||||||
private IWirelessGridRegistry gridRegistry = new WirelessGridRegistry();
|
private IWirelessGridRegistry gridRegistry = new WirelessGridRegistry();
|
||||||
|
private IStorageDiskRegistry storageDiskRegistry = new StorageDiskRegistry();
|
||||||
|
private IStorageDiskSync storageDiskSync = new StorageDiskSync();
|
||||||
|
|
||||||
public static IRSAPI instance() {
|
public static IRSAPI instance() {
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
@@ -113,7 +118,7 @@ public class API implements IRSAPI {
|
|||||||
@Override
|
@Override
|
||||||
public INetworkNodeManager getNetworkNodeManager(World world) {
|
public INetworkNodeManager getNetworkNodeManager(World world) {
|
||||||
if (world.isRemote) {
|
if (world.isRemote) {
|
||||||
throw new IllegalStateException("Attempting to access network node manager on the client");
|
throw new IllegalArgumentException("Attempting to access network node manager on the client");
|
||||||
}
|
}
|
||||||
|
|
||||||
MapStorage storage = world.getPerWorldStorage();
|
MapStorage storage = world.getPerWorldStorage();
|
||||||
@@ -130,12 +135,6 @@ public class API implements IRSAPI {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nonnull
|
|
||||||
public IStorageDiskBehavior getDefaultStorageDiskBehavior() {
|
|
||||||
return storageDiskBehavior;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public ISoldererRegistry getSoldererRegistry() {
|
public ISoldererRegistry getSoldererRegistry() {
|
||||||
@@ -196,6 +195,36 @@ public class API implements IRSAPI {
|
|||||||
return gridRegistry;
|
return gridRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IStorageDiskRegistry getStorageDiskRegistry() {
|
||||||
|
return storageDiskRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IStorageDiskManager getStorageDiskManager(World world) {
|
||||||
|
if (world.isRemote) {
|
||||||
|
throw new IllegalArgumentException("Attempting to access storage disk manager on the client");
|
||||||
|
}
|
||||||
|
|
||||||
|
MapStorage storage = world.getMapStorage();
|
||||||
|
StorageDiskManager instance = (StorageDiskManager) storage.getOrLoadData(StorageDiskManager.class, StorageDiskManager.NAME);
|
||||||
|
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new StorageDiskManager(StorageDiskManager.NAME);
|
||||||
|
|
||||||
|
storage.setData(StorageDiskManager.NAME, instance);
|
||||||
|
} else {
|
||||||
|
instance.tryReadDisks(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IStorageDiskSync getStorageDiskSync() {
|
||||||
|
return storageDiskSync;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void openWirelessGrid(EntityPlayer player, EnumHand hand, int networkDimension, int id) {
|
public void openWirelessGrid(EntityPlayer player, EnumHand hand, int networkDimension, int id) {
|
||||||
player.openGui(RS.INSTANCE, RSGui.WIRELESS_GRID, player.getEntityWorld(), hand.ordinal(), networkDimension, id);
|
player.openGui(RS.INSTANCE, RSGui.WIRELESS_GRID, player.getEntityWorld(), hand.ordinal(), networkDimension, id);
|
||||||
|
|||||||
@@ -28,27 +28,23 @@ public class NetworkNodeManager extends WorldSavedData implements INetworkNodeMa
|
|||||||
|
|
||||||
private ConcurrentHashMap<BlockPos, INetworkNode> nodes = new ConcurrentHashMap<>();
|
private ConcurrentHashMap<BlockPos, INetworkNode> nodes = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public NetworkNodeManager(String s) {
|
public NetworkNodeManager(String name) {
|
||||||
super(s);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT(NBTTagCompound tag) {
|
public void readFromNBT(NBTTagCompound tag) {
|
||||||
ConcurrentHashMap<BlockPos, INetworkNode> newNodes = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
if (tag.hasKey(NBT_NODES)) {
|
if (tag.hasKey(NBT_NODES)) {
|
||||||
this.nodesTag = tag.getTagList(NBT_NODES, Constants.NBT.TAG_COMPOUND);
|
this.nodesTag = tag.getTagList(NBT_NODES, Constants.NBT.TAG_COMPOUND);
|
||||||
this.canReadNodes = true;
|
this.canReadNodes = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.nodes = newNodes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tryReadNodes(World world) {
|
public void tryReadNodes(World world) {
|
||||||
if (canReadNodes) {
|
if (this.canReadNodes) {
|
||||||
canReadNodes = false;
|
this.canReadNodes = false;
|
||||||
|
|
||||||
nodes.clear();
|
this.nodes.clear();
|
||||||
|
|
||||||
for (int i = 0; i < nodesTag.tagCount(); ++i) {
|
for (int i = 0; i < nodesTag.tagCount(); ++i) {
|
||||||
NBTTagCompound nodeTag = nodesTag.getCompoundTagAt(i);
|
NBTTagCompound nodeTag = nodesTag.getCompoundTagAt(i);
|
||||||
@@ -69,7 +65,7 @@ public class NetworkNodeManager extends WorldSavedData implements INetworkNodeMa
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (node != null) {
|
if (node != null) {
|
||||||
nodes.put(pos, node);
|
this.nodes.put(pos, node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,10 @@ public abstract class NetworkNode implements INetworkNode, INetworkNodeVisitor {
|
|||||||
private boolean active;
|
private boolean active;
|
||||||
|
|
||||||
public NetworkNode(World world, BlockPos pos) {
|
public NetworkNode(World world, BlockPos pos) {
|
||||||
|
if (world == null) {
|
||||||
|
throw new IllegalArgumentException("World cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
this.world = world;
|
this.world = world;
|
||||||
this.pos = pos;
|
this.pos = pos;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import com.raoulvdberge.refinedstorage.api.storage.IStorage;
|
|||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageProvider;
|
import com.raoulvdberge.refinedstorage.api.storage.IStorageProvider;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageCacheFluid;
|
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageCacheFluid;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskFluid;
|
|
||||||
import com.raoulvdberge.refinedstorage.block.BlockFluidStorage;
|
import com.raoulvdberge.refinedstorage.block.BlockFluidStorage;
|
||||||
import com.raoulvdberge.refinedstorage.block.FluidStorageType;
|
import com.raoulvdberge.refinedstorage.block.FluidStorageType;
|
||||||
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerFluid;
|
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerFluid;
|
||||||
@@ -24,42 +23,11 @@ import net.minecraft.util.math.BlockPos;
|
|||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class NetworkNodeFluidStorage extends NetworkNode implements IGuiStorage, IStorageProvider, IComparable, IFilterable, IPrioritizable, IExcessVoidable, IAccessType {
|
public class NetworkNodeFluidStorage extends NetworkNode implements IGuiStorage, IStorageProvider, IComparable, IFilterable, IPrioritizable, IExcessVoidable, IAccessType {
|
||||||
public static final String ID = "fluid_storage";
|
public static final String ID = "fluid_storage";
|
||||||
|
|
||||||
class StorageFluid extends StorageDiskFluid {
|
|
||||||
StorageFluid(NBTTagCompound tag) {
|
|
||||||
super(tag, NetworkNodeFluidStorage.this.getCapacity());
|
|
||||||
|
|
||||||
this.onPassContainerContext(
|
|
||||||
NetworkNodeFluidStorage.this::markDirty,
|
|
||||||
NetworkNodeFluidStorage.this::getVoidExcess,
|
|
||||||
NetworkNodeFluidStorage.this::getAccessType
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getPriority() {
|
|
||||||
return priority;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public FluidStack insert(@Nonnull FluidStack stack, int size, boolean simulate) {
|
|
||||||
if (!IFilterable.canTakeFluids(filters, mode, compare, stack)) {
|
|
||||||
return StackUtils.copy(stack, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.insert(stack, size, simulate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final String NBT_STORAGE = "Storage";
|
|
||||||
|
|
||||||
private static final String NBT_PRIORITY = "Priority";
|
private static final String NBT_PRIORITY = "Priority";
|
||||||
private static final String NBT_COMPARE = "Compare";
|
private static final String NBT_COMPARE = "Compare";
|
||||||
private static final String NBT_MODE = "Mode";
|
private static final String NBT_MODE = "Mode";
|
||||||
@@ -67,9 +35,6 @@ public class NetworkNodeFluidStorage extends NetworkNode implements IGuiStorage,
|
|||||||
|
|
||||||
private ItemHandlerFluid filters = new ItemHandlerFluid(9, new ItemHandlerListenerNetworkNode(this));
|
private ItemHandlerFluid filters = new ItemHandlerFluid(9, new ItemHandlerListenerNetworkNode(this));
|
||||||
|
|
||||||
private StorageFluid storage = new StorageFluid(StorageDiskFluid.getTag());
|
|
||||||
private NBTTagCompound storageTagToRead;
|
|
||||||
|
|
||||||
private FluidStorageType type;
|
private FluidStorageType type;
|
||||||
|
|
||||||
private AccessType accessType = AccessType.INSERT_EXTRACT;
|
private AccessType accessType = AccessType.INSERT_EXTRACT;
|
||||||
@@ -87,33 +52,6 @@ public class NetworkNodeFluidStorage extends NetworkNode implements IGuiStorage,
|
|||||||
return RS.INSTANCE.config.fluidStorageUsage;
|
return RS.INSTANCE.config.fluidStorageUsage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update() {
|
|
||||||
super.update();
|
|
||||||
|
|
||||||
if (storageTagToRead != null) {
|
|
||||||
storage = new StorageFluid(storageTagToRead);
|
|
||||||
|
|
||||||
storage.readFromNBT();
|
|
||||||
|
|
||||||
if (network != null) {
|
|
||||||
network.getFluidStorageCache().invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
storageTagToRead = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPlacedWithStorage(NBTTagCompound tag) {
|
|
||||||
storageTagToRead = tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onBreak() {
|
|
||||||
if (storage != null) {
|
|
||||||
storage.writeToNBT();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConnectedStateChange(INetwork network, boolean state) {
|
public void onConnectedStateChange(INetwork network, boolean state) {
|
||||||
super.onConnectedStateChange(network, state);
|
super.onConnectedStateChange(network, state);
|
||||||
@@ -128,18 +66,7 @@ public class NetworkNodeFluidStorage extends NetworkNode implements IGuiStorage,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addFluidStorages(List<IStorage<FluidStack>> storages) {
|
public void addFluidStorages(List<IStorage<FluidStack>> storages) {
|
||||||
if (storage != null) {
|
// NO OP
|
||||||
storages.add(storage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void read(NBTTagCompound tag) {
|
|
||||||
super.read(tag);
|
|
||||||
|
|
||||||
if (tag.hasKey(NBT_STORAGE)) {
|
|
||||||
storageTagToRead = tag.getCompoundTag(NBT_STORAGE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -147,17 +74,6 @@ public class NetworkNodeFluidStorage extends NetworkNode implements IGuiStorage,
|
|||||||
return ID;
|
return ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public NBTTagCompound write(NBTTagCompound tag) {
|
|
||||||
super.write(tag);
|
|
||||||
|
|
||||||
storage.writeToNBT();
|
|
||||||
|
|
||||||
tag.setTag(NBT_STORAGE, storage.getStorageTag());
|
|
||||||
|
|
||||||
return tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NBTTagCompound writeConfiguration(NBTTagCompound tag) {
|
public NBTTagCompound writeConfiguration(NBTTagCompound tag) {
|
||||||
super.writeConfiguration(tag);
|
super.writeConfiguration(tag);
|
||||||
@@ -231,10 +147,6 @@ public class NetworkNodeFluidStorage extends NetworkNode implements IGuiStorage,
|
|||||||
markDirty();
|
markDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public StorageDiskFluid getStorage() {
|
|
||||||
return storage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemHandlerFluid getFilters() {
|
public ItemHandlerFluid getFilters() {
|
||||||
return filters;
|
return filters;
|
||||||
}
|
}
|
||||||
@@ -327,7 +239,7 @@ public class NetworkNodeFluidStorage extends NetworkNode implements IGuiStorage,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getVoidExcess() {
|
public boolean isVoidExcess() {
|
||||||
return voidExcess;
|
return voidExcess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import com.raoulvdberge.refinedstorage.api.storage.IStorage;
|
|||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageProvider;
|
import com.raoulvdberge.refinedstorage.api.storage.IStorageProvider;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageCacheItem;
|
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageCacheItem;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskItem;
|
|
||||||
import com.raoulvdberge.refinedstorage.block.BlockStorage;
|
import com.raoulvdberge.refinedstorage.block.BlockStorage;
|
||||||
import com.raoulvdberge.refinedstorage.block.ItemStorageType;
|
import com.raoulvdberge.refinedstorage.block.ItemStorageType;
|
||||||
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase;
|
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase;
|
||||||
@@ -23,42 +22,12 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
import net.minecraftforge.items.ItemHandlerHelper;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class NetworkNodeStorage extends NetworkNode implements IGuiStorage, IStorageProvider, IComparable, IFilterable, IPrioritizable, IExcessVoidable, IAccessType {
|
public class NetworkNodeStorage extends NetworkNode implements IGuiStorage, IStorageProvider, IComparable, IFilterable, IPrioritizable, IExcessVoidable, IAccessType {
|
||||||
public static final String ID = "storage";
|
public static final String ID = "storage";
|
||||||
|
|
||||||
class StorageItem extends StorageDiskItem {
|
|
||||||
StorageItem(NBTTagCompound tag) {
|
|
||||||
super(tag, NetworkNodeStorage.this.getCapacity());
|
|
||||||
|
|
||||||
this.onPassContainerContext(
|
|
||||||
NetworkNodeStorage.this::markDirty,
|
|
||||||
NetworkNodeStorage.this::getVoidExcess,
|
|
||||||
NetworkNodeStorage.this::getAccessType
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getPriority() {
|
|
||||||
return priority;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack insert(@Nonnull ItemStack stack, int size, boolean simulate) {
|
|
||||||
if (!IFilterable.canTake(filters, mode, compare, stack)) {
|
|
||||||
return ItemHandlerHelper.copyStackWithSize(stack, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.insert(stack, size, simulate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final String NBT_STORAGE = "Storage";
|
|
||||||
|
|
||||||
private static final String NBT_PRIORITY = "Priority";
|
private static final String NBT_PRIORITY = "Priority";
|
||||||
private static final String NBT_COMPARE = "Compare";
|
private static final String NBT_COMPARE = "Compare";
|
||||||
private static final String NBT_MODE = "Mode";
|
private static final String NBT_MODE = "Mode";
|
||||||
@@ -66,9 +35,6 @@ public class NetworkNodeStorage extends NetworkNode implements IGuiStorage, ISto
|
|||||||
|
|
||||||
private ItemHandlerBase filters = new ItemHandlerBase(9, new ItemHandlerListenerNetworkNode(this));
|
private ItemHandlerBase filters = new ItemHandlerBase(9, new ItemHandlerListenerNetworkNode(this));
|
||||||
|
|
||||||
private StorageItem storage = new StorageItem(StorageDiskItem.getTag());
|
|
||||||
private NBTTagCompound storageTagToRead = null;
|
|
||||||
|
|
||||||
private ItemStorageType type;
|
private ItemStorageType type;
|
||||||
|
|
||||||
private AccessType accessType = AccessType.INSERT_EXTRACT;
|
private AccessType accessType = AccessType.INSERT_EXTRACT;
|
||||||
@@ -81,36 +47,11 @@ public class NetworkNodeStorage extends NetworkNode implements IGuiStorage, ISto
|
|||||||
super(world, pos);
|
super(world, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update() {
|
|
||||||
super.update();
|
|
||||||
|
|
||||||
if (storageTagToRead != null) {
|
|
||||||
storage = new StorageItem(storageTagToRead);
|
|
||||||
|
|
||||||
storage.readFromNBT();
|
|
||||||
|
|
||||||
if (network != null) {
|
|
||||||
network.getItemStorageCache().invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
storageTagToRead = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPlacedWithStorage(NBTTagCompound tag) {
|
|
||||||
storageTagToRead = tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getEnergyUsage() {
|
public int getEnergyUsage() {
|
||||||
return RS.INSTANCE.config.storageUsage;
|
return RS.INSTANCE.config.storageUsage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onBreak() {
|
|
||||||
storage.writeToNBT();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConnectedStateChange(INetwork network, boolean state) {
|
public void onConnectedStateChange(INetwork network, boolean state) {
|
||||||
super.onConnectedStateChange(network, state);
|
super.onConnectedStateChange(network, state);
|
||||||
@@ -120,7 +61,7 @@ public class NetworkNodeStorage extends NetworkNode implements IGuiStorage, ISto
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addItemStorages(List<IStorage<ItemStack>> storages) {
|
public void addItemStorages(List<IStorage<ItemStack>> storages) {
|
||||||
storages.add(storage);
|
// NO OP
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -128,31 +69,11 @@ public class NetworkNodeStorage extends NetworkNode implements IGuiStorage, ISto
|
|||||||
// NO OP
|
// NO OP
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void read(NBTTagCompound tag) {
|
|
||||||
super.read(tag);
|
|
||||||
|
|
||||||
if (tag.hasKey(NBT_STORAGE)) {
|
|
||||||
storageTagToRead = tag.getCompoundTag(NBT_STORAGE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return ID;
|
return ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public NBTTagCompound write(NBTTagCompound tag) {
|
|
||||||
super.write(tag);
|
|
||||||
|
|
||||||
storage.writeToNBT();
|
|
||||||
|
|
||||||
tag.setTag(NBT_STORAGE, storage.getStorageTag());
|
|
||||||
|
|
||||||
return tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NBTTagCompound writeConfiguration(NBTTagCompound tag) {
|
public NBTTagCompound writeConfiguration(NBTTagCompound tag) {
|
||||||
super.writeConfiguration(tag);
|
super.writeConfiguration(tag);
|
||||||
@@ -227,7 +148,7 @@ public class NetworkNodeStorage extends NetworkNode implements IGuiStorage, ISto
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getVoidExcess() {
|
public boolean isVoidExcess() {
|
||||||
return voidExcess;
|
return voidExcess;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,10 +159,6 @@ public class NetworkNodeStorage extends NetworkNode implements IGuiStorage, ISto
|
|||||||
markDirty();
|
markDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public StorageDiskItem getStorage() {
|
|
||||||
return storage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemHandlerBase getFilters() {
|
public ItemHandlerBase getFilters() {
|
||||||
return filters;
|
return filters;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,12 @@ package com.raoulvdberge.refinedstorage.apiimpl.network.node.diskdrive;
|
|||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.RS;
|
import com.raoulvdberge.refinedstorage.RS;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.*;
|
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.storage.disk.IStorageDisk;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskProvider;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.IGuiStorage;
|
import com.raoulvdberge.refinedstorage.apiimpl.network.node.IGuiStorage;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNode;
|
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNode;
|
||||||
@@ -29,8 +34,8 @@ import net.minecraftforge.items.IItemHandler;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public class NetworkNodeDiskDrive extends NetworkNode implements IGuiStorage, IStorageProvider, IComparable, IFilterable, IPrioritizable, IType, IExcessVoidable, IAccessType {
|
public class NetworkNodeDiskDrive extends NetworkNode implements IGuiStorage, IStorageProvider, IComparable, IFilterable, IPrioritizable, IType, IExcessVoidable, IAccessType, IStorageDiskContainerContext {
|
||||||
public static final Predicate<ItemStack> VALIDATOR_STORAGE_DISK = s -> s.getItem() instanceof IStorageDiskProvider && ((IStorageDiskProvider) s.getItem()).create(s).isValid(s);
|
public static final Predicate<ItemStack> VALIDATOR_STORAGE_DISK = s -> s.getItem() instanceof IStorageDiskProvider && ((IStorageDiskProvider) s.getItem()).isValid(s);
|
||||||
|
|
||||||
public static final String ID = "disk_drive";
|
public static final String ID = "disk_drive";
|
||||||
|
|
||||||
@@ -47,12 +52,13 @@ public class NetworkNodeDiskDrive extends NetworkNode implements IGuiStorage, IS
|
|||||||
|
|
||||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
|
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
|
||||||
StackUtils.createStorages(
|
StackUtils.createStorages(
|
||||||
|
world,
|
||||||
getStackInSlot(slot),
|
getStackInSlot(slot),
|
||||||
slot,
|
slot,
|
||||||
itemStorages,
|
itemDisks,
|
||||||
fluidStorages,
|
fluidDisks,
|
||||||
s -> new StorageItemDiskDrive(NetworkNodeDiskDrive.this, s),
|
s -> new StorageDiskItemDriveWrapper(NetworkNodeDiskDrive.this, s),
|
||||||
s -> new StorageFluidDiskDrive(NetworkNodeDiskDrive.this, s)
|
s -> new StorageDiskFluidDriveWrapper(NetworkNodeDiskDrive.this, s)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (network != null) {
|
if (network != null) {
|
||||||
@@ -63,26 +69,13 @@ public class NetworkNodeDiskDrive extends NetworkNode implements IGuiStorage, IS
|
|||||||
WorldUtils.updateBlock(world, pos);
|
WorldUtils.updateBlock(world, pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
|
||||||
if (itemStorages[slot] != null) {
|
|
||||||
itemStorages[slot].writeToNBT();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fluidStorages[slot] != null) {
|
|
||||||
fluidStorages[slot].writeToNBT();
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.extractItem(slot, amount, simulate);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private ItemHandlerBase itemFilters = new ItemHandlerBase(9, new ItemHandlerListenerNetworkNode(this));
|
private ItemHandlerBase itemFilters = new ItemHandlerBase(9, new ItemHandlerListenerNetworkNode(this));
|
||||||
private ItemHandlerFluid fluidFilters = new ItemHandlerFluid(9, new ItemHandlerListenerNetworkNode(this));
|
private ItemHandlerFluid fluidFilters = new ItemHandlerFluid(9, new ItemHandlerListenerNetworkNode(this));
|
||||||
|
|
||||||
private IStorageDisk[] itemStorages = new IStorageDisk[8];
|
private IStorageDisk[] itemDisks = new IStorageDisk[8];
|
||||||
private IStorageDisk[] fluidStorages = new IStorageDisk[8];
|
private IStorageDisk[] fluidDisks = new IStorageDisk[8];
|
||||||
|
|
||||||
private AccessType accessType = AccessType.INSERT_EXTRACT;
|
private AccessType accessType = AccessType.INSERT_EXTRACT;
|
||||||
private int priority = 0;
|
private int priority = 0;
|
||||||
@@ -95,24 +88,24 @@ public class NetworkNodeDiskDrive extends NetworkNode implements IGuiStorage, IS
|
|||||||
super(world, pos);
|
super(world, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IStorageDisk[] getItemStorages() {
|
public IStorageDisk[] getItemDisks() {
|
||||||
return itemStorages;
|
return itemDisks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IStorageDisk[] getFluidStorages() {
|
public IStorageDisk[] getFluidDisks() {
|
||||||
return fluidStorages;
|
return fluidDisks;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getEnergyUsage() {
|
public int getEnergyUsage() {
|
||||||
int usage = RS.INSTANCE.config.diskDriveUsage;
|
int usage = RS.INSTANCE.config.diskDriveUsage;
|
||||||
|
|
||||||
for (IStorage storage : itemStorages) {
|
for (IStorage storage : itemDisks) {
|
||||||
if (storage != null) {
|
if (storage != null) {
|
||||||
usage += RS.INSTANCE.config.diskDrivePerDiskUsage;
|
usage += RS.INSTANCE.config.diskDrivePerDiskUsage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (IStorage storage : fluidStorages) {
|
for (IStorage storage : fluidDisks) {
|
||||||
if (storage != null) {
|
if (storage != null) {
|
||||||
usage += RS.INSTANCE.config.diskDrivePerDiskUsage;
|
usage += RS.INSTANCE.config.diskDrivePerDiskUsage;
|
||||||
}
|
}
|
||||||
@@ -121,20 +114,6 @@ public class NetworkNodeDiskDrive extends NetworkNode implements IGuiStorage, IS
|
|||||||
return usage;
|
return usage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onBreak() {
|
|
||||||
for (IStorageDisk storage : this.itemStorages) {
|
|
||||||
if (storage != null) {
|
|
||||||
storage.writeToNBT();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (IStorageDisk storage : this.fluidStorages) {
|
|
||||||
if (storage != null) {
|
|
||||||
storage.writeToNBT();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConnectedStateChange(INetwork network, boolean state) {
|
public void onConnectedStateChange(INetwork network, boolean state) {
|
||||||
super.onConnectedStateChange(network, state);
|
super.onConnectedStateChange(network, state);
|
||||||
@@ -147,7 +126,7 @@ public class NetworkNodeDiskDrive extends NetworkNode implements IGuiStorage, IS
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addItemStorages(List<IStorage<ItemStack>> storages) {
|
public void addItemStorages(List<IStorage<ItemStack>> storages) {
|
||||||
for (IStorage<ItemStack> storage : this.itemStorages) {
|
for (IStorage<ItemStack> storage : this.itemDisks) {
|
||||||
if (storage != null) {
|
if (storage != null) {
|
||||||
storages.add(storage);
|
storages.add(storage);
|
||||||
}
|
}
|
||||||
@@ -156,7 +135,7 @@ public class NetworkNodeDiskDrive extends NetworkNode implements IGuiStorage, IS
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addFluidStorages(List<IStorage<FluidStack>> storages) {
|
public void addFluidStorages(List<IStorage<FluidStack>> storages) {
|
||||||
for (IStorage<FluidStack> storage : this.fluidStorages) {
|
for (IStorage<FluidStack> storage : this.fluidDisks) {
|
||||||
if (storage != null) {
|
if (storage != null) {
|
||||||
storages.add(storage);
|
storages.add(storage);
|
||||||
}
|
}
|
||||||
@@ -179,16 +158,6 @@ public class NetworkNodeDiskDrive extends NetworkNode implements IGuiStorage, IS
|
|||||||
public NBTTagCompound write(NBTTagCompound tag) {
|
public NBTTagCompound write(NBTTagCompound tag) {
|
||||||
super.write(tag);
|
super.write(tag);
|
||||||
|
|
||||||
for (int i = 0; i < disks.getSlots(); ++i) {
|
|
||||||
if (itemStorages[i] != null) {
|
|
||||||
itemStorages[i].writeToNBT();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fluidStorages[i] != null) {
|
|
||||||
fluidStorages[i].writeToNBT();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
StackUtils.writeItems(disks, 0, tag);
|
StackUtils.writeItems(disks, 0, tag);
|
||||||
|
|
||||||
return tag;
|
return tag;
|
||||||
@@ -360,7 +329,7 @@ public class NetworkNodeDiskDrive extends NetworkNode implements IGuiStorage, IS
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getVoidExcess() {
|
public boolean isVoidExcess() {
|
||||||
return voidExcess;
|
return voidExcess;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -388,11 +357,11 @@ public class NetworkNodeDiskDrive extends NetworkNode implements IGuiStorage, IS
|
|||||||
return getType() == IType.ITEMS ? itemFilters : fluidFilters;
|
return getType() == IType.ITEMS ? itemFilters : fluidFilters;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemHandlerBase getItemFilters() {
|
ItemHandlerBase getItemFilters() {
|
||||||
return itemFilters;
|
return itemFilters;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemHandlerFluid getFluidFilters() {
|
ItemHandlerFluid getFluidFilters() {
|
||||||
return fluidFilters;
|
return fluidFilters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,32 +1,30 @@
|
|||||||
package com.raoulvdberge.refinedstorage.apiimpl.network.node.diskdrive;
|
package com.raoulvdberge.refinedstorage.apiimpl.network.node.diskdrive;
|
||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDisk;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.StorageDiskType;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener;
|
||||||
import com.raoulvdberge.refinedstorage.tile.TileDiskDrive;
|
import com.raoulvdberge.refinedstorage.tile.TileDiskDrive;
|
||||||
import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
|
import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
|
||||||
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
||||||
import com.raoulvdberge.refinedstorage.util.WorldUtils;
|
import com.raoulvdberge.refinedstorage.util.WorldUtils;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class StorageFluidDiskDrive implements IStorageDisk<FluidStack> {
|
public class StorageDiskFluidDriveWrapper implements IStorageDisk<FluidStack> {
|
||||||
private NetworkNodeDiskDrive diskDrive;
|
private NetworkNodeDiskDrive diskDrive;
|
||||||
private IStorageDisk<FluidStack> parent;
|
private IStorageDisk<FluidStack> parent;
|
||||||
private int lastState;
|
private int lastState;
|
||||||
|
|
||||||
public StorageFluidDiskDrive(NetworkNodeDiskDrive diskDrive, IStorageDisk<FluidStack> parent) {
|
public StorageDiskFluidDriveWrapper(NetworkNodeDiskDrive diskDrive, IStorageDisk<FluidStack> parent) {
|
||||||
this.diskDrive = diskDrive;
|
this.diskDrive = diskDrive;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.onPassContainerContext(
|
this.setSettings(
|
||||||
() -> {
|
() -> {
|
||||||
diskDrive.markDirty();
|
|
||||||
|
|
||||||
int currentState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
int currentState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||||
|
|
||||||
if (lastState != currentState) {
|
if (lastState != currentState) {
|
||||||
@@ -35,8 +33,7 @@ public class StorageFluidDiskDrive implements IStorageDisk<FluidStack> {
|
|||||||
WorldUtils.updateBlock(diskDrive.getWorld(), diskDrive.getPos());
|
WorldUtils.updateBlock(diskDrive.getWorld(), diskDrive.getPos());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
diskDrive::getVoidExcess,
|
diskDrive
|
||||||
diskDrive::getAccessType
|
|
||||||
);
|
);
|
||||||
this.lastState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
this.lastState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||||
}
|
}
|
||||||
@@ -88,27 +85,17 @@ public class StorageFluidDiskDrive implements IStorageDisk<FluidStack> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValid(ItemStack stack) {
|
public void setSettings(@Nullable IStorageDiskListener listener, IStorageDiskContainerContext context) {
|
||||||
return parent.isValid(stack);
|
parent.setSettings(listener, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPassContainerContext(Runnable listener, Supplier<Boolean> voidExcess, Supplier<AccessType> accessType) {
|
public NBTTagCompound writeToNbt() {
|
||||||
parent.onPassContainerContext(listener, voidExcess, accessType);
|
return parent.writeToNbt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT() {
|
public String getId() {
|
||||||
parent.readFromNBT();
|
return parent.getId();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeToNBT() {
|
|
||||||
parent.writeToNBT();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public StorageDiskType getType() {
|
|
||||||
return parent.getType();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,31 +1,30 @@
|
|||||||
package com.raoulvdberge.refinedstorage.apiimpl.network.node.diskdrive;
|
package com.raoulvdberge.refinedstorage.apiimpl.network.node.diskdrive;
|
||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDisk;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.StorageDiskType;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener;
|
||||||
import com.raoulvdberge.refinedstorage.tile.TileDiskDrive;
|
import com.raoulvdberge.refinedstorage.tile.TileDiskDrive;
|
||||||
import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
|
import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
|
||||||
import com.raoulvdberge.refinedstorage.util.WorldUtils;
|
import com.raoulvdberge.refinedstorage.util.WorldUtils;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraftforge.items.ItemHandlerHelper;
|
import net.minecraftforge.items.ItemHandlerHelper;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class StorageItemDiskDrive implements IStorageDisk<ItemStack> {
|
public class StorageDiskItemDriveWrapper implements IStorageDisk<ItemStack> {
|
||||||
private NetworkNodeDiskDrive diskDrive;
|
private NetworkNodeDiskDrive diskDrive;
|
||||||
private IStorageDisk<ItemStack> parent;
|
private IStorageDisk<ItemStack> parent;
|
||||||
private int lastState;
|
private int lastState;
|
||||||
|
|
||||||
public StorageItemDiskDrive(NetworkNodeDiskDrive diskDrive, IStorageDisk<ItemStack> parent) {
|
public StorageDiskItemDriveWrapper(NetworkNodeDiskDrive diskDrive, IStorageDisk<ItemStack> parent) {
|
||||||
this.diskDrive = diskDrive;
|
this.diskDrive = diskDrive;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.onPassContainerContext(
|
this.setSettings(
|
||||||
() -> {
|
() -> {
|
||||||
diskDrive.markDirty();
|
|
||||||
|
|
||||||
int currentState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
int currentState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||||
|
|
||||||
if (lastState != currentState) {
|
if (lastState != currentState) {
|
||||||
@@ -34,8 +33,7 @@ public class StorageItemDiskDrive implements IStorageDisk<ItemStack> {
|
|||||||
WorldUtils.updateBlock(diskDrive.getWorld(), diskDrive.getPos());
|
WorldUtils.updateBlock(diskDrive.getWorld(), diskDrive.getPos());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
diskDrive::getVoidExcess,
|
diskDrive
|
||||||
diskDrive::getAccessType
|
|
||||||
);
|
);
|
||||||
this.lastState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
this.lastState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||||
}
|
}
|
||||||
@@ -87,27 +85,17 @@ public class StorageItemDiskDrive implements IStorageDisk<ItemStack> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValid(ItemStack stack) {
|
public void setSettings(@Nullable IStorageDiskListener listener, IStorageDiskContainerContext context) {
|
||||||
return parent.isValid(stack);
|
parent.setSettings(listener, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPassContainerContext(Runnable listener, Supplier<Boolean> voidExcess, Supplier<AccessType> accessType) {
|
public NBTTagCompound writeToNbt() {
|
||||||
parent.onPassContainerContext(listener, voidExcess, accessType);
|
return parent.writeToNbt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT() {
|
public String getId() {
|
||||||
parent.readFromNBT();
|
return parent.getId();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeToNBT() {
|
|
||||||
parent.writeToNBT();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public StorageDiskType getType() {
|
|
||||||
return parent.getType();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
package com.raoulvdberge.refinedstorage.apiimpl.network.node.diskmanipulator;
|
package com.raoulvdberge.refinedstorage.apiimpl.network.node.diskmanipulator;
|
||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.RS;
|
import com.raoulvdberge.refinedstorage.RS;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDisk;
|
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNode;
|
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNode;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.diskdrive.NetworkNodeDiskDrive;
|
import com.raoulvdberge.refinedstorage.apiimpl.network.node.diskdrive.NetworkNodeDiskDrive;
|
||||||
@@ -24,11 +26,10 @@ import net.minecraftforge.fml.relauncher.Side;
|
|||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
import net.minecraftforge.items.wrapper.CombinedInvWrapper;
|
import net.minecraftforge.items.wrapper.CombinedInvWrapper;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class NetworkNodeDiskManipulator extends NetworkNode implements IComparable, IFilterable, IType {
|
public class NetworkNodeDiskManipulator extends NetworkNode implements IComparable, IFilterable, IType, IStorageDiskContainerContext {
|
||||||
public static final String ID = "disk_manipulator";
|
public static final String ID = "disk_manipulator";
|
||||||
|
|
||||||
public static final int IO_MODE_INSERT = 0;
|
public static final int IO_MODE_INSERT = 0;
|
||||||
@@ -44,8 +45,8 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
|
|||||||
private int type = IType.ITEMS;
|
private int type = IType.ITEMS;
|
||||||
private int ioMode = IO_MODE_INSERT;
|
private int ioMode = IO_MODE_INSERT;
|
||||||
|
|
||||||
private IStorageDisk<ItemStack>[] itemStorages = new IStorageDisk[6];
|
private IStorageDisk<ItemStack>[] itemDisks = new IStorageDisk[6];
|
||||||
private IStorageDisk<FluidStack>[] fluidStorages = new IStorageDisk[6];
|
private IStorageDisk<FluidStack>[] fluidDisks = new IStorageDisk[6];
|
||||||
|
|
||||||
private ItemHandlerUpgrade upgrades = new ItemHandlerUpgrade(4, new ItemHandlerListenerNetworkNode(this), ItemUpgrade.TYPE_SPEED, ItemUpgrade.TYPE_STACK) {
|
private ItemHandlerUpgrade upgrades = new ItemHandlerUpgrade(4, new ItemHandlerListenerNetworkNode(this), ItemUpgrade.TYPE_SPEED, ItemUpgrade.TYPE_STACK) {
|
||||||
@Override
|
@Override
|
||||||
@@ -67,31 +68,18 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
|
|||||||
|
|
||||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
|
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
|
||||||
StackUtils.createStorages(
|
StackUtils.createStorages(
|
||||||
|
world,
|
||||||
getStackInSlot(slot),
|
getStackInSlot(slot),
|
||||||
slot,
|
slot,
|
||||||
itemStorages,
|
itemDisks,
|
||||||
fluidStorages,
|
fluidDisks,
|
||||||
s -> new StorageItemDiskManipulator(NetworkNodeDiskManipulator.this, s),
|
s -> new StorageDiskItemManipulatorWrapper(NetworkNodeDiskManipulator.this, s),
|
||||||
s -> new StorageFluidDiskManipulator(NetworkNodeDiskManipulator.this, s)
|
s -> new StorageDiskFluidManipulatorWrapper(NetworkNodeDiskManipulator.this, s)
|
||||||
);
|
);
|
||||||
|
|
||||||
WorldUtils.updateBlock(world, pos);
|
WorldUtils.updateBlock(world, pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nonnull
|
|
||||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
|
||||||
if (itemStorages[slot] != null) {
|
|
||||||
itemStorages[slot].writeToNBT();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fluidStorages[slot] != null) {
|
|
||||||
fluidStorages[slot].writeToNBT();
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.extractItem(slot, amount, simulate);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private ItemHandlerBase outputDisks = new ItemHandlerBase(3, new ItemHandlerListenerNetworkNode(this), NetworkNodeDiskDrive.VALIDATOR_STORAGE_DISK) {
|
private ItemHandlerBase outputDisks = new ItemHandlerBase(3, new ItemHandlerListenerNetworkNode(this), NetworkNodeDiskDrive.VALIDATOR_STORAGE_DISK) {
|
||||||
@@ -101,12 +89,13 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
|
|||||||
|
|
||||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
|
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
|
||||||
StackUtils.createStorages(
|
StackUtils.createStorages(
|
||||||
|
world,
|
||||||
getStackInSlot(slot),
|
getStackInSlot(slot),
|
||||||
3 + slot,
|
3 + slot,
|
||||||
itemStorages,
|
itemDisks,
|
||||||
fluidStorages,
|
fluidDisks,
|
||||||
s -> new StorageItemDiskManipulator(NetworkNodeDiskManipulator.this, s),
|
s -> new StorageDiskItemManipulatorWrapper(NetworkNodeDiskManipulator.this, s),
|
||||||
s -> new StorageFluidDiskManipulator(NetworkNodeDiskManipulator.this, s)
|
s -> new StorageDiskFluidManipulatorWrapper(NetworkNodeDiskManipulator.this, s)
|
||||||
);
|
);
|
||||||
|
|
||||||
WorldUtils.updateBlock(world, pos);
|
WorldUtils.updateBlock(world, pos);
|
||||||
@@ -143,7 +132,7 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
|
|||||||
|
|
||||||
int slot = 0;
|
int slot = 0;
|
||||||
if (type == IType.ITEMS) {
|
if (type == IType.ITEMS) {
|
||||||
while (slot < 3 && (itemStorages[slot] == null || checkItemDiskDone(itemStorages[slot], slot))) {
|
while (slot < 3 && (itemDisks[slot] == null || checkItemDiskDone(itemDisks[slot], slot))) {
|
||||||
slot++;
|
slot++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,7 +140,7 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IStorageDisk<ItemStack> storage = itemStorages[slot];
|
IStorageDisk<ItemStack> storage = itemDisks[slot];
|
||||||
|
|
||||||
if (ioMode == IO_MODE_INSERT) {
|
if (ioMode == IO_MODE_INSERT) {
|
||||||
insertItemIntoNetwork(storage, slot);
|
insertItemIntoNetwork(storage, slot);
|
||||||
@@ -159,7 +148,7 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
|
|||||||
extractItemFromNetwork(storage, slot);
|
extractItemFromNetwork(storage, slot);
|
||||||
}
|
}
|
||||||
} else if (type == IType.FLUIDS) {
|
} else if (type == IType.FLUIDS) {
|
||||||
while (slot < 3 && (fluidStorages[slot] == null || checkFluidDiskDone(fluidStorages[slot], slot))) {
|
while (slot < 3 && (fluidDisks[slot] == null || checkFluidDiskDone(fluidDisks[slot], slot))) {
|
||||||
slot++;
|
slot++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,7 +156,7 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IStorageDisk<FluidStack> storage = fluidStorages[slot];
|
IStorageDisk<FluidStack> storage = fluidDisks[slot];
|
||||||
|
|
||||||
if (ioMode == IO_MODE_INSERT) {
|
if (ioMode == IO_MODE_INSERT) {
|
||||||
insertFluidIntoNetwork(storage, slot);
|
insertFluidIntoNetwork(storage, slot);
|
||||||
@@ -384,17 +373,6 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (slot < 3) {
|
|
||||||
if (itemStorages[slot] != null) {
|
|
||||||
itemStorages[slot].writeToNBT();
|
|
||||||
itemStorages[slot] = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fluidStorages[slot] != null) {
|
|
||||||
fluidStorages[slot].writeToNBT();
|
|
||||||
fluidStorages[slot] = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
inputDisks.extractItem(slot, 1, false);
|
inputDisks.extractItem(slot, 1, false);
|
||||||
outputDisks.insertItem(i, disk, false);
|
outputDisks.insertItem(i, disk, false);
|
||||||
}
|
}
|
||||||
@@ -467,12 +445,12 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
|
|||||||
return upgrades;
|
return upgrades;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IStorageDisk[] getItemStorages() {
|
public IStorageDisk[] getItemDisks() {
|
||||||
return itemStorages;
|
return itemDisks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IStorageDisk[] getFluidStorages() {
|
public IStorageDisk[] getFluidDisks() {
|
||||||
return fluidStorages;
|
return fluidDisks;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -493,8 +471,6 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
|
|||||||
public NBTTagCompound write(NBTTagCompound tag) {
|
public NBTTagCompound write(NBTTagCompound tag) {
|
||||||
super.write(tag);
|
super.write(tag);
|
||||||
|
|
||||||
onBreak();
|
|
||||||
|
|
||||||
StackUtils.writeItems(upgrades, 3, tag);
|
StackUtils.writeItems(upgrades, 3, tag);
|
||||||
StackUtils.writeItems(inputDisks, 4, tag);
|
StackUtils.writeItems(inputDisks, 4, tag);
|
||||||
StackUtils.writeItems(outputDisks, 5, tag);
|
StackUtils.writeItems(outputDisks, 5, tag);
|
||||||
@@ -541,22 +517,18 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onBreak() {
|
|
||||||
for (IStorageDisk storage : itemStorages) {
|
|
||||||
if (storage != null) {
|
|
||||||
storage.writeToNBT();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (IStorageDisk storage : fluidStorages) {
|
|
||||||
if (storage != null) {
|
|
||||||
storage.writeToNBT();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IItemHandler getDrops() {
|
public IItemHandler getDrops() {
|
||||||
return new CombinedInvWrapper(inputDisks, outputDisks, upgrades);
|
return new CombinedInvWrapper(inputDisks, outputDisks, upgrades);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isVoidExcess() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AccessType getAccessType() {
|
||||||
|
return AccessType.INSERT_EXTRACT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,32 +1,30 @@
|
|||||||
package com.raoulvdberge.refinedstorage.apiimpl.network.node.diskmanipulator;
|
package com.raoulvdberge.refinedstorage.apiimpl.network.node.diskmanipulator;
|
||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDisk;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.StorageDiskType;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener;
|
||||||
import com.raoulvdberge.refinedstorage.tile.TileDiskDrive;
|
import com.raoulvdberge.refinedstorage.tile.TileDiskDrive;
|
||||||
import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
|
import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
|
||||||
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
||||||
import com.raoulvdberge.refinedstorage.util.WorldUtils;
|
import com.raoulvdberge.refinedstorage.util.WorldUtils;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class StorageFluidDiskManipulator implements IStorageDisk<FluidStack> {
|
public class StorageDiskFluidManipulatorWrapper implements IStorageDisk<FluidStack> {
|
||||||
private NetworkNodeDiskManipulator diskManipulator;
|
private NetworkNodeDiskManipulator diskManipulator;
|
||||||
private IStorageDisk<FluidStack> parent;
|
private IStorageDisk<FluidStack> parent;
|
||||||
private int lastState;
|
private int lastState;
|
||||||
|
|
||||||
public StorageFluidDiskManipulator(NetworkNodeDiskManipulator diskManipulator, IStorageDisk<FluidStack> parent) {
|
public StorageDiskFluidManipulatorWrapper(NetworkNodeDiskManipulator diskManipulator, IStorageDisk<FluidStack> parent) {
|
||||||
this.diskManipulator = diskManipulator;
|
this.diskManipulator = diskManipulator;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.onPassContainerContext(
|
this.setSettings(
|
||||||
() -> {
|
() -> {
|
||||||
diskManipulator.markDirty();
|
|
||||||
|
|
||||||
int currentState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
int currentState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||||
|
|
||||||
if (lastState != currentState) {
|
if (lastState != currentState) {
|
||||||
@@ -35,8 +33,7 @@ public class StorageFluidDiskManipulator implements IStorageDisk<FluidStack> {
|
|||||||
WorldUtils.updateBlock(diskManipulator.getWorld(), diskManipulator.getPos());
|
WorldUtils.updateBlock(diskManipulator.getWorld(), diskManipulator.getPos());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
() -> false,
|
diskManipulator
|
||||||
() -> AccessType.INSERT_EXTRACT
|
|
||||||
);
|
);
|
||||||
this.lastState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
this.lastState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||||
}
|
}
|
||||||
@@ -47,28 +44,18 @@ public class StorageFluidDiskManipulator implements IStorageDisk<FluidStack> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValid(ItemStack stack) {
|
public void setSettings(@Nullable IStorageDiskListener listener, IStorageDiskContainerContext context) {
|
||||||
return parent.isValid(stack);
|
parent.setSettings(listener, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPassContainerContext(Runnable listener, Supplier<Boolean> voidExcess, Supplier<AccessType> accessType) {
|
public NBTTagCompound writeToNbt() {
|
||||||
parent.onPassContainerContext(listener, voidExcess, accessType);
|
return parent.writeToNbt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT() {
|
public String getId() {
|
||||||
parent.readFromNBT();
|
return parent.getId();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeToNBT() {
|
|
||||||
parent.writeToNBT();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public StorageDiskType getType() {
|
|
||||||
return parent.getType();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1,31 +1,30 @@
|
|||||||
package com.raoulvdberge.refinedstorage.apiimpl.network.node.diskmanipulator;
|
package com.raoulvdberge.refinedstorage.apiimpl.network.node.diskmanipulator;
|
||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDisk;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.StorageDiskType;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener;
|
||||||
import com.raoulvdberge.refinedstorage.tile.TileDiskDrive;
|
import com.raoulvdberge.refinedstorage.tile.TileDiskDrive;
|
||||||
import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
|
import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
|
||||||
import com.raoulvdberge.refinedstorage.util.WorldUtils;
|
import com.raoulvdberge.refinedstorage.util.WorldUtils;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraftforge.items.ItemHandlerHelper;
|
import net.minecraftforge.items.ItemHandlerHelper;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class StorageItemDiskManipulator implements IStorageDisk<ItemStack> {
|
public class StorageDiskItemManipulatorWrapper implements IStorageDisk<ItemStack> {
|
||||||
private NetworkNodeDiskManipulator diskManipulator;
|
private NetworkNodeDiskManipulator diskManipulator;
|
||||||
private IStorageDisk<ItemStack> parent;
|
private IStorageDisk<ItemStack> parent;
|
||||||
private int lastState;
|
private int lastState;
|
||||||
|
|
||||||
public StorageItemDiskManipulator(NetworkNodeDiskManipulator diskManipulator, IStorageDisk<ItemStack> parent) {
|
public StorageDiskItemManipulatorWrapper(NetworkNodeDiskManipulator diskManipulator, IStorageDisk<ItemStack> parent) {
|
||||||
this.diskManipulator = diskManipulator;
|
this.diskManipulator = diskManipulator;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.onPassContainerContext(
|
this.setSettings(
|
||||||
() -> {
|
() -> {
|
||||||
diskManipulator.markDirty();
|
|
||||||
|
|
||||||
int currentState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
int currentState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||||
|
|
||||||
if (lastState != currentState) {
|
if (lastState != currentState) {
|
||||||
@@ -34,8 +33,7 @@ public class StorageItemDiskManipulator implements IStorageDisk<ItemStack> {
|
|||||||
WorldUtils.updateBlock(diskManipulator.getWorld(), diskManipulator.getPos());
|
WorldUtils.updateBlock(diskManipulator.getWorld(), diskManipulator.getPos());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
() -> false,
|
diskManipulator
|
||||||
() -> AccessType.INSERT_EXTRACT
|
|
||||||
);
|
);
|
||||||
this.lastState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
this.lastState = TileDiskDrive.getDiskState(getStored(), getCapacity());
|
||||||
}
|
}
|
||||||
@@ -46,28 +44,13 @@ public class StorageItemDiskManipulator implements IStorageDisk<ItemStack> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValid(ItemStack stack) {
|
public void setSettings(@Nullable IStorageDiskListener listener, IStorageDiskContainerContext context) {
|
||||||
return parent.isValid(stack);
|
parent.setSettings(listener, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPassContainerContext(Runnable listener, Supplier<Boolean> voidExcess, Supplier<AccessType> accessType) {
|
public NBTTagCompound writeToNbt() {
|
||||||
parent.onPassContainerContext(listener, voidExcess, accessType);
|
return parent.writeToNbt();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readFromNBT() {
|
|
||||||
parent.readFromNBT();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeToNBT() {
|
|
||||||
parent.writeToNBT();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public StorageDiskType getType() {
|
|
||||||
return StorageDiskType.ITEMS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -114,4 +97,9 @@ public class StorageItemDiskManipulator implements IStorageDisk<ItemStack> {
|
|||||||
public int getCacheDelta(int storedPreInsertion, int size, @Nullable ItemStack remainder) {
|
public int getCacheDelta(int storedPreInsertion, int size, @Nullable ItemStack remainder) {
|
||||||
return parent.getCacheDelta(storedPreInsertion, size, remainder);
|
return parent.getCacheDelta(storedPreInsertion, size, remainder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getId() {
|
||||||
|
return parent.getId();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
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!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.apiimpl.storage.disk;
|
||||||
|
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskFactory;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
|
|
||||||
|
public class StorageDiskFactoryFluid implements IStorageDiskFactory<FluidStack> {
|
||||||
|
public static final String ID = "normal_fluid";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IStorageDisk<FluidStack> createFromNbt(World world, NBTTagCompound tag) {
|
||||||
|
StorageDiskFluid disk = new StorageDiskFluid(world, tag.getInteger(StorageDiskFluid.NBT_CAPACITY));
|
||||||
|
|
||||||
|
NBTTagList list = (NBTTagList) tag.getTag(StorageDiskFluid.NBT_FLUIDS);
|
||||||
|
|
||||||
|
for (int i = 0; i < list.tagCount(); ++i) {
|
||||||
|
FluidStack stack = FluidStack.loadFluidStackFromNBT(list.getCompoundTagAt(i));
|
||||||
|
|
||||||
|
if (stack != null) {
|
||||||
|
disk.getRawStacks().put(stack.getFluid(), stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return disk;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IStorageDisk<FluidStack> create(World world, int capacity) {
|
||||||
|
return new StorageDiskFluid(world, capacity);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.apiimpl.storage.disk;
|
||||||
|
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskFactory;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
public class StorageDiskFactoryItem implements IStorageDiskFactory<ItemStack> {
|
||||||
|
public static final String ID = "normal_item";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IStorageDisk<ItemStack> createFromNbt(World world, NBTTagCompound tag) {
|
||||||
|
StorageDiskItem disk = new StorageDiskItem(world, tag.getInteger(StorageDiskItem.NBT_CAPACITY));
|
||||||
|
|
||||||
|
NBTTagList list = (NBTTagList) tag.getTag(StorageDiskItem.NBT_ITEMS);
|
||||||
|
|
||||||
|
for (int i = 0; i < list.tagCount(); ++i) {
|
||||||
|
NBTTagCompound item = list.getCompoundTagAt(i);
|
||||||
|
|
||||||
|
ItemStack stack = new ItemStack(
|
||||||
|
Item.getItemById(item.getInteger(StorageDiskItem.NBT_ITEM_TYPE)),
|
||||||
|
item.getInteger(StorageDiskItem.NBT_ITEM_QUANTITY),
|
||||||
|
item.getInteger(StorageDiskItem.NBT_ITEM_DAMAGE),
|
||||||
|
item.hasKey(StorageDiskItem.NBT_ITEM_CAPS) ? item.getCompoundTag(StorageDiskItem.NBT_ITEM_CAPS) : null
|
||||||
|
);
|
||||||
|
|
||||||
|
stack.setTagCompound(item.hasKey(StorageDiskItem.NBT_ITEM_NBT) ? item.getCompoundTag(StorageDiskItem.NBT_ITEM_NBT) : null);
|
||||||
|
|
||||||
|
if (!stack.isEmpty()) {
|
||||||
|
disk.getRawStacks().put(stack.getItem(), stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return disk;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IStorageDisk<ItemStack> create(World world, int capacity) {
|
||||||
|
return new StorageDiskItem(world, capacity);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,65 +1,48 @@
|
|||||||
package com.raoulvdberge.refinedstorage.apiimpl.storage;
|
package com.raoulvdberge.refinedstorage.apiimpl.storage.disk;
|
||||||
|
|
||||||
import com.google.common.collect.ArrayListMultimap;
|
import com.google.common.collect.ArrayListMultimap;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDisk;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.StorageDiskType;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||||
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.fluids.Fluid;
|
import net.minecraftforge.fluids.Fluid;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class StorageDiskFluid implements IStorageDisk<FluidStack> {
|
public class StorageDiskFluid implements IStorageDisk<FluidStack> {
|
||||||
private static final int PROTOCOL = 1;
|
static final String NBT_CAPACITY = "Capacity";
|
||||||
|
static final String NBT_FLUIDS = "Fluids";
|
||||||
|
|
||||||
private static final String NBT_PROTOCOL = "Protocol";
|
private World world;
|
||||||
|
|
||||||
private static final String NBT_FLUIDS = "Fluids";
|
|
||||||
private static final String NBT_STORED = "Stored";
|
|
||||||
|
|
||||||
private NBTTagCompound tag;
|
|
||||||
private int capacity;
|
private int capacity;
|
||||||
|
|
||||||
private Multimap<Fluid, FluidStack> stacks = ArrayListMultimap.create();
|
private Multimap<Fluid, FluidStack> stacks = ArrayListMultimap.create();
|
||||||
|
|
||||||
private Runnable listener = () -> {
|
@Nullable
|
||||||
};
|
private IStorageDiskListener listener;
|
||||||
private Supplier<Boolean> voidExcess;
|
private IStorageDiskContainerContext context;
|
||||||
private Supplier<AccessType> accessType;
|
|
||||||
|
|
||||||
public StorageDiskFluid(NBTTagCompound tag, int capacity) {
|
public StorageDiskFluid(World world, int capacity) {
|
||||||
this.tag = tag;
|
if (world == null) {
|
||||||
|
throw new IllegalArgumentException("World cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.world = world;
|
||||||
this.capacity = capacity;
|
this.capacity = capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NBTTagCompound getStorageTag() {
|
|
||||||
return tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT() {
|
public NBTTagCompound writeToNbt() {
|
||||||
NBTTagList list = (NBTTagList) tag.getTag(NBT_FLUIDS);
|
NBTTagCompound tag = new NBTTagCompound();
|
||||||
|
|
||||||
for (int i = 0; i < list.tagCount(); ++i) {
|
|
||||||
FluidStack stack = FluidStack.loadFluidStackFromNBT(list.getCompoundTagAt(i));
|
|
||||||
|
|
||||||
if (stack != null) {
|
|
||||||
stacks.put(stack.getFluid(), stack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeToNBT() {
|
|
||||||
NBTTagList list = new NBTTagList();
|
NBTTagList list = new NBTTagList();
|
||||||
|
|
||||||
for (FluidStack stack : stacks.values()) {
|
for (FluidStack stack : stacks.values()) {
|
||||||
@@ -67,12 +50,9 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tag.setTag(NBT_FLUIDS, list);
|
tag.setTag(NBT_FLUIDS, list);
|
||||||
tag.setInteger(NBT_PROTOCOL, PROTOCOL);
|
tag.setInteger(NBT_CAPACITY, capacity);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
return tag;
|
||||||
public StorageDiskType getType() {
|
|
||||||
return StorageDiskType.FLUIDS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -82,14 +62,14 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public synchronized FluidStack insert(@Nonnull FluidStack stack, int size, boolean simulate) {
|
public FluidStack insert(@Nonnull FluidStack stack, int size, boolean simulate) {
|
||||||
for (FluidStack otherStack : stacks.get(stack.getFluid())) {
|
for (FluidStack otherStack : stacks.get(stack.getFluid())) {
|
||||||
if (otherStack.isFluidEqual(stack)) {
|
if (otherStack.isFluidEqual(stack)) {
|
||||||
if (getCapacity() != -1 && getStored() + size > getCapacity()) {
|
if (getCapacity() != -1 && getStored() + size > getCapacity()) {
|
||||||
int remainingSpace = getCapacity() - getStored();
|
int remainingSpace = getCapacity() - getStored();
|
||||||
|
|
||||||
if (remainingSpace <= 0) {
|
if (remainingSpace <= 0) {
|
||||||
if (voidExcess.get()) {
|
if (context.isVoidExcess()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,21 +77,17 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!simulate) {
|
if (!simulate) {
|
||||||
tag.setInteger(NBT_STORED, getStored() + remainingSpace);
|
|
||||||
|
|
||||||
otherStack.amount += remainingSpace;
|
otherStack.amount += remainingSpace;
|
||||||
|
|
||||||
listener.run();
|
onChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
return voidExcess.get() ? null : StackUtils.copy(otherStack, size - remainingSpace);
|
return context.isVoidExcess() ? null : StackUtils.copy(otherStack, size - remainingSpace);
|
||||||
} else {
|
} else {
|
||||||
if (!simulate) {
|
if (!simulate) {
|
||||||
tag.setInteger(NBT_STORED, getStored() + size);
|
|
||||||
|
|
||||||
otherStack.amount += size;
|
otherStack.amount += size;
|
||||||
|
|
||||||
listener.run();
|
onChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -123,7 +99,7 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
|
|||||||
int remainingSpace = getCapacity() - getStored();
|
int remainingSpace = getCapacity() - getStored();
|
||||||
|
|
||||||
if (remainingSpace <= 0) {
|
if (remainingSpace <= 0) {
|
||||||
if (voidExcess.get()) {
|
if (context.isVoidExcess()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,21 +107,17 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!simulate) {
|
if (!simulate) {
|
||||||
tag.setInteger(NBT_STORED, getStored() + remainingSpace);
|
|
||||||
|
|
||||||
stacks.put(stack.getFluid(), StackUtils.copy(stack, remainingSpace));
|
stacks.put(stack.getFluid(), StackUtils.copy(stack, remainingSpace));
|
||||||
|
|
||||||
listener.run();
|
onChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
return voidExcess.get() ? null : StackUtils.copy(stack, size - remainingSpace);
|
return context.isVoidExcess() ? null : StackUtils.copy(stack, size - remainingSpace);
|
||||||
} else {
|
} else {
|
||||||
if (!simulate) {
|
if (!simulate) {
|
||||||
tag.setInteger(NBT_STORED, getStored() + size);
|
|
||||||
|
|
||||||
stacks.put(stack.getFluid(), StackUtils.copy(stack, size));
|
stacks.put(stack.getFluid(), StackUtils.copy(stack, size));
|
||||||
|
|
||||||
listener.run();
|
onChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -154,7 +126,7 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public synchronized FluidStack extract(@Nonnull FluidStack stack, int size, int flags, boolean simulate) {
|
public FluidStack extract(@Nonnull FluidStack stack, int size, int flags, boolean simulate) {
|
||||||
for (FluidStack otherStack : stacks.get(stack.getFluid())) {
|
for (FluidStack otherStack : stacks.get(stack.getFluid())) {
|
||||||
if (API.instance().getComparer().isEqual(otherStack, stack, flags)) {
|
if (API.instance().getComparer().isEqual(otherStack, stack, flags)) {
|
||||||
if (size > otherStack.amount) {
|
if (size > otherStack.amount) {
|
||||||
@@ -168,9 +140,7 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
|
|||||||
otherStack.amount -= size;
|
otherStack.amount -= size;
|
||||||
}
|
}
|
||||||
|
|
||||||
tag.setInteger(NBT_STORED, getStored() - size);
|
onChanged();
|
||||||
|
|
||||||
listener.run();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return StackUtils.copy(otherStack, size);
|
return StackUtils.copy(otherStack, size);
|
||||||
@@ -182,7 +152,7 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getStored() {
|
public int getStored() {
|
||||||
return getStored(tag);
|
return stacks.values().stream().mapToInt(s -> s.amount).sum();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -192,7 +162,7 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AccessType getAccessType() {
|
public AccessType getAccessType() {
|
||||||
return accessType.get();
|
return context.getAccessType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -208,7 +178,7 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
|
|||||||
|
|
||||||
int inserted = remainder == null ? size : (size - remainder.amount);
|
int inserted = remainder == null ? size : (size - remainder.amount);
|
||||||
|
|
||||||
if (voidExcess.get() && storedPreInsertion + inserted > getCapacity()) {
|
if (context.isVoidExcess() && storedPreInsertion + inserted > getCapacity()) {
|
||||||
inserted = getCapacity() - storedPreInsertion;
|
inserted = getCapacity() - storedPreInsertion;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,38 +186,25 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValid(ItemStack stack) {
|
public void setSettings(@Nullable IStorageDiskListener listener, IStorageDiskContainerContext context) {
|
||||||
return stack.hasTagCompound() && stack.getTagCompound().hasKey(NBT_FLUIDS) && stack.getTagCompound().hasKey(NBT_STORED);
|
this.listener = listener;
|
||||||
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPassContainerContext(Runnable listener, Supplier<Boolean> voidExcess, Supplier<AccessType> accessType) {
|
public String getId() {
|
||||||
this.listener = listener;
|
return StorageDiskFactoryFluid.ID;
|
||||||
this.voidExcess = voidExcess;
|
|
||||||
this.accessType = accessType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NBTTagCompound getShareTag(@Nullable NBTTagCompound tag) {
|
Multimap<Fluid, FluidStack> getRawStacks() {
|
||||||
NBTTagCompound otherTag = new NBTTagCompound();
|
return stacks;
|
||||||
|
|
||||||
otherTag.setInteger(NBT_STORED, getStored(tag));
|
|
||||||
otherTag.setTag(NBT_FLUIDS, new NBTTagList());
|
|
||||||
otherTag.setInteger(NBT_PROTOCOL, PROTOCOL);
|
|
||||||
|
|
||||||
return otherTag;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getStored(@Nullable NBTTagCompound tag) {
|
private void onChanged() {
|
||||||
return tag == null ? 0 : tag.getInteger(NBT_STORED);
|
if (listener != null) {
|
||||||
}
|
listener.onChanged();
|
||||||
|
}
|
||||||
|
|
||||||
public static NBTTagCompound getTag() {
|
API.instance().getStorageDiskManager(world).markForSaving();
|
||||||
NBTTagCompound tag = new NBTTagCompound();
|
|
||||||
|
|
||||||
tag.setTag(NBT_FLUIDS, new NBTTagList());
|
|
||||||
tag.setInteger(NBT_STORED, 0);
|
|
||||||
tag.setInteger(NBT_PROTOCOL, PROTOCOL);
|
|
||||||
|
|
||||||
return tag;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
package com.raoulvdberge.refinedstorage.apiimpl.storage;
|
package com.raoulvdberge.refinedstorage.apiimpl.storage.disk;
|
||||||
|
|
||||||
import com.google.common.collect.ArrayListMultimap;
|
import com.google.common.collect.ArrayListMultimap;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDisk;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.StorageDiskType;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||||
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
||||||
@@ -12,71 +13,45 @@ import net.minecraft.item.Item;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.items.ItemHandlerHelper;
|
import net.minecraftforge.items.ItemHandlerHelper;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
||||||
private static final int PROTOCOL = 1;
|
static final String NBT_CAPACITY = "Capacity";
|
||||||
|
static final String NBT_ITEMS = "Items";
|
||||||
|
|
||||||
private static final String NBT_PROTOCOL = "Protocol";
|
static final String NBT_ITEM_TYPE = "Type";
|
||||||
|
static final String NBT_ITEM_QUANTITY = "Quantity";
|
||||||
|
static final String NBT_ITEM_DAMAGE = "Damage";
|
||||||
|
static final String NBT_ITEM_NBT = "NBT";
|
||||||
|
static final String NBT_ITEM_CAPS = "Caps";
|
||||||
|
|
||||||
private static final String NBT_ITEMS = "Items";
|
private World world;
|
||||||
private static final String NBT_STORED = "Stored";
|
|
||||||
|
|
||||||
private static final String NBT_ITEM_TYPE = "Type";
|
|
||||||
private static final String NBT_ITEM_QUANTITY = "Quantity";
|
|
||||||
private static final String NBT_ITEM_DAMAGE = "Damage";
|
|
||||||
private static final String NBT_ITEM_NBT = "NBT";
|
|
||||||
private static final String NBT_ITEM_CAPS = "Caps";
|
|
||||||
|
|
||||||
private NBTTagCompound tag;
|
|
||||||
private int capacity;
|
private int capacity;
|
||||||
|
|
||||||
private Runnable listener = () -> {
|
|
||||||
};
|
|
||||||
private Supplier<Boolean> voidExcess;
|
|
||||||
private Supplier<AccessType> accessType;
|
|
||||||
|
|
||||||
private Multimap<Item, ItemStack> stacks = ArrayListMultimap.create();
|
private Multimap<Item, ItemStack> stacks = ArrayListMultimap.create();
|
||||||
|
|
||||||
public StorageDiskItem(NBTTagCompound tag, int capacity) {
|
@Nullable
|
||||||
this.tag = tag;
|
private IStorageDiskListener listener;
|
||||||
|
private IStorageDiskContainerContext context;
|
||||||
|
|
||||||
|
public StorageDiskItem(World world, int capacity) {
|
||||||
|
if (world == null) {
|
||||||
|
throw new IllegalArgumentException("World cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.world = world;
|
||||||
this.capacity = capacity;
|
this.capacity = capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NBTTagCompound getStorageTag() {
|
|
||||||
return tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT() {
|
public NBTTagCompound writeToNbt() {
|
||||||
NBTTagList list = (NBTTagList) tag.getTag(NBT_ITEMS);
|
NBTTagCompound tag = new NBTTagCompound();
|
||||||
|
|
||||||
for (int i = 0; i < list.tagCount(); ++i) {
|
|
||||||
NBTTagCompound tag = list.getCompoundTagAt(i);
|
|
||||||
|
|
||||||
ItemStack stack = new ItemStack(
|
|
||||||
Item.getItemById(tag.getInteger(NBT_ITEM_TYPE)),
|
|
||||||
tag.getInteger(NBT_ITEM_QUANTITY),
|
|
||||||
tag.getInteger(NBT_ITEM_DAMAGE),
|
|
||||||
tag.hasKey(NBT_ITEM_CAPS) ? tag.getCompoundTag(NBT_ITEM_CAPS) : null
|
|
||||||
);
|
|
||||||
|
|
||||||
stack.setTagCompound(tag.hasKey(NBT_ITEM_NBT) ? tag.getCompoundTag(NBT_ITEM_NBT) : null);
|
|
||||||
|
|
||||||
if (!stack.isEmpty()) {
|
|
||||||
stacks.put(stack.getItem(), stack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeToNBT() {
|
|
||||||
NBTTagList list = new NBTTagList();
|
NBTTagList list = new NBTTagList();
|
||||||
|
|
||||||
// Dummy value for extracting ForgeCaps
|
// Dummy value for extracting ForgeCaps
|
||||||
@@ -105,12 +80,14 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tag.setTag(NBT_ITEMS, list);
|
tag.setTag(NBT_ITEMS, list);
|
||||||
tag.setInteger(NBT_PROTOCOL, PROTOCOL);
|
tag.setInteger(NBT_CAPACITY, capacity);
|
||||||
|
|
||||||
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StorageDiskType getType() {
|
public String getId() {
|
||||||
return StorageDiskType.ITEMS;
|
return StorageDiskFactoryItem.ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -120,14 +97,14 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public synchronized ItemStack insert(@Nonnull ItemStack stack, int size, boolean simulate) {
|
public ItemStack insert(@Nonnull ItemStack stack, int size, boolean simulate) {
|
||||||
for (ItemStack otherStack : stacks.get(stack.getItem())) {
|
for (ItemStack otherStack : stacks.get(stack.getItem())) {
|
||||||
if (API.instance().getComparer().isEqualNoQuantity(otherStack, stack)) {
|
if (API.instance().getComparer().isEqualNoQuantity(otherStack, stack)) {
|
||||||
if (getCapacity() != -1 && getStored() + size > getCapacity()) {
|
if (getCapacity() != -1 && getStored() + size > getCapacity()) {
|
||||||
int remainingSpace = getCapacity() - getStored();
|
int remainingSpace = getCapacity() - getStored();
|
||||||
|
|
||||||
if (remainingSpace <= 0) {
|
if (remainingSpace <= 0) {
|
||||||
if (voidExcess.get()) {
|
if (context.isVoidExcess()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,21 +112,17 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!simulate) {
|
if (!simulate) {
|
||||||
tag.setInteger(NBT_STORED, getStored() + remainingSpace);
|
|
||||||
|
|
||||||
otherStack.grow(remainingSpace);
|
otherStack.grow(remainingSpace);
|
||||||
|
|
||||||
listener.run();
|
onChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
return voidExcess.get() ? null : ItemHandlerHelper.copyStackWithSize(otherStack, size - remainingSpace);
|
return context.isVoidExcess() ? null : ItemHandlerHelper.copyStackWithSize(otherStack, size - remainingSpace);
|
||||||
} else {
|
} else {
|
||||||
if (!simulate) {
|
if (!simulate) {
|
||||||
tag.setInteger(NBT_STORED, getStored() + size);
|
|
||||||
|
|
||||||
otherStack.grow(size);
|
otherStack.grow(size);
|
||||||
|
|
||||||
listener.run();
|
onChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -161,7 +134,7 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
|||||||
int remainingSpace = getCapacity() - getStored();
|
int remainingSpace = getCapacity() - getStored();
|
||||||
|
|
||||||
if (remainingSpace <= 0) {
|
if (remainingSpace <= 0) {
|
||||||
if (voidExcess.get()) {
|
if (context.isVoidExcess()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,21 +142,17 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!simulate) {
|
if (!simulate) {
|
||||||
tag.setInteger(NBT_STORED, getStored() + remainingSpace);
|
|
||||||
|
|
||||||
stacks.put(stack.getItem(), ItemHandlerHelper.copyStackWithSize(stack, remainingSpace));
|
stacks.put(stack.getItem(), ItemHandlerHelper.copyStackWithSize(stack, remainingSpace));
|
||||||
|
|
||||||
listener.run();
|
onChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
return voidExcess.get() ? null : ItemHandlerHelper.copyStackWithSize(stack, size - remainingSpace);
|
return context.isVoidExcess() ? null : ItemHandlerHelper.copyStackWithSize(stack, size - remainingSpace);
|
||||||
} else {
|
} else {
|
||||||
if (!simulate) {
|
if (!simulate) {
|
||||||
tag.setInteger(NBT_STORED, getStored() + size);
|
|
||||||
|
|
||||||
stacks.put(stack.getItem(), ItemHandlerHelper.copyStackWithSize(stack, size));
|
stacks.put(stack.getItem(), ItemHandlerHelper.copyStackWithSize(stack, size));
|
||||||
|
|
||||||
listener.run();
|
onChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -192,7 +161,7 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public synchronized ItemStack extract(@Nonnull ItemStack stack, int size, int flags, boolean simulate) {
|
public ItemStack extract(@Nonnull ItemStack stack, int size, int flags, boolean simulate) {
|
||||||
Collection<ItemStack> toAttempt = null;
|
Collection<ItemStack> toAttempt = null;
|
||||||
|
|
||||||
if ((flags & IComparer.COMPARE_OREDICT) == IComparer.COMPARE_OREDICT) {
|
if ((flags & IComparer.COMPARE_OREDICT) == IComparer.COMPARE_OREDICT) {
|
||||||
@@ -222,9 +191,7 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
|||||||
otherStack.shrink(size);
|
otherStack.shrink(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
tag.setInteger(NBT_STORED, getStored() - size);
|
onChanged();
|
||||||
|
|
||||||
listener.run();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ItemHandlerHelper.copyStackWithSize(otherStack, size);
|
return ItemHandlerHelper.copyStackWithSize(otherStack, size);
|
||||||
@@ -236,7 +203,7 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getStored() {
|
public int getStored() {
|
||||||
return getStored(tag);
|
return stacks.values().stream().mapToInt(ItemStack::getCount).sum();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -246,7 +213,7 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AccessType getAccessType() {
|
public AccessType getAccessType() {
|
||||||
return accessType.get();
|
return context.getAccessType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -255,15 +222,9 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValid(ItemStack stack) {
|
public void setSettings(@Nullable IStorageDiskListener listener, IStorageDiskContainerContext context) {
|
||||||
return stack.hasTagCompound() && stack.getTagCompound().hasKey(NBT_ITEMS) && stack.getTagCompound().hasKey(NBT_STORED);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPassContainerContext(Runnable listener, Supplier<Boolean> voidExcess, Supplier<AccessType> accessType) {
|
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
this.voidExcess = voidExcess;
|
this.context = context;
|
||||||
this.accessType = accessType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -274,34 +235,22 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
|||||||
|
|
||||||
int inserted = remainder == null ? size : (size - remainder.getCount());
|
int inserted = remainder == null ? size : (size - remainder.getCount());
|
||||||
|
|
||||||
if (voidExcess.get() && storedPreInsertion + inserted > getCapacity()) {
|
if (context.isVoidExcess() && storedPreInsertion + inserted > getCapacity()) {
|
||||||
inserted = getCapacity() - storedPreInsertion;
|
inserted = getCapacity() - storedPreInsertion;
|
||||||
}
|
}
|
||||||
|
|
||||||
return inserted;
|
return inserted;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NBTTagCompound getShareTag(@Nullable NBTTagCompound tag) {
|
Multimap<Item, ItemStack> getRawStacks() {
|
||||||
NBTTagCompound otherTag = new NBTTagCompound();
|
return stacks;
|
||||||
|
|
||||||
otherTag.setInteger(NBT_STORED, getStored(tag));
|
|
||||||
otherTag.setTag(NBT_ITEMS, new NBTTagList());
|
|
||||||
otherTag.setInteger(NBT_PROTOCOL, PROTOCOL);
|
|
||||||
|
|
||||||
return otherTag;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getStored(@Nullable NBTTagCompound tag) {
|
private void onChanged() {
|
||||||
return tag == null ? 0 : tag.getInteger(NBT_STORED);
|
if (listener != null) {
|
||||||
}
|
listener.onChanged();
|
||||||
|
}
|
||||||
|
|
||||||
public static NBTTagCompound getTag() {
|
API.instance().getStorageDiskManager(world).markForSaving();
|
||||||
NBTTagCompound tag = new NBTTagCompound();
|
|
||||||
|
|
||||||
tag.setTag(NBT_ITEMS, new NBTTagList());
|
|
||||||
tag.setInteger(NBT_STORED, 0);
|
|
||||||
tag.setInteger(NBT_PROTOCOL, PROTOCOL);
|
|
||||||
|
|
||||||
return tag;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,16 @@
|
|||||||
package com.raoulvdberge.refinedstorage.apiimpl.storage;
|
package com.raoulvdberge.refinedstorage.apiimpl.storage.disk;
|
||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDisk;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.StorageDiskType;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener;
|
||||||
import com.raoulvdberge.refinedstorage.tile.grid.portable.IPortableGrid;
|
import com.raoulvdberge.refinedstorage.tile.grid.portable.IPortableGrid;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class StorageDiskItemPortable implements IStorageDisk<ItemStack> {
|
public class StorageDiskItemPortable implements IStorageDisk<ItemStack> {
|
||||||
private IStorageDisk<ItemStack> parent;
|
private IStorageDisk<ItemStack> parent;
|
||||||
@@ -26,28 +27,13 @@ public class StorageDiskItemPortable implements IStorageDisk<ItemStack> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValid(ItemStack stack) {
|
public void setSettings(@Nullable IStorageDiskListener listener, IStorageDiskContainerContext context) {
|
||||||
return parent.isValid(stack);
|
parent.setSettings(listener, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPassContainerContext(Runnable listener, Supplier<Boolean> voidExcess, Supplier<AccessType> accessType) {
|
public NBTTagCompound writeToNbt() {
|
||||||
parent.onPassContainerContext(listener, voidExcess, accessType);
|
return parent.writeToNbt();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readFromNBT() {
|
|
||||||
parent.readFromNBT();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeToNBT() {
|
|
||||||
parent.writeToNBT();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public StorageDiskType getType() {
|
|
||||||
return parent.getType();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -104,4 +90,9 @@ public class StorageDiskItemPortable implements IStorageDisk<ItemStack> {
|
|||||||
public int getCacheDelta(int storedPreInsertion, int size, @Nullable ItemStack remainder) {
|
public int getCacheDelta(int storedPreInsertion, int size, @Nullable ItemStack remainder) {
|
||||||
return parent.getCacheDelta(storedPreInsertion, size, remainder);
|
return parent.getCacheDelta(storedPreInsertion, size, remainder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getId() {
|
||||||
|
return parent.getId();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.apiimpl.storage.disk;
|
||||||
|
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskFactory;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskManager;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskProvider;
|
||||||
|
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.storage.WorldSavedData;
|
||||||
|
import net.minecraftforge.common.util.Constants;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
public class StorageDiskManager extends WorldSavedData implements IStorageDiskManager {
|
||||||
|
public static final String NAME = "refinedstorage_disks";
|
||||||
|
|
||||||
|
private static final String NBT_DISKS = "Disks";
|
||||||
|
private static final String NBT_DISK_ID = "Id";
|
||||||
|
private static final String NBT_DISK_TYPE = "Type";
|
||||||
|
private static final String NBT_DISK_DATA = "Data";
|
||||||
|
|
||||||
|
private boolean canReadDisks;
|
||||||
|
private NBTTagList disksTag;
|
||||||
|
|
||||||
|
private ConcurrentHashMap<UUID, IStorageDisk> disks = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public StorageDiskManager(String name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public IStorageDisk get(UUID id) {
|
||||||
|
return disks.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public IStorageDisk getByStack(ItemStack disk) {
|
||||||
|
if (!(disk.getItem() instanceof IStorageDiskProvider)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
IStorageDiskProvider provider = (IStorageDiskProvider) disk.getItem();
|
||||||
|
|
||||||
|
if (!provider.isValid(disk)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return get(provider.getId(disk));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void set(UUID id, IStorageDisk disk) {
|
||||||
|
if (disks.containsKey(id)) {
|
||||||
|
throw new IllegalArgumentException("Disks already contains id '" + id + "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
disks.put(id, disk);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void markForSaving() {
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readFromNBT(NBTTagCompound tag) {
|
||||||
|
if (tag.hasKey(NBT_DISKS)) {
|
||||||
|
this.disksTag = tag.getTagList(NBT_DISKS, Constants.NBT.TAG_COMPOUND);
|
||||||
|
this.canReadDisks = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void tryReadDisks(World world) {
|
||||||
|
if (this.canReadDisks) {
|
||||||
|
this.canReadDisks = false;
|
||||||
|
|
||||||
|
for (int i = 0; i < disksTag.tagCount(); ++i) {
|
||||||
|
NBTTagCompound diskTag = disksTag.getCompoundTagAt(i);
|
||||||
|
|
||||||
|
UUID id = diskTag.getUniqueId(NBT_DISK_ID);
|
||||||
|
NBTTagCompound data = diskTag.getCompoundTag(NBT_DISK_DATA);
|
||||||
|
String type = diskTag.getString(NBT_DISK_TYPE);
|
||||||
|
|
||||||
|
IStorageDiskFactory factory = API.instance().getStorageDiskRegistry().get(type);
|
||||||
|
if (factory != null) {
|
||||||
|
disks.put(id, factory.createFromNbt(world, data));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NBTTagCompound writeToNBT(NBTTagCompound tag) {
|
||||||
|
NBTTagList disks = new NBTTagList();
|
||||||
|
|
||||||
|
for (Map.Entry<UUID, IStorageDisk> entry : this.disks.entrySet()) {
|
||||||
|
NBTTagCompound diskTag = new NBTTagCompound();
|
||||||
|
|
||||||
|
diskTag.setUniqueId(NBT_DISK_ID, entry.getKey());
|
||||||
|
diskTag.setTag(NBT_DISK_DATA, entry.getValue().writeToNbt());
|
||||||
|
diskTag.setString(NBT_DISK_TYPE, entry.getValue().getId());
|
||||||
|
|
||||||
|
disks.appendTag(diskTag);
|
||||||
|
}
|
||||||
|
|
||||||
|
tag.setTag(NBT_DISKS, disks);
|
||||||
|
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.apiimpl.storage.disk;
|
||||||
|
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskFactory;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskRegistry;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class StorageDiskRegistry implements IStorageDiskRegistry {
|
||||||
|
private Map<String, IStorageDiskFactory> factories = new HashMap<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void add(String id, IStorageDiskFactory factory) {
|
||||||
|
factories.put(id, factory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public IStorageDiskFactory get(String id) {
|
||||||
|
return factories.get(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.apiimpl.storage.disk;
|
||||||
|
|
||||||
|
import com.raoulvdberge.refinedstorage.RS;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskSync;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskSyncData;
|
||||||
|
import com.raoulvdberge.refinedstorage.network.MessageStorageDiskSizeRequest;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class StorageDiskSync implements IStorageDiskSync {
|
||||||
|
private static final int THROTTLE_MS = 500;
|
||||||
|
|
||||||
|
private Map<UUID, IStorageDiskSyncData> data = new HashMap<>();
|
||||||
|
private Map<UUID, Long> syncTime = new HashMap<>();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public IStorageDiskSyncData getData(UUID id) {
|
||||||
|
return data.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setData(UUID id, IStorageDiskSyncData data) {
|
||||||
|
this.data.put(id, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendRequest(UUID id) {
|
||||||
|
long lastSync = syncTime.getOrDefault(id, 0L);
|
||||||
|
|
||||||
|
if (System.currentTimeMillis() - lastSync > THROTTLE_MS) {
|
||||||
|
RS.INSTANCE.network.sendToServer(new MessageStorageDiskSizeRequest(id));
|
||||||
|
|
||||||
|
syncTime.put(id, System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.apiimpl.storage.disk;
|
||||||
|
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskSyncData;
|
||||||
|
|
||||||
|
public class StorageDiskSyncData implements IStorageDiskSyncData {
|
||||||
|
private int stored;
|
||||||
|
private int capacity;
|
||||||
|
|
||||||
|
public StorageDiskSyncData(int stored, int capacity) {
|
||||||
|
this.stored = stored;
|
||||||
|
this.capacity = capacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getStored() {
|
||||||
|
return stored;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCapacity() {
|
||||||
|
return capacity;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -51,11 +51,4 @@ public class BlockDiskDrive extends BlockNode {
|
|||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void breakBlock(World world, BlockPos pos, IBlockState state) {
|
|
||||||
((TileDiskDrive) world.getTileEntity(pos)).getNode().onBreak();
|
|
||||||
|
|
||||||
super.breakBlock(world, pos, state);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,13 +52,6 @@ public class BlockDiskManipulator extends BlockNode {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void breakBlock(World world, BlockPos pos, IBlockState state) {
|
|
||||||
((TileDiskManipulator) world.getTileEntity(pos)).getNode().onBreak();
|
|
||||||
|
|
||||||
super.breakBlock(world, pos, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasConnectivityState() {
|
public boolean hasConnectivityState() {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -1,25 +1,20 @@
|
|||||||
package com.raoulvdberge.refinedstorage.block;
|
package com.raoulvdberge.refinedstorage.block;
|
||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.RSBlocks;
|
|
||||||
import com.raoulvdberge.refinedstorage.RSGui;
|
import com.raoulvdberge.refinedstorage.RSGui;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeFluidStorage;
|
|
||||||
import com.raoulvdberge.refinedstorage.item.ItemBlockFluidStorage;
|
import com.raoulvdberge.refinedstorage.item.ItemBlockFluidStorage;
|
||||||
import com.raoulvdberge.refinedstorage.tile.TileFluidStorage;
|
import com.raoulvdberge.refinedstorage.tile.TileFluidStorage;
|
||||||
import net.minecraft.block.properties.PropertyEnum;
|
import net.minecraft.block.properties.PropertyEnum;
|
||||||
import net.minecraft.block.state.BlockStateContainer;
|
import net.minecraft.block.state.BlockStateContainer;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.creativetab.CreativeTabs;
|
import net.minecraft.creativetab.CreativeTabs;
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.EnumHand;
|
import net.minecraft.util.EnumHand;
|
||||||
import net.minecraft.util.NonNullList;
|
import net.minecraft.util.NonNullList;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.IBlockAccess;
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@@ -36,7 +31,7 @@ public class BlockFluidStorage extends BlockNode {
|
|||||||
@Override
|
@Override
|
||||||
public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> items) {
|
public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> items) {
|
||||||
for (int i = 0; i <= 4; ++i) {
|
for (int i = 0; i <= 4; ++i) {
|
||||||
items.add(ItemBlockFluidStorage.initNBT(new ItemStack(this, 1, i)));
|
items.add(new ItemStack(this, 1, i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,36 +66,6 @@ public class BlockFluidStorage extends BlockNode {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack stack) {
|
|
||||||
super.onBlockPlacedBy(world, pos, state, player, stack);
|
|
||||||
|
|
||||||
if (!world.isRemote && stack.hasTagCompound() && stack.getTagCompound().hasKey(NetworkNodeFluidStorage.NBT_STORAGE)) {
|
|
||||||
((TileFluidStorage) world.getTileEntity(pos)).getNode().onPlacedWithStorage(stack.getTagCompound().getCompoundTag(NetworkNodeFluidStorage.NBT_STORAGE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void breakBlock(World world, BlockPos pos, IBlockState state) {
|
|
||||||
((TileFluidStorage) world.getTileEntity(pos)).getNode().onBreak();
|
|
||||||
|
|
||||||
super.breakBlock(world, pos, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
|
|
||||||
TileFluidStorage storage = (TileFluidStorage) world.getTileEntity(pos);
|
|
||||||
|
|
||||||
ItemStack stack = new ItemStack(RSBlocks.FLUID_STORAGE, 1, getMetaFromState(state));
|
|
||||||
stack.setTagCompound(new NBTTagCompound());
|
|
||||||
|
|
||||||
storage.getNode().getStorage().writeToNBT();
|
|
||||||
|
|
||||||
stack.getTagCompound().setTag(NetworkNodeFluidStorage.NBT_STORAGE, storage.getNode().getStorage().getStorageTag());
|
|
||||||
|
|
||||||
drops.add(stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Item createItem() {
|
public Item createItem() {
|
||||||
return new ItemBlockFluidStorage();
|
return new ItemBlockFluidStorage();
|
||||||
|
|||||||
@@ -1,25 +1,20 @@
|
|||||||
package com.raoulvdberge.refinedstorage.block;
|
package com.raoulvdberge.refinedstorage.block;
|
||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.RSBlocks;
|
|
||||||
import com.raoulvdberge.refinedstorage.RSGui;
|
import com.raoulvdberge.refinedstorage.RSGui;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeStorage;
|
|
||||||
import com.raoulvdberge.refinedstorage.item.ItemBlockStorage;
|
import com.raoulvdberge.refinedstorage.item.ItemBlockStorage;
|
||||||
import com.raoulvdberge.refinedstorage.tile.TileStorage;
|
import com.raoulvdberge.refinedstorage.tile.TileStorage;
|
||||||
import net.minecraft.block.properties.PropertyEnum;
|
import net.minecraft.block.properties.PropertyEnum;
|
||||||
import net.minecraft.block.state.BlockStateContainer;
|
import net.minecraft.block.state.BlockStateContainer;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.creativetab.CreativeTabs;
|
import net.minecraft.creativetab.CreativeTabs;
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.EnumHand;
|
import net.minecraft.util.EnumHand;
|
||||||
import net.minecraft.util.NonNullList;
|
import net.minecraft.util.NonNullList;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.IBlockAccess;
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@@ -36,7 +31,7 @@ public class BlockStorage extends BlockNode {
|
|||||||
@Override
|
@Override
|
||||||
public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> items) {
|
public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> items) {
|
||||||
for (int i = 0; i <= 4; ++i) {
|
for (int i = 0; i <= 4; ++i) {
|
||||||
items.add(ItemBlockStorage.initNBT(new ItemStack(this, 1, i)));
|
items.add(new ItemStack(this, 1, i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,36 +66,6 @@ public class BlockStorage extends BlockNode {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack stack) {
|
|
||||||
super.onBlockPlacedBy(world, pos, state, player, stack);
|
|
||||||
|
|
||||||
if (!world.isRemote && stack.hasTagCompound() && stack.getTagCompound().hasKey(NetworkNodeStorage.NBT_STORAGE)) {
|
|
||||||
((TileStorage) world.getTileEntity(pos)).getNode().onPlacedWithStorage(stack.getTagCompound().getCompoundTag(NetworkNodeStorage.NBT_STORAGE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void breakBlock(World world, BlockPos pos, IBlockState state) {
|
|
||||||
((TileStorage) world.getTileEntity(pos)).getNode().onBreak();
|
|
||||||
|
|
||||||
super.breakBlock(world, pos, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
|
|
||||||
TileStorage storage = (TileStorage) world.getTileEntity(pos);
|
|
||||||
|
|
||||||
ItemStack stack = new ItemStack(RSBlocks.STORAGE, 1, getMetaFromState(state));
|
|
||||||
stack.setTagCompound(new NBTTagCompound());
|
|
||||||
|
|
||||||
storage.getNode().getStorage().writeToNBT();
|
|
||||||
|
|
||||||
stack.getTagCompound().setTag(NetworkNodeStorage.NBT_STORAGE, storage.getNode().getStorage().getStorageTag());
|
|
||||||
|
|
||||||
drops.add(stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Item createItem() {
|
public Item createItem() {
|
||||||
return new ItemBlockStorage();
|
return new ItemBlockStorage();
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import com.raoulvdberge.refinedstorage.api.network.grid.handler.IFluidGridHandle
|
|||||||
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IItemGridHandler;
|
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IItemGridHandler;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageCache;
|
import com.raoulvdberge.refinedstorage.api.storage.IStorageCache;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageCacheListener;
|
import com.raoulvdberge.refinedstorage.api.storage.IStorageCacheListener;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDiskProvider;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskFactory;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeGrid;
|
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeGrid;
|
||||||
import com.raoulvdberge.refinedstorage.container.slot.*;
|
import com.raoulvdberge.refinedstorage.container.slot.*;
|
||||||
import com.raoulvdberge.refinedstorage.gui.IResizableDisplay;
|
import com.raoulvdberge.refinedstorage.gui.IResizableDisplay;
|
||||||
@@ -245,7 +245,7 @@ public class ContainerGrid extends ContainerBase {
|
|||||||
|
|
||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
}
|
}
|
||||||
} else if ((grid.getType() == GridType.PATTERN && stack.getItem() == RSItems.PATTERN) || (grid instanceof IPortableGrid && stack.getItem() instanceof IStorageDiskProvider)) {
|
} else if ((grid.getType() == GridType.PATTERN && stack.getItem() == RSItems.PATTERN) || (grid instanceof IPortableGrid && stack.getItem() instanceof IStorageDiskFactory)) {
|
||||||
int startIndex = 4;
|
int startIndex = 4;
|
||||||
int endIndex = startIndex + 1;
|
int endIndex = startIndex + 1;
|
||||||
|
|
||||||
|
|||||||
@@ -1,113 +1,9 @@
|
|||||||
package com.raoulvdberge.refinedstorage.item;
|
package com.raoulvdberge.refinedstorage.item;
|
||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.RSBlocks;
|
import com.raoulvdberge.refinedstorage.RSBlocks;
|
||||||
import com.raoulvdberge.refinedstorage.RSItems;
|
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeFluidStorage;
|
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskFluid;
|
|
||||||
import com.raoulvdberge.refinedstorage.block.FluidStorageType;
|
|
||||||
import net.minecraft.client.resources.I18n;
|
|
||||||
import net.minecraft.client.util.ITooltipFlag;
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.inventory.InventoryHelper;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.util.ActionResult;
|
|
||||||
import net.minecraft.util.EnumActionResult;
|
|
||||||
import net.minecraft.util.EnumHand;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ItemBlockFluidStorage extends ItemBlockBase {
|
public class ItemBlockFluidStorage extends ItemBlockBase {
|
||||||
public ItemBlockFluidStorage() {
|
public ItemBlockFluidStorage() {
|
||||||
super(RSBlocks.FLUID_STORAGE, RSBlocks.FLUID_STORAGE.getDirection(), true);
|
super(RSBlocks.FLUID_STORAGE, RSBlocks.FLUID_STORAGE.getDirection(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addInformation(ItemStack stack, @Nullable World world, List<String> tooltip, ITooltipFlag flag) {
|
|
||||||
super.addInformation(stack, world, tooltip, flag);
|
|
||||||
|
|
||||||
FluidStorageType type = FluidStorageType.getById(stack.getMetadata());
|
|
||||||
|
|
||||||
if (type != null && isValid(stack)) {
|
|
||||||
NBTTagCompound tag = stack.getTagCompound().getCompoundTag(NetworkNodeFluidStorage.NBT_STORAGE);
|
|
||||||
|
|
||||||
if (type == FluidStorageType.TYPE_CREATIVE) {
|
|
||||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored", API.instance().getQuantityFormatter().format(StorageDiskFluid.getStored(tag))));
|
|
||||||
} else {
|
|
||||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored_capacity", API.instance().getQuantityFormatter().format(StorageDiskFluid.getStored(tag)), API.instance().getQuantityFormatter().format(type.getCapacity())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
|
|
||||||
ItemStack stack = player.getHeldItem(hand);
|
|
||||||
|
|
||||||
FluidStorageType type = FluidStorageType.getById(stack.getMetadata());
|
|
||||||
|
|
||||||
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())) {
|
|
||||||
InventoryHelper.spawnItemStack(world, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), storagePart);
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemStack processor = new ItemStack(RSItems.PROCESSOR, 1, ItemProcessor.TYPE_BASIC);
|
|
||||||
|
|
||||||
if (!player.inventory.addItemStackToInventory(processor.copy())) {
|
|
||||||
InventoryHelper.spawnItemStack(world, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), processor);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ActionResult<>(EnumActionResult.SUCCESS, new ItemStack(RSBlocks.MACHINE_CASING));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ActionResult<>(EnumActionResult.PASS, stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isValid(ItemStack stack) {
|
|
||||||
return stack.getTagCompound() != null && stack.getTagCompound().hasKey(NetworkNodeFluidStorage.NBT_STORAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean selected) {
|
|
||||||
super.onUpdate(stack, world, entity, slot, selected);
|
|
||||||
|
|
||||||
if (!stack.hasTagCompound()) {
|
|
||||||
initNBT(stack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreated(ItemStack stack, World world, EntityPlayer player) {
|
|
||||||
super.onCreated(stack, world, player);
|
|
||||||
|
|
||||||
initNBT(stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getEntityLifespan(ItemStack stack, World world) {
|
|
||||||
return Integer.MAX_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NBTTagCompound getNBTShareTag(ItemStack stack) {
|
|
||||||
if (!isValid(stack)) {
|
|
||||||
return super.getNBTShareTag(stack);
|
|
||||||
} else {
|
|
||||||
NBTTagCompound shareTag = new NBTTagCompound();
|
|
||||||
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, StorageDiskFluid.getTag());
|
|
||||||
stack.setTagCompound(tag);
|
|
||||||
return stack;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,113 +1,9 @@
|
|||||||
package com.raoulvdberge.refinedstorage.item;
|
package com.raoulvdberge.refinedstorage.item;
|
||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.RSBlocks;
|
import com.raoulvdberge.refinedstorage.RSBlocks;
|
||||||
import com.raoulvdberge.refinedstorage.RSItems;
|
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeStorage;
|
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskItem;
|
|
||||||
import com.raoulvdberge.refinedstorage.block.ItemStorageType;
|
|
||||||
import net.minecraft.client.resources.I18n;
|
|
||||||
import net.minecraft.client.util.ITooltipFlag;
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.inventory.InventoryHelper;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.util.ActionResult;
|
|
||||||
import net.minecraft.util.EnumActionResult;
|
|
||||||
import net.minecraft.util.EnumHand;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ItemBlockStorage extends ItemBlockBase {
|
public class ItemBlockStorage extends ItemBlockBase {
|
||||||
public ItemBlockStorage() {
|
public ItemBlockStorage() {
|
||||||
super(RSBlocks.STORAGE, RSBlocks.STORAGE.getDirection(), true);
|
super(RSBlocks.STORAGE, RSBlocks.STORAGE.getDirection(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addInformation(ItemStack stack, @Nullable World world, List<String> tooltip, ITooltipFlag flag) {
|
|
||||||
super.addInformation(stack, world, tooltip, flag);
|
|
||||||
|
|
||||||
ItemStorageType type = ItemStorageType.getById(stack.getMetadata());
|
|
||||||
|
|
||||||
if (type != null && isValid(stack)) {
|
|
||||||
NBTTagCompound tag = stack.getTagCompound().getCompoundTag(NetworkNodeStorage.NBT_STORAGE);
|
|
||||||
|
|
||||||
if (type == ItemStorageType.TYPE_CREATIVE) {
|
|
||||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored", API.instance().getQuantityFormatter().format(StorageDiskItem.getStored(tag))));
|
|
||||||
} else {
|
|
||||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored_capacity", API.instance().getQuantityFormatter().format(StorageDiskItem.getStored(tag)), API.instance().getQuantityFormatter().format(type.getCapacity())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
|
|
||||||
ItemStack stack = player.getHeldItem(hand);
|
|
||||||
|
|
||||||
ItemStorageType type = ItemStorageType.getById(stack.getMetadata());
|
|
||||||
|
|
||||||
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())) {
|
|
||||||
InventoryHelper.spawnItemStack(world, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), storagePart);
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemStack processor = new ItemStack(RSItems.PROCESSOR, 1, ItemProcessor.TYPE_BASIC);
|
|
||||||
|
|
||||||
if (!player.inventory.addItemStackToInventory(processor.copy())) {
|
|
||||||
InventoryHelper.spawnItemStack(world, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), processor);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ActionResult<>(EnumActionResult.SUCCESS, new ItemStack(RSBlocks.MACHINE_CASING));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ActionResult<>(EnumActionResult.PASS, stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isValid(ItemStack stack) {
|
|
||||||
return stack.getTagCompound() != null && stack.getTagCompound().hasKey(NetworkNodeStorage.NBT_STORAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean selected) {
|
|
||||||
super.onUpdate(stack, world, entity, slot, selected);
|
|
||||||
|
|
||||||
if (!stack.hasTagCompound()) {
|
|
||||||
initNBT(stack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreated(ItemStack stack, World world, EntityPlayer player) {
|
|
||||||
super.onCreated(stack, world, player);
|
|
||||||
|
|
||||||
initNBT(stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getEntityLifespan(ItemStack stack, World world) {
|
|
||||||
return Integer.MAX_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NBTTagCompound getNBTShareTag(ItemStack stack) {
|
|
||||||
if (!isValid(stack)) {
|
|
||||||
return super.getNBTShareTag(stack);
|
|
||||||
} else {
|
|
||||||
NBTTagCompound shareTag = new NBTTagCompound();
|
|
||||||
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, StorageDiskItem.getTag());
|
|
||||||
stack.setTagCompound(tag);
|
|
||||||
return stack;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,40 +1,32 @@
|
|||||||
package com.raoulvdberge.refinedstorage.item;
|
package com.raoulvdberge.refinedstorage.item;
|
||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.RSItems;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskProvider;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDisk;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskSyncData;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDiskProvider;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.StorageDiskType;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.StorageDiskType;
|
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskFluid;
|
import com.raoulvdberge.refinedstorage.apiimpl.storage.disk.StorageDiskFluid;
|
||||||
import com.raoulvdberge.refinedstorage.block.FluidStorageType;
|
import com.raoulvdberge.refinedstorage.block.FluidStorageType;
|
||||||
import net.minecraft.client.resources.I18n;
|
import net.minecraft.client.resources.I18n;
|
||||||
import net.minecraft.client.util.ITooltipFlag;
|
import net.minecraft.client.util.ITooltipFlag;
|
||||||
import net.minecraft.creativetab.CreativeTabs;
|
import net.minecraft.creativetab.CreativeTabs;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.inventory.InventoryHelper;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.ActionResult;
|
|
||||||
import net.minecraft.util.EnumActionResult;
|
|
||||||
import net.minecraft.util.EnumHand;
|
|
||||||
import net.minecraft.util.NonNullList;
|
import net.minecraft.util.NonNullList;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.fluids.Fluid;
|
|
||||||
import net.minecraftforge.fluids.FluidRegistry;
|
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class ItemFluidStorageDisk extends ItemBase implements IStorageDiskProvider {
|
||||||
|
private static final String NBT_ID = "Id";
|
||||||
|
|
||||||
public class ItemFluidStorageDisk extends ItemBase implements IStorageDiskProvider<FluidStack> {
|
|
||||||
public static final int TYPE_64K = 0;
|
public static final int TYPE_64K = 0;
|
||||||
public static final int TYPE_128K = 1;
|
public static final int TYPE_128K = 1;
|
||||||
public static final int TYPE_256K = 2;
|
public static final int TYPE_256K = 2;
|
||||||
public static final int TYPE_512K = 3;
|
public static final int TYPE_512K = 3;
|
||||||
public static final int TYPE_CREATIVE = 4;
|
public static final int TYPE_CREATIVE = 4;
|
||||||
public static final int TYPE_DEBUG = 5;
|
|
||||||
|
|
||||||
public ItemFluidStorageDisk() {
|
public ItemFluidStorageDisk() {
|
||||||
super("fluid_storage_disk");
|
super("fluid_storage_disk");
|
||||||
@@ -51,77 +43,50 @@ public class ItemFluidStorageDisk extends ItemBase implements IStorageDiskProvid
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 5; ++i) {
|
for (int i = 0; i < 5; ++i) {
|
||||||
items.add(API.instance().getDefaultStorageDiskBehavior().initDisk(StorageDiskType.FLUIDS, new ItemStack(this, 1, i)));
|
items.add(new ItemStack(this, 1, i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyDebugDiskData(ItemStack stack) {
|
|
||||||
NBTTagCompound debugDiskTag = API.instance().getDefaultStorageDiskBehavior().getTag(StorageDiskType.FLUIDS);
|
|
||||||
|
|
||||||
StorageDiskFluid storage = new StorageDiskFluid(debugDiskTag, -1);
|
|
||||||
|
|
||||||
for (Fluid fluid : FluidRegistry.getRegisteredFluids().values()) {
|
|
||||||
storage.insert(new FluidStack(fluid, 0), Fluid.BUCKET_VOLUME * 1000, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
storage.writeToNBT();
|
|
||||||
|
|
||||||
stack.setTagCompound(debugDiskTag);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean selected) {
|
public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean selected) {
|
||||||
super.onUpdate(stack, world, entity, slot, selected);
|
super.onUpdate(stack, world, entity, slot, selected);
|
||||||
|
|
||||||
if (!stack.hasTagCompound()) {
|
if (!world.isRemote && !stack.hasTagCompound()) {
|
||||||
if (stack.getMetadata() == TYPE_DEBUG) {
|
UUID id = UUID.randomUUID();
|
||||||
applyDebugDiskData(stack);
|
|
||||||
} else {
|
stack.setTagCompound(new NBTTagCompound());
|
||||||
API.instance().getDefaultStorageDiskBehavior().initDisk(StorageDiskType.FLUIDS, stack);
|
stack.getTagCompound().setUniqueId(NBT_ID, id);
|
||||||
}
|
|
||||||
|
API.instance().getStorageDiskManager(world).set(id, new StorageDiskFluid(world, FluidStorageType.getById(stack.getItemDamage()).getCapacity()));
|
||||||
|
API.instance().getStorageDiskManager(world).markForSaving();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
|
|
||||||
ItemStack disk = player.getHeldItem(hand);
|
|
||||||
|
|
||||||
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())) {
|
|
||||||
InventoryHelper.spawnItemStack(world, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), storagePart);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ActionResult<>(EnumActionResult.SUCCESS, new ItemStack(RSItems.STORAGE_HOUSING));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ActionResult<>(EnumActionResult.PASS, disk);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addInformation(ItemStack stack, @Nullable World world, List<String> tooltip, ITooltipFlag flag) {
|
public void addInformation(ItemStack stack, @Nullable World world, List<String> tooltip, ITooltipFlag flag) {
|
||||||
super.addInformation(stack, world, tooltip, flag);
|
super.addInformation(stack, world, tooltip, flag);
|
||||||
|
|
||||||
IStorageDisk storage = create(stack);
|
if (isValid(stack)) {
|
||||||
|
UUID id = getId(stack);
|
||||||
|
|
||||||
if (storage.isValid(stack)) {
|
API.instance().getStorageDiskSync().sendRequest(id);
|
||||||
if (storage.getCapacity() == -1) {
|
|
||||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored", API.instance().getQuantityFormatter().format(storage.getStored())));
|
IStorageDiskSyncData data = API.instance().getStorageDiskSync().getData(id);
|
||||||
} else {
|
if (data != null) {
|
||||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored_capacity", API.instance().getQuantityFormatter().format(storage.getStored()), API.instance().getQuantityFormatter().format(storage.getCapacity())));
|
if (data.getCapacity() == -1) {
|
||||||
|
tooltip.add(I18n.format("misc.refinedstorage:storage.stored", API.instance().getQuantityFormatter().format(data.getStored())));
|
||||||
|
} else {
|
||||||
|
tooltip.add(I18n.format("misc.refinedstorage:storage.stored_capacity", API.instance().getQuantityFormatter().format(data.getStored()), API.instance().getQuantityFormatter().format(data.getCapacity())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flag.isAdvanced()) {
|
||||||
|
tooltip.add(id.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// TODO: onItemRightClick
|
||||||
public void onCreated(ItemStack stack, World world, EntityPlayer player) {
|
|
||||||
super.onCreated(stack, world, player);
|
|
||||||
|
|
||||||
API.instance().getDefaultStorageDiskBehavior().initDisk(StorageDiskType.FLUIDS, stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getEntityLifespan(ItemStack stack, World world) {
|
public int getEntityLifespan(ItemStack stack, World world) {
|
||||||
@@ -129,13 +94,17 @@ public class ItemFluidStorageDisk extends ItemBase implements IStorageDiskProvid
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NBTTagCompound getNBTShareTag(ItemStack stack) {
|
public UUID getId(ItemStack disk) {
|
||||||
return API.instance().getDefaultStorageDiskBehavior().getShareTag(StorageDiskType.FLUIDS, stack);
|
return disk.getTagCompound().getUniqueId(NBT_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public IStorageDisk<FluidStack> create(ItemStack disk) {
|
public boolean isValid(ItemStack disk) {
|
||||||
return API.instance().getDefaultStorageDiskBehavior().createFluidStorage(disk.getTagCompound(), FluidStorageType.getById(disk.getItemDamage()).getCapacity());
|
return disk.hasTagCompound() && disk.getTagCompound().hasUniqueId(NBT_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StorageDiskType getType() {
|
||||||
|
return StorageDiskType.FLUID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,39 +1,32 @@
|
|||||||
package com.raoulvdberge.refinedstorage.item;
|
package com.raoulvdberge.refinedstorage.item;
|
||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.RSItems;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskProvider;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDisk;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskSyncData;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDiskProvider;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.StorageDiskType;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.StorageDiskType;
|
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskItem;
|
import com.raoulvdberge.refinedstorage.apiimpl.storage.disk.StorageDiskItem;
|
||||||
import com.raoulvdberge.refinedstorage.block.ItemStorageType;
|
import com.raoulvdberge.refinedstorage.block.ItemStorageType;
|
||||||
import net.minecraft.client.resources.I18n;
|
import net.minecraft.client.resources.I18n;
|
||||||
import net.minecraft.client.util.ITooltipFlag;
|
import net.minecraft.client.util.ITooltipFlag;
|
||||||
import net.minecraft.creativetab.CreativeTabs;
|
import net.minecraft.creativetab.CreativeTabs;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.inventory.InventoryHelper;
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.ActionResult;
|
|
||||||
import net.minecraft.util.EnumActionResult;
|
|
||||||
import net.minecraft.util.EnumHand;
|
|
||||||
import net.minecraft.util.NonNullList;
|
import net.minecraft.util.NonNullList;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class ItemStorageDisk extends ItemBase implements IStorageDiskProvider {
|
||||||
|
private static final String NBT_ID = "Id";
|
||||||
|
|
||||||
public class ItemStorageDisk extends ItemBase implements IStorageDiskProvider<ItemStack> {
|
|
||||||
public static final int TYPE_1K = 0;
|
public static final int TYPE_1K = 0;
|
||||||
public static final int TYPE_4K = 1;
|
public static final int TYPE_4K = 1;
|
||||||
public static final int TYPE_16K = 2;
|
public static final int TYPE_16K = 2;
|
||||||
public static final int TYPE_64K = 3;
|
public static final int TYPE_64K = 3;
|
||||||
public static final int TYPE_CREATIVE = 4;
|
public static final int TYPE_CREATIVE = 4;
|
||||||
public static final int TYPE_DEBUG = 5;
|
|
||||||
|
|
||||||
public ItemStorageDisk() {
|
public ItemStorageDisk() {
|
||||||
super("storage_disk");
|
super("storage_disk");
|
||||||
@@ -50,7 +43,7 @@ public class ItemStorageDisk extends ItemBase implements IStorageDiskProvider<It
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 5; ++i) {
|
for (int i = 0; i < 5; ++i) {
|
||||||
items.add(API.instance().getDefaultStorageDiskBehavior().initDisk(StorageDiskType.ITEMS, new ItemStack(this, 1, i)));
|
items.add(new ItemStack(this, 1, i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,81 +51,42 @@ public class ItemStorageDisk extends ItemBase implements IStorageDiskProvider<It
|
|||||||
public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean selected) {
|
public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean selected) {
|
||||||
super.onUpdate(stack, world, entity, slot, selected);
|
super.onUpdate(stack, world, entity, slot, selected);
|
||||||
|
|
||||||
if (!stack.hasTagCompound()) {
|
if (!world.isRemote && !stack.hasTagCompound()) {
|
||||||
if (stack.getItemDamage() == TYPE_DEBUG) {
|
UUID id = UUID.randomUUID();
|
||||||
applyDebugDiskData(stack);
|
|
||||||
} else {
|
stack.setTagCompound(new NBTTagCompound());
|
||||||
API.instance().getDefaultStorageDiskBehavior().initDisk(StorageDiskType.ITEMS, stack);
|
stack.getTagCompound().setUniqueId(NBT_ID, id);
|
||||||
}
|
|
||||||
|
API.instance().getStorageDiskManager(world).set(id, new StorageDiskItem(world, ItemStorageType.getById(stack.getItemDamage()).getCapacity())); //TODO: create factory in API
|
||||||
|
API.instance().getStorageDiskManager(world).markForSaving();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyDebugDiskData(ItemStack stack) {
|
|
||||||
NBTTagCompound debugDiskTag = API.instance().getDefaultStorageDiskBehavior().getTag(StorageDiskType.ITEMS);
|
|
||||||
|
|
||||||
StorageDiskItem storage = new StorageDiskItem(debugDiskTag, -1);
|
|
||||||
|
|
||||||
Iterator<Item> it = REGISTRY.iterator();
|
|
||||||
|
|
||||||
while (it.hasNext()) {
|
|
||||||
Item item = it.next();
|
|
||||||
|
|
||||||
if (item != RSItems.STORAGE_DISK) {
|
|
||||||
NonNullList<ItemStack> stacks = NonNullList.create();
|
|
||||||
|
|
||||||
item.getSubItems(CreativeTabs.SEARCH, stacks);
|
|
||||||
|
|
||||||
for (ItemStack itemStack : stacks) {
|
|
||||||
storage.insert(itemStack, 1000, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
storage.writeToNBT();
|
|
||||||
|
|
||||||
stack.setTagCompound(debugDiskTag);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addInformation(ItemStack stack, @Nullable World world, List<String> tooltip, ITooltipFlag flag) {
|
public void addInformation(ItemStack stack, @Nullable World world, List<String> tooltip, ITooltipFlag flag) {
|
||||||
super.addInformation(stack, world, tooltip, flag);
|
super.addInformation(stack, world, tooltip, flag);
|
||||||
|
|
||||||
IStorageDisk storage = create(stack);
|
if (isValid(stack)) {
|
||||||
|
UUID id = getId(stack);
|
||||||
|
|
||||||
if (storage.isValid(stack)) {
|
API.instance().getStorageDiskSync().sendRequest(id);
|
||||||
if (storage.getCapacity() == -1) {
|
|
||||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored", API.instance().getQuantityFormatter().format(storage.getStored())));
|
IStorageDiskSyncData data = API.instance().getStorageDiskSync().getData(id);
|
||||||
} else {
|
if (data != null) {
|
||||||
tooltip.add(I18n.format("misc.refinedstorage:storage.stored_capacity", API.instance().getQuantityFormatter().format(storage.getStored()), API.instance().getQuantityFormatter().format(storage.getCapacity())));
|
if (data.getCapacity() == -1) {
|
||||||
|
tooltip.add(I18n.format("misc.refinedstorage:storage.stored", API.instance().getQuantityFormatter().format(data.getStored())));
|
||||||
|
} else {
|
||||||
|
tooltip.add(I18n.format("misc.refinedstorage:storage.stored_capacity", API.instance().getQuantityFormatter().format(data.getStored()), API.instance().getQuantityFormatter().format(data.getCapacity())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flag.isAdvanced()) {
|
||||||
|
tooltip.add(id.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// TODO: onItemRightClick
|
||||||
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
|
|
||||||
ItemStack disk = player.getHeldItem(hand);
|
|
||||||
|
|
||||||
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())) {
|
|
||||||
InventoryHelper.spawnItemStack(world, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), storagePart);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ActionResult<>(EnumActionResult.SUCCESS, new ItemStack(RSItems.STORAGE_HOUSING));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ActionResult<>(EnumActionResult.PASS, disk);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreated(ItemStack stack, World world, EntityPlayer player) {
|
|
||||||
super.onCreated(stack, world, player);
|
|
||||||
|
|
||||||
API.instance().getDefaultStorageDiskBehavior().initDisk(StorageDiskType.ITEMS, stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getEntityLifespan(ItemStack stack, World world) {
|
public int getEntityLifespan(ItemStack stack, World world) {
|
||||||
@@ -140,13 +94,17 @@ public class ItemStorageDisk extends ItemBase implements IStorageDiskProvider<It
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NBTTagCompound getNBTShareTag(ItemStack stack) {
|
public UUID getId(ItemStack disk) {
|
||||||
return API.instance().getDefaultStorageDiskBehavior().getShareTag(StorageDiskType.ITEMS, stack);
|
return disk.getTagCompound().getUniqueId(NBT_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public IStorageDisk<ItemStack> create(ItemStack disk) {
|
public boolean isValid(ItemStack disk) {
|
||||||
return API.instance().getDefaultStorageDiskBehavior().createItemStorage(disk.getTagCompound(), ItemStorageType.getById(disk.getItemDamage()).getCapacity());
|
return disk.hasTagCompound() && disk.getTagCompound().hasUniqueId(NBT_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StorageDiskType getType() {
|
||||||
|
return StorageDiskType.ITEM;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.network;
|
||||||
|
|
||||||
|
import com.raoulvdberge.refinedstorage.RS;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
|
||||||
|
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
|
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||||
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class MessageStorageDiskSizeRequest extends MessageHandlerPlayerToServer<MessageStorageDiskSizeRequest> implements IMessage {
|
||||||
|
private UUID id;
|
||||||
|
|
||||||
|
public MessageStorageDiskSizeRequest() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageStorageDiskSizeRequest(UUID id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handle(MessageStorageDiskSizeRequest message, EntityPlayerMP player) {
|
||||||
|
IStorageDisk disk = API.instance().getStorageDiskManager(player.getEntityWorld()).get(message.id);
|
||||||
|
|
||||||
|
if (disk != null) {
|
||||||
|
RS.INSTANCE.network.sendTo(new MessageStorageDiskSizeResponse(message.id, disk.getStored(), disk.getCapacity()), player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fromBytes(ByteBuf buf) {
|
||||||
|
id = UUID.fromString(ByteBufUtils.readUTF8String(buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void toBytes(ByteBuf buf) {
|
||||||
|
ByteBufUtils.writeUTF8String(buf, id.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.network;
|
||||||
|
|
||||||
|
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||||
|
import com.raoulvdberge.refinedstorage.apiimpl.storage.disk.StorageDiskSync;
|
||||||
|
import com.raoulvdberge.refinedstorage.apiimpl.storage.disk.StorageDiskSyncData;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||||
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||||
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||||
|
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class MessageStorageDiskSizeResponse implements IMessage, IMessageHandler<MessageStorageDiskSizeResponse, IMessage> {
|
||||||
|
private UUID id;
|
||||||
|
private int stored;
|
||||||
|
private int capacity;
|
||||||
|
|
||||||
|
public MessageStorageDiskSizeResponse() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageStorageDiskSizeResponse(UUID id, int stored, int capacity) {
|
||||||
|
this.id = id;
|
||||||
|
this.stored = stored;
|
||||||
|
this.capacity = capacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fromBytes(ByteBuf buf) {
|
||||||
|
id = UUID.fromString(ByteBufUtils.readUTF8String(buf));
|
||||||
|
stored = buf.readInt();
|
||||||
|
capacity = buf.readInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void toBytes(ByteBuf buf) {
|
||||||
|
ByteBufUtils.writeUTF8String(buf, id.toString());
|
||||||
|
buf.writeInt(stored);
|
||||||
|
buf.writeInt(capacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IMessage onMessage(MessageStorageDiskSizeResponse message, MessageContext ctx) {
|
||||||
|
((StorageDiskSync) API.instance().getStorageDiskSync()).setData(message.id, new StorageDiskSyncData(message.stored, message.capacity));
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,6 +20,8 @@ import com.raoulvdberge.refinedstorage.apiimpl.network.readerwriter.ReaderWriter
|
|||||||
import com.raoulvdberge.refinedstorage.apiimpl.network.readerwriter.ReaderWriterHandlerItems;
|
import com.raoulvdberge.refinedstorage.apiimpl.network.readerwriter.ReaderWriterHandlerItems;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.network.readerwriter.ReaderWriterHandlerRedstone;
|
import com.raoulvdberge.refinedstorage.apiimpl.network.readerwriter.ReaderWriterHandlerRedstone;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.solderer.SoldererRecipeLoader;
|
import com.raoulvdberge.refinedstorage.apiimpl.solderer.SoldererRecipeLoader;
|
||||||
|
import com.raoulvdberge.refinedstorage.apiimpl.storage.disk.StorageDiskFactoryFluid;
|
||||||
|
import com.raoulvdberge.refinedstorage.apiimpl.storage.disk.StorageDiskFactoryItem;
|
||||||
import com.raoulvdberge.refinedstorage.block.BlockBase;
|
import com.raoulvdberge.refinedstorage.block.BlockBase;
|
||||||
import com.raoulvdberge.refinedstorage.capability.CapabilityNetworkNodeProxy;
|
import com.raoulvdberge.refinedstorage.capability.CapabilityNetworkNodeProxy;
|
||||||
import com.raoulvdberge.refinedstorage.gui.GuiHandler;
|
import com.raoulvdberge.refinedstorage.gui.GuiHandler;
|
||||||
@@ -108,6 +110,9 @@ public class ProxyCommon {
|
|||||||
API.instance().getReaderWriterHandlerRegistry().add(ReaderWriterHandlerRedstone.ID, tag -> new ReaderWriterHandlerRedstone());
|
API.instance().getReaderWriterHandlerRegistry().add(ReaderWriterHandlerRedstone.ID, tag -> new ReaderWriterHandlerRedstone());
|
||||||
API.instance().getReaderWriterHandlerRegistry().add(ReaderWriterHandlerForgeEnergy.ID, ReaderWriterHandlerForgeEnergy::new);
|
API.instance().getReaderWriterHandlerRegistry().add(ReaderWriterHandlerForgeEnergy.ID, ReaderWriterHandlerForgeEnergy::new);
|
||||||
|
|
||||||
|
API.instance().getStorageDiskRegistry().add(StorageDiskFactoryItem.ID, new StorageDiskFactoryItem());
|
||||||
|
API.instance().getStorageDiskRegistry().add(StorageDiskFactoryFluid.ID, new StorageDiskFactoryFluid());
|
||||||
|
|
||||||
int id = 0;
|
int id = 0;
|
||||||
|
|
||||||
RS.INSTANCE.network.registerMessage(MessageTileDataParameter.class, MessageTileDataParameter.class, id++, Side.CLIENT);
|
RS.INSTANCE.network.registerMessage(MessageTileDataParameter.class, MessageTileDataParameter.class, id++, Side.CLIENT);
|
||||||
@@ -140,6 +145,8 @@ public class ProxyCommon {
|
|||||||
RS.INSTANCE.network.registerMessage(MessageCrafterManagerSlotSizes.class, MessageCrafterManagerSlotSizes.class, id++, Side.CLIENT);
|
RS.INSTANCE.network.registerMessage(MessageCrafterManagerSlotSizes.class, MessageCrafterManagerSlotSizes.class, id++, Side.CLIENT);
|
||||||
RS.INSTANCE.network.registerMessage(MessageCrafterManagerRequestSlotData.class, MessageCrafterManagerRequestSlotData.class, id++, Side.SERVER);
|
RS.INSTANCE.network.registerMessage(MessageCrafterManagerRequestSlotData.class, MessageCrafterManagerRequestSlotData.class, id++, Side.SERVER);
|
||||||
RS.INSTANCE.network.registerMessage(MessageWirelessCraftingMonitorSize.class, MessageWirelessCraftingMonitorSize.class, id++, Side.SERVER);
|
RS.INSTANCE.network.registerMessage(MessageWirelessCraftingMonitorSize.class, MessageWirelessCraftingMonitorSize.class, id++, Side.SERVER);
|
||||||
|
RS.INSTANCE.network.registerMessage(MessageStorageDiskSizeRequest.class, MessageStorageDiskSizeRequest.class, id++, Side.SERVER);
|
||||||
|
RS.INSTANCE.network.registerMessage(MessageStorageDiskSizeResponse.class, MessageStorageDiskSizeResponse.class, id++, Side.CLIENT);
|
||||||
|
|
||||||
NetworkRegistry.INSTANCE.registerGuiHandler(RS.INSTANCE, new GuiHandler());
|
NetworkRegistry.INSTANCE.registerGuiHandler(RS.INSTANCE, new GuiHandler());
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.raoulvdberge.refinedstorage.tile;
|
package com.raoulvdberge.refinedstorage.tile;
|
||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDisk;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.diskdrive.NetworkNodeDiskDrive;
|
import com.raoulvdberge.refinedstorage.apiimpl.network.node.diskdrive.NetworkNodeDiskDrive;
|
||||||
import com.raoulvdberge.refinedstorage.tile.config.*;
|
import com.raoulvdberge.refinedstorage.tile.config.*;
|
||||||
import com.raoulvdberge.refinedstorage.tile.data.TileDataParameter;
|
import com.raoulvdberge.refinedstorage.tile.data.TileDataParameter;
|
||||||
@@ -26,13 +26,13 @@ public class TileDiskDrive extends TileNode<NetworkNodeDiskDrive> {
|
|||||||
public static final TileDataParameter<Integer, TileDiskDrive> STORED = new TileDataParameter<>(DataSerializers.VARINT, 0, t -> {
|
public static final TileDataParameter<Integer, TileDiskDrive> STORED = new TileDataParameter<>(DataSerializers.VARINT, 0, t -> {
|
||||||
int stored = 0;
|
int stored = 0;
|
||||||
|
|
||||||
for (IStorageDisk storage : t.getNode().getItemStorages()) {
|
for (IStorageDisk storage : t.getNode().getItemDisks()) {
|
||||||
if (storage != null) {
|
if (storage != null) {
|
||||||
stored += storage.getStored();
|
stored += storage.getStored();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (IStorageDisk storage : t.getNode().getFluidStorages()) {
|
for (IStorageDisk storage : t.getNode().getFluidDisks()) {
|
||||||
if (storage != null) {
|
if (storage != null) {
|
||||||
stored += storage.getStored();
|
stored += storage.getStored();
|
||||||
}
|
}
|
||||||
@@ -43,7 +43,7 @@ public class TileDiskDrive extends TileNode<NetworkNodeDiskDrive> {
|
|||||||
public static final TileDataParameter<Integer, TileDiskDrive> CAPACITY = new TileDataParameter<>(DataSerializers.VARINT, 0, t -> {
|
public static final TileDataParameter<Integer, TileDiskDrive> CAPACITY = new TileDataParameter<>(DataSerializers.VARINT, 0, t -> {
|
||||||
int capacity = 0;
|
int capacity = 0;
|
||||||
|
|
||||||
for (IStorageDisk storage : t.getNode().getItemStorages()) {
|
for (IStorageDisk storage : t.getNode().getItemDisks()) {
|
||||||
if (storage != null) {
|
if (storage != null) {
|
||||||
if (storage.getCapacity() == -1) {
|
if (storage.getCapacity() == -1) {
|
||||||
return -1;
|
return -1;
|
||||||
@@ -53,7 +53,7 @@ public class TileDiskDrive extends TileNode<NetworkNodeDiskDrive> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (IStorageDisk storage : t.getNode().getFluidStorages()) {
|
for (IStorageDisk storage : t.getNode().getFluidDisks()) {
|
||||||
if (storage != null) {
|
if (storage != null) {
|
||||||
if (storage.getCapacity() == -1) {
|
if (storage.getCapacity() == -1) {
|
||||||
return -1;
|
return -1;
|
||||||
@@ -93,7 +93,7 @@ public class TileDiskDrive extends TileNode<NetworkNodeDiskDrive> {
|
|||||||
public NBTTagCompound writeUpdate(NBTTagCompound tag) {
|
public NBTTagCompound writeUpdate(NBTTagCompound tag) {
|
||||||
super.writeUpdate(tag);
|
super.writeUpdate(tag);
|
||||||
|
|
||||||
writeDiskState(tag, 8, getNode().getNetwork() != null, getNode().getItemStorages(), getNode().getFluidStorages());
|
writeDiskState(tag, 8, getNode().getNetwork() != null, getNode().getItemDisks(), getNode().getFluidDisks());
|
||||||
|
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class TileDiskManipulator extends TileNode<NetworkNodeDiskManipulator> {
|
|||||||
public NBTTagCompound writeUpdate(NBTTagCompound tag) {
|
public NBTTagCompound writeUpdate(NBTTagCompound tag) {
|
||||||
super.writeUpdate(tag);
|
super.writeUpdate(tag);
|
||||||
|
|
||||||
TileDiskDrive.writeDiskState(tag, 6, getNode().getNetwork() != null, getNode().getItemStorages(), getNode().getFluidStorages());
|
TileDiskDrive.writeDiskState(tag, 6, getNode().getNetwork() != null, getNode().getItemDisks(), getNode().getFluidDisks());
|
||||||
|
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public class TileFluidStorage extends TileNode<NetworkNodeFluidStorage> {
|
|||||||
public static final TileDataParameter<Boolean, TileFluidStorage> VOID_EXCESS = IExcessVoidable.createParameter();
|
public static final TileDataParameter<Boolean, TileFluidStorage> VOID_EXCESS = IExcessVoidable.createParameter();
|
||||||
public static final TileDataParameter<Integer, TileFluidStorage> MODE = IFilterable.createParameter();
|
public static final TileDataParameter<Integer, TileFluidStorage> MODE = IFilterable.createParameter();
|
||||||
public static final TileDataParameter<AccessType, TileFluidStorage> ACCESS_TYPE = IAccessType.createParameter();
|
public static final TileDataParameter<AccessType, TileFluidStorage> ACCESS_TYPE = IAccessType.createParameter();
|
||||||
public static final TileDataParameter<Integer, TileFluidStorage> STORED = new TileDataParameter<>(DataSerializers.VARINT, 0, t -> t.getNode().getStorage().getStored());
|
public static final TileDataParameter<Integer, TileFluidStorage> STORED = new TileDataParameter<>(DataSerializers.VARINT, 0, t -> 0); // TODO
|
||||||
|
|
||||||
public TileFluidStorage() {
|
public TileFluidStorage() {
|
||||||
dataManager.addWatchedParameter(PRIORITY);
|
dataManager.addWatchedParameter(PRIORITY);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ public class TileStorage extends TileNode<NetworkNodeStorage> {
|
|||||||
public static final TileDataParameter<Integer, TileStorage> COMPARE = IComparable.createParameter();
|
public static final TileDataParameter<Integer, TileStorage> COMPARE = IComparable.createParameter();
|
||||||
public static final TileDataParameter<Integer, TileStorage> MODE = IFilterable.createParameter();
|
public static final TileDataParameter<Integer, TileStorage> MODE = IFilterable.createParameter();
|
||||||
public static final TileDataParameter<AccessType, TileStorage> ACCESS_TYPE = IAccessType.createParameter();
|
public static final TileDataParameter<AccessType, TileStorage> ACCESS_TYPE = IAccessType.createParameter();
|
||||||
public static final TileDataParameter<Integer, TileStorage> STORED = new TileDataParameter<>(DataSerializers.VARINT, 0, t -> t.getNode().getStorage().getStored());
|
public static final TileDataParameter<Integer, TileStorage> STORED = new TileDataParameter<>(DataSerializers.VARINT, 0, t -> 0); // TODO
|
||||||
public static final TileDataParameter<Boolean, TileStorage> VOID_EXCESS = IExcessVoidable.createParameter();
|
public static final TileDataParameter<Boolean, TileStorage> VOID_EXCESS = IExcessVoidable.createParameter();
|
||||||
|
|
||||||
public TileStorage() {
|
public TileStorage() {
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ import net.minecraft.tileentity.TileEntity;
|
|||||||
|
|
||||||
public interface IExcessVoidable {
|
public interface IExcessVoidable {
|
||||||
static <T extends TileEntity & INetworkNodeProxy> TileDataParameter<Boolean, T> createParameter() {
|
static <T extends TileEntity & INetworkNodeProxy> TileDataParameter<Boolean, T> createParameter() {
|
||||||
return new TileDataParameter<>(DataSerializers.BOOLEAN, false, t -> ((IExcessVoidable) t.getNode()).getVoidExcess(), (t, v) -> ((IExcessVoidable) t.getNode()).setVoidExcess(v));
|
return new TileDataParameter<>(DataSerializers.BOOLEAN, false, t -> ((IExcessVoidable) t.getNode()).isVoidExcess(), (t, v) -> ((IExcessVoidable) t.getNode()).setVoidExcess(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean getVoidExcess();
|
boolean isVoidExcess();
|
||||||
|
|
||||||
void setVoidExcess(boolean voidExcess);
|
void setVoidExcess(boolean voidExcess);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.raoulvdberge.refinedstorage.tile.grid.portable;
|
package com.raoulvdberge.refinedstorage.tile.grid.portable;
|
||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageCache;
|
import com.raoulvdberge.refinedstorage.api.storage.IStorageCache;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDisk;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageTrackerItem;
|
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageTrackerItem;
|
||||||
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase;
|
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
|||||||
@@ -6,14 +6,19 @@ import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
|
|||||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGridTab;
|
import com.raoulvdberge.refinedstorage.api.network.grid.IGridTab;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IFluidGridHandler;
|
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IFluidGridHandler;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IItemGridHandler;
|
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IItemGridHandler;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.*;
|
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.IStorageCache;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.IStorageCacheListener;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IFilter;
|
import com.raoulvdberge.refinedstorage.api.util.IFilter;
|
||||||
|
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.network.grid.handler.ItemGridHandlerPortable;
|
import com.raoulvdberge.refinedstorage.apiimpl.network.grid.handler.ItemGridHandlerPortable;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.diskdrive.NetworkNodeDiskDrive;
|
import com.raoulvdberge.refinedstorage.apiimpl.network.node.diskdrive.NetworkNodeDiskDrive;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageCacheItemPortable;
|
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageCacheItemPortable;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageCacheListenerGridPortable;
|
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageCacheListenerGridPortable;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskItemPortable;
|
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageTrackerItem;
|
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageTrackerItem;
|
||||||
|
import com.raoulvdberge.refinedstorage.apiimpl.storage.disk.StorageDiskItemPortable;
|
||||||
import com.raoulvdberge.refinedstorage.gui.GuiBase;
|
import com.raoulvdberge.refinedstorage.gui.GuiBase;
|
||||||
import com.raoulvdberge.refinedstorage.gui.grid.GuiGrid;
|
import com.raoulvdberge.refinedstorage.gui.grid.GuiGrid;
|
||||||
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase;
|
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase;
|
||||||
@@ -36,12 +41,11 @@ import net.minecraftforge.fml.common.FMLCommonHandler;
|
|||||||
import net.minecraftforge.fml.relauncher.Side;
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class PortableGrid implements IGrid, IPortableGrid {
|
public class PortableGrid implements IGrid, IPortableGrid, IStorageDiskContainerContext {
|
||||||
public static int ID;
|
public static int ID;
|
||||||
|
|
||||||
public static final String NBT_STORAGE_TRACKER = "StorageTracker";
|
public static final String NBT_STORAGE_TRACKER = "StorageTracker";
|
||||||
@@ -77,23 +81,24 @@ public class PortableGrid implements IGrid, IPortableGrid {
|
|||||||
StackUtils.writeItems(this, 0, stack.getTagCompound());
|
StackUtils.writeItems(this, 0, stack.getTagCompound());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private ItemHandlerBase disk = new ItemHandlerBase(1, s -> NetworkNodeDiskDrive.VALIDATOR_STORAGE_DISK.test(s) && ((IStorageDiskProvider) s.getItem()).create(s).getType() == StorageDiskType.ITEMS) {
|
private ItemHandlerBase disk = new ItemHandlerBase(1, s -> NetworkNodeDiskDrive.VALIDATOR_STORAGE_DISK.test(s) && true) {
|
||||||
@Override
|
@Override
|
||||||
protected void onContentsChanged(int slot) {
|
protected void onContentsChanged(int slot) {
|
||||||
super.onContentsChanged(slot);
|
super.onContentsChanged(slot);
|
||||||
|
|
||||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER || (player == null && FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)) {
|
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER || (player == null && FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)) {
|
||||||
if (getStackInSlot(slot).isEmpty()) {
|
ItemStack diskStack = getStackInSlot(slot);
|
||||||
|
|
||||||
|
if (diskStack.isEmpty()) {
|
||||||
storage = null;
|
storage = null;
|
||||||
} else {
|
} else {
|
||||||
IStorageDiskProvider provider = (IStorageDiskProvider) getStackInSlot(slot).getItem();
|
IStorageDisk disk = API.instance().getStorageDiskManager(player.getEntityWorld()).getByStack(diskStack);
|
||||||
|
|
||||||
storage = new StorageDiskItemPortable(provider.create(getStackInSlot(slot)), PortableGrid.this);
|
if (disk != null) {
|
||||||
|
storage = new StorageDiskItemPortable(disk, PortableGrid.this);
|
||||||
if (player != null) {
|
storage.setSettings(null, PortableGrid.this);
|
||||||
storage.readFromNBT();
|
} else {
|
||||||
storage.onPassContainerContext(() -> {
|
storage = null;
|
||||||
}, () -> false, () -> AccessType.INSERT_EXTRACT);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,16 +109,6 @@ public class PortableGrid implements IGrid, IPortableGrid {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
|
||||||
if (storage != null) {
|
|
||||||
storage.writeToNBT();
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.extractItem(slot, amount, simulate);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public PortableGrid(@Nullable EntityPlayer player, ItemStack stack) {
|
public PortableGrid(@Nullable EntityPlayer player, ItemStack stack) {
|
||||||
@@ -138,12 +133,9 @@ public class PortableGrid implements IGrid, IPortableGrid {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
|
StackUtils.readItems(disk, 4, stack.getTagCompound());
|
||||||
StackUtils.readItems(filter, 0, stack.getTagCompound());
|
StackUtils.readItems(filter, 0, stack.getTagCompound());
|
||||||
}
|
|
||||||
|
|
||||||
StackUtils.readItems(disk, 4, stack.getTagCompound());
|
|
||||||
|
|
||||||
if (player != null) {
|
|
||||||
drainEnergy(RS.INSTANCE.config.portableGridOpenUsage);
|
drainEnergy(RS.INSTANCE.config.portableGridOpenUsage);
|
||||||
|
|
||||||
// If there is no disk onContentsChanged isn't called and the update isn't sent, thus items from the previous grid view would remain clientside
|
// If there is no disk onContentsChanged isn't called and the update isn't sent, thus items from the previous grid view would remain clientside
|
||||||
@@ -377,9 +369,7 @@ public class PortableGrid implements IGrid, IPortableGrid {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClosed(EntityPlayer player) {
|
public void onClosed(EntityPlayer player) {
|
||||||
if (!player.getEntityWorld().isRemote && storage != null) {
|
if (!player.getEntityWorld().isRemote) {
|
||||||
storage.writeToNBT();
|
|
||||||
|
|
||||||
StackUtils.writeItems(disk, 4, stack.getTagCompound());
|
StackUtils.writeItems(disk, 4, stack.getTagCompound());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -396,4 +386,14 @@ public class PortableGrid implements IGrid, IPortableGrid {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isVoidExcess() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AccessType getAccessType() {
|
||||||
|
return AccessType.INSERT_EXTRACT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,15 +7,22 @@ import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
|
|||||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGridTab;
|
import com.raoulvdberge.refinedstorage.api.network.grid.IGridTab;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IFluidGridHandler;
|
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IFluidGridHandler;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IItemGridHandler;
|
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IItemGridHandler;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.*;
|
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.IStorageCache;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.IStorageCacheListener;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskProvider;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.disk.StorageDiskType;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IFilter;
|
import com.raoulvdberge.refinedstorage.api.util.IFilter;
|
||||||
|
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.network.grid.handler.ItemGridHandlerPortable;
|
import com.raoulvdberge.refinedstorage.apiimpl.network.grid.handler.ItemGridHandlerPortable;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeGrid;
|
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeGrid;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.diskdrive.NetworkNodeDiskDrive;
|
import com.raoulvdberge.refinedstorage.apiimpl.network.node.diskdrive.NetworkNodeDiskDrive;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageCacheItemPortable;
|
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageCacheItemPortable;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageCacheListenerGridPortable;
|
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageCacheListenerGridPortable;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskItemPortable;
|
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageTrackerItem;
|
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageTrackerItem;
|
||||||
|
import com.raoulvdberge.refinedstorage.apiimpl.storage.disk.StorageDiskItemPortable;
|
||||||
import com.raoulvdberge.refinedstorage.block.BlockPortableGrid;
|
import com.raoulvdberge.refinedstorage.block.BlockPortableGrid;
|
||||||
import com.raoulvdberge.refinedstorage.block.PortableGridDiskState;
|
import com.raoulvdberge.refinedstorage.block.PortableGridDiskState;
|
||||||
import com.raoulvdberge.refinedstorage.block.PortableGridType;
|
import com.raoulvdberge.refinedstorage.block.PortableGridType;
|
||||||
@@ -47,8 +54,6 @@ import net.minecraft.util.EnumFacing;
|
|||||||
import net.minecraftforge.common.capabilities.Capability;
|
import net.minecraftforge.common.capabilities.Capability;
|
||||||
import net.minecraftforge.common.util.Constants;
|
import net.minecraftforge.common.util.Constants;
|
||||||
import net.minecraftforge.energy.CapabilityEnergy;
|
import net.minecraftforge.energy.CapabilityEnergy;
|
||||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
|
||||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@@ -56,7 +61,7 @@ import javax.annotation.Nullable;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TilePortableGrid extends TileBase implements IGrid, IPortableGrid, IRedstoneConfigurable {
|
public class TilePortableGrid extends TileBase implements IGrid, IPortableGrid, IRedstoneConfigurable, IStorageDiskContainerContext {
|
||||||
public static final TileDataParameter<Integer, TilePortableGrid> REDSTONE_MODE = RedstoneMode.createParameter();
|
public static final TileDataParameter<Integer, TilePortableGrid> REDSTONE_MODE = RedstoneMode.createParameter();
|
||||||
public static final TileDataParameter<Integer, TilePortableGrid> ENERGY_STORED = new TileDataParameter<>(DataSerializers.VARINT, 0, t -> t.energyStorage.getEnergyStored());
|
public static final TileDataParameter<Integer, TilePortableGrid> ENERGY_STORED = new TileDataParameter<>(DataSerializers.VARINT, 0, t -> t.energyStorage.getEnergyStored());
|
||||||
public static final TileDataParameter<Integer, TilePortableGrid> SORTING_DIRECTION = new TileDataParameter<>(DataSerializers.VARINT, 0, TilePortableGrid::getSortingDirection, (t, v) -> {
|
public static final TileDataParameter<Integer, TilePortableGrid> SORTING_DIRECTION = new TileDataParameter<>(DataSerializers.VARINT, 0, TilePortableGrid::getSortingDirection, (t, v) -> {
|
||||||
@@ -101,7 +106,6 @@ public class TilePortableGrid extends TileBase implements IGrid, IPortableGrid,
|
|||||||
private static final String NBT_ENERGY = "Energy";
|
private static final String NBT_ENERGY = "Energy";
|
||||||
private static final String NBT_DISK_STATE = "DiskState";
|
private static final String NBT_DISK_STATE = "DiskState";
|
||||||
private static final String NBT_CONNECTED = "Connected";
|
private static final String NBT_CONNECTED = "Connected";
|
||||||
|
|
||||||
private static final String NBT_STORAGE_TRACKER = "StorageTracker";
|
private static final String NBT_STORAGE_TRACKER = "StorageTracker";
|
||||||
|
|
||||||
private EnergyForge energyStorage = new EnergyForge(ItemEnergyItem.CAPACITY);
|
private EnergyForge energyStorage = new EnergyForge(ItemEnergyItem.CAPACITY);
|
||||||
@@ -119,46 +123,20 @@ public class TilePortableGrid extends TileBase implements IGrid, IPortableGrid,
|
|||||||
private List<IFilter> filters = new ArrayList<>();
|
private List<IFilter> filters = new ArrayList<>();
|
||||||
private List<IGridTab> tabs = new ArrayList<>();
|
private List<IGridTab> tabs = new ArrayList<>();
|
||||||
private ItemHandlerFilter filter = new ItemHandlerFilter(filters, tabs, new ItemHandlerListenerTile(this));
|
private ItemHandlerFilter filter = new ItemHandlerFilter(filters, tabs, new ItemHandlerListenerTile(this));
|
||||||
private ItemHandlerBase disk = new ItemHandlerBase(1, new ItemHandlerListenerTile(this), s -> NetworkNodeDiskDrive.VALIDATOR_STORAGE_DISK.test(s) && ((IStorageDiskProvider) s.getItem()).create(s).getType() == StorageDiskType.ITEMS) {
|
private ItemHandlerBase disk = new ItemHandlerBase(1, new ItemHandlerListenerTile(this), s -> NetworkNodeDiskDrive.VALIDATOR_STORAGE_DISK.test(s) && ((IStorageDiskProvider) s.getItem()).getType() == StorageDiskType.ITEM) {
|
||||||
@Override
|
@Override
|
||||||
protected void onContentsChanged(int slot) {
|
protected void onContentsChanged(int slot) {
|
||||||
super.onContentsChanged(slot);
|
super.onContentsChanged(slot);
|
||||||
|
|
||||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
|
if (world != null && !world.isRemote) {
|
||||||
if (getStackInSlot(slot).isEmpty()) {
|
loadStorage();
|
||||||
storage = null;
|
|
||||||
} else {
|
|
||||||
IStorageDiskProvider provider = (IStorageDiskProvider) getStackInSlot(slot).getItem();
|
|
||||||
|
|
||||||
storage = new StorageDiskItemPortable(provider.create(getStackInSlot(slot)), TilePortableGrid.this);
|
|
||||||
storage.readFromNBT();
|
|
||||||
storage.onPassContainerContext(() -> {
|
|
||||||
TilePortableGrid.this.markDirty();
|
|
||||||
TilePortableGrid.this.checkIfDiskStateChanged();
|
|
||||||
}, () -> false, () -> AccessType.INSERT_EXTRACT);
|
|
||||||
}
|
|
||||||
|
|
||||||
cache.invalidate();
|
|
||||||
|
|
||||||
if (world != null) {
|
|
||||||
checkIfDiskStateChanged();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
|
||||||
if (storage != null) {
|
|
||||||
storage.writeToNBT();
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.extractItem(slot, amount, simulate);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private IStorageDisk<ItemStack> storage;
|
private IStorageDisk<ItemStack> storage;
|
||||||
|
|
||||||
private StorageCacheItemPortable cache = new StorageCacheItemPortable(this);
|
private StorageCacheItemPortable cache = new StorageCacheItemPortable(this);
|
||||||
private ItemGridHandlerPortable handler = new ItemGridHandlerPortable(this, this);
|
private ItemGridHandlerPortable handler = new ItemGridHandlerPortable(this, this);
|
||||||
private PortableGridDiskState diskState = PortableGridDiskState.NONE;
|
private PortableGridDiskState diskState = PortableGridDiskState.NONE;
|
||||||
@@ -177,6 +155,27 @@ public class TilePortableGrid extends TileBase implements IGrid, IPortableGrid,
|
|||||||
dataManager.addWatchedParameter(TAB_PAGE);
|
dataManager.addWatchedParameter(TAB_PAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadStorage() {
|
||||||
|
ItemStack diskStack = getDisk().getStackInSlot(0);
|
||||||
|
|
||||||
|
if (diskStack.isEmpty()) {
|
||||||
|
this.storage = null;
|
||||||
|
} else {
|
||||||
|
IStorageDisk disk = API.instance().getStorageDiskManager(world).getByStack(getDisk().getStackInSlot(0));
|
||||||
|
|
||||||
|
if (disk != null) {
|
||||||
|
this.storage = new StorageDiskItemPortable(disk, this);
|
||||||
|
this.storage.setSettings(TilePortableGrid.this::checkIfDiskStateChanged, TilePortableGrid.this);
|
||||||
|
} else {
|
||||||
|
this.storage = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.cache.invalidate();
|
||||||
|
|
||||||
|
this.checkIfDiskStateChanged();
|
||||||
|
}
|
||||||
|
|
||||||
public PortableGridDiskState getDiskState() {
|
public PortableGridDiskState getDiskState() {
|
||||||
return diskState;
|
return diskState;
|
||||||
}
|
}
|
||||||
@@ -223,10 +222,6 @@ public class TilePortableGrid extends TileBase implements IGrid, IPortableGrid,
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getAsItem() {
|
public ItemStack getAsItem() {
|
||||||
if (storage != null) {
|
|
||||||
storage.writeToNBT();
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemStack stack = new ItemStack(RSBlocks.PORTABLE_GRID, 1, getPortableType() == PortableGridType.NORMAL ? ItemBlockPortableGrid.TYPE_NORMAL : ItemBlockPortableGrid.TYPE_CREATIVE);
|
ItemStack stack = new ItemStack(RSBlocks.PORTABLE_GRID, 1, getPortableType() == PortableGridType.NORMAL ? ItemBlockPortableGrid.TYPE_NORMAL : ItemBlockPortableGrid.TYPE_CREATIVE);
|
||||||
|
|
||||||
stack.setTagCompound(new NBTTagCompound());
|
stack.setTagCompound(new NBTTagCompound());
|
||||||
@@ -519,10 +514,6 @@ public class TilePortableGrid extends TileBase implements IGrid, IPortableGrid,
|
|||||||
public NBTTagCompound write(NBTTagCompound tag) {
|
public NBTTagCompound write(NBTTagCompound tag) {
|
||||||
super.write(tag);
|
super.write(tag);
|
||||||
|
|
||||||
if (storage != null) {
|
|
||||||
storage.writeToNBT();
|
|
||||||
}
|
|
||||||
|
|
||||||
tag.setInteger(NetworkNodeGrid.NBT_SORTING_DIRECTION, sortingDirection);
|
tag.setInteger(NetworkNodeGrid.NBT_SORTING_DIRECTION, sortingDirection);
|
||||||
tag.setInteger(NetworkNodeGrid.NBT_SORTING_TYPE, sortingType);
|
tag.setInteger(NetworkNodeGrid.NBT_SORTING_TYPE, sortingType);
|
||||||
tag.setInteger(NetworkNodeGrid.NBT_SEARCH_BOX_MODE, searchBoxMode);
|
tag.setInteger(NetworkNodeGrid.NBT_SEARCH_BOX_MODE, searchBoxMode);
|
||||||
@@ -588,8 +579,10 @@ public class TilePortableGrid extends TileBase implements IGrid, IPortableGrid,
|
|||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
super.onLoad();
|
super.onLoad();
|
||||||
|
|
||||||
connected = getEnergy() != 0;
|
this.loadStorage();
|
||||||
diskState = getDiskState(this);
|
|
||||||
|
this.connected = getEnergy() != 0;
|
||||||
|
this.diskState = getDiskState(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -655,4 +648,14 @@ public class TilePortableGrid extends TileBase implements IGrid, IPortableGrid,
|
|||||||
return PortableGridDiskState.NORMAL;
|
return PortableGridDiskState.NORMAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isVoidExcess() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AccessType getAccessType() {
|
||||||
|
return AccessType.INSERT_EXTRACT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.raoulvdberge.refinedstorage.util;
|
package com.raoulvdberge.refinedstorage.util;
|
||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDisk;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDiskProvider;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskProvider;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IStackList;
|
import com.raoulvdberge.refinedstorage.api.util.IStackList;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||||
@@ -16,6 +16,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
import net.minecraft.potion.PotionUtils;
|
import net.minecraft.potion.PotionUtils;
|
||||||
import net.minecraft.util.NonNullList;
|
import net.minecraft.util.NonNullList;
|
||||||
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.util.Constants;
|
import net.minecraftforge.common.util.Constants;
|
||||||
import net.minecraftforge.fluids.Fluid;
|
import net.minecraftforge.fluids.Fluid;
|
||||||
import net.minecraftforge.fluids.FluidRegistry;
|
import net.minecraftforge.fluids.FluidRegistry;
|
||||||
@@ -140,23 +141,27 @@ public final class StackUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static void createStorages(ItemStack disk, int slot, IStorageDisk<ItemStack>[] itemStorages, IStorageDisk<FluidStack>[] fluidStorages, Function<IStorageDisk<ItemStack>, IStorageDisk> itemStorageWrapper, Function<IStorageDisk<FluidStack>, IStorageDisk> fluidStorageWrapper) {
|
public static void createStorages(World world, ItemStack diskStack, int slot, IStorageDisk<ItemStack>[] itemDisks, IStorageDisk<FluidStack>[] fluidDisks, Function<IStorageDisk<ItemStack>, IStorageDisk> itemDiskWrapper, Function<IStorageDisk<FluidStack>, IStorageDisk> fluidDiskWrapper) {
|
||||||
if (disk.isEmpty()) {
|
if (diskStack.isEmpty()) {
|
||||||
itemStorages[slot] = null;
|
itemDisks[slot] = null;
|
||||||
fluidStorages[slot] = null;
|
fluidDisks[slot] = null;
|
||||||
} else {
|
} else {
|
||||||
IStorageDiskProvider provider = (IStorageDiskProvider) disk.getItem();
|
IStorageDisk disk = API.instance().getStorageDiskManager(world).getByStack(diskStack);
|
||||||
IStorageDisk storage = provider.create(disk);
|
|
||||||
|
|
||||||
storage.readFromNBT();
|
if (disk != null) {
|
||||||
|
switch (((IStorageDiskProvider) diskStack.getItem()).getType()) {
|
||||||
switch (storage.getType()) {
|
case ITEM: {
|
||||||
case ITEMS:
|
itemDisks[slot] = itemDiskWrapper.apply(disk);
|
||||||
itemStorages[slot] = itemStorageWrapper.apply(storage);
|
break;
|
||||||
break;
|
}
|
||||||
case FLUIDS:
|
case FLUID: {
|
||||||
fluidStorages[slot] = fluidStorageWrapper.apply(storage);
|
fluidDisks[slot] = fluidDiskWrapper.apply(disk);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
itemDisks[slot] = null;
|
||||||
|
fluidDisks[slot] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user