Skip to content

Commit

Permalink
Fixed storage GUIs overflowing on large numbers. Fixes #2098
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulvdberge committed Nov 28, 2018
1 parent 3fb5337 commit 61405f4
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: "#,###".
Expand All @@ -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".
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface IGuiStorage {

TileDataParameter<AccessType, ?> getAccessTypeParameter();

int getStored();
long getStored();

int getCapacity();
long getCapacity();
}
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,12 @@ public String getGuiTitle() {
}

@Override
public int getStored() {
public long getStored() {
return TileExternalStorage.STORED.getValue();
}

@Override
public int getCapacity() {
public long getCapacity() {
return TileExternalStorage.CAPACITY.getValue();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,12 @@ public String getGuiTitle() {
}

@Override
public int getStored() {
public long getStored() {
return TileDiskDrive.STORED.getValue();
}

@Override
public int getCapacity() {
public long getCapacity() {
return TileDiskDrive.CAPACITY.getValue();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,12 @@ public String getGuiTitle() {
}

@Override
public int getStored() {
public long getStored() {
return TileFluidStorage.STORED.getValue();
}

@Override
public int getCapacity() {
public long getCapacity() {
return getType().getCapacity();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,12 @@ public String getGuiTitle() {
}

@Override
public int getStored() {
public long getStored() {
return TileStorage.STORED.getValue();
}

@Override
public int getCapacity() {
public long getCapacity() {
return getType().getCapacity();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public QuantityFormatter() {

@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;

Expand All @@ -46,6 +51,11 @@ public String format(int qty) {
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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
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;
Expand All @@ -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) {
Expand All @@ -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();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
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;
Expand All @@ -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();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
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;

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
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;

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,26 @@ public AccessType copyValue(AccessType value) {
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;
}
};
}

0 comments on commit 61405f4

Please sign in to comment.