Fixed external storage cache being de-synced from the network cache

This commit is contained in:
BlueAgent
2022-12-19 21:36:02 +08:00
committed by Raoul
parent 2aa79b9f7e
commit 958ab0ceee
5 changed files with 46 additions and 22 deletions

View File

@@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Fixed
- Fixed external storage cache being de-synced from the network cache.
## [v1.11.2] - 2022-12-17
### Added

View File

@@ -64,6 +64,8 @@ public class FluidExternalStorage implements IExternalStorage<FluidStack> {
IFluidHandler fluidHandler = handlerSupplier.get();
if (fluidHandler != null) {
cache.initCache(fluidHandler);
List<FluidStack> fluids = new ArrayList<>();
for (int i = 0; i < fluidHandler.getTanks(); ++i) {

View File

@@ -18,23 +18,31 @@ public class FluidExternalStorageCache {
return stored;
}
public boolean initCache(IFluidHandler handler) {
if (cache != null) {
return false;
}
cache = new ArrayList<>();
int stored = 0;
for (int i = 0; i < handler.getTanks(); ++i) {
FluidStack stack = handler.getFluidInTank(i).copy();
cache.add(stack);
stored += stack.getAmount();
}
this.stored = stored;
return true;
}
public void update(INetwork network, @Nullable IFluidHandler handler) {
if (handler == null) {
stored = 0;
return;
}
if (cache == null) {
cache = new ArrayList<>();
int stored = 0;
for (int i = 0; i < handler.getTanks(); ++i) {
FluidStack stack = handler.getFluidInTank(i).copy();
cache.add(stack);
stored += stack.getAmount();
}
this.stored = stored;
if (initCache(handler)) {
return;
}

View File

@@ -68,6 +68,8 @@ public class ItemExternalStorage implements IExternalStorage<ItemStack> {
return Collections.emptyList();
}
cache.initCache(handler);
List<ItemStack> stacks = new ArrayList<>();
for (int i = 0; i < handler.getSlots(); ++i) {

View File

@@ -17,23 +17,31 @@ public class ItemExternalStorageCache {
return stored;
}
public boolean initCache(IItemHandler handler) {
if (cache != null) {
return false;
}
cache = new ArrayList<>();
int stored = 0;
for (int i = 0; i < handler.getSlots(); ++i) {
ItemStack stack = handler.getStackInSlot(i).copy();
cache.add(stack);
stored += stack.getCount();
}
this.stored = stored;
return true;
}
public void update(INetwork network, @Nullable IItemHandler handler) {
if (handler == null) {
stored = 0;
return;
}
if (cache == null) {
cache = new ArrayList<>();
int stored = 0;
for (int i = 0; i < handler.getSlots(); ++i) {
ItemStack stack = handler.getStackInSlot(i).copy();
cache.add(stack);
stored += stack.getCount();
}
this.stored = stored;
if (initCache(handler)) {
return;
}