Skip to content

Commit

Permalink
Merge pull request #626 from refinedmods/refactor/NO-ISSUE/storage-types
Browse files Browse the repository at this point in the history
cleanup duplication around storage types
  • Loading branch information
raoulvdberge authored Jul 17, 2024
2 parents 13c41ea + 8d793d1 commit 30e9191
Show file tree
Hide file tree
Showing 30 changed files with 309 additions and 361 deletions.
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
refinedarchitectVersion=0.16.6
# Gradle
org.gradle.jvmargs=-Xmx1G
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import com.refinedmods.refinedstorage.platform.common.security.FallbackSecurityCardScreen;
import com.refinedmods.refinedstorage.platform.common.security.SecurityCardScreen;
import com.refinedmods.refinedstorage.platform.common.security.SecurityManagerScreen;
import com.refinedmods.refinedstorage.platform.common.storage.FluidStorageType;
import com.refinedmods.refinedstorage.platform.common.storage.ItemStorageType;
import com.refinedmods.refinedstorage.platform.common.storage.FluidStorageVariant;
import com.refinedmods.refinedstorage.platform.common.storage.ItemStorageVariant;
import com.refinedmods.refinedstorage.platform.common.storage.diskdrive.DiskDriveScreen;
import com.refinedmods.refinedstorage.platform.common.storage.diskinterface.DiskInterfaceScreen;
import com.refinedmods.refinedstorage.platform.common.storage.externalstorage.ExternalStorageScreen;
Expand Down Expand Up @@ -113,15 +113,15 @@ protected static void handleInputEvents() {

protected static void registerDiskModels() {
final ResourceLocation diskModel = createIdentifier("block/disk/disk");
for (final ItemStorageType.Variant variant : ItemStorageType.Variant.values()) {
for (final ItemStorageVariant variant : ItemStorageVariant.values()) {
PlatformApi.INSTANCE.getStorageContainerItemHelper().registerDiskModel(
Items.INSTANCE.getItemStorageDisk(variant),
diskModel
);
}

final ResourceLocation fluidDiskModel = createIdentifier("block/disk/fluid_disk");
for (final FluidStorageType.Variant variant : FluidStorageType.Variant.values()) {
for (final FluidStorageVariant variant : FluidStorageVariant.values()) {
PlatformApi.INSTANCE.getStorageContainerItemHelper().registerDiskModel(
Items.INSTANCE.getFluidStorageDisk(variant),
fluidDiskModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
import com.refinedmods.refinedstorage.platform.common.security.SecurityCardPermissions;
import com.refinedmods.refinedstorage.platform.common.security.SecurityManagerBlockEntity;
import com.refinedmods.refinedstorage.platform.common.security.SecurityManagerContainerMenu;
import com.refinedmods.refinedstorage.platform.common.storage.FluidStorageType;
import com.refinedmods.refinedstorage.platform.common.storage.ItemStorageType;
import com.refinedmods.refinedstorage.platform.common.storage.FluidStorageVariant;
import com.refinedmods.refinedstorage.platform.common.storage.ItemStorageVariant;
import com.refinedmods.refinedstorage.platform.common.storage.StorageTypes;
import com.refinedmods.refinedstorage.platform.common.storage.diskdrive.AbstractDiskDriveBlockEntity;
import com.refinedmods.refinedstorage.platform.common.storage.diskdrive.DiskDriveBlock;
Expand Down Expand Up @@ -336,13 +336,13 @@ protected final void registerBlocks(
callback.register(DISK_DRIVE, () -> new DiskDriveBlock(diskDriveBlockEntityFactory))
);
Blocks.INSTANCE.setMachineCasing(callback.register(MACHINE_CASING, SimpleBlock::new));
for (final ItemStorageType.Variant variant : ItemStorageType.Variant.values()) {
for (final ItemStorageVariant variant : ItemStorageVariant.values()) {
Blocks.INSTANCE.setItemStorageBlock(variant, callback.register(
forItemStorageBlock(variant),
() -> new ItemStorageBlock(variant)
));
}
for (final FluidStorageType.Variant variant : FluidStorageType.Variant.values()) {
for (final FluidStorageVariant variant : FluidStorageVariant.values()) {
Blocks.INSTANCE.setFluidStorageBlock(variant, callback.register(
forFluidStorageBlock(variant),
() -> new FluidStorageBlock(variant)
Expand Down Expand Up @@ -436,17 +436,17 @@ private void registerProcessor(final RegistryCallback<Item> callback, final Proc
}

private void registerStorageItems(final RegistryCallback<Item> callback) {
for (final ItemStorageType.Variant variant : ItemStorageType.Variant.values()) {
for (final ItemStorageVariant variant : ItemStorageVariant.values()) {
registerItemStorageItems(callback, variant);
}
for (final FluidStorageType.Variant variant : FluidStorageType.Variant.values()) {
for (final FluidStorageVariant variant : FluidStorageVariant.values()) {
registerFluidStorageItems(callback, variant);
}
}

private void registerItemStorageItems(final RegistryCallback<Item> callback,
final ItemStorageType.Variant variant) {
if (variant != ItemStorageType.Variant.CREATIVE) {
final ItemStorageVariant variant) {
if (variant != ItemStorageVariant.CREATIVE) {
Items.INSTANCE.setItemStoragePart(variant, callback.register(
forItemStoragePart(variant),
SimpleItem::new)
Expand All @@ -463,8 +463,8 @@ private void registerItemStorageItems(final RegistryCallback<Item> callback,
}

private void registerFluidStorageItems(final RegistryCallback<Item> callback,
final FluidStorageType.Variant variant) {
if (variant != FluidStorageType.Variant.CREATIVE) {
final FluidStorageVariant variant) {
if (variant != FluidStorageVariant.CREATIVE) {
Items.INSTANCE.setFluidStoragePart(variant, callback.register(
forFluidStoragePart(variant),
SimpleItem::new)
Expand Down Expand Up @@ -602,7 +602,7 @@ protected final void registerBlockEntities(
CRAFTING_GRID,
() -> typeFactory.create(CraftingGridBlockEntity::new, Blocks.INSTANCE.getCraftingGrid().toArray())
));
for (final ItemStorageType.Variant variant : ItemStorageType.Variant.values()) {
for (final ItemStorageVariant variant : ItemStorageVariant.values()) {
BlockEntities.INSTANCE.setItemStorageBlock(variant, callback.register(
forItemStorageBlock(variant),
() -> typeFactory.create(
Expand All @@ -611,7 +611,7 @@ protected final void registerBlockEntities(
)
));
}
for (final FluidStorageType.Variant variant : FluidStorageType.Variant.values()) {
for (final FluidStorageVariant variant : FluidStorageVariant.values()) {
BlockEntities.INSTANCE.setFluidStorageBlock(variant, callback.register(
forFluidStorageBlock(variant),
() -> typeFactory.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import com.refinedmods.refinedstorage.platform.common.networking.NetworkTransmitterBlockEntity;
import com.refinedmods.refinedstorage.platform.common.networking.RelayBlockEntity;
import com.refinedmods.refinedstorage.platform.common.security.SecurityManagerBlockEntity;
import com.refinedmods.refinedstorage.platform.common.storage.FluidStorageType;
import com.refinedmods.refinedstorage.platform.common.storage.ItemStorageType;
import com.refinedmods.refinedstorage.platform.common.storage.FluidStorageVariant;
import com.refinedmods.refinedstorage.platform.common.storage.ItemStorageVariant;
import com.refinedmods.refinedstorage.platform.common.storage.diskdrive.AbstractDiskDriveBlockEntity;
import com.refinedmods.refinedstorage.platform.common.storage.diskinterface.AbstractDiskInterfaceBlockEntity;
import com.refinedmods.refinedstorage.platform.common.storage.externalstorage.ExternalStorageBlockEntity;
Expand Down Expand Up @@ -50,10 +50,10 @@ public final class BlockEntities {
private Supplier<BlockEntityType<ControllerBlockEntity>> controller;
@Nullable
private Supplier<BlockEntityType<ControllerBlockEntity>> creativeController;
private final Map<ItemStorageType.Variant, Supplier<BlockEntityType<ItemStorageBlockBlockEntity>>>
itemStorageBlocks = new EnumMap<>(ItemStorageType.Variant.class);
private final Map<FluidStorageType.Variant, Supplier<BlockEntityType<FluidStorageBlockBlockEntity>>>
fluidStorageBlocks = new EnumMap<>(FluidStorageType.Variant.class);
private final Map<ItemStorageVariant, Supplier<BlockEntityType<ItemStorageBlockBlockEntity>>>
itemStorageBlocks = new EnumMap<>(ItemStorageVariant.class);
private final Map<FluidStorageVariant, Supplier<BlockEntityType<FluidStorageBlockBlockEntity>>>
fluidStorageBlocks = new EnumMap<>(FluidStorageVariant.class);
@Nullable
private Supplier<BlockEntityType<ImporterBlockEntity>> importer;
@Nullable
Expand Down Expand Up @@ -140,21 +140,21 @@ public void setCreativeController(final Supplier<BlockEntityType<ControllerBlock
this.creativeController = supplier;
}

public void setItemStorageBlock(final ItemStorageType.Variant variant,
public void setItemStorageBlock(final ItemStorageVariant variant,
final Supplier<BlockEntityType<ItemStorageBlockBlockEntity>> supplier) {
itemStorageBlocks.put(variant, supplier);
}

public BlockEntityType<ItemStorageBlockBlockEntity> getItemStorageBlock(final ItemStorageType.Variant variant) {
public BlockEntityType<ItemStorageBlockBlockEntity> getItemStorageBlock(final ItemStorageVariant variant) {
return itemStorageBlocks.get(variant).get();
}

public void setFluidStorageBlock(final FluidStorageType.Variant variant,
public void setFluidStorageBlock(final FluidStorageVariant variant,
final Supplier<BlockEntityType<FluidStorageBlockBlockEntity>> supplier) {
fluidStorageBlocks.put(variant, supplier);
}

public BlockEntityType<FluidStorageBlockBlockEntity> getFluidStorageBlock(final FluidStorageType.Variant variant) {
public BlockEntityType<FluidStorageBlockBlockEntity> getFluidStorageBlock(final FluidStorageVariant variant) {
return fluidStorageBlocks.get(variant).get();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import com.refinedmods.refinedstorage.platform.common.networking.NetworkTransmitterBlock;
import com.refinedmods.refinedstorage.platform.common.networking.RelayBlock;
import com.refinedmods.refinedstorage.platform.common.security.SecurityManagerBlock;
import com.refinedmods.refinedstorage.platform.common.storage.FluidStorageType;
import com.refinedmods.refinedstorage.platform.common.storage.ItemStorageType;
import com.refinedmods.refinedstorage.platform.common.storage.FluidStorageVariant;
import com.refinedmods.refinedstorage.platform.common.storage.ItemStorageVariant;
import com.refinedmods.refinedstorage.platform.common.storage.diskdrive.DiskDriveBlock;
import com.refinedmods.refinedstorage.platform.common.storage.diskinterface.AbstractDiskInterfaceBlockEntity;
import com.refinedmods.refinedstorage.platform.common.storage.diskinterface.DiskInterfaceBlock;
Expand Down Expand Up @@ -167,10 +167,10 @@ public final class Blocks {
private Supplier<DiskDriveBlock> diskDrive;
@Nullable
private Supplier<SimpleBlock> machineCasing;
private final Map<ItemStorageType.Variant, Supplier<ItemStorageBlock>> itemStorageBlocks =
new EnumMap<>(ItemStorageType.Variant.class);
private final Map<FluidStorageType.Variant, Supplier<FluidStorageBlock>> fluidStorageBlocks =
new EnumMap<>(FluidStorageType.Variant.class);
private final Map<ItemStorageVariant, Supplier<ItemStorageBlock>> itemStorageBlocks =
new EnumMap<>(ItemStorageVariant.class);
private final Map<FluidStorageVariant, Supplier<FluidStorageBlock>> fluidStorageBlocks =
new EnumMap<>(FluidStorageVariant.class);
@Nullable
private Supplier<InterfaceBlock> iface;
@Nullable
Expand Down Expand Up @@ -237,20 +237,20 @@ public void setMachineCasing(final Supplier<SimpleBlock> machineCasingSupplier)
this.machineCasing = machineCasingSupplier;
}

public void setItemStorageBlock(final ItemStorageType.Variant variant, final Supplier<ItemStorageBlock> supplier) {
public void setItemStorageBlock(final ItemStorageVariant variant, final Supplier<ItemStorageBlock> supplier) {
itemStorageBlocks.put(variant, supplier);
}

public ItemStorageBlock getItemStorageBlock(final ItemStorageType.Variant variant) {
public ItemStorageBlock getItemStorageBlock(final ItemStorageVariant variant) {
return itemStorageBlocks.get(variant).get();
}

public void setFluidStorageBlock(final FluidStorageType.Variant variant,
public void setFluidStorageBlock(final FluidStorageVariant variant,
final Supplier<FluidStorageBlock> supplier) {
fluidStorageBlocks.put(variant, supplier);
}

public FluidStorageBlock getFluidStorageBlock(final FluidStorageType.Variant variant) {
public FluidStorageBlock getFluidStorageBlock(final FluidStorageVariant variant) {
return fluidStorageBlocks.get(variant).get();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.refinedmods.refinedstorage.platform.common.content;

import com.refinedmods.refinedstorage.platform.common.misc.ProcessorItem;
import com.refinedmods.refinedstorage.platform.common.storage.FluidStorageType;
import com.refinedmods.refinedstorage.platform.common.storage.ItemStorageType;
import com.refinedmods.refinedstorage.platform.common.storage.FluidStorageVariant;
import com.refinedmods.refinedstorage.platform.common.storage.ItemStorageVariant;

import net.minecraft.resources.ResourceLocation;

Expand Down Expand Up @@ -67,31 +67,31 @@ public final class ContentIds {
private ContentIds() {
}

public static ResourceLocation forItemStoragePart(final ItemStorageType.Variant variant) {
public static ResourceLocation forItemStoragePart(final ItemStorageVariant variant) {
return createIdentifier(variant.getName() + "_storage_part");
}

public static ResourceLocation forItemStorageBlock(final ItemStorageType.Variant variant) {
public static ResourceLocation forItemStorageBlock(final ItemStorageVariant variant) {
return createIdentifier(variant.getName() + "_storage_block");
}

public static ResourceLocation forFluidStoragePart(final FluidStorageType.Variant variant) {
public static ResourceLocation forFluidStoragePart(final FluidStorageVariant variant) {
return createIdentifier(variant.getName() + "_fluid_storage_part");
}

public static ResourceLocation forFluidStorageBlock(final FluidStorageType.Variant variant) {
public static ResourceLocation forFluidStorageBlock(final FluidStorageVariant variant) {
return createIdentifier(variant.getName() + "_fluid_storage_block");
}

public static ResourceLocation forProcessor(final ProcessorItem.Type type) {
return createIdentifier(type.getName() + "_processor");
}

public static ResourceLocation forStorageDisk(final ItemStorageType.Variant variant) {
public static ResourceLocation forStorageDisk(final ItemStorageVariant variant) {
return createIdentifier(variant.getName() + "_storage_disk");
}

public static ResourceLocation forFluidStorageDisk(final FluidStorageType.Variant variant) {
public static ResourceLocation forFluidStorageDisk(final FluidStorageVariant variant) {
return createIdentifier(variant.getName() + "_fluid_storage_disk");
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.refinedmods.refinedstorage.platform.common.content;

import com.refinedmods.refinedstorage.platform.common.misc.ProcessorItem;
import com.refinedmods.refinedstorage.platform.common.storage.FluidStorageType;
import com.refinedmods.refinedstorage.platform.common.storage.ItemStorageType;
import com.refinedmods.refinedstorage.platform.common.storage.FluidStorageVariant;
import com.refinedmods.refinedstorage.platform.common.storage.ItemStorageVariant;

import java.util.Arrays;
import java.util.function.Consumer;
Expand Down Expand Up @@ -42,10 +42,10 @@ private static void appendBlocks(final Consumer<ItemStack> consumer) {
itemConsumer.accept(Items.INSTANCE.getCreativePortableGrid());
Items.INSTANCE.getDetectors().stream().map(Supplier::get).forEach(itemConsumer);
itemConsumer.accept(Blocks.INSTANCE.getInterface());
Arrays.stream(ItemStorageType.Variant.values()).forEach(variant -> itemConsumer.accept(
Arrays.stream(ItemStorageVariant.values()).forEach(variant -> itemConsumer.accept(
Blocks.INSTANCE.getItemStorageBlock(variant)
));
Arrays.stream(FluidStorageType.Variant.values()).forEach(variant -> itemConsumer.accept(
Arrays.stream(FluidStorageVariant.values()).forEach(variant -> itemConsumer.accept(
Blocks.INSTANCE.getFluidStorageBlock(variant)
));
itemConsumer.accept(Blocks.INSTANCE.getMachineCasing());
Expand Down Expand Up @@ -76,19 +76,19 @@ private static void appendItems(final Consumer<ItemStack> consumer) {
itemConsumer.accept(Items.INSTANCE.getConstructionCore());
itemConsumer.accept(Items.INSTANCE.getDestructionCore());

Arrays.stream(ItemStorageType.Variant.values())
.filter(variant -> variant != ItemStorageType.Variant.CREATIVE)
Arrays.stream(ItemStorageVariant.values())
.filter(variant -> variant != ItemStorageVariant.CREATIVE)
.map(Items.INSTANCE::getItemStoragePart)
.forEach(itemConsumer);
Arrays.stream(FluidStorageType.Variant.values())
.filter(variant -> variant != FluidStorageType.Variant.CREATIVE)
Arrays.stream(FluidStorageVariant.values())
.filter(variant -> variant != FluidStorageVariant.CREATIVE)
.map(Items.INSTANCE::getFluidStoragePart)
.forEach(itemConsumer);

Arrays.stream(ItemStorageType.Variant.values()).forEach(variant -> itemConsumer.accept(
Arrays.stream(ItemStorageVariant.values()).forEach(variant -> itemConsumer.accept(
Items.INSTANCE.getItemStorageDisk(variant)
));
Arrays.stream(FluidStorageType.Variant.values()).forEach(variant -> itemConsumer.accept(
Arrays.stream(FluidStorageVariant.values()).forEach(variant -> itemConsumer.accept(
Items.INSTANCE.getFluidStorageDisk(variant)
));
itemConsumer.accept(Items.INSTANCE.getStorageHousing());
Expand Down
Loading

0 comments on commit 30e9191

Please sign in to comment.