Fixed external storage cache being de-synced from the network cache
This commit is contained in:
@@ -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
|
||||
|
@@ -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) {
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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) {
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user