This commit is contained in:
Raoul Van den Berge
2016-06-04 00:00:59 +02:00
parent c62211654e
commit e244b887b5
9 changed files with 64 additions and 33 deletions

View File

@@ -25,9 +25,9 @@ public class ItemBlockStorage extends ItemBlockBase {
NBTTagCompound tag = stack.getTagCompound().getCompoundTag(TileStorage.NBT_STORAGE);
if (type == EnumStorageType.TYPE_CREATIVE) {
list.add(String.format(I18n.format("misc.refinedstorage:storage.stored"), NBTStorage.getStored(tag)));
list.add(I18n.format("misc.refinedstorage:storage.stored", NBTStorage.getStoredFromNBT(tag)));
} else {
list.add(String.format(I18n.format("misc.refinedstorage:storage.stored_capacity"), NBTStorage.getStored(tag), type.getCapacity()));
list.add(I18n.format("misc.refinedstorage:storage.stored_capacity", NBTStorage.getStoredFromNBT(tag), type.getCapacity()));
}
}
}

View File

@@ -43,15 +43,15 @@ public class ItemStorageDisk extends ItemBase {
int capacity = EnumStorageType.getById(disk.getItemDamage()).getCapacity();
if (capacity == -1) {
list.add(I18n.format("misc.refinedstorage:storage.stored", NBTStorage.getStored(disk.getTagCompound())));
list.add(I18n.format("misc.refinedstorage:storage.stored", NBTStorage.getStoredFromNBT(disk.getTagCompound())));
} else {
list.add(I18n.format("misc.refinedstorage:storage.stored_capacity", NBTStorage.getStored(disk.getTagCompound()), capacity));
list.add(I18n.format("misc.refinedstorage:storage.stored_capacity", NBTStorage.getStoredFromNBT(disk.getTagCompound()), capacity));
}
}
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
if (!world.isRemote && player.isSneaking() && NBTStorage.getStored(stack.getTagCompound()) == 0 && stack.getMetadata() != TYPE_CREATIVE) {
if (!world.isRemote && player.isSneaking() && NBTStorage.getStoredFromNBT(stack.getTagCompound()) == 0 && stack.getMetadata() != TYPE_CREATIVE) {
ItemStack storagePart = new ItemStack(RefinedStorageItems.STORAGE_PART, 1, stack.getMetadata());
if (!player.inventory.addItemStackToInventory(storagePart.copy())) {

View File

@@ -13,5 +13,7 @@ public interface IStorage {
boolean mayPush(ItemStack stack);
int getStored();
int getPriority();
}

View File

@@ -78,7 +78,7 @@ public abstract class NBTStorage implements IStorage {
@Override
public void push(ItemStack stack) {
tag.setInteger(NBT_STORED, getStored(tag) + stack.stackSize);
tag.setInteger(NBT_STORED, getStored() + stack.stackSize);
for (ItemStack s : stacks) {
if (RefinedStorageUtils.compareStackNoQuantity(s, stack)) {
@@ -109,7 +109,7 @@ public abstract class NBTStorage implements IStorage {
s.stackSize -= size;
}
tag.setInteger(NBT_STORED, getStored(tag) - size);
tag.setInteger(NBT_STORED, getStored() - size);
markDirty();
@@ -122,7 +122,12 @@ public abstract class NBTStorage implements IStorage {
@Override
public boolean mayPush(ItemStack stack) {
return capacity == -1 || (getStored(tag) + stack.stackSize) <= capacity;
return capacity == -1 || (getStored() + stack.stackSize) <= capacity;
}
@Override
public int getStored() {
return getStoredFromNBT(tag);
}
public int getCapacity() {
@@ -145,7 +150,7 @@ public abstract class NBTStorage implements IStorage {
this.dirty = false;
}
public static int getStored(NBTTagCompound tag) {
public static int getStoredFromNBT(NBTTagCompound tag) {
return tag.getInteger(NBT_STORED);
}

View File

@@ -3,6 +3,7 @@ package refinedstorage.tile;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.state.IBlockState;
import net.minecraft.inventory.Container;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
@@ -52,6 +53,11 @@ public class TileConstructor extends TileMachine implements ICompareConfig {
public void updateMachine() {
if (ticks % RefinedStorageUtils.getSpeed(upgrades, BASE_SPEED, 4) == 0 && filter.getStackInSlot(0) != null) {
BlockPos front = pos.offset(getDirection());
IBlockState frontBlockState = worldObj.getBlockState(front);
if (!frontBlockState.getBlock().isAir(frontBlockState, worldObj, front)) {
return;
}
Item item = filter.getStackInSlot(0).getItem();
Block block = null;

View File

@@ -216,7 +216,7 @@ public class TileDiskDrive extends TileMachine implements IStorageProvider, ISto
ItemStack stack = disks.getStackInSlot(i);
if (stack != null) {
stored += NBTStorage.getStored(stack.getTagCompound());
stored += NBTStorage.getStoredFromNBT(stack.getTagCompound());
}
}

View File

@@ -155,27 +155,7 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
buf.writeInt(priority);
IDeepStorageUnit storageUnit = getStorageUnit();
if (storageUnit != null) {
buf.writeInt(storageUnit.getStoredItemType() == null ? 0 : storageUnit.getStoredItemType().stackSize);
} else {
IItemHandler handler = getItemHandler();
if (handler != null) {
int amount = 0;
for (int i = 0; i < handler.getSlots(); ++i) {
if (handler.getStackInSlot(i) != null) {
amount += handler.getStackInSlot(i).stackSize;
}
}
buf.writeInt(amount);
} else {
buf.writeInt(0);
}
}
buf.writeInt(getStored());
buf.writeInt(compare);
buf.writeInt(mode);
@@ -290,7 +270,31 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
@Override
public int getStored() {
return stored;
if (worldObj.isRemote) {
return stored;
}
IDeepStorageUnit storageUnit = getStorageUnit();
if (storageUnit != null) {
return storageUnit.getStoredItemType() == null ? 0 : storageUnit.getStoredItemType().stackSize;
} else {
IItemHandler handler = getItemHandler();
if (handler != null) {
int size = 0;
for (int i = 0; i < handler.getSlots(); ++i) {
if (handler.getStackInSlot(i) != null) {
size += handler.getStackInSlot(i).stackSize;
}
}
return size;
} else {
return 0;
}
}
}
@Override

View File

@@ -114,7 +114,7 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
public void writeContainerData(ByteBuf buf) {
super.writeContainerData(buf);
buf.writeInt(NBTStorage.getStored(storageTag));
buf.writeInt(NBTStorage.getStoredFromNBT(storageTag));
buf.writeInt(priority);
buf.writeInt(compare);
buf.writeInt(mode);

View File

@@ -283,6 +283,20 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
this.energyUsage += machine.getEnergyUsage();
}
Collections.sort(storages, new Comparator<IStorage>() {
@Override
public int compare(IStorage left, IStorage right) {
int leftStored = left.getStored();
int rightStored = right.getStored();
if (leftStored == rightStored) {
return 0;
}
return (leftStored > rightStored) ? -1 : 1;
}
});
Collections.sort(storages, new Comparator<IStorage>() {
@Override
public int compare(IStorage left, IStorage right) {