Skip to content

Commit

Permalink
fix: crash when trying to export fluids on Fabric via external storage
Browse files Browse the repository at this point in the history
Related: 22e08a9

That commit only solved it when using the exporter
straight away.
Exporter uses FabricStorageInsertableStorage
But External Utorage uses FabricStorageExtractableStorage
so also patch it there.
  • Loading branch information
raoulvdberge committed Oct 11, 2024
1 parent 4e5cd40 commit f679bee
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 13 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

- Fixed mouse keybindings not working on NeoForge.
- Fixed upgrade destinations not being shown on upgrades.
- Fixed resources with changed data format or ID causing entire storage to fail to load.
- Fixed resources with changed data format or ID causing entire storage to fail to load.
- Fixed crash when trying to export fluids from an External Storage on Fabric.

## [2.0.0-milestone.4.7] - 2024-08-11

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.refinedmods.refinedstorage.fabric.exporter;

import com.refinedmods.refinedstorage.api.core.NullableType;
import com.refinedmods.refinedstorage.api.network.impl.node.exporter.ExporterTransferStrategyImpl;
import com.refinedmods.refinedstorage.api.network.node.exporter.ExporterTransferStrategy;
import com.refinedmods.refinedstorage.api.resource.ResourceKey;
Expand All @@ -20,11 +21,11 @@

