Fixed storage GUIs overflowing on large numbers. Fixes #2098

This commit is contained in:
raoulvdberge
2018-11-28 21:26:12 +01:00
parent 3fb53378ca
commit 61405f41b4
13 changed files with 80 additions and 26 deletions

View File

@@ -4,6 +4,7 @@
- Increased the speed of autocrafting (raoulvdberge)
- Fixed External Storage sending storage updates when it is disabled (raoulvdberge)
- Fixed slight performance issue with loading Crafters from disk (raoulvdberge)
- Fixed storage GUIs overflowing on large numbers (raoulvdberge)
- Added a completion percentage to the Crafting Monitor (raoulvdberge)
- Updated Russian translation (kellixon)

View File

@@ -16,6 +16,18 @@ public interface IQuantityFormatter {
*/
String formatWithUnits(int qty);
/**
* Formats a quantity as they are formatted in the Grid.
* Formatted as following: "####0.#".
* <p>
* If the quantity is equal to or bigger than 1000 it will be displayed as the quantity divided by 1000 (without any decimals) and a "K" appended.
* If the quantity is equal to or bigger than 1000000 it will be displayed as the quantity divided by 1000000 (without any decimals) and a "M" appended.
*
* @param qty the quantity
* @return the formatted quantity
*/
String formatWithUnits(long qty);
/**
* Formats a quantity as they are formatted on the disk tooltips.
* Formatted as following: "#,###".
@@ -25,6 +37,15 @@ public interface IQuantityFormatter {
*/
String format(int qty);
/**
* Formats a quantity as they are formatted on the disk tooltips.
* Formatted as following: "#,###".
*
* @param qty the quantity
* @return the formatted quantity
*/
String format(long qty);
/**
* Divides quantity by 1000 and appends "B".
*

View File

@@ -18,7 +18,7 @@ public interface IGuiStorage {
TileDataParameter<AccessType, ?> getAccessTypeParameter();
int getStored();
long getStored();
int getCapacity();
long getCapacity();
}

View File

@@ -293,12 +293,12 @@ public class NetworkNodeExternalStorage extends NetworkNode implements IStorageP
}
@Override
public int getStored() {
public long getStored() {
return TileExternalStorage.STORED.getValue();
}
@Override
public int getCapacity() {
public long getCapacity() {
return TileExternalStorage.CAPACITY.getValue();
}

View File

@@ -304,12 +304,12 @@ public class NetworkNodeDiskDrive extends NetworkNode implements IGuiStorage, IS
}
@Override
public int getStored() {
public long getStored() {
return TileDiskDrive.STORED.getValue();
}
@Override
public int getCapacity() {
public long getCapacity() {
return TileDiskDrive.CAPACITY.getValue();
}

View File

@@ -252,12 +252,12 @@ public class NetworkNodeFluidStorage extends NetworkNode implements IGuiStorage,
}
@Override
public int getStored() {
public long getStored() {
return TileFluidStorage.STORED.getValue();
}
@Override
public int getCapacity() {
public long getCapacity() {
return getType().getCapacity();
}

View File

@@ -251,12 +251,12 @@ public class NetworkNodeStorage extends NetworkNode implements IGuiStorage, ISto
}
@Override
public int getStored() {
public long getStored() {
return TileStorage.STORED.getValue();
}
@Override
public int getCapacity() {
public long getCapacity() {
return getType().getCapacity();
}

View File

@@ -20,6 +20,11 @@ public class QuantityFormatter implements IQuantityFormatter {
@Override
public String formatWithUnits(int qty) {
return formatWithUnits((long) qty);
}
@Override
public String formatWithUnits(long qty) {
if (qty >= 1_000_000) {
float qtyShort = (float) qty / 1_000_000F;
@@ -46,6 +51,11 @@ public class QuantityFormatter implements IQuantityFormatter {
return formatter.format(qty);
}
@Override
public String format(long qty) {
return formatter.format(qty);
}
@Override
public String formatInBucketForm(int qty) {
return bucketFormatter.format((float) qty / (float) Fluid.BUCKET_VOLUME) + " B";

View File

@@ -5,9 +5,9 @@ import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
import com.raoulvdberge.refinedstorage.apiimpl.network.node.diskdrive.NetworkNodeDiskDrive;
import com.raoulvdberge.refinedstorage.render.constants.ConstantsDisk;
import com.raoulvdberge.refinedstorage.tile.config.*;
import com.raoulvdberge.refinedstorage.tile.data.RSSerializers;
import com.raoulvdberge.refinedstorage.tile.data.TileDataParameter;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@@ -23,8 +23,8 @@ public class TileDiskDrive extends TileNode<NetworkNodeDiskDrive> {
public static final TileDataParameter<Integer, TileDiskDrive> MODE = IFilterable.createParameter();
public static final TileDataParameter<Integer, TileDiskDrive> TYPE = IType.createParameter();
public static final TileDataParameter<AccessType, TileDiskDrive> ACCESS_TYPE = IAccessType.createParameter();
public static final TileDataParameter<Integer, TileDiskDrive> STORED = new TileDataParameter<>(DataSerializers.VARINT, 0, t -> {
int stored = 0;
public static final TileDataParameter<Long, TileDiskDrive> STORED = new TileDataParameter<>(RSSerializers.LONG_SERIALIZER, 0L, t -> {
long stored = 0;
for (IStorageDisk storage : t.getNode().getItemDisks()) {
if (storage != null) {
@@ -40,13 +40,13 @@ public class TileDiskDrive extends TileNode<NetworkNodeDiskDrive> {
return stored;
});
public static final TileDataParameter<Integer, TileDiskDrive> CAPACITY = new TileDataParameter<>(DataSerializers.VARINT, 0, t -> {
int capacity = 0;
public static final TileDataParameter<Long, TileDiskDrive> CAPACITY = new TileDataParameter<>(RSSerializers.LONG_SERIALIZER, 0L, t -> {
long capacity = 0;
for (IStorageDisk storage : t.getNode().getItemDisks()) {
if (storage != null) {
if (storage.getCapacity() == -1) {
return -1;
return -1L;
}
capacity += storage.getCapacity();
@@ -56,7 +56,7 @@ public class TileDiskDrive extends TileNode<NetworkNodeDiskDrive> {
for (IStorageDisk storage : t.getNode().getFluidDisks()) {
if (storage != null) {
if (storage.getCapacity() == -1) {
return -1;
return -1L;
}
capacity += storage.getCapacity();

View File

@@ -4,9 +4,9 @@ import com.raoulvdberge.refinedstorage.api.storage.AccessType;
import com.raoulvdberge.refinedstorage.api.storage.externalstorage.IStorageExternal;
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeExternalStorage;
import com.raoulvdberge.refinedstorage.tile.config.*;
import com.raoulvdberge.refinedstorage.tile.data.RSSerializers;
import com.raoulvdberge.refinedstorage.tile.data.TileDataParameter;
import net.minecraft.item.ItemStack;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;
@@ -19,8 +19,8 @@ public class TileExternalStorage extends TileNode<NetworkNodeExternalStorage> {
public static final TileDataParameter<Integer, TileExternalStorage> MODE = IFilterable.createParameter();
public static final TileDataParameter<Integer, TileExternalStorage> TYPE = IType.createParameter();
public static final TileDataParameter<AccessType, TileExternalStorage> ACCESS_TYPE = IAccessType.createParameter();
public static final TileDataParameter<Integer, TileExternalStorage> STORED = new TileDataParameter<>(DataSerializers.VARINT, 0, t -> {
int stored = 0;
public static final TileDataParameter<Long, TileExternalStorage> STORED = new TileDataParameter<>(RSSerializers.LONG_SERIALIZER, 0L, t -> {
long stored = 0;
for (IStorageExternal<ItemStack> storage : t.getNode().getItemStorages()) {
stored += storage.getStored();
@@ -32,8 +32,8 @@ public class TileExternalStorage extends TileNode<NetworkNodeExternalStorage> {
return stored;
});
public static final TileDataParameter<Integer, TileExternalStorage> CAPACITY = new TileDataParameter<>(DataSerializers.VARINT, 0, t -> {
int capacity = 0;
public static final TileDataParameter<Long, TileExternalStorage> CAPACITY = new TileDataParameter<>(RSSerializers.LONG_SERIALIZER, 0L, t -> {
long capacity = 0;
for (IStorageExternal<ItemStack> storage : t.getNode().getItemStorages()) {
capacity += storage.getCapacity();

View File

@@ -6,8 +6,8 @@ import com.raoulvdberge.refinedstorage.tile.config.IAccessType;
import com.raoulvdberge.refinedstorage.tile.config.IComparable;
import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
import com.raoulvdberge.refinedstorage.tile.config.IPrioritizable;
import com.raoulvdberge.refinedstorage.tile.data.RSSerializers;
import com.raoulvdberge.refinedstorage.tile.data.TileDataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@@ -18,7 +18,7 @@ public class TileFluidStorage extends TileNode<NetworkNodeFluidStorage> {
public static final TileDataParameter<Integer, TileFluidStorage> COMPARE = IComparable.createParameter();
public static final TileDataParameter<Integer, TileFluidStorage> MODE = IFilterable.createParameter();
public static final TileDataParameter<AccessType, TileFluidStorage> ACCESS_TYPE = IAccessType.createParameter();
public static final TileDataParameter<Integer, TileFluidStorage> STORED = new TileDataParameter<>(DataSerializers.VARINT, 0, t -> t.getNode().getStorage().getStored());
public static final TileDataParameter<Long, TileFluidStorage> STORED = new TileDataParameter<>(RSSerializers.LONG_SERIALIZER, 0L, t -> (long) t.getNode().getStorage().getStored());
public TileFluidStorage() {
dataManager.addWatchedParameter(PRIORITY);

View File

@@ -6,8 +6,8 @@ import com.raoulvdberge.refinedstorage.tile.config.IAccessType;
import com.raoulvdberge.refinedstorage.tile.config.IComparable;
import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
import com.raoulvdberge.refinedstorage.tile.config.IPrioritizable;
import com.raoulvdberge.refinedstorage.tile.data.RSSerializers;
import com.raoulvdberge.refinedstorage.tile.data.TileDataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@@ -18,7 +18,7 @@ public class TileStorage extends TileNode<NetworkNodeStorage> {
public static final TileDataParameter<Integer, TileStorage> COMPARE = IComparable.createParameter();
public static final TileDataParameter<Integer, TileStorage> MODE = IFilterable.createParameter();
public static final TileDataParameter<AccessType, TileStorage> ACCESS_TYPE = IAccessType.createParameter();
public static final TileDataParameter<Integer, TileStorage> STORED = new TileDataParameter<>(DataSerializers.VARINT, 0, t -> t.getNode().getStorage().getStored());
public static final TileDataParameter<Long, TileStorage> STORED = new TileDataParameter<>(RSSerializers.LONG_SERIALIZER, 0L, t -> (long) t.getNode().getStorage().getStored());
public TileStorage() {
dataManager.addWatchedParameter(PRIORITY);

View File

@@ -109,4 +109,26 @@ public final class RSSerializers {
return value;
}
};
public static final DataSerializer<Long> LONG_SERIALIZER = new DataSerializer<Long>() {
@Override
public void write(PacketBuffer buf, Long value) {
buf.writeLong(value);
}
@Override
public Long read(PacketBuffer buf) throws IOException {
return buf.readLong();
}
@Override
public DataParameter<Long> createKey(int id) {
return null;
}
@Override
public Long copyValue(Long value) {
return value;
}
};
}