Fix disk drives + storage blocks
This commit is contained in:
@@ -76,10 +76,8 @@ public class BlockStorage extends BlockMachine {
|
||||
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack stack) {
|
||||
super.onBlockPlacedBy(world, pos, state, player, stack);
|
||||
|
||||
if (!world.isRemote) {
|
||||
NBTTagCompound tag = stack.getTagCompound();
|
||||
|
||||
((TileStorage) world.getTileEntity(pos)).onPlaced((tag != null && tag.hasKey(TileStorage.NBT_STORAGE)) ? tag.getCompoundTag(TileStorage.NBT_STORAGE) : null);
|
||||
if (!world.isRemote && stack.hasTagCompound() && stack.getTagCompound().hasKey(TileStorage.NBT_STORAGE)) {
|
||||
((TileStorage) world.getTileEntity(pos)).setStorageTag(stack.getTagCompound().getCompoundTag(TileStorage.NBT_STORAGE));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,11 +9,16 @@ public class DiskStorage extends NBTStorage {
|
||||
private TileDiskDrive diskDrive;
|
||||
|
||||
public DiskStorage(ItemStack disk, TileDiskDrive diskDrive) {
|
||||
super(disk.getTagCompound(), EnumStorageType.getById(disk.getItemDamage()).getCapacity(), diskDrive.getPriority());
|
||||
super(disk.getTagCompound(), EnumStorageType.getById(disk.getItemDamage()).getCapacity());
|
||||
|
||||
this.diskDrive = diskDrive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return diskDrive.getPriority();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPush(ItemStack stack) {
|
||||
return ModeConfigUtils.doesNotViolateMode(diskDrive.getInventory(), diskDrive.getModeConfig(), diskDrive.getCompare(), stack) && super.canPush(stack);
|
||||
|
||||
@@ -10,7 +10,7 @@ import net.minecraft.nbt.NBTTagList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class NBTStorage implements IStorage {
|
||||
public abstract class NBTStorage implements IStorage {
|
||||
public static final String NBT_ITEMS = "Items";
|
||||
public static final String NBT_STORED = "Stored";
|
||||
|
||||
@@ -21,16 +21,14 @@ public class NBTStorage implements IStorage {
|
||||
|
||||
private NBTTagCompound tag;
|
||||
private int capacity;
|
||||
private int priority;
|
||||
|
||||
private boolean dirty;
|
||||
|
||||
private Multimap<Item, ItemGroup> groups = ArrayListMultimap.create();
|
||||
|
||||
public NBTStorage(NBTTagCompound tag, int capacity, int priority) {
|
||||
public NBTStorage(NBTTagCompound tag, int capacity) {
|
||||
this.tag = tag;
|
||||
this.capacity = capacity;
|
||||
this.priority = priority;
|
||||
|
||||
readFromNBT();
|
||||
}
|
||||
@@ -136,11 +134,6 @@ public class NBTStorage implements IStorage {
|
||||
return capacity == -1 || (getStored(tag) + stack.stackSize) <= capacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return priority;
|
||||
}
|
||||
|
||||
public int getCapacity() {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ public class StorageBlockStorage extends NBTStorage {
|
||||
private TileStorage storage;
|
||||
|
||||
public StorageBlockStorage(TileStorage storage) {
|
||||
super(storage.getStorageTag(), storage.getCapacity(), 0);
|
||||
super(storage.getStorageTag(), storage.getCapacity());
|
||||
|
||||
this.storage = storage;
|
||||
}
|
||||
|
||||
@@ -43,6 +43,10 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
|
||||
|
||||
@Override
|
||||
public void updateMachine() {
|
||||
if (storage == null && storageTag != null) {
|
||||
storage = new StorageBlockStorage(this);
|
||||
}
|
||||
|
||||
if (storage != null && storage.isDirty()) {
|
||||
markDirty();
|
||||
|
||||
@@ -51,14 +55,6 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
|
||||
}
|
||||
}
|
||||
|
||||
public void onPlaced(NBTTagCompound tag) {
|
||||
if (tag != null) {
|
||||
this.storageTag = tag;
|
||||
}
|
||||
|
||||
this.storage = new StorageBlockStorage(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void provide(List<IStorage> storages) {
|
||||
if (storage != null) {
|
||||
@@ -80,8 +76,6 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
|
||||
storageTag = nbt.getCompoundTag(NBT_STORAGE);
|
||||
}
|
||||
|
||||
storage = new StorageBlockStorage(this);
|
||||
|
||||
if (nbt.hasKey(NBT_COMPARE)) {
|
||||
compare = nbt.getInteger(NBT_COMPARE);
|
||||
}
|
||||
@@ -206,6 +200,10 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
|
||||
return storageTag;
|
||||
}
|
||||
|
||||
public void setStorageTag(NBTTagCompound storageTag) {
|
||||
this.storageTag = storageTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return priority;
|
||||
|
||||
Reference in New Issue
Block a user