Fix lag due to excessive saving

This commit is contained in:
Raoul Van den Berge
2016-06-21 23:06:50 +02:00
parent 32b130619f
commit 5d0e64dfde
8 changed files with 40 additions and 12 deletions

View File

@@ -530,12 +530,12 @@ public class NetworkMaster {
}
}
if (!simulate) {
int sizePushed = remainder != null ? (orginalSize - remainder.stackSize) : orginalSize;
if (!simulate && sizePushed > 0) {
syncItems();
syncItemsWithClients();
int sizePushed = remainder != null ? (orginalSize - remainder.stackSize) : orginalSize;
for (int i = 0; i < sizePushed; ++i) {
if (!craftingTasks.empty()) {
ICraftingTask top = craftingTasks.peek();

View File

@@ -11,6 +11,7 @@ import refinedstorage.RefinedStorageUtils;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.FutureTask;
/**
* A implementation of {@link IStorage} that stores storage items in NBT.
@@ -202,8 +203,6 @@ public abstract class NBTStorage implements IStorage {
}
public void onStorageChanged() {
writeToNBT();
if (tile != null) {
tile.markDirty();
}

View File

@@ -6,7 +6,7 @@ import refinedstorage.RefinedStorageUtils;
import refinedstorage.api.network.NetworkMaster;
public class CraftingTaskScheduler {
public static String NBT_SCHEDULED = "CraftingTaskScheduled";
public static final String NBT_SCHEDULED = "CraftingTaskScheduled";
private ItemStack scheduledItem;

View File

@@ -83,13 +83,17 @@ public class BlockStorage extends BlockSlave {
@Override
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
TileStorage storage = (TileStorage) world.getTileEntity(pos);
if (storage.getStorage() != null) {
storage.getStorage().writeToNBT();
}
List<ItemStack> drops = new ArrayList<ItemStack>();
ItemStack stack = new ItemStack(RefinedStorageBlocks.STORAGE, 1, RefinedStorageBlocks.STORAGE.getMetaFromState(state));
NBTTagCompound tag = new NBTTagCompound();
tag.setTag(TileStorage.NBT_STORAGE, ((TileStorage) world.getTileEntity(pos)).getStorageTag());
stack.setTagCompound(tag);
stack.setTagCompound(new NBTTagCompound());
stack.getTagCompound().setTag(TileStorage.NBT_STORAGE, storage.getStorageTag());
drops.add(stack);

View File

@@ -73,6 +73,7 @@ public class GuiGrid extends GuiBase {
super(container, 193, (grid.getType() == EnumGridType.CRAFTING || grid.getType() == EnumGridType.PATTERN) ? 256 : 208);
setScrollbar(new Scrollbar(174, 20, 12, (grid.getType() == EnumGridType.CRAFTING || grid.getType() == EnumGridType.PATTERN) ? 70 : 88));
getScrollbar().setCanScroll(false);
this.container = container;
this.grid = grid;

View File

@@ -62,6 +62,15 @@ public class TileDiskDrive extends TileSlave implements IStorageProvider, IStora
storages[slot] = new Storage(disk);
}
}
@Override
public ItemStack extractItem(int slot, int amount, boolean simulate) {
if (storages[slot] != null) {
storages[slot].writeToNBT();
}
return super.extractItem(slot, amount, simulate);
}
};
private BasicItemHandler filters = new BasicItemHandler(9, this);
@@ -121,6 +130,12 @@ public class TileDiskDrive extends TileSlave implements IStorageProvider, IStora
public NBTTagCompound write(NBTTagCompound tag) {
super.write(tag);
for (int i = 0; i < disks.getSlots(); ++i) {
if (storages[i] != null) {
storages[i].writeToNBT();
}
}
RefinedStorageUtils.writeItems(disks, 0, tag);
RefinedStorageUtils.writeItems(filters, 1, tag);

View File

@@ -43,13 +43,13 @@ public class TileExporter extends TileSlave implements ICompareConfig {
public void updateSlave() {
IItemHandler handler = RefinedStorageUtils.getItemHandler(getFacingTile(), getDirection().getOpposite());
int size = RefinedStorageUtils.hasUpgrade(upgrades, ItemUpgrade.TYPE_STACK) ? 64 : 1;
if (handler != null && ticks % RefinedStorageUtils.getSpeed(upgrades) == 0) {
for (int i = 0; i < filters.getSlots(); ++i) {
ItemStack slot = filters.getStackInSlot(i);
if (slot != null) {
int size = RefinedStorageUtils.hasUpgrade(upgrades, ItemUpgrade.TYPE_STACK) ? 64 : 1;
ItemStack took = network.take(slot, size, compare);
if (took != null) {

View File

@@ -115,6 +115,11 @@ public class TileStorage extends TileSlave implements IStorageProvider, IStorage
RefinedStorageUtils.writeItems(filters, 0, tag);
tag.setInteger(NBT_PRIORITY, priority);
if (storage != null) {
storage.writeToNBT();
}
tag.setTag(NBT_STORAGE, storageTag);
tag.setInteger(NBT_COMPARE, compare);
tag.setInteger(NBT_MODE, mode);
@@ -217,6 +222,10 @@ public class TileStorage extends TileSlave implements IStorageProvider, IStorage
this.storageTag = storageTag;
}
public NBTStorage getStorage() {
return storage;
}
@Override
public int getPriority() {
return priority;