public class FabricStorageExporterTransferStrategyFactory<T> implements ExporterTransferStrategyFactory {
private final BlockApiLookup<Storage<T>, Direction> lookup;
private final Function<ResourceKey, T> toPlatformMapper;
private final Function<ResourceKey, @NullableType T> toPlatformMapper;
private final long singleAmount;

public FabricStorageExporterTransferStrategyFactory(final BlockApiLookup<Storage<T>, Direction> lookup,
final Function<ResourceKey, T> toPlatformMapper,
final Function<ResourceKey, @NullableType T> toPlatformMapper,
final long singleAmount) {
this.lookup = lookup;
this.toPlatformMapper = toPlatformMapper;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.refinedmods.refinedstorage.fabric.importer;

import com.refinedmods.refinedstorage.api.core.Action;
import com.refinedmods.refinedstorage.api.core.NullableType;
import com.refinedmods.refinedstorage.api.network.impl.node.importer.ImporterSource;
import com.refinedmods.refinedstorage.api.resource.ResourceKey;
import com.refinedmods.refinedstorage.api.storage.Actor;
Expand Down Expand Up @@ -32,7 +33,7 @@ class FabricStorageImporterSource<T> implements ImporterSource {

FabricStorageImporterSource(final BlockApiLookup<Storage<T>, Direction> lookup,
final Function<T, ResourceKey> fromPlatformMapper,
final Function<ResourceKey, T> toPlatformMapper,
@NullableType final Function<ResourceKey, T> toPlatformMapper,
final ServerLevel serverLevel,
final BlockPos pos,
final Direction direction,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.refinedmods.refinedstorage.fabric.importer;

import com.refinedmods.refinedstorage.api.core.NullableType;
import com.refinedmods.refinedstorage.api.network.impl.node.importer.ImporterSource;
import com.refinedmods.refinedstorage.api.network.impl.node.importer.ImporterTransferStrategyImpl;
import com.refinedmods.refinedstorage.api.network.node.importer.ImporterTransferStrategy;
Expand All @@ -20,12 +21,12 @@
public class FabricStorageImporterTransferStrategyFactory<P> implements ImporterTransferStrategyFactory {
private final BlockApiLookup<Storage<P>, Direction> lookup;
private final Function<P, ResourceKey> fromPlatformMapper;
private final Function<ResourceKey, P> toPlatformMapper;
private final Function<ResourceKey, @NullableType P> toPlatformMapper;
private final long singleAmount;

public FabricStorageImporterTransferStrategyFactory(final BlockApiLookup<Storage<P>, Direction> lookup,
final Function<P, ResourceKey> fromPlatformMapper,
final Function<ResourceKey, P> toPlatformMapper,
final Function<ResourceKey, @NullableType P> toPlatformMapper,
final long singleAmount) {
this.lookup = lookup;
this.fromPlatformMapper = fromPlatformMapper;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.refinedmods.refinedstorage.fabric.storage;

import com.refinedmods.refinedstorage.api.core.Action;
import com.refinedmods.refinedstorage.api.core.NullableType;
import com.refinedmods.refinedstorage.api.resource.ResourceKey;
import com.refinedmods.refinedstorage.api.storage.Actor;
import com.refinedmods.refinedstorage.api.storage.ExtractableStorage;
Expand All @@ -18,12 +19,12 @@

public class FabricStorageExtractableStorage<P> implements ExtractableStorage {
private final BlockApiCache<Storage<P>, Direction> cache;
private final Function<ResourceKey, P> toPlatformMapper;
private final Function<ResourceKey, @NullableType P> toPlatformMapper;
private final Direction direction;
private final AmountOverride amountOverride;

public FabricStorageExtractableStorage(final BlockApiLookup<Storage<P>, Direction> lookup,
final Function<ResourceKey, P> toPlatformMapper,
final Function<ResourceKey, @NullableType P> toPlatformMapper,
final ServerLevel serverLevel,
final BlockPos pos,
final Direction direction,
Expand All @@ -41,6 +42,9 @@ public long extract(final ResourceKey resource, final long amount, final Action
return 0L;
}
final P platformResource = toPlatformMapper.apply(resource);
if (platformResource == null) {
return 0L;
}
final long correctedAmount = amountOverride.overrideAmount(
resource,
amount,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.refinedmods.refinedstorage.fabric.storage;

import com.refinedmods.refinedstorage.api.core.Action;
import com.refinedmods.refinedstorage.api.core.NullableType;
import com.refinedmods.refinedstorage.api.resource.ResourceKey;
import com.refinedmods.refinedstorage.api.storage.Actor;
import com.refinedmods.refinedstorage.api.storage.InsertableStorage;
Expand All @@ -18,12 +19,12 @@

public class FabricStorageInsertableStorage<T> implements InsertableStorage {
private final BlockApiCache<Storage<T>, Direction> cache;
private final Function<ResourceKey, T> toPlatformMapper;
private final Function<ResourceKey, @NullableType T> toPlatformMapper;
private final Direction direction;
private final AmountOverride amountOverride;

public FabricStorageInsertableStorage(final BlockApiLookup<Storage<T>, Direction> lookup,
final Function<ResourceKey, T> toPlatformMapper,
final Function<ResourceKey, @NullableType T> toPlatformMapper,
final ServerLevel serverLevel,
final BlockPos pos,
final Direction direction,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.refinedmods.refinedstorage.fabric.storage.externalstorage;

import com.refinedmods.refinedstorage.api.core.Action;
import com.refinedmods.refinedstorage.api.core.NullableType;
import com.refinedmods.refinedstorage.api.resource.ResourceAmount;
import com.refinedmods.refinedstorage.api.resource.ResourceKey;
import com.refinedmods.refinedstorage.api.storage.Actor;
Expand Down Expand Up @@ -33,7 +34,7 @@ class FabricStorageExternalStorageProvider<P> implements ExternalStorageProvider

FabricStorageExternalStorageProvider(final BlockApiLookup<Storage<P>, Direction> lookup,
final Function<P, ResourceKey> fromPlatformMapper,
final Function<ResourceKey, P> toPlatformMapper,
final Function<ResourceKey, @NullableType P> toPlatformMapper,
final ServerLevel serverLevel,
final BlockPos pos,
final Direction direction) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.refinedmods.refinedstorage.fabric.storage.externalstorage;

import com.refinedmods.refinedstorage.api.core.NullableType;
import com.refinedmods.refinedstorage.api.resource.ResourceKey;
import com.refinedmods.refinedstorage.api.storage.external.ExternalStorageProvider;
import com.refinedmods.refinedstorage.common.api.storage.externalstorage.PlatformExternalStorageProviderFactory;
Expand All @@ -17,11 +18,12 @@ public class FabricStoragePlatformExternalStorageProviderFactory<T>
implements PlatformExternalStorageProviderFactory {
private final BlockApiLookup<Storage<T>, Direction> lookup;
private final Function<T, ResourceKey> fromPlatformMapper;
private final Function<ResourceKey, T> toPlatformMapper;
private final Function<ResourceKey, @NullableType T> toPlatformMapper;

public FabricStoragePlatformExternalStorageProviderFactory(final BlockApiLookup<Storage<T>, Direction> lookup,
final Function<T, ResourceKey> fromPlatformMapper,
final Function<ResourceKey, T> toPlatformMapper) {
@NullableType final Function<ResourceKey, T>
toPlatformMapper) {
this.lookup = lookup;
this.fromPlatformMapper = fromPlatformMapper;
this.toPlatformMapper = toPlatformMapper;
Expand Down

0 comments on commit f679bee

Please sign in to comment.