Fix disk drives + storage blocks

This commit is contained in:
Raoul Van den Berge
2016-05-19 16:41:49 +02:00
parent ffa948adad
commit 5ab7cfd2e6
5 changed files with 19 additions and 25 deletions

View File

@@ -76,10 +76,8 @@ public class BlockStorage extends BlockMachine {
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack stack) { public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack stack) {
super.onBlockPlacedBy(world, pos, state, player, stack); super.onBlockPlacedBy(world, pos, state, player, stack);
if (!world.isRemote) { if (!world.isRemote && stack.hasTagCompound() && stack.getTagCompound().hasKey(TileStorage.NBT_STORAGE)) {
NBTTagCompound tag = stack.getTagCompound(); ((TileStorage) world.getTileEntity(pos)).setStorageTag(stack.getTagCompound().getCompoundTag(TileStorage.NBT_STORAGE));
((TileStorage) world.getTileEntity(pos)).onPlaced((tag != null && tag.hasKey(TileStorage.NBT_STORAGE)) ? tag.getCompoundTag(TileStorage.NBT_STORAGE) : null);
} }
} }

View File

@@ -9,11 +9,16 @@ public class DiskStorage extends NBTStorage {
private TileDiskDrive diskDrive; private TileDiskDrive diskDrive;
public DiskStorage(ItemStack disk, 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; this.diskDrive = diskDrive;
} }
@Override
public int getPriority() {
return diskDrive.getPriority();
}
@Override @Override
public boolean canPush(ItemStack stack) { public boolean canPush(ItemStack stack) {
return ModeConfigUtils.doesNotViolateMode(diskDrive.getInventory(), diskDrive.getModeConfig(), diskDrive.getCompare(), stack) && super.canPush(stack); return ModeConfigUtils.doesNotViolateMode(diskDrive.getInventory(), diskDrive.getModeConfig(), diskDrive.getCompare(), stack) && super.canPush(stack);

View File

@@ -10,7 +10,7 @@ import net.minecraft.nbt.NBTTagList;
import java.util.Collection; import java.util.Collection;
import java.util.List; 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_ITEMS = "Items";
public static final String NBT_STORED = "Stored"; public static final String NBT_STORED = "Stored";
@@ -21,16 +21,14 @@ public class NBTStorage implements IStorage {
private NBTTagCompound tag; private NBTTagCompound tag;
private int capacity; private int capacity;
private int priority;
private boolean dirty; private boolean dirty;
private Multimap<Item, ItemGroup> groups = ArrayListMultimap.create(); 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.tag = tag;
this.capacity = capacity; this.capacity = capacity;
this.priority = priority;
readFromNBT(); readFromNBT();
} }
@@ -136,11 +134,6 @@ public class NBTStorage implements IStorage {
return capacity == -1 || (getStored(tag) + stack.stackSize) <= capacity; return capacity == -1 || (getStored(tag) + stack.stackSize) <= capacity;
} }
@Override
public int getPriority() {
return priority;
}
public int getCapacity() { public int getCapacity() {
return capacity; return capacity;
} }

View File

@@ -8,7 +8,7 @@ public class StorageBlockStorage extends NBTStorage {
private TileStorage storage; private TileStorage storage;
public StorageBlockStorage(TileStorage storage) { public StorageBlockStorage(TileStorage storage) {
super(storage.getStorageTag(), storage.getCapacity(), 0); super(storage.getStorageTag(), storage.getCapacity());
this.storage = storage; this.storage = storage;
} }

View File

@@ -43,6 +43,10 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
@Override @Override
public void updateMachine() { public void updateMachine() {
if (storage == null && storageTag != null) {
storage = new StorageBlockStorage(this);
}
if (storage != null && storage.isDirty()) { if (storage != null && storage.isDirty()) {
markDirty(); 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 @Override
public void provide(List<IStorage> storages) { public void provide(List<IStorage> storages) {
if (storage != null) { if (storage != null) {
@@ -80,8 +76,6 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
storageTag = nbt.getCompoundTag(NBT_STORAGE); storageTag = nbt.getCompoundTag(NBT_STORAGE);
} }
storage = new StorageBlockStorage(this);
if (nbt.hasKey(NBT_COMPARE)) { if (nbt.hasKey(NBT_COMPARE)) {
compare = nbt.getInteger(NBT_COMPARE); compare = nbt.getInteger(NBT_COMPARE);
} }
@@ -206,6 +200,10 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
return storageTag; return storageTag;
} }
public void setStorageTag(NBTTagCompound storageTag) {
this.storageTag = storageTag;
}
@Override @Override
public int getPriority() { public int getPriority() {
return priority; return priority;