Added support for deep storage unit API, fixes #120
This commit is contained in:
35
src/main/java/powercrystals/minefactoryreloaded/api/IDeepStorageUnit.java
Executable file
35
src/main/java/powercrystals/minefactoryreloaded/api/IDeepStorageUnit.java
Executable file
@@ -0,0 +1,35 @@
|
||||
package powercrystals.minefactoryreloaded.api;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IDeepStorageUnit {
|
||||
|
||||
/**
|
||||
* @return A populated ItemStack with stackSize for the full amount of
|
||||
* materials in the DSU. <br>
|
||||
* May have a stackSize > getMaxStackSize(). May have a stackSize of
|
||||
* 0 (indicating locked contents).
|
||||
*/
|
||||
ItemStack getStoredItemType();
|
||||
|
||||
/**
|
||||
* Sets the total amount of the item currently being stored, or zero if all
|
||||
* items are to be removed.
|
||||
*/
|
||||
void setStoredItemCount(int amount);
|
||||
|
||||
/**
|
||||
* Sets the type of the stored item and initializes the number of stored
|
||||
* items to amount.
|
||||
* <p>
|
||||
* Will overwrite any existing stored items.
|
||||
*/
|
||||
void setStoredItemType(ItemStack type, int amount);
|
||||
|
||||
/**
|
||||
* @return The maximum number of items the DSU can hold. <br>
|
||||
* May change based on the current type stored.
|
||||
*/
|
||||
int getMaxStoredCount();
|
||||
|
||||
}
|
||||
110
src/main/java/refinedstorage/tile/externalstorage/DeepStorageUnitStorage.java
Executable file
110
src/main/java/refinedstorage/tile/externalstorage/DeepStorageUnitStorage.java
Executable file
@@ -0,0 +1,110 @@
|
||||
package refinedstorage.tile.externalstorage;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import powercrystals.minefactoryreloaded.api.IDeepStorageUnit;
|
||||
import refinedstorage.RefinedStorageUtils;
|
||||
import refinedstorage.tile.config.ModeFilter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
|
||||
public class DeepStorageUnitStorage extends ExternalStorage {
|
||||
private TileExternalStorage externalStorage;
|
||||
private IDeepStorageUnit unit;
|
||||
|
||||
public DeepStorageUnitStorage(TileExternalStorage externalStorage, IDeepStorageUnit unit) {
|
||||
this.externalStorage = externalStorage;
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity() {
|
||||
return unit.getMaxStoredCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addItems(List<ItemStack> items) {
|
||||
if (unit.getStoredItemType() != null && unit.getStoredItemType().stackSize > 0) {
|
||||
items.add(unit.getStoredItemType().copy());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack push(@Nonnull ItemStack stack, int size, boolean simulate) {
|
||||
if (ModeFilter.respectsMode(externalStorage.getFilters(), externalStorage, externalStorage.getCompare(), stack)) {
|
||||
if (unit.getStoredItemType() != null) {
|
||||
if (RefinedStorageUtils.compareStackNoQuantity(unit.getStoredItemType(), stack)) {
|
||||
if (getStored() + size > unit.getMaxStoredCount()) {
|
||||
int remainingSpace = getCapacity() - getStored();
|
||||
|
||||
if (remainingSpace <= 0) {
|
||||
return ItemHandlerHelper.copyStackWithSize(stack, size);
|
||||
}
|
||||
|
||||
if (!simulate) {
|
||||
unit.setStoredItemCount(unit.getStoredItemType().stackSize + remainingSpace);
|
||||
}
|
||||
|
||||
return ItemHandlerHelper.copyStackWithSize(stack, size - remainingSpace);
|
||||
} else {
|
||||
if (!simulate) {
|
||||
unit.setStoredItemCount(unit.getStoredItemType().stackSize + size);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (getStored() + size > unit.getMaxStoredCount()) {
|
||||
int remainingSpace = getCapacity() - getStored();
|
||||
|
||||
if (remainingSpace <= 0) {
|
||||
return ItemHandlerHelper.copyStackWithSize(stack, size);
|
||||
}
|
||||
|
||||
if (!simulate) {
|
||||
unit.setStoredItemType(stack.copy(), remainingSpace);
|
||||
}
|
||||
|
||||
return ItemHandlerHelper.copyStackWithSize(stack, size - remainingSpace);
|
||||
} else {
|
||||
if (!simulate) {
|
||||
unit.setStoredItemType(stack.copy(), size);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ItemHandlerHelper.copyStackWithSize(stack, size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack take(@Nonnull ItemStack stack, int size, int flags) {
|
||||
if (RefinedStorageUtils.compareStack(stack, unit.getStoredItemType(), flags)) {
|
||||
if (size > unit.getStoredItemType().stackSize) {
|
||||
size = unit.getStoredItemType().stackSize;
|
||||
}
|
||||
|
||||
ItemStack stored = unit.getStoredItemType();
|
||||
|
||||
unit.setStoredItemCount(stored.stackSize - size);
|
||||
|
||||
return ItemHandlerHelper.copyStackWithSize(stored, size);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStored() {
|
||||
return unit.getStoredItemType() != null ? unit.getStoredItemType().stackSize : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return externalStorage.getPriority();
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,11 @@ import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroup;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import powercrystals.minefactoryreloaded.api.IDeepStorageUnit;
|
||||
import refinedstorage.RefinedStorage;
|
||||
import refinedstorage.RefinedStorageUtils;
|
||||
import refinedstorage.api.RefinedStorageCapabilities;
|
||||
@@ -145,8 +147,10 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
|
||||
|
||||
@Override
|
||||
public void provide(List<IStorage> storages) {
|
||||
if (getFacingTile() instanceof IDrawerGroup) {
|
||||
IDrawerGroup group = (IDrawerGroup) getFacingTile();
|
||||
TileEntity facing = getFacingTile();
|
||||
|
||||
if (facing instanceof IDrawerGroup) {
|
||||
IDrawerGroup group = (IDrawerGroup) facing;
|
||||
|
||||
energyUsage = group.getDrawerCount();
|
||||
stored = 0;
|
||||
@@ -162,8 +166,16 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
|
||||
capacity += storage.getCapacity();
|
||||
}
|
||||
}
|
||||
} else if (getFacingTile() instanceof IDrawer) {
|
||||
DrawerStorage storage = new DrawerStorage(this, (IDrawer) getFacingTile());
|
||||
} else if (facing instanceof IDrawer) {
|
||||
DrawerStorage storage = new DrawerStorage(this, (IDrawer) facing);
|
||||
|
||||
storages.add(storage);
|
||||
|
||||
energyUsage = 1;
|
||||
stored = storage.getStored();
|
||||
capacity = storage.getCapacity();
|
||||
} else if (facing instanceof IDeepStorageUnit) {
|
||||
DeepStorageUnitStorage storage = new DeepStorageUnitStorage(this, (IDeepStorageUnit) facing);
|
||||
|
||||
storages.add(storage);
|
||||
|
||||
@@ -171,7 +183,7 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
|
||||
stored = storage.getStored();
|
||||
capacity = storage.getCapacity();
|
||||
} else {
|
||||
IItemHandler handler = RefinedStorageUtils.getItemHandler(getFacingTile(), getDirection().getOpposite());
|
||||
IItemHandler handler = RefinedStorageUtils.getItemHandler(facing, getDirection().getOpposite());
|
||||
|
||||
if (handler != null) {
|
||||
ItemHandlerStorage storage = new ItemHandlerStorage(this, handler);
|
||||
@@ -183,6 +195,8 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
|
||||
capacity = storage.getCapacity();
|
||||
} else {
|
||||
energyUsage = 0;
|
||||
stored = 0;
|
||||
capacity = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user