Storage blocks aren't working yet
This commit is contained in:
@@ -78,9 +78,7 @@ public class BlockStorage extends BlockMachine {
|
|||||||
|
|
||||||
NBTTagCompound tag = stack.getTagCompound();
|
NBTTagCompound tag = stack.getTagCompound();
|
||||||
|
|
||||||
if (tag != null && tag.hasKey(TileStorage.NBT_STORAGE)) {
|
((TileStorage) world.getTileEntity(pos)).onPlaced((tag != null && tag.hasKey(TileStorage.NBT_STORAGE)) ? tag.getCompoundTag(TileStorage.NBT_STORAGE) : null);
|
||||||
((TileStorage) world.getTileEntity(pos)).setStorageTag((NBTTagCompound) tag.getTag(TileStorage.NBT_STORAGE));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -143,6 +143,14 @@ public class NBTStorage implements IStorage {
|
|||||||
this.priority = priority;
|
this.priority = priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getCapacity() {
|
||||||
|
return capacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCapacity(int capacity) {
|
||||||
|
this.capacity = capacity;
|
||||||
|
}
|
||||||
|
|
||||||
public NBTTagCompound getTag() {
|
public NBTTagCompound getTag() {
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|||||||
25
src/main/java/refinedstorage/storage/StorageBlockStorage.java
Executable file
25
src/main/java/refinedstorage/storage/StorageBlockStorage.java
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
package refinedstorage.storage;
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import refinedstorage.tile.TileStorage;
|
||||||
|
import refinedstorage.tile.config.ModeConfigUtils;
|
||||||
|
|
||||||
|
public class StorageBlockStorage extends NBTStorage {
|
||||||
|
private TileStorage storage;
|
||||||
|
|
||||||
|
public StorageBlockStorage(TileStorage storage) {
|
||||||
|
super(storage.getStorageTag(), storage.getCapacity(), 0);
|
||||||
|
|
||||||
|
this.storage = storage;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPriority() {
|
||||||
|
return storage.getPriority();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canPush(ItemStack stack) {
|
||||||
|
return ModeConfigUtils.doesNotViolateMode(storage.getInventory(), storage, storage.getCompare(), stack) && super.canPush(stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,6 @@ package refinedstorage.tile;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import net.minecraft.inventory.Container;
|
import net.minecraft.inventory.Container;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import refinedstorage.RefinedStorage;
|
import refinedstorage.RefinedStorage;
|
||||||
import refinedstorage.RefinedStorageBlocks;
|
import refinedstorage.RefinedStorageBlocks;
|
||||||
@@ -17,11 +16,10 @@ import refinedstorage.storage.*;
|
|||||||
import refinedstorage.tile.config.ICompareConfig;
|
import refinedstorage.tile.config.ICompareConfig;
|
||||||
import refinedstorage.tile.config.IModeConfig;
|
import refinedstorage.tile.config.IModeConfig;
|
||||||
import refinedstorage.tile.config.IRedstoneModeConfig;
|
import refinedstorage.tile.config.IRedstoneModeConfig;
|
||||||
import refinedstorage.tile.config.ModeConfigUtils;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TileStorage extends TileMachine implements IStorageProvider, IStorage, IStorageGui, ICompareConfig, IModeConfig {
|
public class TileStorage extends TileMachine implements IStorageProvider, IStorageGui, ICompareConfig, IModeConfig {
|
||||||
public static final String NBT_STORAGE = "Storage";
|
public static final String NBT_STORAGE = "Storage";
|
||||||
public static final String NBT_PRIORITY = "Priority";
|
public static final String NBT_PRIORITY = "Priority";
|
||||||
public static final String NBT_COMPARE = "Compare";
|
public static final String NBT_COMPARE = "Compare";
|
||||||
@@ -29,9 +27,9 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
|
|||||||
|
|
||||||
private InventorySimple inventory = new InventorySimple("storage", 9, this);
|
private InventorySimple inventory = new InventorySimple("storage", 9, this);
|
||||||
|
|
||||||
private NBTTagCompound storageTag = NBTStorage.createNBT();
|
private NBTTagCompound storageTag;
|
||||||
|
|
||||||
private NBTStorage storage;
|
private StorageBlockStorage storage;
|
||||||
|
|
||||||
private int priority = 0;
|
private int priority = 0;
|
||||||
private int compare = 0;
|
private int compare = 0;
|
||||||
@@ -45,19 +43,31 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateMachine() {
|
public void updateMachine() {
|
||||||
|
if (getStorage().isDirty()) {
|
||||||
|
markDirty();
|
||||||
|
|
||||||
|
getStorage().markClean();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPlaced(NBTTagCompound tag) {
|
||||||
|
if (tag == null) {
|
||||||
|
storageTag = NBTStorage.createNBT();
|
||||||
|
} else {
|
||||||
|
storageTag = tag;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public NBTStorage getStorage() {
|
public NBTStorage getStorage() {
|
||||||
if (storage == null) {
|
if (storage == null) {
|
||||||
storage = new NBTStorage(storageTag, priority, getCapacity());
|
storage = new StorageBlockStorage(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
return storage;
|
return storage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void provide(List<IStorage> storages) {
|
public void provide(List<IStorage> storages) {
|
||||||
storages.add(this);
|
storages.add(getStorage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -72,6 +82,8 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
|
|||||||
|
|
||||||
if (nbt.hasKey(NBT_STORAGE)) {
|
if (nbt.hasKey(NBT_STORAGE)) {
|
||||||
storageTag = nbt.getCompoundTag(NBT_STORAGE);
|
storageTag = nbt.getCompoundTag(NBT_STORAGE);
|
||||||
|
} else {
|
||||||
|
storageTag = NBTStorage.createNBT();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nbt.hasKey(NBT_COMPARE)) {
|
if (nbt.hasKey(NBT_COMPARE)) {
|
||||||
@@ -90,7 +102,7 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
|
|||||||
RefinedStorageUtils.saveInventory(inventory, 0, nbt);
|
RefinedStorageUtils.saveInventory(inventory, 0, nbt);
|
||||||
|
|
||||||
nbt.setInteger(NBT_PRIORITY, priority);
|
nbt.setInteger(NBT_PRIORITY, priority);
|
||||||
nbt.setTag(NBT_STORAGE, getStorage().getTag());
|
nbt.setTag(NBT_STORAGE, storageTag);
|
||||||
nbt.setInteger(NBT_COMPARE, compare);
|
nbt.setInteger(NBT_COMPARE, compare);
|
||||||
nbt.setInteger(NBT_MODE, mode);
|
nbt.setInteger(NBT_MODE, mode);
|
||||||
}
|
}
|
||||||
@@ -128,34 +140,6 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
|
|||||||
return ContainerStorage.class;
|
return ContainerStorage.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addItems(List<ItemGroup> items) {
|
|
||||||
getStorage().addItems(items);
|
|
||||||
|
|
||||||
markDirty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void push(ItemStack stack) {
|
|
||||||
getStorage().push(stack);
|
|
||||||
|
|
||||||
markDirty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack take(ItemStack stack, int flags) {
|
|
||||||
ItemStack result = getStorage().take(stack, flags);
|
|
||||||
|
|
||||||
markDirty();
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canPush(ItemStack stack) {
|
|
||||||
return ModeConfigUtils.doesNotViolateMode(inventory, this, compare, stack) && getStorage().canPush(stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCompare() {
|
public int getCompare() {
|
||||||
return compare;
|
return compare;
|
||||||
@@ -240,7 +224,6 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
|
|||||||
public void setPriority(int priority) {
|
public void setPriority(int priority) {
|
||||||
markDirty();
|
markDirty();
|
||||||
|
|
||||||
this.getStorage().setPriority(priority);
|
|
||||||
this.priority = priority;
|
this.priority = priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user