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]
|
## [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
|
||||||
|
@@ -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) {
|
||||||
|
@@ -18,23 +18,31 @@ public class FluidExternalStorageCache {
|
|||||||
return stored;
|
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) {
|
public void update(INetwork network, @Nullable IFluidHandler handler) {
|
||||||
if (handler == null) {
|
if (handler == null) {
|
||||||
stored = 0;
|
stored = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cache == null) {
|
if (initCache(handler)) {
|
||||||
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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) {
|
||||||
|
@@ -17,23 +17,31 @@ public class ItemExternalStorageCache {
|
|||||||
return stored;
|
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) {
|
public void update(INetwork network, @Nullable IItemHandler handler) {
|
||||||
if (handler == null) {
|
if (handler == null) {
|
||||||
stored = 0;
|
stored = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cache == null) {
|
if (initCache(handler)) {
|
||||||
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user