Skip to content

Commit

Permalink
refactor: move FabricStorageUtil to storage package
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulvdberge committed Nov 3, 2023
1 parent 82658d8 commit d0ccbba
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.refinedmods.refinedstorage2.platform.api.upgrade.UpgradeState;
import com.refinedmods.refinedstorage2.platform.common.content.Items;
import com.refinedmods.refinedstorage2.platform.common.exporter.AbstractFuzzyExporterTransferStrategy;
import com.refinedmods.refinedstorage2.platform.fabric.storage.StorageInsertableStorage;
import com.refinedmods.refinedstorage2.platform.fabric.storage.FabricStorageInsertableStorage;

import java.util.Optional;
import java.util.function.Function;
Expand Down Expand Up @@ -46,7 +46,7 @@ public ExporterTransferStrategy create(final ServerLevel level,
final UpgradeState upgradeState,
final AmountOverride amountOverride,
final boolean fuzzyMode) {
final StorageInsertableStorage<T, P> insertTarget = new StorageInsertableStorage<>(
final FabricStorageInsertableStorage<T, P> insertTarget = new FabricStorageInsertableStorage<>(
lookup,
toPlatformMapper,
level,
Expand All @@ -61,7 +61,7 @@ public ExporterTransferStrategy create(final ServerLevel level,
}

private AbstractExporterTransferStrategy<T> create(final boolean fuzzyMode,
final StorageInsertableStorage<T, P> insertTarget,
final FabricStorageInsertableStorage<T, P> insertTarget,
final long transferQuota) {
if (fuzzyMode) {
return new AbstractFuzzyExporterTransferStrategy<>(insertTarget, storageChannelType, transferQuota) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import com.refinedmods.refinedstorage2.api.network.node.importer.ImporterSource;
import com.refinedmods.refinedstorage2.api.storage.Actor;
import com.refinedmods.refinedstorage2.platform.api.exporter.AmountOverride;
import com.refinedmods.refinedstorage2.platform.fabric.storage.StorageExtractableStorage;
import com.refinedmods.refinedstorage2.platform.fabric.storage.StorageInsertableStorage;
import com.refinedmods.refinedstorage2.platform.fabric.storage.FabricStorageExtractableStorage;
import com.refinedmods.refinedstorage2.platform.fabric.storage.FabricStorageInsertableStorage;

import java.util.Collections;
import java.util.Iterator;
Expand All @@ -25,8 +25,8 @@
public class StorageImporterSource<T, P> implements ImporterSource<T> {
private final BlockApiCache<Storage<P>, Direction> cache;
private final Function<P, T> fromPlatformMapper;
private final StorageInsertableStorage<T, P> insertTarget;
private final StorageExtractableStorage<T, P> extractTarget;
private final FabricStorageInsertableStorage<T, P> insertTarget;
private final FabricStorageExtractableStorage<T, P> extractTarget;
private final Direction direction;

public StorageImporterSource(final BlockApiLookup<Storage<P>, Direction> lookup,
Expand All @@ -38,15 +38,15 @@ public StorageImporterSource(final BlockApiLookup<Storage<P>, Direction> lookup,
final AmountOverride amountOverride) {
this.cache = BlockApiCache.create(lookup, serverLevel, pos);
this.fromPlatformMapper = fromPlatformMapper;
this.insertTarget = new StorageInsertableStorage<>(
this.insertTarget = new FabricStorageInsertableStorage<>(
lookup,
toPlatformMapper,
serverLevel,
pos,
direction,
AmountOverride.NONE
);
this.extractTarget = new StorageExtractableStorage<>(
this.extractTarget = new FabricStorageExtractableStorage<>(
lookup,
toPlatformMapper,
serverLevel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.refinedmods.refinedstorage2.api.storage.Actor;
import com.refinedmods.refinedstorage2.api.storage.ExtractableStorage;
import com.refinedmods.refinedstorage2.platform.api.exporter.AmountOverride;
import com.refinedmods.refinedstorage2.platform.fabric.util.FabricStorageUtil;

import java.util.function.Function;

Expand All @@ -16,18 +15,18 @@
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;

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

public StorageExtractableStorage(final BlockApiLookup<Storage<P>, Direction> lookup,
final Function<T, P> toPlatformMapper,
final ServerLevel serverLevel,
final BlockPos pos,
final Direction direction,
final AmountOverride amountOverride) {
public FabricStorageExtractableStorage(final BlockApiLookup<Storage<P>, Direction> lookup,
final Function<T, P> toPlatformMapper,
final ServerLevel serverLevel,
final BlockPos pos,
final Direction direction,
final AmountOverride amountOverride) {
this.cache = BlockApiCache.create(lookup, serverLevel, pos);
this.toPlatformMapper = toPlatformMapper;
this.direction = direction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.refinedmods.refinedstorage2.api.storage.Actor;
import com.refinedmods.refinedstorage2.api.storage.InsertableStorage;
import com.refinedmods.refinedstorage2.platform.api.exporter.AmountOverride;
import com.refinedmods.refinedstorage2.platform.fabric.util.FabricStorageUtil;

import java.util.function.Function;

Expand All @@ -16,18 +15,18 @@
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;

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

public StorageInsertableStorage(final BlockApiLookup<Storage<P>, Direction> lookup,
final Function<T, P> toPlatformMapper,
final ServerLevel serverLevel,
final BlockPos pos,
final Direction direction,
final AmountOverride amountOverride) {
public FabricStorageInsertableStorage(final BlockApiLookup<Storage<P>, Direction> lookup,
final Function<T, P> toPlatformMapper,
final ServerLevel serverLevel,
final BlockPos pos,
final Direction direction,
final AmountOverride amountOverride) {
this.cache = BlockApiCache.create(lookup, serverLevel, pos);
this.toPlatformMapper = toPlatformMapper;
this.direction = direction;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.refinedmods.refinedstorage2.platform.fabric.util;
package com.refinedmods.refinedstorage2.platform.fabric.storage;

import net.fabricmc.fabric.api.transfer.v1.storage.Storage;
import net.fabricmc.fabric.api.transfer.v1.storage.StorageView;

public final class FabricStorageUtil {
final class FabricStorageUtil {
private FabricStorageUtil() {
}

public static <T> long getCurrentAmount(final Storage<T> storage, final T resource) {
static <T> long getCurrentAmount(final Storage<T> storage, final T resource) {
long amount = 0;
final Iterable<StorageView<T>> views = storage.nonEmptyViews();
for (final StorageView<T> view : views) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import com.refinedmods.refinedstorage2.api.storage.Actor;
import com.refinedmods.refinedstorage2.api.storage.external.ExternalStorageProvider;
import com.refinedmods.refinedstorage2.platform.api.exporter.AmountOverride;
import com.refinedmods.refinedstorage2.platform.fabric.storage.StorageExtractableStorage;
import com.refinedmods.refinedstorage2.platform.fabric.storage.StorageInsertableStorage;
import com.refinedmods.refinedstorage2.platform.fabric.storage.FabricStorageExtractableStorage;
import com.refinedmods.refinedstorage2.platform.fabric.storage.FabricStorageInsertableStorage;

import java.util.Collections;
import java.util.Iterator;
Expand All @@ -26,8 +26,8 @@
public class StorageExternalStorageProvider<T, P> implements ExternalStorageProvider<T> {
private final BlockApiCache<Storage<P>, Direction> cache;
private final Function<P, T> fromPlatformMapper;
private final StorageExtractableStorage<T, P> extractTarget;
private final StorageInsertableStorage<T, P> insertTarget;
private final FabricStorageExtractableStorage<T, P> extractTarget;
private final FabricStorageInsertableStorage<T, P> insertTarget;
private final Direction direction;

public StorageExternalStorageProvider(final BlockApiLookup<Storage<P>, Direction> lookup,
Expand All @@ -38,15 +38,15 @@ public StorageExternalStorageProvider(final BlockApiLookup<Storage<P>, Direction
final Direction direction) {
this.cache = BlockApiCache.create(lookup, serverLevel, pos);
this.fromPlatformMapper = fromPlatformMapper;
this.extractTarget = new StorageExtractableStorage<>(
this.extractTarget = new FabricStorageExtractableStorage<>(
lookup,
toPlatformMapper,
serverLevel,
pos,
direction,
AmountOverride.NONE
);
this.insertTarget = new StorageInsertableStorage<>(
this.insertTarget = new FabricStorageInsertableStorage<>(
lookup,
toPlatformMapper,
serverLevel,
Expand Down

0 comments on commit d0ccbba

Please sign in to comment.