Fix disk drive crash
This commit is contained in:
@@ -15,7 +15,6 @@ import refinedstorage.RefinedStorage;
|
||||
import refinedstorage.RefinedStorageGui;
|
||||
import refinedstorage.tile.TileDiskDrive;
|
||||
|
||||
// @TODO: Fix bug where it doesn't display correctly
|
||||
public class BlockDiskDrive extends BlockNode {
|
||||
private static final PropertyInteger STORED = PropertyInteger.create("stored", 0, 7);
|
||||
|
||||
|
||||
@@ -38,10 +38,6 @@ public enum EnumFluidStorageType implements IStringSerializable {
|
||||
}
|
||||
|
||||
public static EnumFluidStorageType getById(int id) {
|
||||
if (id == 5) {
|
||||
return TYPE_CREATIVE;
|
||||
}
|
||||
|
||||
for (EnumFluidStorageType type : EnumFluidStorageType.values()) {
|
||||
if (type.getId() == id) {
|
||||
return type;
|
||||
|
||||
@@ -38,10 +38,6 @@ public enum EnumItemStorageType implements IStringSerializable {
|
||||
}
|
||||
|
||||
public static EnumItemStorageType getById(int id) {
|
||||
if (id == 5) {
|
||||
return TYPE_CREATIVE;
|
||||
}
|
||||
|
||||
for (EnumItemStorageType type : EnumItemStorageType.values()) {
|
||||
if (type.getId() == id) {
|
||||
return type;
|
||||
|
||||
@@ -159,8 +159,8 @@ public class TileDiskDrive extends TileNode implements IItemStorageProvider, IFl
|
||||
@Override
|
||||
public void update() {
|
||||
if (!worldObj.isRemote) {
|
||||
if (stored != getStoredForDisplayServer()) {
|
||||
stored = getStoredForDisplayServer();
|
||||
if (stored != getStoredForDisplay()) {
|
||||
stored = getStoredForDisplay();
|
||||
|
||||
updateBlock();
|
||||
}
|
||||
@@ -317,33 +317,33 @@ public class TileDiskDrive extends TileNode implements IItemStorageProvider, IFl
|
||||
markDirty();
|
||||
}
|
||||
|
||||
public int getStoredForDisplayServer() {
|
||||
float stored = 0;
|
||||
float capacity = 0;
|
||||
|
||||
for (int i = 0; i < disks.getSlots(); ++i) {
|
||||
ItemStack disk = disks.getStackInSlot(i);
|
||||
|
||||
if (disk != null) {
|
||||
int diskCapacity = disk.getItem() == RefinedStorageItems.STORAGE_DISK ? EnumItemStorageType.getById(disk.getItemDamage()).getCapacity() : EnumFluidStorageType.getById(disk.getItemDamage()).getCapacity();
|
||||
|
||||
if (capacity == -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
stored += disk.getItem() == RefinedStorageItems.STORAGE_DISK ? ItemStorageNBT.getStoredFromNBT(disk.getTagCompound()) : FluidStorageNBT.getStoredFromNBT(disk.getTagCompound());
|
||||
capacity += diskCapacity;
|
||||
}
|
||||
}
|
||||
|
||||
if (capacity == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (int) Math.floor((stored / capacity) * 7F);
|
||||
}
|
||||
|
||||
public int getStoredForDisplay() {
|
||||
if (!worldObj.isRemote) {
|
||||
float stored = 0;
|
||||
float capacity = 0;
|
||||
|
||||
for (int i = 0; i < disks.getSlots(); ++i) {
|
||||
ItemStack disk = disks.getStackInSlot(i);
|
||||
|
||||
if (disk != null) {
|
||||
int diskCapacity = disk.getItem() == RefinedStorageItems.STORAGE_DISK ? EnumItemStorageType.getById(disk.getItemDamage()).getCapacity() : EnumFluidStorageType.getById(disk.getItemDamage()).getCapacity();
|
||||
|
||||
if (diskCapacity == -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
stored += disk.getItem() == RefinedStorageItems.STORAGE_DISK ? ItemStorageNBT.getStoredFromNBT(disk.getTagCompound()) : FluidStorageNBT.getStoredFromNBT(disk.getTagCompound());
|
||||
capacity += diskCapacity;
|
||||
}
|
||||
}
|
||||
|
||||
if (capacity == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (int) Math.floor((stored / capacity) * 7F);
|
||||
}
|
||||
|
||||
return stored;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ public interface IType {
|
||||
if (value == 0 || value == 1) {
|
||||
((IType) tile).setType(value);
|
||||
|
||||
// @TODO: This doesn't work serverside
|
||||
tile.getWorld().playerEntities.stream()
|
||||
.filter(p -> p.openContainer instanceof ContainerBase && ((ContainerBase) p.openContainer).getTile().getPos().equals(tile.getPos()))
|
||||
.forEach(p -> p.openContainer.detectAndSendChanges());
|
||||
|
||||
Reference in New Issue
Block a user