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] ## [Unreleased]
### Fixed
- Fixed external storage cache being de-synced from the network cache.
## [v1.11.2] - 2022-12-17 ## [v1.11.2] - 2022-12-17
### Added ### Added

View File

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

View File

@@ -18,13 +18,11 @@ public class FluidExternalStorageCache {
return stored; return stored;
} }
public void update(INetwork network, @Nullable IFluidHandler handler) { public boolean initCache(IFluidHandler handler) {
if (handler == null) { if (cache != null) {
stored = 0; return false;
return;
} }
if (cache == null) {
cache = new ArrayList<>(); cache = new ArrayList<>();
int stored = 0; int stored = 0;
@@ -35,6 +33,16 @@ public class FluidExternalStorageCache {
} }
this.stored = stored; this.stored = stored;
return true;
}
public void update(INetwork network, @Nullable IFluidHandler handler) {
if (handler == null) {
stored = 0;
return;
}
if (initCache(handler)) {
return; return;
} }

View File

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

View File

@@ -17,13 +17,11 @@ public class ItemExternalStorageCache {
return stored; return stored;
} }
public void update(INetwork network, @Nullable IItemHandler handler) { public boolean initCache(IItemHandler handler) {
if (handler == null) { if (cache != null) {
stored = 0; return false;
return;
} }
if (cache == null) {
cache = new ArrayList<>(); cache = new ArrayList<>();
int stored = 0; int stored = 0;
@@ -34,6 +32,16 @@ public class ItemExternalStorageCache {
} }
this.stored = stored; this.stored = stored;
return true;
}
public void update(INetwork network, @Nullable IItemHandler handler) {
if (handler == null) {
stored = 0;
return;
}
if (initCache(handler)) {
return; return;
} }