From 7602449a9c9654f66d7614c908ec4091d8d85e7c Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Sun, 3 Sep 2023 10:30:13 +0200 Subject: [PATCH] feat: storage monitor --- CHANGELOG.md | 1 + .../platform/api/PlatformApi.java | 10 + .../platform/api/PlatformApiProxy.java | 704 +++++++------ .../StorageMonitorExtractionStrategy.java | 13 + .../StorageMonitorInsertionStrategy.java | 15 + .../storagemonitor/package-info.java | 7 + .../api/resource/ResourceRendering.java | 7 +- .../common/AbstractClientModInitializer.java | 2 + .../common/AbstractModInitializer.java | 35 +- .../platform/common/Config.java | 2 + .../platform/common/ContainedFluid.java | 9 + .../platform/common/Platform.java | 3 +- .../platform/common/PlatformApiImpl.java | 992 +++++++++--------- .../platform/common/PlatformProxy.java | 5 +- .../common/block/StorageMonitorBlock.java | 101 ++ .../block/entity/ControllerBlockEntity.java | 8 +- .../block/entity/ImporterBlockEntity.java | 5 +- .../constructor/ConstructorBlockEntity.java | 5 +- .../destructor/DestructorBlockEntity.java | 5 +- .../entity/detector/DetectorBlockEntity.java | 5 +- .../AbstractDiskDriveBlockEntity.java | 12 +- .../entity/exporter/ExporterBlockEntity.java | 5 +- .../ExternalStorageBlockEntity.java | 5 +- .../entity/grid/CraftingGridBlockEntity.java | 5 +- .../block/entity/grid/GridBlockEntity.java | 5 +- .../entity/iface/InterfaceBlockEntity.java | 5 +- ...ositeStorageMonitorExtractionStrategy.java | 32 + ...positeStorageMonitorInsertionStrategy.java | 31 + ...FluidStorageMonitorExtractionStrategy.java | 42 + .../FluidStorageMonitorInsertionStrategy.java | 69 ++ .../entity/storagemonitor/InsertTracker.java | 37 + .../ItemStorageMonitorExtractionStrategy.java | 36 + .../ItemStorageMonitorInsertionStrategy.java | 37 + .../StorageMonitorBlockEntity.java | 317 ++++++ .../entity/storagemonitor/package-info.java | 7 + .../StorageMonitorContainerMenu.java | 54 + .../common/content/BlockEntities.java | 11 + .../platform/common/content/Blocks.java | 11 + .../platform/common/content/ContentIds.java | 1 + .../platform/common/content/ContentNames.java | 4 + .../common/content/CreativeModeTabItems.java | 1 + .../common/content/DefaultEnergyUsage.java | 2 + .../platform/common/content/Menus.java | 11 + .../resource/FluidResourceFactory.java | 4 +- .../resource/FluidResourceRendering.java | 17 +- .../resource/ItemResourceRendering.java | 34 +- .../resource/ResourceContainerImpl.java | 1 + ...ucketPlayerInventoryInsertableStorage.java | 89 ++ .../common/item/RegulatorUpgradeItem.java | 3 +- .../platform/common/render/FluidRenderer.java | 3 + .../StorageMonitorBlockEntityRenderer.java | 137 +++ .../render/model/AbstractFluidRenderer.java | 47 + .../common/screen/AbstractBaseScreen.java | 2 +- .../common/screen/StorageMonitorScreen.java | 41 + .../common/screen/amount/DetectorScreen.java | 2 +- .../grid/hint/FluidGridInsertionHint.java | 15 +- .../ResourceClientTooltipComponent.java | 2 +- .../widget/FuzzyModeSideButtonWidget.java | 2 +- .../platform/common/util/BiDirection.java | 32 +- .../blockstates/storage_monitor.json | 57 + .../assets/refinedstorage2/lang/en_us.json | 11 +- .../refinedstorage2/models/block/disk.json | 2 +- .../models/block/disk_drive_base.json | 10 +- .../models/block/disk_inactive.json | 2 +- .../models/block/interface_active.json | 2 +- .../models/block/interface_inactive.json | 2 +- .../models/block/storage_monitor.json | 12 + .../models/item/storage_monitor.json | 3 + .../bottom.png} | Bin .../textures/block/{ => disk_drive}/disk.png | Bin .../{disk_drive.png => disk_drive/front.png} | Bin .../side.png} | Bin .../top.png} | Bin .../active.png} | Bin .../inactive.png} | Bin .../refinedstorage2/textures/block/side.png | Bin 0 -> 15349 bytes .../textures/block/storage_monitor/back.png | Bin 0 -> 1415 bytes .../textures/block/storage_monitor/front.png | Bin 0 -> 1273 bytes .../textures/block/storage_monitor/left.png | Bin 0 -> 1451 bytes .../textures/block/storage_monitor/right.png | Bin 0 -> 1443 bytes .../textures/block/storage_monitor/top.png | Bin 0 -> 1391 bytes .../textures/gui/storage_monitor.png | Bin 0 -> 1816 bytes .../advancements/better_than_a_barrel.json | 28 + .../loot_tables/blocks/storage_monitor.json | 19 + .../recipes/storage_monitor.json | 31 + .../fabric/ClientModInitializerImpl.java | 5 + .../platform/fabric/ConfigImpl.java | 10 + .../platform/fabric/PlatformImpl.java | 36 +- .../grid/FluidGridExtractionStrategy.java | 8 +- .../render/FluidVariantFluidRenderer.java | 22 +- ...orage.java => SingleStackStorageImpl.java} | 12 +- .../platform/forge/ClientModInitializer.java | 5 + .../platform/forge/ConfigImpl.java | 11 + .../platform/forge/PlatformImpl.java | 26 +- .../forge/render/FluidStackFluidRenderer.java | 17 + .../refinedstorage2/textures/slot/curios.png | Bin 261 -> 257 bytes 96 files changed, 2492 insertions(+), 944 deletions(-) create mode 100644 refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/blockentity/storagemonitor/StorageMonitorExtractionStrategy.java create mode 100644 refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/blockentity/storagemonitor/StorageMonitorInsertionStrategy.java create mode 100644 refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/blockentity/storagemonitor/package-info.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/ContainedFluid.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/StorageMonitorBlock.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/CompositeStorageMonitorExtractionStrategy.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/CompositeStorageMonitorInsertionStrategy.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/FluidStorageMonitorExtractionStrategy.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/FluidStorageMonitorInsertionStrategy.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/InsertTracker.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/ItemStorageMonitorExtractionStrategy.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/ItemStorageMonitorInsertionStrategy.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/StorageMonitorBlockEntity.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/package-info.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/StorageMonitorContainerMenu.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/storage/BucketPlayerInventoryInsertableStorage.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/render/entity/StorageMonitorBlockEntityRenderer.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/StorageMonitorScreen.java create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/blockstates/storage_monitor.json create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/storage_monitor.json create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/storage_monitor.json rename refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/{disk_drive_bottom.png => disk_drive/bottom.png} (100%) rename refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/{ => disk_drive}/disk.png (100%) rename refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/{disk_drive.png => disk_drive/front.png} (100%) rename refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/{disk_drive_side.png => disk_drive/side.png} (100%) rename refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/{disk_drive_top.png => disk_drive/top.png} (100%) rename refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/{interface_active.png => interface/active.png} (100%) rename refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/{interface_inactive.png => interface/inactive.png} (100%) create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/side.png create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/storage_monitor/back.png create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/storage_monitor/front.png create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/storage_monitor/left.png create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/storage_monitor/right.png create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/storage_monitor/top.png create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/gui/storage_monitor.png create mode 100644 refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/advancements/better_than_a_barrel.json create mode 100644 refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/loot_tables/blocks/storage_monitor.json create mode 100644 refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/storage_monitor.json rename refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/util/{BucketSingleStackStorage.java => SingleStackStorageImpl.java} (54%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a05cfdcd..584a35d3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - "Open Wireless Grid" keybinding. - Curios integration on Forge. - Trinkets integration on Fabric. +- Storage Monitor ### Changed diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApi.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApi.java index 1356e971f..5387f40f7 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApi.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApi.java @@ -7,6 +7,8 @@ import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer; import com.refinedmods.refinedstorage2.platform.api.blockentity.constructor.ConstructorStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.blockentity.destructor.DestructorStrategyFactory; +import com.refinedmods.refinedstorage2.platform.api.blockentity.storagemonitor.StorageMonitorExtractionStrategy; +import com.refinedmods.refinedstorage2.platform.api.blockentity.storagemonitor.StorageMonitorInsertionStrategy; import com.refinedmods.refinedstorage2.platform.api.blockentity.wirelesstransmitter.WirelessTransmitterRangeModifier; import com.refinedmods.refinedstorage2.platform.api.grid.Grid; import com.refinedmods.refinedstorage2.platform.api.grid.GridExtractionStrategy; @@ -81,6 +83,14 @@ public interface PlatformApi { void addConstructorStrategyFactory(ConstructorStrategyFactory factory); + void addStorageMonitorExtractionStrategy(StorageMonitorExtractionStrategy strategy); + + StorageMonitorExtractionStrategy getStorageMonitorExtractionStrategy(); + + void addStorageMonitorInsertionStrategy(StorageMonitorInsertionStrategy strategy); + + StorageMonitorInsertionStrategy getStorageMonitorInsertionStrategy(); + MutableComponent createTranslation(String category, String value, Object... args); ComponentMapFactory getNetworkComponentMapFactory(); diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApiProxy.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApiProxy.java index b142df2cc..b4f895589 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApiProxy.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApiProxy.java @@ -1,341 +1,363 @@ -package com.refinedmods.refinedstorage2.platform.api; - -import com.refinedmods.refinedstorage2.api.core.component.ComponentMapFactory; -import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.component.NetworkComponent; -import com.refinedmods.refinedstorage2.api.network.energy.EnergyStorage; -import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer; -import com.refinedmods.refinedstorage2.platform.api.blockentity.constructor.ConstructorStrategyFactory; -import com.refinedmods.refinedstorage2.platform.api.blockentity.destructor.DestructorStrategyFactory; -import com.refinedmods.refinedstorage2.platform.api.blockentity.wirelesstransmitter.WirelessTransmitterRangeModifier; -import com.refinedmods.refinedstorage2.platform.api.grid.Grid; -import com.refinedmods.refinedstorage2.platform.api.grid.GridExtractionStrategy; -import com.refinedmods.refinedstorage2.platform.api.grid.GridExtractionStrategyFactory; -import com.refinedmods.refinedstorage2.platform.api.grid.GridInsertionHint; -import com.refinedmods.refinedstorage2.platform.api.grid.GridInsertionHints; -import com.refinedmods.refinedstorage2.platform.api.grid.GridInsertionStrategy; -import com.refinedmods.refinedstorage2.platform.api.grid.GridInsertionStrategyFactory; -import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollingStrategy; -import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollingStrategyFactory; -import com.refinedmods.refinedstorage2.platform.api.grid.GridSynchronizer; -import com.refinedmods.refinedstorage2.platform.api.integration.recipemod.IngredientConverter; -import com.refinedmods.refinedstorage2.platform.api.item.EnergyItemHelper; -import com.refinedmods.refinedstorage2.platform.api.item.NetworkBoundItemHelper; -import com.refinedmods.refinedstorage2.platform.api.item.SlotReference; -import com.refinedmods.refinedstorage2.platform.api.item.SlotReferenceFactory; -import com.refinedmods.refinedstorage2.platform.api.item.SlotReferenceProvider; -import com.refinedmods.refinedstorage2.platform.api.item.StorageContainerItemHelper; -import com.refinedmods.refinedstorage2.platform.api.network.node.exporter.ExporterTransferStrategyFactory; -import com.refinedmods.refinedstorage2.platform.api.network.node.externalstorage.PlatformExternalStorageProviderFactory; -import com.refinedmods.refinedstorage2.platform.api.network.node.importer.ImporterTransferStrategyFactory; -import com.refinedmods.refinedstorage2.platform.api.registry.PlatformRegistry; -import com.refinedmods.refinedstorage2.platform.api.resource.FluidResource; -import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.api.resource.ResourceFactory; -import com.refinedmods.refinedstorage2.platform.api.resource.ResourceRendering; -import com.refinedmods.refinedstorage2.platform.api.storage.StorageRepository; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; -import com.refinedmods.refinedstorage2.platform.api.storage.type.StorageType; -import com.refinedmods.refinedstorage2.platform.api.upgrade.BuiltinUpgradeDestinations; -import com.refinedmods.refinedstorage2.platform.api.upgrade.UpgradeRegistry; - -import java.util.Collection; -import java.util.Optional; -import java.util.Set; -import javax.annotation.Nullable; - -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.chat.MutableComponent; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; - -public class PlatformApiProxy implements PlatformApi { - @Nullable - private PlatformApi delegate; - - public void setDelegate(final PlatformApi delegate) { - if (this.delegate != null) { - throw new IllegalStateException("Platform API already injected"); - } - this.delegate = delegate; - } - - @Override - public PlatformRegistry> getStorageTypeRegistry() { - return ensureLoaded().getStorageTypeRegistry(); - } - - @Override - public StorageRepository getStorageRepository(final Level level) { - return ensureLoaded().getStorageRepository(level); - } - - @Override - public StorageContainerItemHelper getStorageContainerItemHelper() { - return ensureLoaded().getStorageContainerItemHelper(); - } - - @Override - public PlatformRegistry> getStorageChannelTypeRegistry() { - return ensureLoaded().getStorageChannelTypeRegistry(); - } - - @Override - public PlatformRegistry getImporterTransferStrategyRegistry() { - return ensureLoaded().getImporterTransferStrategyRegistry(); - } - - @Override - public PlatformRegistry getExporterTransferStrategyRegistry() { - return ensureLoaded().getExporterTransferStrategyRegistry(); - } - - @Override - public void addExternalStorageProviderFactory(final PlatformExternalStorageProviderFactory factory) { - ensureLoaded().addExternalStorageProviderFactory(factory); - } - - @Override - public Collection getExternalStorageProviderFactories() { - return ensureLoaded().getExternalStorageProviderFactories(); - } - - @Override - public Collection getDestructorStrategyFactories() { - return ensureLoaded().getDestructorStrategyFactories(); - } - - @Override - public void addDestructorStrategyFactory(final DestructorStrategyFactory factory) { - ensureLoaded().addDestructorStrategyFactory(factory); - } - - @Override - public Collection getConstructorStrategyFactories() { - return ensureLoaded().getConstructorStrategyFactories(); - } - - @Override - public void addConstructorStrategyFactory(final ConstructorStrategyFactory factory) { - ensureLoaded().addConstructorStrategyFactory(factory); - } - - @Override - public MutableComponent createTranslation(final String category, final String value, final Object... args) { - return ensureLoaded().createTranslation(category, value, args); - } - - @Override - public ComponentMapFactory getNetworkComponentMapFactory() { - return ensureLoaded().getNetworkComponentMapFactory(); - } - - @Override - public PlatformRegistry getGridSynchronizerRegistry() { - return ensureLoaded().getGridSynchronizerRegistry(); - } - - @Override - public UpgradeRegistry getUpgradeRegistry() { - return ensureLoaded().getUpgradeRegistry(); - } - - @Override - public BuiltinUpgradeDestinations getBuiltinUpgradeDestinations() { - return ensureLoaded().getBuiltinUpgradeDestinations(); - } - - @Override - public void requestNetworkNodeInitialization(final NetworkNodeContainer container, - final Level level, - final Runnable callback) { - ensureLoaded().requestNetworkNodeInitialization(container, level, callback); - } - - @Override - public void requestNetworkNodeRemoval(final NetworkNodeContainer container, final Level level) { - ensureLoaded().requestNetworkNodeRemoval(container, level); - } - - @Override - public void requestNetworkNodeUpdate(final NetworkNodeContainer container, final Level level) { - ensureLoaded().requestNetworkNodeUpdate(container, level); - } - - @Override - public GridInsertionStrategy createGridInsertionStrategy(final AbstractContainerMenu containerMenu, - final Player player, - final Grid grid) { - return ensureLoaded().createGridInsertionStrategy(containerMenu, player, grid); - } - - @Override - public void addGridInsertionStrategyFactory(final GridInsertionStrategyFactory insertionStrategyFactory) { - ensureLoaded().addGridInsertionStrategyFactory(insertionStrategyFactory); - } - - @Override - public void addAlternativeGridInsertionHint(final GridInsertionHint hint) { - ensureLoaded().addAlternativeGridInsertionHint(hint); - } - - @Override - public GridInsertionHints getGridInsertionHints() { - return ensureLoaded().getGridInsertionHints(); - } - - @Override - public GridExtractionStrategy createGridExtractionStrategy(final AbstractContainerMenu containerMenu, - final Player player, - final Grid grid) { - return ensureLoaded().createGridExtractionStrategy(containerMenu, player, grid); - } - - @Override - public void addGridExtractionStrategyFactory(final GridExtractionStrategyFactory extractionStrategyFactory) { - ensureLoaded().addGridExtractionStrategyFactory(extractionStrategyFactory); - } - - @Override - public GridScrollingStrategy createGridScrollingStrategy(final AbstractContainerMenu containerMenu, - final Player player, - final Grid grid) { - return ensureLoaded().createGridScrollingStrategy(containerMenu, player, grid); - } - - @Override - public void addGridScrollingStrategyFactory(final GridScrollingStrategyFactory scrollingStrategyFactory) { - ensureLoaded().addGridScrollingStrategyFactory(scrollingStrategyFactory); - } - - @Override - public void addResourceFactory(final ResourceFactory factory) { - ensureLoaded().addResourceFactory(factory); - } - - @Override - public ResourceFactory getItemResourceFactory() { - return ensureLoaded().getItemResourceFactory(); - } - - @Override - public PlatformStorageChannelType getItemStorageChannelType() { - return ensureLoaded().getItemStorageChannelType(); - } - - @Override - public StorageType getItemStorageType() { - return ensureLoaded().getItemStorageType(); - } - - @Override - public ResourceFactory getFluidResourceFactory() { - return ensureLoaded().getFluidResourceFactory(); - } - - @Override - public PlatformStorageChannelType getFluidStorageChannelType() { - return ensureLoaded().getFluidStorageChannelType(); - } - - @Override - public StorageType getFluidStorageType() { - return ensureLoaded().getFluidStorageType(); - } - - @Override - public Set> getAlternativeResourceFactories() { - return ensureLoaded().getAlternativeResourceFactories(); - } - - @Override - public void registerResourceRendering(final Class resourceClass, final ResourceRendering rendering) { - ensureLoaded().registerResourceRendering(resourceClass, rendering); - } - - @Override - public ResourceRendering getResourceRendering(final T resource) { - return ensureLoaded().getResourceRendering(resource); - } - - @Override - public void registerIngredientConverter(final IngredientConverter converter) { - ensureLoaded().registerIngredientConverter(converter); - } - - @Override - public IngredientConverter getIngredientConverter() { - return ensureLoaded().getIngredientConverter(); - } - - @Override - public void addWirelessTransmitterRangeModifier(final WirelessTransmitterRangeModifier rangeModifier) { - ensureLoaded().addWirelessTransmitterRangeModifier(rangeModifier); - } - - @Override - public WirelessTransmitterRangeModifier getWirelessTransmitterRangeModifier() { - return ensureLoaded().getWirelessTransmitterRangeModifier(); - } - - @Override - public Optional getEnergyStorage(final ItemStack stack) { - return ensureLoaded().getEnergyStorage(stack); - } - - @Override - public EnergyItemHelper getEnergyItemHelper() { - return ensureLoaded().getEnergyItemHelper(); - } - - @Override - public EnergyStorage asItemEnergyStorage(final EnergyStorage energyStorage, final ItemStack stack) { - return ensureLoaded().asItemEnergyStorage(energyStorage, stack); - } - - @Override - public NetworkBoundItemHelper getNetworkBoundItemHelper() { - return ensureLoaded().getNetworkBoundItemHelper(); - } - - @Override - public PlatformRegistry getSlotReferenceFactoryRegistry() { - return ensureLoaded().getSlotReferenceFactoryRegistry(); - } - - @Override - public void writeSlotReference(final SlotReference slotReference, final FriendlyByteBuf buf) { - ensureLoaded().writeSlotReference(slotReference, buf); - } - - @Override - public Optional getSlotReference(final FriendlyByteBuf buf) { - return ensureLoaded().getSlotReference(buf); - } - - @Override - public void addSlotReferenceProvider(final SlotReferenceProvider slotReferenceProvider) { - ensureLoaded().addSlotReferenceProvider(slotReferenceProvider); - } - - @Override - public SlotReference createInventorySlotReference(final Player player, final InteractionHand hand) { - return ensureLoaded().createInventorySlotReference(player, hand); - } - - @Override - public void useNetworkBoundItem(final Player player, final Item... items) { - ensureLoaded().useNetworkBoundItem(player, items); - } - - private PlatformApi ensureLoaded() { - if (delegate == null) { - throw new IllegalStateException("Platform API not loaded yet"); - } - return delegate; - } -} +package com.refinedmods.refinedstorage2.platform.api; + +import com.refinedmods.refinedstorage2.api.core.component.ComponentMapFactory; +import com.refinedmods.refinedstorage2.api.network.Network; +import com.refinedmods.refinedstorage2.api.network.component.NetworkComponent; +import com.refinedmods.refinedstorage2.api.network.energy.EnergyStorage; +import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer; +import com.refinedmods.refinedstorage2.platform.api.blockentity.constructor.ConstructorStrategyFactory; +import com.refinedmods.refinedstorage2.platform.api.blockentity.destructor.DestructorStrategyFactory; +import com.refinedmods.refinedstorage2.platform.api.blockentity.storagemonitor.StorageMonitorExtractionStrategy; +import com.refinedmods.refinedstorage2.platform.api.blockentity.storagemonitor.StorageMonitorInsertionStrategy; +import com.refinedmods.refinedstorage2.platform.api.blockentity.wirelesstransmitter.WirelessTransmitterRangeModifier; +import com.refinedmods.refinedstorage2.platform.api.grid.Grid; +import com.refinedmods.refinedstorage2.platform.api.grid.GridExtractionStrategy; +import com.refinedmods.refinedstorage2.platform.api.grid.GridExtractionStrategyFactory; +import com.refinedmods.refinedstorage2.platform.api.grid.GridInsertionHint; +import com.refinedmods.refinedstorage2.platform.api.grid.GridInsertionHints; +import com.refinedmods.refinedstorage2.platform.api.grid.GridInsertionStrategy; +import com.refinedmods.refinedstorage2.platform.api.grid.GridInsertionStrategyFactory; +import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollingStrategy; +import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollingStrategyFactory; +import com.refinedmods.refinedstorage2.platform.api.grid.GridSynchronizer; +import com.refinedmods.refinedstorage2.platform.api.integration.recipemod.IngredientConverter; +import com.refinedmods.refinedstorage2.platform.api.item.EnergyItemHelper; +import com.refinedmods.refinedstorage2.platform.api.item.NetworkBoundItemHelper; +import com.refinedmods.refinedstorage2.platform.api.item.SlotReference; +import com.refinedmods.refinedstorage2.platform.api.item.SlotReferenceFactory; +import com.refinedmods.refinedstorage2.platform.api.item.SlotReferenceProvider; +import com.refinedmods.refinedstorage2.platform.api.item.StorageContainerItemHelper; +import com.refinedmods.refinedstorage2.platform.api.network.node.exporter.ExporterTransferStrategyFactory; +import com.refinedmods.refinedstorage2.platform.api.network.node.externalstorage.PlatformExternalStorageProviderFactory; +import com.refinedmods.refinedstorage2.platform.api.network.node.importer.ImporterTransferStrategyFactory; +import com.refinedmods.refinedstorage2.platform.api.registry.PlatformRegistry; +import com.refinedmods.refinedstorage2.platform.api.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.api.resource.ResourceFactory; +import com.refinedmods.refinedstorage2.platform.api.resource.ResourceRendering; +import com.refinedmods.refinedstorage2.platform.api.storage.StorageRepository; +import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.api.storage.type.StorageType; +import com.refinedmods.refinedstorage2.platform.api.upgrade.BuiltinUpgradeDestinations; +import com.refinedmods.refinedstorage2.platform.api.upgrade.UpgradeRegistry; + +import java.util.Collection; +import java.util.Optional; +import java.util.Set; +import javax.annotation.Nullable; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; + +public class PlatformApiProxy implements PlatformApi { + @Nullable + private PlatformApi delegate; + + public void setDelegate(final PlatformApi delegate) { + if (this.delegate != null) { + throw new IllegalStateException("Platform API already injected"); + } + this.delegate = delegate; + } + + @Override + public PlatformRegistry> getStorageTypeRegistry() { + return ensureLoaded().getStorageTypeRegistry(); + } + + @Override + public StorageRepository getStorageRepository(final Level level) { + return ensureLoaded().getStorageRepository(level); + } + + @Override + public StorageContainerItemHelper getStorageContainerItemHelper() { + return ensureLoaded().getStorageContainerItemHelper(); + } + + @Override + public PlatformRegistry> getStorageChannelTypeRegistry() { + return ensureLoaded().getStorageChannelTypeRegistry(); + } + + @Override + public PlatformRegistry getImporterTransferStrategyRegistry() { + return ensureLoaded().getImporterTransferStrategyRegistry(); + } + + @Override + public PlatformRegistry getExporterTransferStrategyRegistry() { + return ensureLoaded().getExporterTransferStrategyRegistry(); + } + + @Override + public void addExternalStorageProviderFactory(final PlatformExternalStorageProviderFactory factory) { + ensureLoaded().addExternalStorageProviderFactory(factory); + } + + @Override + public Collection getExternalStorageProviderFactories() { + return ensureLoaded().getExternalStorageProviderFactories(); + } + + @Override + public Collection getDestructorStrategyFactories() { + return ensureLoaded().getDestructorStrategyFactories(); + } + + @Override + public void addDestructorStrategyFactory(final DestructorStrategyFactory factory) { + ensureLoaded().addDestructorStrategyFactory(factory); + } + + @Override + public Collection getConstructorStrategyFactories() { + return ensureLoaded().getConstructorStrategyFactories(); + } + + @Override + public void addConstructorStrategyFactory(final ConstructorStrategyFactory factory) { + ensureLoaded().addConstructorStrategyFactory(factory); + } + + @Override + public void addStorageMonitorExtractionStrategy(final StorageMonitorExtractionStrategy strategy) { + ensureLoaded().addStorageMonitorExtractionStrategy(strategy); + } + + @Override + public StorageMonitorExtractionStrategy getStorageMonitorExtractionStrategy() { + return ensureLoaded().getStorageMonitorExtractionStrategy(); + } + + @Override + public void addStorageMonitorInsertionStrategy(final StorageMonitorInsertionStrategy strategy) { + ensureLoaded().addStorageMonitorInsertionStrategy(strategy); + } + + @Override + public StorageMonitorInsertionStrategy getStorageMonitorInsertionStrategy() { + return ensureLoaded().getStorageMonitorInsertionStrategy(); + } + + @Override + public MutableComponent createTranslation(final String category, final String value, final Object... args) { + return ensureLoaded().createTranslation(category, value, args); + } + + @Override + public ComponentMapFactory getNetworkComponentMapFactory() { + return ensureLoaded().getNetworkComponentMapFactory(); + } + + @Override + public PlatformRegistry getGridSynchronizerRegistry() { + return ensureLoaded().getGridSynchronizerRegistry(); + } + + @Override + public UpgradeRegistry getUpgradeRegistry() { + return ensureLoaded().getUpgradeRegistry(); + } + + @Override + public BuiltinUpgradeDestinations getBuiltinUpgradeDestinations() { + return ensureLoaded().getBuiltinUpgradeDestinations(); + } + + @Override + public void requestNetworkNodeInitialization(final NetworkNodeContainer container, + final Level level, + final Runnable callback) { + ensureLoaded().requestNetworkNodeInitialization(container, level, callback); + } + + @Override + public void requestNetworkNodeRemoval(final NetworkNodeContainer container, final Level level) { + ensureLoaded().requestNetworkNodeRemoval(container, level); + } + + @Override + public void requestNetworkNodeUpdate(final NetworkNodeContainer container, final Level level) { + ensureLoaded().requestNetworkNodeUpdate(container, level); + } + + @Override + public GridInsertionStrategy createGridInsertionStrategy(final AbstractContainerMenu containerMenu, + final Player player, + final Grid grid) { + return ensureLoaded().createGridInsertionStrategy(containerMenu, player, grid); + } + + @Override + public void addGridInsertionStrategyFactory(final GridInsertionStrategyFactory insertionStrategyFactory) { + ensureLoaded().addGridInsertionStrategyFactory(insertionStrategyFactory); + } + + @Override + public void addAlternativeGridInsertionHint(final GridInsertionHint hint) { + ensureLoaded().addAlternativeGridInsertionHint(hint); + } + + @Override + public GridInsertionHints getGridInsertionHints() { + return ensureLoaded().getGridInsertionHints(); + } + + @Override + public GridExtractionStrategy createGridExtractionStrategy(final AbstractContainerMenu containerMenu, + final Player player, + final Grid grid) { + return ensureLoaded().createGridExtractionStrategy(containerMenu, player, grid); + } + + @Override + public void addGridExtractionStrategyFactory(final GridExtractionStrategyFactory extractionStrategyFactory) { + ensureLoaded().addGridExtractionStrategyFactory(extractionStrategyFactory); + } + + @Override + public GridScrollingStrategy createGridScrollingStrategy(final AbstractContainerMenu containerMenu, + final Player player, + final Grid grid) { + return ensureLoaded().createGridScrollingStrategy(containerMenu, player, grid); + } + + @Override + public void addGridScrollingStrategyFactory(final GridScrollingStrategyFactory scrollingStrategyFactory) { + ensureLoaded().addGridScrollingStrategyFactory(scrollingStrategyFactory); + } + + @Override + public void addResourceFactory(final ResourceFactory factory) { + ensureLoaded().addResourceFactory(factory); + } + + @Override + public ResourceFactory getItemResourceFactory() { + return ensureLoaded().getItemResourceFactory(); + } + + @Override + public PlatformStorageChannelType getItemStorageChannelType() { + return ensureLoaded().getItemStorageChannelType(); + } + + @Override + public StorageType getItemStorageType() { + return ensureLoaded().getItemStorageType(); + } + + @Override + public ResourceFactory getFluidResourceFactory() { + return ensureLoaded().getFluidResourceFactory(); + } + + @Override + public PlatformStorageChannelType getFluidStorageChannelType() { + return ensureLoaded().getFluidStorageChannelType(); + } + + @Override + public StorageType getFluidStorageType() { + return ensureLoaded().getFluidStorageType(); + } + + @Override + public Set> getAlternativeResourceFactories() { + return ensureLoaded().getAlternativeResourceFactories(); + } + + @Override + public void registerResourceRendering(final Class resourceClass, final ResourceRendering rendering) { + ensureLoaded().registerResourceRendering(resourceClass, rendering); + } + + @Override + public ResourceRendering getResourceRendering(final T resource) { + return ensureLoaded().getResourceRendering(resource); + } + + @Override + public void registerIngredientConverter(final IngredientConverter converter) { + ensureLoaded().registerIngredientConverter(converter); + } + + @Override + public IngredientConverter getIngredientConverter() { + return ensureLoaded().getIngredientConverter(); + } + + @Override + public void addWirelessTransmitterRangeModifier(final WirelessTransmitterRangeModifier rangeModifier) { + ensureLoaded().addWirelessTransmitterRangeModifier(rangeModifier); + } + + @Override + public WirelessTransmitterRangeModifier getWirelessTransmitterRangeModifier() { + return ensureLoaded().getWirelessTransmitterRangeModifier(); + } + + @Override + public Optional getEnergyStorage(final ItemStack stack) { + return ensureLoaded().getEnergyStorage(stack); + } + + @Override + public EnergyItemHelper getEnergyItemHelper() { + return ensureLoaded().getEnergyItemHelper(); + } + + @Override + public EnergyStorage asItemEnergyStorage(final EnergyStorage energyStorage, final ItemStack stack) { + return ensureLoaded().asItemEnergyStorage(energyStorage, stack); + } + + @Override + public NetworkBoundItemHelper getNetworkBoundItemHelper() { + return ensureLoaded().getNetworkBoundItemHelper(); + } + + @Override + public PlatformRegistry getSlotReferenceFactoryRegistry() { + return ensureLoaded().getSlotReferenceFactoryRegistry(); + } + + @Override + public void writeSlotReference(final SlotReference slotReference, final FriendlyByteBuf buf) { + ensureLoaded().writeSlotReference(slotReference, buf); + } + + @Override + public Optional getSlotReference(final FriendlyByteBuf buf) { + return ensureLoaded().getSlotReference(buf); + } + + @Override + public void addSlotReferenceProvider(final SlotReferenceProvider slotReferenceProvider) { + ensureLoaded().addSlotReferenceProvider(slotReferenceProvider); + } + + @Override + public SlotReference createInventorySlotReference(final Player player, final InteractionHand hand) { + return ensureLoaded().createInventorySlotReference(player, hand); + } + + @Override + public void useNetworkBoundItem(final Player player, final Item... items) { + ensureLoaded().useNetworkBoundItem(player, items); + } + + private PlatformApi ensureLoaded() { + if (delegate == null) { + throw new IllegalStateException("Platform API not loaded yet"); + } + return delegate; + } +} diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/blockentity/storagemonitor/StorageMonitorExtractionStrategy.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/blockentity/storagemonitor/StorageMonitorExtractionStrategy.java new file mode 100644 index 000000000..519fd326a --- /dev/null +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/blockentity/storagemonitor/StorageMonitorExtractionStrategy.java @@ -0,0 +1,13 @@ +package com.refinedmods.refinedstorage2.platform.api.blockentity.storagemonitor; + +import com.refinedmods.refinedstorage2.api.network.Network; +import com.refinedmods.refinedstorage2.api.storage.Actor; + +import net.minecraft.world.entity.player.Player; +import org.apiguardian.api.API; + +@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.1") +@FunctionalInterface +public interface StorageMonitorExtractionStrategy { + boolean extract(Object resource, boolean fullStack, Player player, Actor actor, Network network); +} diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/blockentity/storagemonitor/StorageMonitorInsertionStrategy.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/blockentity/storagemonitor/StorageMonitorInsertionStrategy.java new file mode 100644 index 000000000..b2168b22c --- /dev/null +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/blockentity/storagemonitor/StorageMonitorInsertionStrategy.java @@ -0,0 +1,15 @@ +package com.refinedmods.refinedstorage2.platform.api.blockentity.storagemonitor; + +import com.refinedmods.refinedstorage2.api.network.Network; +import com.refinedmods.refinedstorage2.api.storage.Actor; + +import java.util.Optional; + +import net.minecraft.world.item.ItemStack; +import org.apiguardian.api.API; + +@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.1") +@FunctionalInterface +public interface StorageMonitorInsertionStrategy { + Optional insert(Object configuredResource, ItemStack stack, Actor actor, Network network); +} diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/blockentity/storagemonitor/package-info.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/blockentity/storagemonitor/package-info.java new file mode 100644 index 000000000..34cea1edd --- /dev/null +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/blockentity/storagemonitor/package-info.java @@ -0,0 +1,7 @@ +@ParametersAreNonnullByDefault +@FieldsAndMethodsAreNonnullByDefault +package com.refinedmods.refinedstorage2.platform.api.blockentity.storagemonitor; + +import com.refinedmods.refinedstorage2.api.core.FieldsAndMethodsAreNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/resource/ResourceRendering.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/resource/ResourceRendering.java index 1e6cd6f8e..87bc86a42 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/resource/ResourceRendering.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/resource/ResourceRendering.java @@ -2,17 +2,22 @@ import java.util.List; +import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.network.chat.Component; +import net.minecraft.world.level.Level; import org.apiguardian.api.API; @API(status = API.Status.STABLE, since = "2.0.0-milestone.2.13") public interface ResourceRendering { - String getDisplayedAmount(long amount); + String getDisplayedAmount(long amount, boolean withUnits); Component getDisplayName(T resource); List getTooltip(T resource); void render(T resource, GuiGraphics graphics, int x, int y); + + void render(T resource, PoseStack poseStack, MultiBufferSource renderTypeBuffer, int light, Level level); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractClientModInitializer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractClientModInitializer.java index e445ddc49..8fb4b7f45 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractClientModInitializer.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractClientModInitializer.java @@ -21,6 +21,7 @@ import com.refinedmods.refinedstorage2.platform.common.screen.InterfaceScreen; import com.refinedmods.refinedstorage2.platform.common.screen.ItemStorageBlockScreen; import com.refinedmods.refinedstorage2.platform.common.screen.RegulatorUpgradeScreen; +import com.refinedmods.refinedstorage2.platform.common.screen.StorageMonitorScreen; import com.refinedmods.refinedstorage2.platform.common.screen.WirelessTransmitterScreen; import com.refinedmods.refinedstorage2.platform.common.screen.amount.DetectorScreen; import com.refinedmods.refinedstorage2.platform.common.screen.grid.CraftingGridScreen; @@ -55,6 +56,7 @@ protected static void registerScreens(final ScreenRegistration registration) { registration.register(Menus.INSTANCE.getConstructor(), ConstructorScreen::new); registration.register(Menus.INSTANCE.getRegulatorUpgrade(), RegulatorUpgradeScreen::new); registration.register(Menus.INSTANCE.getWirelessTransmitter(), WirelessTransmitterScreen::new); + registration.register(Menus.INSTANCE.getStorageMonitor(), StorageMonitorScreen::new); } protected static void registerAlternativeGridHints() { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractModInitializer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractModInitializer.java index d8eb8065c..161c294ef 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractModInitializer.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractModInitializer.java @@ -13,6 +13,7 @@ import com.refinedmods.refinedstorage2.platform.common.block.InterfaceBlock; import com.refinedmods.refinedstorage2.platform.common.block.ItemStorageBlock; import com.refinedmods.refinedstorage2.platform.common.block.SimpleBlock; +import com.refinedmods.refinedstorage2.platform.common.block.StorageMonitorBlock; import com.refinedmods.refinedstorage2.platform.common.block.entity.CableBlockEntity; import com.refinedmods.refinedstorage2.platform.common.block.entity.ControllerBlockEntity; import com.refinedmods.refinedstorage2.platform.common.block.entity.ImporterBlockEntity; @@ -34,6 +35,11 @@ import com.refinedmods.refinedstorage2.platform.common.block.entity.iface.InterfaceBlockEntity; import com.refinedmods.refinedstorage2.platform.common.block.entity.storage.FluidStorageBlockBlockEntity; import com.refinedmods.refinedstorage2.platform.common.block.entity.storage.ItemStorageBlockBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.block.entity.storagemonitor.FluidStorageMonitorExtractionStrategy; +import com.refinedmods.refinedstorage2.platform.common.block.entity.storagemonitor.FluidStorageMonitorInsertionStrategy; +import com.refinedmods.refinedstorage2.platform.common.block.entity.storagemonitor.ItemStorageMonitorExtractionStrategy; +import com.refinedmods.refinedstorage2.platform.common.block.entity.storagemonitor.ItemStorageMonitorInsertionStrategy; +import com.refinedmods.refinedstorage2.platform.common.block.entity.storagemonitor.StorageMonitorBlockEntity; import com.refinedmods.refinedstorage2.platform.common.block.entity.wirelesstransmitter.BaseWirelessTransmitterRangeModifier; import com.refinedmods.refinedstorage2.platform.common.block.entity.wirelesstransmitter.CreativeRangeUpgradeWirelessTransmitterRangeModifier; import com.refinedmods.refinedstorage2.platform.common.block.entity.wirelesstransmitter.RangeUpgradeWirelessTransmitterRangeModifier; @@ -45,6 +51,7 @@ import com.refinedmods.refinedstorage2.platform.common.containermenu.ImporterContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.InterfaceContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.RegulatorUpgradeContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.containermenu.StorageMonitorContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.WirelessTransmitterContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.detector.DetectorContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.grid.CraftingGridContainerMenu; @@ -108,6 +115,7 @@ import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.CONTROLLER; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.CRAFTING_GRID; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.CREATIVE_CONTROLLER; +import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.CREATIVE_WIRELESS_GRID; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.DESTRUCTION_CORE; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.DESTRUCTOR; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.DETECTOR; @@ -127,6 +135,7 @@ import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.SILICON; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.STORAGE_BLOCK; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.STORAGE_HOUSING; +import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.STORAGE_MONITOR; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.WIRELESS_GRID; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.WIRELESS_TRANSMITTER; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.WRENCH; @@ -153,6 +162,8 @@ protected final void initializePlatformApi() { registerAdditionalResourceFactories(); registerDestructorStrategyFactories(); registerConstructorStrategyFactories(); + registerStorageMonitorInsertionStrategies(); + registerStorageMonitorExtractionStrategies(); registerNetworkComponents(); registerWirelessTransmitterRangeModifiers(); } @@ -191,6 +202,16 @@ private void registerConstructorStrategyFactories() { PlatformApi.INSTANCE.addConstructorStrategyFactory(new ItemDropConstructorStrategyFactory()); } + private void registerStorageMonitorInsertionStrategies() { + PlatformApi.INSTANCE.addStorageMonitorInsertionStrategy(new ItemStorageMonitorInsertionStrategy()); + PlatformApi.INSTANCE.addStorageMonitorInsertionStrategy(new FluidStorageMonitorInsertionStrategy()); + } + + private void registerStorageMonitorExtractionStrategies() { + PlatformApi.INSTANCE.addStorageMonitorExtractionStrategy(new ItemStorageMonitorExtractionStrategy()); + PlatformApi.INSTANCE.addStorageMonitorExtractionStrategy(new FluidStorageMonitorExtractionStrategy()); + } + private void registerNetworkComponents() { PlatformApi.INSTANCE.getNetworkComponentMapFactory().addFactory( EnergyNetworkComponent.class, @@ -250,6 +271,7 @@ protected final void registerBlocks( Blocks.INSTANCE.getDestructor().registerBlocks(callback); Blocks.INSTANCE.setInterface(callback.register(INTERFACE, InterfaceBlock::new)); Blocks.INSTANCE.getWirelessTransmitter().registerBlocks(callback); + Blocks.INSTANCE.setStorageMonitor(callback.register(STORAGE_MONITOR, StorageMonitorBlock::new)); } protected final void registerItems( @@ -273,11 +295,12 @@ protected final void registerItems( Blocks.INSTANCE.getWirelessTransmitter().registerItems(callback, Items.INSTANCE::addWirelessTransmitter); registerStorageItems(callback); registerUpgrades(callback, regulatorUpgradeItemSupplier); - Items.INSTANCE.setWirelessGrid(callback.register(ContentIds.WIRELESS_GRID, wirelessGridItemSupplier)); + Items.INSTANCE.setWirelessGrid(callback.register(WIRELESS_GRID, wirelessGridItemSupplier)); Items.INSTANCE.setCreativeWirelessGrid(callback.register( - ContentIds.CREATIVE_WIRELESS_GRID, + CREATIVE_WIRELESS_GRID, creativeWirelessGridItemSupplier )); + callback.register(STORAGE_MONITOR, () -> new SimpleBlockItem(Blocks.INSTANCE.getStorageMonitor())); } private void registerSimpleItems(final RegistryCallback callback) { @@ -531,6 +554,10 @@ protected final void registerBlockEntities( Blocks.INSTANCE.getWirelessTransmitter().toArray() ) )); + BlockEntities.INSTANCE.setStorageMonitor(callback.register( + STORAGE_MONITOR, + () -> typeFactory.create(StorageMonitorBlockEntity::new, Blocks.INSTANCE.getStorageMonitor()) + )); } protected final void registerMenus(final RegistryCallback> callback, @@ -599,6 +626,10 @@ protected final void registerMenus(final RegistryCallback> callback, WIRELESS_TRANSMITTER, () -> menuTypeFactory.create(WirelessTransmitterContainerMenu::new) )); + Menus.INSTANCE.setStorageMonitor(callback.register( + STORAGE_MONITOR, + () -> menuTypeFactory.create(StorageMonitorContainerMenu::new) + )); } protected final void registerLootFunctions(final RegistryCallback callback) { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/Config.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/Config.java index 70523581c..7f89c1abb 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/Config.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/Config.java @@ -44,6 +44,8 @@ public interface Config { WirelessTransmitterEntry getWirelessTransmitter(); + SimpleEnergyUsageEntry getStorageMonitor(); + interface SimpleEnergyUsageEntry { long getEnergyUsage(); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/ContainedFluid.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/ContainedFluid.java new file mode 100644 index 000000000..f5d161b7c --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/ContainedFluid.java @@ -0,0 +1,9 @@ +package com.refinedmods.refinedstorage2.platform.common; + +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; +import com.refinedmods.refinedstorage2.platform.api.resource.FluidResource; + +import net.minecraft.world.item.ItemStack; + +public record ContainedFluid(ItemStack remainderContainer, ResourceAmount fluid) { +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/Platform.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/Platform.java index 79ca84bb4..4368389a8 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/Platform.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/Platform.java @@ -3,7 +3,6 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.grid.view.GridResourceFactory; import com.refinedmods.refinedstorage2.api.network.energy.EnergyStorage; -import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.platform.api.grid.GridInsertionStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.resource.FluidResource; import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; @@ -74,7 +73,7 @@ public interface Platform { FluidRenderer getFluidRenderer(); - Optional> convertToFluid(ItemStack stack); + Optional getContainedFluid(ItemStack stack); Optional convertJeiIngredientToFluid(Object ingredient); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java index 9a08fe597..ccd58f6ad 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java @@ -1,482 +1,510 @@ -package com.refinedmods.refinedstorage2.platform.common; - -import com.refinedmods.refinedstorage2.api.core.component.ComponentMapFactory; -import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.NetworkBuilder; -import com.refinedmods.refinedstorage2.api.network.component.NetworkComponent; -import com.refinedmods.refinedstorage2.api.network.energy.EnergyStorage; -import com.refinedmods.refinedstorage2.api.network.impl.NetworkBuilderImpl; -import com.refinedmods.refinedstorage2.api.network.impl.NetworkFactory; -import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer; -import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.blockentity.constructor.ConstructorStrategyFactory; -import com.refinedmods.refinedstorage2.platform.api.blockentity.destructor.DestructorStrategyFactory; -import com.refinedmods.refinedstorage2.platform.api.blockentity.wirelesstransmitter.WirelessTransmitterRangeModifier; -import com.refinedmods.refinedstorage2.platform.api.grid.Grid; -import com.refinedmods.refinedstorage2.platform.api.grid.GridExtractionStrategy; -import com.refinedmods.refinedstorage2.platform.api.grid.GridExtractionStrategyFactory; -import com.refinedmods.refinedstorage2.platform.api.grid.GridInsertionHint; -import com.refinedmods.refinedstorage2.platform.api.grid.GridInsertionHints; -import com.refinedmods.refinedstorage2.platform.api.grid.GridInsertionStrategy; -import com.refinedmods.refinedstorage2.platform.api.grid.GridInsertionStrategyFactory; -import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollingStrategy; -import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollingStrategyFactory; -import com.refinedmods.refinedstorage2.platform.api.grid.GridSynchronizer; -import com.refinedmods.refinedstorage2.platform.api.integration.recipemod.IngredientConverter; -import com.refinedmods.refinedstorage2.platform.api.item.EnergyItemHelper; -import com.refinedmods.refinedstorage2.platform.api.item.NetworkBoundItemHelper; -import com.refinedmods.refinedstorage2.platform.api.item.SlotReference; -import com.refinedmods.refinedstorage2.platform.api.item.SlotReferenceFactory; -import com.refinedmods.refinedstorage2.platform.api.item.SlotReferenceProvider; -import com.refinedmods.refinedstorage2.platform.api.item.StorageContainerItemHelper; -import com.refinedmods.refinedstorage2.platform.api.network.node.exporter.ExporterTransferStrategyFactory; -import com.refinedmods.refinedstorage2.platform.api.network.node.externalstorage.PlatformExternalStorageProviderFactory; -import com.refinedmods.refinedstorage2.platform.api.network.node.importer.ImporterTransferStrategyFactory; -import com.refinedmods.refinedstorage2.platform.api.registry.PlatformRegistry; -import com.refinedmods.refinedstorage2.platform.api.resource.FluidResource; -import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.api.resource.ResourceFactory; -import com.refinedmods.refinedstorage2.platform.api.resource.ResourceRendering; -import com.refinedmods.refinedstorage2.platform.api.storage.StorageRepository; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; -import com.refinedmods.refinedstorage2.platform.api.storage.type.StorageType; -import com.refinedmods.refinedstorage2.platform.api.upgrade.BuiltinUpgradeDestinations; -import com.refinedmods.refinedstorage2.platform.api.upgrade.UpgradeRegistry; -import com.refinedmods.refinedstorage2.platform.common.block.entity.wirelesstransmitter.CompositeWirelessTransmitterRangeModifier; -import com.refinedmods.refinedstorage2.platform.common.integration.recipemod.CompositeIngredientConverter; -import com.refinedmods.refinedstorage2.platform.common.internal.energy.ItemEnergyStorage; -import com.refinedmods.refinedstorage2.platform.common.internal.grid.CompositeGridExtractionStrategy; -import com.refinedmods.refinedstorage2.platform.common.internal.grid.CompositeGridInsertionStrategy; -import com.refinedmods.refinedstorage2.platform.common.internal.grid.CompositeGridScrollingStrategy; -import com.refinedmods.refinedstorage2.platform.common.internal.grid.NoOpGridSynchronizer; -import com.refinedmods.refinedstorage2.platform.common.internal.item.CompositeSlotReferenceProvider; -import com.refinedmods.refinedstorage2.platform.common.internal.item.EnergyItemHelperImpl; -import com.refinedmods.refinedstorage2.platform.common.internal.item.InventorySlotReference; -import com.refinedmods.refinedstorage2.platform.common.internal.item.InventorySlotReferenceFactory; -import com.refinedmods.refinedstorage2.platform.common.internal.item.NetworkBoundItemHelperImpl; -import com.refinedmods.refinedstorage2.platform.common.internal.item.StorageContainerItemHelperImpl; -import com.refinedmods.refinedstorage2.platform.common.internal.network.LevelConnectionProvider; -import com.refinedmods.refinedstorage2.platform.common.internal.registry.PlatformRegistryImpl; -import com.refinedmods.refinedstorage2.platform.common.internal.resource.FluidResourceFactory; -import com.refinedmods.refinedstorage2.platform.common.internal.resource.ItemResourceFactory; -import com.refinedmods.refinedstorage2.platform.common.internal.storage.ClientStorageRepository; -import com.refinedmods.refinedstorage2.platform.common.internal.storage.StorageRepositoryImpl; -import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; -import com.refinedmods.refinedstorage2.platform.common.internal.storage.type.StorageTypes; -import com.refinedmods.refinedstorage2.platform.common.internal.upgrade.BuiltinUpgradeDestinationsImpl; -import com.refinedmods.refinedstorage2.platform.common.internal.upgrade.UpgradeRegistryImpl; -import com.refinedmods.refinedstorage2.platform.common.screen.grid.hint.GridInsertionHintsImpl; -import com.refinedmods.refinedstorage2.platform.common.screen.grid.hint.ItemGridInsertionHint; -import com.refinedmods.refinedstorage2.platform.common.screen.grid.hint.SingleItemGridInsertionHint; -import com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil; -import com.refinedmods.refinedstorage2.platform.common.util.TickHandler; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.PriorityQueue; -import java.util.Queue; -import java.util.Set; - -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.chat.MutableComponent; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; - -import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; - -public class PlatformApiImpl implements PlatformApi { - private static final String ITEM_REGISTRY_KEY = "item"; - - private final StorageRepository clientStorageRepository = - new ClientStorageRepository(Platform.INSTANCE.getClientToServerCommunications()::sendStorageInfoRequest); - private final ComponentMapFactory networkComponentMapFactory = - new ComponentMapFactory<>(); - private final NetworkBuilder networkBuilder = - new NetworkBuilderImpl(new NetworkFactory(networkComponentMapFactory)); - private final PlatformRegistry> storageTypeRegistry = - new PlatformRegistryImpl<>(createIdentifier(ITEM_REGISTRY_KEY), StorageTypes.ITEM); - private final PlatformRegistry> storageChannelTypeRegistry = - new PlatformRegistryImpl<>(createIdentifier(ITEM_REGISTRY_KEY), StorageChannelTypes.ITEM); - private final PlatformRegistry gridSynchronizerRegistry = - new PlatformRegistryImpl<>(createIdentifier("off"), new NoOpGridSynchronizer()); - private final PlatformRegistry importerTransferStrategyRegistry = - new PlatformRegistryImpl<>(createIdentifier("noop"), - (level, pos, direction, upgradeState, amountOverride) -> (filter, actor, network) -> false); - private final PlatformRegistry exporterTransferStrategyRegistry = - new PlatformRegistryImpl<>(createIdentifier("noop"), - (level, pos, direction, upgradeState, amountOverride, fuzzyMode) -> (resource, actor, network) -> false); - private final UpgradeRegistry upgradeRegistry = new UpgradeRegistryImpl(); - private final BuiltinUpgradeDestinations builtinUpgradeDestinations = new BuiltinUpgradeDestinationsImpl(); - private final Queue externalStorageProviderFactories = new PriorityQueue<>( - Comparator.comparingInt(PlatformExternalStorageProviderFactory::getPriority) - ); - private final Queue destructorStrategyFactories = new PriorityQueue<>( - Comparator.comparingInt(DestructorStrategyFactory::getPriority) - ); - private final Queue constructorStrategyFactories = new PriorityQueue<>( - Comparator.comparingInt(ConstructorStrategyFactory::getPriority) - ); - private final CompositeIngredientConverter compositeConverter = new CompositeIngredientConverter(); - private final StorageContainerItemHelper storageContainerItemHelper = new StorageContainerItemHelperImpl(); - private final List gridInsertionStrategyFactories = new ArrayList<>(); - private final GridInsertionHintsImpl gridInsertionHints = new GridInsertionHintsImpl( - new ItemGridInsertionHint(), - new SingleItemGridInsertionHint() - ); - private final List gridExtractionStrategyFactories = new ArrayList<>(); - private final List gridScrollingStrategyFactories = new ArrayList<>(); - private final ResourceFactory itemResourceFactory = new ItemResourceFactory(); - private final ResourceFactory fluidResourceFactory = new FluidResourceFactory(); - private final Set> resourceFactories = new HashSet<>(); - private final Map, ResourceRendering> resourceRenderingMap = new HashMap<>(); - private final CompositeWirelessTransmitterRangeModifier wirelessTransmitterRangeModifier = - new CompositeWirelessTransmitterRangeModifier(); - private final EnergyItemHelper energyItemHelper = new EnergyItemHelperImpl(); - private final NetworkBoundItemHelper networkBoundItemHelper = new NetworkBoundItemHelperImpl(); - private final PlatformRegistry slotReferenceFactoryRegistry = new PlatformRegistryImpl<>( - createIdentifier("inventory"), - InventorySlotReferenceFactory.INSTANCE - ); - private final CompositeSlotReferenceProvider slotReferenceProvider = new CompositeSlotReferenceProvider(); - - @Override - public PlatformRegistry> getStorageTypeRegistry() { - return storageTypeRegistry; - } - - @Override - public StorageRepository getStorageRepository(final Level level) { - if (level.getServer() == null) { - return clientStorageRepository; - } - final ServerLevel serverLevel = Objects.requireNonNull(level.getServer().getLevel(Level.OVERWORLD)); - return serverLevel - .getDataStorage() - .computeIfAbsent( - this::createStorageRepository, - this::createStorageRepository, - StorageRepositoryImpl.NAME - ); - } - - @Override - public StorageContainerItemHelper getStorageContainerItemHelper() { - return storageContainerItemHelper; - } - - private StorageRepositoryImpl createStorageRepository(final CompoundTag tag) { - final StorageRepositoryImpl repository = createStorageRepository(); - repository.read(tag); - return repository; - } - - private StorageRepositoryImpl createStorageRepository() { - return new StorageRepositoryImpl(storageTypeRegistry); - } - - @Override - public PlatformRegistry> getStorageChannelTypeRegistry() { - return storageChannelTypeRegistry; - } - - @Override - public PlatformRegistry getImporterTransferStrategyRegistry() { - return importerTransferStrategyRegistry; - } - - @Override - public PlatformRegistry getExporterTransferStrategyRegistry() { - return exporterTransferStrategyRegistry; - } - - @Override - public void addExternalStorageProviderFactory(final PlatformExternalStorageProviderFactory factory) { - externalStorageProviderFactories.add(factory); - } - - @Override - public Collection getExternalStorageProviderFactories() { - return externalStorageProviderFactories; - } - - @Override - public Collection getDestructorStrategyFactories() { - return destructorStrategyFactories; - } - - @Override - public void addDestructorStrategyFactory(final DestructorStrategyFactory factory) { - destructorStrategyFactories.add(factory); - } - - @Override - public Collection getConstructorStrategyFactories() { - return constructorStrategyFactories; - } - - @Override - public void addConstructorStrategyFactory(final ConstructorStrategyFactory factory) { - constructorStrategyFactories.add(factory); - } - - @Override - public MutableComponent createTranslation(final String category, final String value, final Object... args) { - return IdentifierUtil.createTranslation(category, value, args); - } - - @Override - public ComponentMapFactory getNetworkComponentMapFactory() { - return networkComponentMapFactory; - } - - @Override - public PlatformRegistry getGridSynchronizerRegistry() { - return gridSynchronizerRegistry; - } - - @Override - public UpgradeRegistry getUpgradeRegistry() { - return upgradeRegistry; - } - - @Override - public BuiltinUpgradeDestinations getBuiltinUpgradeDestinations() { - return builtinUpgradeDestinations; - } - - @Override - public void requestNetworkNodeInitialization(final NetworkNodeContainer container, - final Level level, - final Runnable callback) { - final LevelConnectionProvider connectionProvider = new LevelConnectionProvider(level); - TickHandler.runWhenReady(() -> { - networkBuilder.initialize(container, connectionProvider); - callback.run(); - }); - } - - @Override - public void requestNetworkNodeRemoval(final NetworkNodeContainer container, final Level level) { - final LevelConnectionProvider connectionProvider = new LevelConnectionProvider(level); - networkBuilder.remove(container, connectionProvider); - } - - @Override - public void requestNetworkNodeUpdate(final NetworkNodeContainer container, final Level level) { - final LevelConnectionProvider connectionProvider = new LevelConnectionProvider(level); - networkBuilder.update(container, connectionProvider); - } - - @Override - public GridInsertionStrategy createGridInsertionStrategy(final AbstractContainerMenu containerMenu, - final Player player, - final Grid grid) { - return new CompositeGridInsertionStrategy( - Platform.INSTANCE.getDefaultGridInsertionStrategyFactory().create( - containerMenu, - player, - grid - ), - gridInsertionStrategyFactories.stream().map(f -> f.create( - containerMenu, - player, - grid - )).toList() - ); - } - - @Override - public void addGridInsertionStrategyFactory(final GridInsertionStrategyFactory insertionStrategyFactory) { - gridInsertionStrategyFactories.add(insertionStrategyFactory); - } - - @Override - public void addAlternativeGridInsertionHint(final GridInsertionHint hint) { - gridInsertionHints.addAlternativeHint(hint); - } - - @Override - public GridInsertionHints getGridInsertionHints() { - return gridInsertionHints; - } - - @Override - public GridExtractionStrategy createGridExtractionStrategy(final AbstractContainerMenu containerMenu, - final Player player, - final Grid grid) { - final List strategies = gridExtractionStrategyFactories - .stream() - .map(f -> f.create(containerMenu, player, grid)) - .toList(); - return new CompositeGridExtractionStrategy(strategies); - } - - @Override - public void addGridExtractionStrategyFactory(final GridExtractionStrategyFactory extractionStrategyFactory) { - gridExtractionStrategyFactories.add(extractionStrategyFactory); - } - - @Override - public GridScrollingStrategy createGridScrollingStrategy(final AbstractContainerMenu containerMenu, - final Player player, - final Grid grid) { - final List strategies = gridScrollingStrategyFactories - .stream() - .map(f -> f.create(containerMenu, player, grid)) - .toList(); - return new CompositeGridScrollingStrategy(strategies); - } - - @Override - public void addGridScrollingStrategyFactory(final GridScrollingStrategyFactory scrollingStrategyFactory) { - gridScrollingStrategyFactories.add(scrollingStrategyFactory); - } - - @Override - public void addResourceFactory(final ResourceFactory factory) { - resourceFactories.add(factory); - } - - @Override - public ResourceFactory getItemResourceFactory() { - return itemResourceFactory; - } - - @Override - public PlatformStorageChannelType getItemStorageChannelType() { - return StorageChannelTypes.ITEM; - } - - @Override - public StorageType getItemStorageType() { - return StorageTypes.ITEM; - } - - @Override - public ResourceFactory getFluidResourceFactory() { - return fluidResourceFactory; - } - - @Override - public PlatformStorageChannelType getFluidStorageChannelType() { - return StorageChannelTypes.FLUID; - } - - @Override - public StorageType getFluidStorageType() { - return StorageTypes.FLUID; - } - - @Override - public Set> getAlternativeResourceFactories() { - return resourceFactories; - } - - @Override - public void registerResourceRendering(final Class resourceClass, final ResourceRendering rendering) { - resourceRenderingMap.put(resourceClass, rendering); - } - - @Override - @SuppressWarnings("unchecked") - public ResourceRendering getResourceRendering(final T resource) { - return (ResourceRendering) resourceRenderingMap.get(resource.getClass()); - } - - @Override - public void registerIngredientConverter(final IngredientConverter converter) { - this.compositeConverter.addConverter(converter); - } - - @Override - public IngredientConverter getIngredientConverter() { - return compositeConverter; - } - - @Override - public void addWirelessTransmitterRangeModifier(final WirelessTransmitterRangeModifier rangeModifier) { - wirelessTransmitterRangeModifier.addModifier(rangeModifier); - } - - @Override - public WirelessTransmitterRangeModifier getWirelessTransmitterRangeModifier() { - return wirelessTransmitterRangeModifier; - } - - @Override - public Optional getEnergyStorage(final ItemStack stack) { - return Platform.INSTANCE.getEnergyStorage(stack); - } - - @Override - public EnergyItemHelper getEnergyItemHelper() { - return energyItemHelper; - } - - @Override - public EnergyStorage asItemEnergyStorage(final EnergyStorage energyStorage, - final ItemStack stack) { - return new ItemEnergyStorage(stack, energyStorage); - } - - @Override - public NetworkBoundItemHelper getNetworkBoundItemHelper() { - return networkBoundItemHelper; - } - - @Override - public PlatformRegistry getSlotReferenceFactoryRegistry() { - return slotReferenceFactoryRegistry; - } - - @Override - public void writeSlotReference(final SlotReference slotReference, final FriendlyByteBuf buf) { - this.slotReferenceFactoryRegistry.getId(slotReference.getFactory()).ifPresentOrElse(id -> { - buf.writeBoolean(true); - buf.writeResourceLocation(id); - slotReference.writeToBuffer(buf); - }, () -> buf.writeBoolean(false)); - } - - @Override - public Optional getSlotReference(final FriendlyByteBuf buf) { - if (!buf.readBoolean()) { - return Optional.empty(); - } - final ResourceLocation id = buf.readResourceLocation(); - return slotReferenceFactoryRegistry.get(id).map(factory -> factory.create(buf)); - } - - @Override - public void addSlotReferenceProvider(final SlotReferenceProvider provider) { - slotReferenceProvider.addProvider(provider); - } - - @Override - public SlotReference createInventorySlotReference(final Player player, final InteractionHand hand) { - return InventorySlotReference.of(player, hand); - } - - @Override - public void useNetworkBoundItem(final Player player, final Item... items) { - final Set validItems = new HashSet<>(Arrays.asList(items)); - slotReferenceProvider.findForUse(player, items[0], validItems).ifPresent( - slotReference -> Platform.INSTANCE.getClientToServerCommunications().sendUseNetworkBoundItem(slotReference) - ); - } -} +package com.refinedmods.refinedstorage2.platform.common; + +import com.refinedmods.refinedstorage2.api.core.component.ComponentMapFactory; +import com.refinedmods.refinedstorage2.api.network.Network; +import com.refinedmods.refinedstorage2.api.network.NetworkBuilder; +import com.refinedmods.refinedstorage2.api.network.component.NetworkComponent; +import com.refinedmods.refinedstorage2.api.network.energy.EnergyStorage; +import com.refinedmods.refinedstorage2.api.network.impl.NetworkBuilderImpl; +import com.refinedmods.refinedstorage2.api.network.impl.NetworkFactory; +import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer; +import com.refinedmods.refinedstorage2.platform.api.PlatformApi; +import com.refinedmods.refinedstorage2.platform.api.blockentity.constructor.ConstructorStrategyFactory; +import com.refinedmods.refinedstorage2.platform.api.blockentity.destructor.DestructorStrategyFactory; +import com.refinedmods.refinedstorage2.platform.api.blockentity.storagemonitor.StorageMonitorExtractionStrategy; +import com.refinedmods.refinedstorage2.platform.api.blockentity.storagemonitor.StorageMonitorInsertionStrategy; +import com.refinedmods.refinedstorage2.platform.api.blockentity.wirelesstransmitter.WirelessTransmitterRangeModifier; +import com.refinedmods.refinedstorage2.platform.api.grid.Grid; +import com.refinedmods.refinedstorage2.platform.api.grid.GridExtractionStrategy; +import com.refinedmods.refinedstorage2.platform.api.grid.GridExtractionStrategyFactory; +import com.refinedmods.refinedstorage2.platform.api.grid.GridInsertionHint; +import com.refinedmods.refinedstorage2.platform.api.grid.GridInsertionHints; +import com.refinedmods.refinedstorage2.platform.api.grid.GridInsertionStrategy; +import com.refinedmods.refinedstorage2.platform.api.grid.GridInsertionStrategyFactory; +import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollingStrategy; +import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollingStrategyFactory; +import com.refinedmods.refinedstorage2.platform.api.grid.GridSynchronizer; +import com.refinedmods.refinedstorage2.platform.api.integration.recipemod.IngredientConverter; +import com.refinedmods.refinedstorage2.platform.api.item.EnergyItemHelper; +import com.refinedmods.refinedstorage2.platform.api.item.NetworkBoundItemHelper; +import com.refinedmods.refinedstorage2.platform.api.item.SlotReference; +import com.refinedmods.refinedstorage2.platform.api.item.SlotReferenceFactory; +import com.refinedmods.refinedstorage2.platform.api.item.SlotReferenceProvider; +import com.refinedmods.refinedstorage2.platform.api.item.StorageContainerItemHelper; +import com.refinedmods.refinedstorage2.platform.api.network.node.exporter.ExporterTransferStrategyFactory; +import com.refinedmods.refinedstorage2.platform.api.network.node.externalstorage.PlatformExternalStorageProviderFactory; +import com.refinedmods.refinedstorage2.platform.api.network.node.importer.ImporterTransferStrategyFactory; +import com.refinedmods.refinedstorage2.platform.api.registry.PlatformRegistry; +import com.refinedmods.refinedstorage2.platform.api.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.api.resource.ResourceFactory; +import com.refinedmods.refinedstorage2.platform.api.resource.ResourceRendering; +import com.refinedmods.refinedstorage2.platform.api.storage.StorageRepository; +import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.api.storage.type.StorageType; +import com.refinedmods.refinedstorage2.platform.api.upgrade.BuiltinUpgradeDestinations; +import com.refinedmods.refinedstorage2.platform.api.upgrade.UpgradeRegistry; +import com.refinedmods.refinedstorage2.platform.common.block.entity.storagemonitor.CompositeStorageMonitorExtractionStrategy; +import com.refinedmods.refinedstorage2.platform.common.block.entity.storagemonitor.CompositeStorageMonitorInsertionStrategy; +import com.refinedmods.refinedstorage2.platform.common.block.entity.wirelesstransmitter.CompositeWirelessTransmitterRangeModifier; +import com.refinedmods.refinedstorage2.platform.common.integration.recipemod.CompositeIngredientConverter; +import com.refinedmods.refinedstorage2.platform.common.internal.energy.ItemEnergyStorage; +import com.refinedmods.refinedstorage2.platform.common.internal.grid.CompositeGridExtractionStrategy; +import com.refinedmods.refinedstorage2.platform.common.internal.grid.CompositeGridInsertionStrategy; +import com.refinedmods.refinedstorage2.platform.common.internal.grid.CompositeGridScrollingStrategy; +import com.refinedmods.refinedstorage2.platform.common.internal.grid.NoOpGridSynchronizer; +import com.refinedmods.refinedstorage2.platform.common.internal.item.CompositeSlotReferenceProvider; +import com.refinedmods.refinedstorage2.platform.common.internal.item.EnergyItemHelperImpl; +import com.refinedmods.refinedstorage2.platform.common.internal.item.InventorySlotReference; +import com.refinedmods.refinedstorage2.platform.common.internal.item.InventorySlotReferenceFactory; +import com.refinedmods.refinedstorage2.platform.common.internal.item.NetworkBoundItemHelperImpl; +import com.refinedmods.refinedstorage2.platform.common.internal.item.StorageContainerItemHelperImpl; +import com.refinedmods.refinedstorage2.platform.common.internal.network.LevelConnectionProvider; +import com.refinedmods.refinedstorage2.platform.common.internal.registry.PlatformRegistryImpl; +import com.refinedmods.refinedstorage2.platform.common.internal.resource.FluidResourceFactory; +import com.refinedmods.refinedstorage2.platform.common.internal.resource.ItemResourceFactory; +import com.refinedmods.refinedstorage2.platform.common.internal.storage.ClientStorageRepository; +import com.refinedmods.refinedstorage2.platform.common.internal.storage.StorageRepositoryImpl; +import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.common.internal.storage.type.StorageTypes; +import com.refinedmods.refinedstorage2.platform.common.internal.upgrade.BuiltinUpgradeDestinationsImpl; +import com.refinedmods.refinedstorage2.platform.common.internal.upgrade.UpgradeRegistryImpl; +import com.refinedmods.refinedstorage2.platform.common.screen.grid.hint.GridInsertionHintsImpl; +import com.refinedmods.refinedstorage2.platform.common.screen.grid.hint.ItemGridInsertionHint; +import com.refinedmods.refinedstorage2.platform.common.screen.grid.hint.SingleItemGridInsertionHint; +import com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil; +import com.refinedmods.refinedstorage2.platform.common.util.TickHandler; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.PriorityQueue; +import java.util.Queue; +import java.util.Set; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; + +import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; + +public class PlatformApiImpl implements PlatformApi { + private static final String ITEM_REGISTRY_KEY = "item"; + + private final StorageRepository clientStorageRepository = + new ClientStorageRepository(Platform.INSTANCE.getClientToServerCommunications()::sendStorageInfoRequest); + private final ComponentMapFactory networkComponentMapFactory = + new ComponentMapFactory<>(); + private final NetworkBuilder networkBuilder = + new NetworkBuilderImpl(new NetworkFactory(networkComponentMapFactory)); + private final PlatformRegistry> storageTypeRegistry = + new PlatformRegistryImpl<>(createIdentifier(ITEM_REGISTRY_KEY), StorageTypes.ITEM); + private final PlatformRegistry> storageChannelTypeRegistry = + new PlatformRegistryImpl<>(createIdentifier(ITEM_REGISTRY_KEY), StorageChannelTypes.ITEM); + private final PlatformRegistry gridSynchronizerRegistry = + new PlatformRegistryImpl<>(createIdentifier("off"), new NoOpGridSynchronizer()); + private final PlatformRegistry importerTransferStrategyRegistry = + new PlatformRegistryImpl<>(createIdentifier("noop"), + (level, pos, direction, upgradeState, amountOverride) -> (filter, actor, network) -> false); + private final PlatformRegistry exporterTransferStrategyRegistry = + new PlatformRegistryImpl<>(createIdentifier("noop"), + (level, pos, direction, upgradeState, amountOverride, fuzzyMode) -> (resource, actor, network) -> false); + private final UpgradeRegistry upgradeRegistry = new UpgradeRegistryImpl(); + private final BuiltinUpgradeDestinations builtinUpgradeDestinations = new BuiltinUpgradeDestinationsImpl(); + private final Queue externalStorageProviderFactories = new PriorityQueue<>( + Comparator.comparingInt(PlatformExternalStorageProviderFactory::getPriority) + ); + private final Queue destructorStrategyFactories = new PriorityQueue<>( + Comparator.comparingInt(DestructorStrategyFactory::getPriority) + ); + private final Queue constructorStrategyFactories = new PriorityQueue<>( + Comparator.comparingInt(ConstructorStrategyFactory::getPriority) + ); + private final CompositeStorageMonitorInsertionStrategy storageMonitorInsertionStrategy = + new CompositeStorageMonitorInsertionStrategy(); + private final CompositeStorageMonitorExtractionStrategy storageMonitorExtractionStrategy = + new CompositeStorageMonitorExtractionStrategy(); + private final CompositeIngredientConverter compositeConverter = new CompositeIngredientConverter(); + private final StorageContainerItemHelper storageContainerItemHelper = new StorageContainerItemHelperImpl(); + private final List gridInsertionStrategyFactories = new ArrayList<>(); + private final GridInsertionHintsImpl gridInsertionHints = new GridInsertionHintsImpl( + new ItemGridInsertionHint(), + new SingleItemGridInsertionHint() + ); + private final List gridExtractionStrategyFactories = new ArrayList<>(); + private final List gridScrollingStrategyFactories = new ArrayList<>(); + private final ResourceFactory itemResourceFactory = new ItemResourceFactory(); + private final ResourceFactory fluidResourceFactory = new FluidResourceFactory(); + private final Set> resourceFactories = new HashSet<>(); + private final Map, ResourceRendering> resourceRenderingMap = new HashMap<>(); + private final CompositeWirelessTransmitterRangeModifier wirelessTransmitterRangeModifier = + new CompositeWirelessTransmitterRangeModifier(); + private final EnergyItemHelper energyItemHelper = new EnergyItemHelperImpl(); + private final NetworkBoundItemHelper networkBoundItemHelper = new NetworkBoundItemHelperImpl(); + private final PlatformRegistry slotReferenceFactoryRegistry = new PlatformRegistryImpl<>( + createIdentifier("inventory"), + InventorySlotReferenceFactory.INSTANCE + ); + private final CompositeSlotReferenceProvider slotReferenceProvider = new CompositeSlotReferenceProvider(); + + @Override + public PlatformRegistry> getStorageTypeRegistry() { + return storageTypeRegistry; + } + + @Override + public StorageRepository getStorageRepository(final Level level) { + if (level.getServer() == null) { + return clientStorageRepository; + } + final ServerLevel serverLevel = Objects.requireNonNull(level.getServer().getLevel(Level.OVERWORLD)); + return serverLevel + .getDataStorage() + .computeIfAbsent( + this::createStorageRepository, + this::createStorageRepository, + StorageRepositoryImpl.NAME + ); + } + + @Override + public StorageContainerItemHelper getStorageContainerItemHelper() { + return storageContainerItemHelper; + } + + private StorageRepositoryImpl createStorageRepository(final CompoundTag tag) { + final StorageRepositoryImpl repository = createStorageRepository(); + repository.read(tag); + return repository; + } + + private StorageRepositoryImpl createStorageRepository() { + return new StorageRepositoryImpl(storageTypeRegistry); + } + + @Override + public PlatformRegistry> getStorageChannelTypeRegistry() { + return storageChannelTypeRegistry; + } + + @Override + public PlatformRegistry getImporterTransferStrategyRegistry() { + return importerTransferStrategyRegistry; + } + + @Override + public PlatformRegistry getExporterTransferStrategyRegistry() { + return exporterTransferStrategyRegistry; + } + + @Override + public void addExternalStorageProviderFactory(final PlatformExternalStorageProviderFactory factory) { + externalStorageProviderFactories.add(factory); + } + + @Override + public Collection getExternalStorageProviderFactories() { + return externalStorageProviderFactories; + } + + @Override + public Collection getDestructorStrategyFactories() { + return destructorStrategyFactories; + } + + @Override + public void addDestructorStrategyFactory(final DestructorStrategyFactory factory) { + destructorStrategyFactories.add(factory); + } + + @Override + public Collection getConstructorStrategyFactories() { + return constructorStrategyFactories; + } + + @Override + public void addConstructorStrategyFactory(final ConstructorStrategyFactory factory) { + constructorStrategyFactories.add(factory); + } + + @Override + public void addStorageMonitorExtractionStrategy(final StorageMonitorExtractionStrategy strategy) { + storageMonitorExtractionStrategy.addStrategy(strategy); + } + + @Override + public StorageMonitorExtractionStrategy getStorageMonitorExtractionStrategy() { + return storageMonitorExtractionStrategy; + } + + @Override + public void addStorageMonitorInsertionStrategy(final StorageMonitorInsertionStrategy strategy) { + storageMonitorInsertionStrategy.addStrategy(strategy); + } + + @Override + public StorageMonitorInsertionStrategy getStorageMonitorInsertionStrategy() { + return storageMonitorInsertionStrategy; + } + + @Override + public MutableComponent createTranslation(final String category, final String value, final Object... args) { + return IdentifierUtil.createTranslation(category, value, args); + } + + @Override + public ComponentMapFactory getNetworkComponentMapFactory() { + return networkComponentMapFactory; + } + + @Override + public PlatformRegistry getGridSynchronizerRegistry() { + return gridSynchronizerRegistry; + } + + @Override + public UpgradeRegistry getUpgradeRegistry() { + return upgradeRegistry; + } + + @Override + public BuiltinUpgradeDestinations getBuiltinUpgradeDestinations() { + return builtinUpgradeDestinations; + } + + @Override + public void requestNetworkNodeInitialization(final NetworkNodeContainer container, + final Level level, + final Runnable callback) { + final LevelConnectionProvider connectionProvider = new LevelConnectionProvider(level); + TickHandler.runWhenReady(() -> { + networkBuilder.initialize(container, connectionProvider); + callback.run(); + }); + } + + @Override + public void requestNetworkNodeRemoval(final NetworkNodeContainer container, final Level level) { + final LevelConnectionProvider connectionProvider = new LevelConnectionProvider(level); + networkBuilder.remove(container, connectionProvider); + } + + @Override + public void requestNetworkNodeUpdate(final NetworkNodeContainer container, final Level level) { + final LevelConnectionProvider connectionProvider = new LevelConnectionProvider(level); + networkBuilder.update(container, connectionProvider); + } + + @Override + public GridInsertionStrategy createGridInsertionStrategy(final AbstractContainerMenu containerMenu, + final Player player, + final Grid grid) { + return new CompositeGridInsertionStrategy( + Platform.INSTANCE.getDefaultGridInsertionStrategyFactory().create( + containerMenu, + player, + grid + ), + gridInsertionStrategyFactories.stream().map(f -> f.create( + containerMenu, + player, + grid + )).toList() + ); + } + + @Override + public void addGridInsertionStrategyFactory(final GridInsertionStrategyFactory insertionStrategyFactory) { + gridInsertionStrategyFactories.add(insertionStrategyFactory); + } + + @Override + public void addAlternativeGridInsertionHint(final GridInsertionHint hint) { + gridInsertionHints.addAlternativeHint(hint); + } + + @Override + public GridInsertionHints getGridInsertionHints() { + return gridInsertionHints; + } + + @Override + public GridExtractionStrategy createGridExtractionStrategy(final AbstractContainerMenu containerMenu, + final Player player, + final Grid grid) { + final List strategies = gridExtractionStrategyFactories + .stream() + .map(f -> f.create(containerMenu, player, grid)) + .toList(); + return new CompositeGridExtractionStrategy(strategies); + } + + @Override + public void addGridExtractionStrategyFactory(final GridExtractionStrategyFactory extractionStrategyFactory) { + gridExtractionStrategyFactories.add(extractionStrategyFactory); + } + + @Override + public GridScrollingStrategy createGridScrollingStrategy(final AbstractContainerMenu containerMenu, + final Player player, + final Grid grid) { + final List strategies = gridScrollingStrategyFactories + .stream() + .map(f -> f.create(containerMenu, player, grid)) + .toList(); + return new CompositeGridScrollingStrategy(strategies); + } + + @Override + public void addGridScrollingStrategyFactory(final GridScrollingStrategyFactory scrollingStrategyFactory) { + gridScrollingStrategyFactories.add(scrollingStrategyFactory); + } + + @Override + public void addResourceFactory(final ResourceFactory factory) { + resourceFactories.add(factory); + } + + @Override + public ResourceFactory getItemResourceFactory() { + return itemResourceFactory; + } + + @Override + public PlatformStorageChannelType getItemStorageChannelType() { + return StorageChannelTypes.ITEM; + } + + @Override + public StorageType getItemStorageType() { + return StorageTypes.ITEM; + } + + @Override + public ResourceFactory getFluidResourceFactory() { + return fluidResourceFactory; + } + + @Override + public PlatformStorageChannelType getFluidStorageChannelType() { + return StorageChannelTypes.FLUID; + } + + @Override + public StorageType getFluidStorageType() { + return StorageTypes.FLUID; + } + + @Override + public Set> getAlternativeResourceFactories() { + return resourceFactories; + } + + @Override + public void registerResourceRendering(final Class resourceClass, final ResourceRendering rendering) { + resourceRenderingMap.put(resourceClass, rendering); + } + + @Override + @SuppressWarnings("unchecked") + public ResourceRendering getResourceRendering(final T resource) { + return (ResourceRendering) resourceRenderingMap.get(resource.getClass()); + } + + @Override + public void registerIngredientConverter(final IngredientConverter converter) { + this.compositeConverter.addConverter(converter); + } + + @Override + public IngredientConverter getIngredientConverter() { + return compositeConverter; + } + + @Override + public void addWirelessTransmitterRangeModifier(final WirelessTransmitterRangeModifier rangeModifier) { + wirelessTransmitterRangeModifier.addModifier(rangeModifier); + } + + @Override + public WirelessTransmitterRangeModifier getWirelessTransmitterRangeModifier() { + return wirelessTransmitterRangeModifier; + } + + @Override + public Optional getEnergyStorage(final ItemStack stack) { + return Platform.INSTANCE.getEnergyStorage(stack); + } + + @Override + public EnergyItemHelper getEnergyItemHelper() { + return energyItemHelper; + } + + @Override + public EnergyStorage asItemEnergyStorage(final EnergyStorage energyStorage, + final ItemStack stack) { + return new ItemEnergyStorage(stack, energyStorage); + } + + @Override + public NetworkBoundItemHelper getNetworkBoundItemHelper() { + return networkBoundItemHelper; + } + + @Override + public PlatformRegistry getSlotReferenceFactoryRegistry() { + return slotReferenceFactoryRegistry; + } + + @Override + public void writeSlotReference(final SlotReference slotReference, final FriendlyByteBuf buf) { + this.slotReferenceFactoryRegistry.getId(slotReference.getFactory()).ifPresentOrElse(id -> { + buf.writeBoolean(true); + buf.writeResourceLocation(id); + slotReference.writeToBuffer(buf); + }, () -> buf.writeBoolean(false)); + } + + @Override + public Optional getSlotReference(final FriendlyByteBuf buf) { + if (!buf.readBoolean()) { + return Optional.empty(); + } + final ResourceLocation id = buf.readResourceLocation(); + return slotReferenceFactoryRegistry.get(id).map(factory -> factory.create(buf)); + } + + @Override + public void addSlotReferenceProvider(final SlotReferenceProvider provider) { + slotReferenceProvider.addProvider(provider); + } + + @Override + public SlotReference createInventorySlotReference(final Player player, final InteractionHand hand) { + return InventorySlotReference.of(player, hand); + } + + @Override + public void useNetworkBoundItem(final Player player, final Item... items) { + final Set validItems = new HashSet<>(Arrays.asList(items)); + slotReferenceProvider.findForUse(player, items[0], validItems).ifPresent( + slotReference -> Platform.INSTANCE.getClientToServerCommunications().sendUseNetworkBoundItem(slotReference) + ); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformProxy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformProxy.java index cc86cbe36..9867803af 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformProxy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformProxy.java @@ -3,7 +3,6 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.grid.view.GridResourceFactory; import com.refinedmods.refinedstorage2.api.network.energy.EnergyStorage; -import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.platform.api.grid.GridInsertionStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.resource.FluidResource; import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; @@ -122,8 +121,8 @@ public FluidRenderer getFluidRenderer() { } @Override - public Optional> convertToFluid(final ItemStack stack) { - return ensureLoaded().convertToFluid(stack); + public Optional getContainedFluid(final ItemStack stack) { + return ensureLoaded().getContainedFluid(stack); } @Override diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/StorageMonitorBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/StorageMonitorBlock.java new file mode 100644 index 000000000..74a6fef2f --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/StorageMonitorBlock.java @@ -0,0 +1,101 @@ +package com.refinedmods.refinedstorage2.platform.common.block; + +import com.refinedmods.refinedstorage2.platform.common.block.direction.BiDirectionType; +import com.refinedmods.refinedstorage2.platform.common.block.direction.DirectionType; +import com.refinedmods.refinedstorage2.platform.common.block.entity.storagemonitor.StorageMonitorBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.block.ticker.AbstractBlockEntityTicker; +import com.refinedmods.refinedstorage2.platform.common.block.ticker.NetworkNodeBlockEntityTicker; +import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; +import com.refinedmods.refinedstorage2.platform.common.util.BiDirection; + +import javax.annotation.Nullable; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.ClipContext; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.EntityBlock; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityTicker; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.Vec3; + +public class StorageMonitorBlock extends AbstractDirectionalBlock implements EntityBlock { + private static final AbstractBlockEntityTicker TICKER = + new NetworkNodeBlockEntityTicker<>(BlockEntities.INSTANCE::getStorageMonitor); + + public StorageMonitorBlock() { + super(BlockConstants.PROPERTIES.strength(1.5F, 6.0F)); + } + + @Override + protected DirectionType getDirectionType() { + return BiDirectionType.INSTANCE; + } + + @Nullable + @Override + public BlockEntity newBlockEntity(final BlockPos pos, final BlockState state) { + return new StorageMonitorBlockEntity(pos, state); + } + + @Override + public BlockEntityTicker getTicker(final Level level, + final BlockState state, + final BlockEntityType type) { + return TICKER.get(level, type); + } + + @Override + public InteractionResult use(final BlockState state, + final Level level, + final BlockPos pos, + final Player player, + final InteractionHand hand, + final BlockHitResult hit) { + if (player.isCrouching()) { + return super.use(state, level, pos, player, hand, hit); + } + if (!level.isClientSide()) { + final BlockEntity blockEntity = level.getBlockEntity(pos); + if (blockEntity instanceof StorageMonitorBlockEntity storageMonitor) { + storageMonitor.insert(player, hand); + } + } + return InteractionResult.SUCCESS; + } + + @Override + @SuppressWarnings("deprecation") + public void attack(final BlockState state, final Level level, final BlockPos pos, final Player player) { + super.attack(state, level, pos, player); + if (level.isClientSide()) { + return; + } + if (!(level.getBlockEntity(pos) instanceof StorageMonitorBlockEntity storageMonitor)) { + return; + } + final BiDirection direction = getDirection(state); + if (direction == null) { + return; + } + final Vec3 base = player.getEyePosition(1.0F); + final Vec3 look = player.getLookAngle(); + final Vec3 target = base.add(look.x * 20, look.y * 20, look.z * 20); + final BlockHitResult hitResult = level.clip(new ClipContext( + base, + target, + ClipContext.Block.OUTLINE, + ClipContext.Fluid.NONE, + player + )); + if (hitResult.getDirection() != direction.asDirection()) { + return; + } + storageMonitor.extract(player); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/ControllerBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/ControllerBlockEntity.java index b487a290f..f45ad0545 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/ControllerBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/ControllerBlockEntity.java @@ -10,6 +10,7 @@ import com.refinedmods.refinedstorage2.platform.common.block.ControllerType; import com.refinedmods.refinedstorage2.platform.common.containermenu.ControllerContainerMenu; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; +import com.refinedmods.refinedstorage2.platform.common.content.ContentNames; import com.refinedmods.refinedstorage2.platform.common.internal.energy.CreativeEnergyStorage; import com.refinedmods.refinedstorage2.platform.common.menu.ExtendedMenuProvider; @@ -28,8 +29,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; - public class ControllerBlockEntity extends AbstractInternalNetworkNodeContainerBlockEntity implements ExtendedMenuProvider, EnergyBlockEntity { private static final Logger LOGGER = LoggerFactory.getLogger(ControllerBlockEntity.class); @@ -106,10 +105,7 @@ public void load(final CompoundTag tag) { @Override public Component getDisplayName() { - return createTranslation( - "block", - type == ControllerType.CREATIVE ? "creative_controller" : "controller" - ); + return type == ControllerType.CREATIVE ? ContentNames.CREATIVE_CONTROLLER : ContentNames.CONTROLLER; } @Override diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/ImporterBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/ImporterBlockEntity.java index f283e7c8e..71b12cea2 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/ImporterBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/ImporterBlockEntity.java @@ -10,6 +10,7 @@ import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.containermenu.ImporterContainerMenu; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; +import com.refinedmods.refinedstorage2.platform.common.content.ContentNames; import com.refinedmods.refinedstorage2.platform.common.content.Items; import com.refinedmods.refinedstorage2.platform.common.internal.resource.ResourceContainerImpl; import com.refinedmods.refinedstorage2.platform.common.internal.upgrade.UpgradeDestinations; @@ -33,8 +34,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; - public class ImporterBlockEntity extends AbstractUpgradeableNetworkNodeContainerBlockEntity implements AmountOverride, ExtendedMenuProvider { @@ -127,7 +126,7 @@ public void writeScreenOpeningData(final ServerPlayer player, final FriendlyByte @Override public Component getDisplayName() { - return createTranslation("block", "importer"); + return ContentNames.IMPORTER; } @Nullable diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/constructor/ConstructorBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/constructor/ConstructorBlockEntity.java index 83bc15bcf..104736dc4 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/constructor/ConstructorBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/constructor/ConstructorBlockEntity.java @@ -13,6 +13,7 @@ import com.refinedmods.refinedstorage2.platform.common.block.entity.AbstractSchedulingNetworkNodeContainerBlockEntity; import com.refinedmods.refinedstorage2.platform.common.containermenu.ConstructorContainerMenu; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; +import com.refinedmods.refinedstorage2.platform.common.content.ContentNames; import com.refinedmods.refinedstorage2.platform.common.internal.upgrade.UpgradeDestinations; import java.util.ArrayList; @@ -30,8 +31,6 @@ import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.level.block.state.BlockState; -import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; - public class ConstructorBlockEntity extends AbstractSchedulingNetworkNodeContainerBlockEntity { private static final String TAG_DROP_ITEMS = "di"; @@ -127,7 +126,7 @@ public void setDropItems(final boolean dropItems) { @Override public Component getDisplayName() { - return createTranslation("block", "constructor"); + return ContentNames.CONSTRUCTOR; } @Nullable diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/destructor/DestructorBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/destructor/DestructorBlockEntity.java index 5cff0b162..f9e4f9aa9 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/destructor/DestructorBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/destructor/DestructorBlockEntity.java @@ -13,6 +13,7 @@ import com.refinedmods.refinedstorage2.platform.common.block.entity.FilterWithFuzzyMode; import com.refinedmods.refinedstorage2.platform.common.containermenu.DestructorContainerMenu; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; +import com.refinedmods.refinedstorage2.platform.common.content.ContentNames; import com.refinedmods.refinedstorage2.platform.common.internal.resource.ResourceContainerImpl; import com.refinedmods.refinedstorage2.platform.common.internal.upgrade.UpgradeDestinations; import com.refinedmods.refinedstorage2.platform.common.menu.ExtendedMenuProvider; @@ -32,8 +33,6 @@ import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.level.block.state.BlockState; -import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; - public class DestructorBlockEntity extends AbstractUpgradeableNetworkNodeContainerBlockEntity implements ExtendedMenuProvider { private static final String TAG_FILTER_MODE = "fim"; @@ -116,7 +115,7 @@ public void writeScreenOpeningData(final ServerPlayer player, final FriendlyByte @Override public Component getDisplayName() { - return createTranslation("block", "destructor"); + return ContentNames.DESTRUCTOR; } @Nullable diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/detector/DetectorBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/detector/DetectorBlockEntity.java index 8932661d8..98afeed4f 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/detector/DetectorBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/detector/DetectorBlockEntity.java @@ -13,6 +13,7 @@ import com.refinedmods.refinedstorage2.platform.common.containermenu.AbstractSingleAmountContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.detector.DetectorContainerMenu; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; +import com.refinedmods.refinedstorage2.platform.common.content.ContentNames; import com.refinedmods.refinedstorage2.platform.common.internal.resource.ResourceContainerImpl; import com.refinedmods.refinedstorage2.platform.common.menu.ExtendedMenuProvider; @@ -33,8 +34,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; - public class DetectorBlockEntity extends AbstractInternalNetworkNodeContainerBlockEntity implements ExtendedMenuProvider { private static final Logger LOGGER = LoggerFactory.getLogger(DetectorBlockEntity.class); @@ -140,7 +139,7 @@ public void writeScreenOpeningData(final ServerPlayer player, final FriendlyByte @Override public Component getDisplayName() { - return createTranslation("block", "detector"); + return ContentNames.DETECTOR; } @Nullable diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/diskdrive/AbstractDiskDriveBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/diskdrive/AbstractDiskDriveBlockEntity.java index f09eea6c8..2e99a8364 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/diskdrive/AbstractDiskDriveBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/diskdrive/AbstractDiskDriveBlockEntity.java @@ -13,6 +13,7 @@ import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.diskdrive.DiskDriveContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.diskdrive.EmptyStorageDiskInfoAccessor; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; +import com.refinedmods.refinedstorage2.platform.common.content.ContentNames; import com.refinedmods.refinedstorage2.platform.common.internal.resource.ResourceContainerImpl; import com.refinedmods.refinedstorage2.platform.common.menu.ExtendedMenuProvider; import com.refinedmods.refinedstorage2.platform.common.util.ContainerUtil; @@ -40,14 +41,11 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.BooleanProperty; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; - public abstract class AbstractDiskDriveBlockEntity extends AbstractInternalNetworkNodeContainerBlockEntity implements BlockEntityWithDrops, MultiStorageListener, ExtendedMenuProvider { @@ -110,7 +108,7 @@ public void updateDiskStateIfNecessaryInLevel() { private void sync() { if (level != null) { - level.sendBlockUpdated(worldPosition, this.getBlockState(), this.getBlockState(), Block.UPDATE_ALL); + level.sendBlockUpdated(worldPosition, getBlockState(), getBlockState(), Block.UPDATE_ALL); } } @@ -222,12 +220,12 @@ private void fromClientTag(final CompoundTag tag) { } protected void onDriveStateUpdated() { - LevelUtil.updateBlock(level, worldPosition, this.getBlockState()); + LevelUtil.updateBlock(level, worldPosition, getBlockState()); } @Override public Packet getUpdatePacket() { - return ClientboundBlockEntityDataPacket.create(this, BlockEntity::getUpdateTag); + return ClientboundBlockEntityDataPacket.create(this); } @Override @@ -247,7 +245,7 @@ public CompoundTag getUpdateTag() { @Override public Component getDisplayName() { - return createTranslation("block", "disk_drive"); + return ContentNames.DISK_DRIVE; } @Override diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/exporter/ExporterBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/exporter/ExporterBlockEntity.java index cd9be6ecb..1dd5071d4 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/exporter/ExporterBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/exporter/ExporterBlockEntity.java @@ -11,6 +11,7 @@ import com.refinedmods.refinedstorage2.platform.common.block.entity.AbstractSchedulingNetworkNodeContainerBlockEntity; import com.refinedmods.refinedstorage2.platform.common.containermenu.ExporterContainerMenu; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; +import com.refinedmods.refinedstorage2.platform.common.content.ContentNames; import com.refinedmods.refinedstorage2.platform.common.content.Items; import com.refinedmods.refinedstorage2.platform.common.internal.upgrade.UpgradeDestinations; @@ -29,8 +30,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; - public class ExporterBlockEntity extends AbstractSchedulingNetworkNodeContainerBlockEntity implements AmountOverride { @@ -80,7 +79,7 @@ protected void setEnergyUsage(final long upgradeEnergyUsage) { @Override public Component getDisplayName() { - return createTranslation("block", "exporter"); + return ContentNames.EXPORTER; } @Nullable diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/externalstorage/ExternalStorageBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/externalstorage/ExternalStorageBlockEntity.java index 81888eadd..94bebab8c 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/externalstorage/ExternalStorageBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/externalstorage/ExternalStorageBlockEntity.java @@ -11,6 +11,7 @@ import com.refinedmods.refinedstorage2.platform.common.block.entity.StorageConfigurationContainerImpl; import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.ExternalStorageContainerMenu; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; +import com.refinedmods.refinedstorage2.platform.common.content.ContentNames; import com.refinedmods.refinedstorage2.platform.common.internal.resource.ResourceContainerImpl; import com.refinedmods.refinedstorage2.platform.common.menu.ExtendedMenuProvider; @@ -33,8 +34,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; - public class ExternalStorageBlockEntity extends AbstractInternalNetworkNodeContainerBlockEntity implements ExtendedMenuProvider { @@ -155,7 +154,7 @@ public void writeScreenOpeningData(final ServerPlayer player, final FriendlyByte @Override public Component getDisplayName() { - return createTranslation("block", "external_storage"); + return ContentNames.EXTERNAL_STORAGE; } @Nullable diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/grid/CraftingGridBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/grid/CraftingGridBlockEntity.java index 733451ef6..54900e49e 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/grid/CraftingGridBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/grid/CraftingGridBlockEntity.java @@ -11,6 +11,7 @@ import com.refinedmods.refinedstorage2.platform.common.containermenu.grid.AbstractGridContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.grid.CraftingGridContainerMenu; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; +import com.refinedmods.refinedstorage2.platform.common.content.ContentNames; import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; import com.refinedmods.refinedstorage2.platform.common.util.ContainerUtil; @@ -30,8 +31,6 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; -import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; - public class CraftingGridBlockEntity extends AbstractGridBlockEntity { private static final String TAG_CRAFTING_MATRIX = "matrix"; @@ -101,7 +100,7 @@ public NonNullList getRemainingItems(final Player player) { @Override public Component getDisplayName() { - return createTranslation("block", "crafting_grid"); + return ContentNames.CRAFTING_GRID; } @Override diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/grid/GridBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/grid/GridBlockEntity.java index 702ac5de2..5a31f7b21 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/grid/GridBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/grid/GridBlockEntity.java @@ -4,6 +4,7 @@ import com.refinedmods.refinedstorage2.platform.common.containermenu.grid.AbstractGridContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.grid.GridContainerMenu; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; +import com.refinedmods.refinedstorage2.platform.common.content.ContentNames; import javax.annotation.Nullable; @@ -13,8 +14,6 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.block.state.BlockState; -import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; - public class GridBlockEntity extends AbstractGridBlockEntity { public GridBlockEntity(final BlockPos pos, final BlockState state) { super(BlockEntities.INSTANCE.getGrid(), pos, state, Platform.INSTANCE.getConfig().getGrid().getEnergyUsage()); @@ -22,7 +21,7 @@ public GridBlockEntity(final BlockPos pos, final BlockState state) { @Override public Component getDisplayName() { - return createTranslation("block", "grid"); + return ContentNames.GRID; } @Override diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/iface/InterfaceBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/iface/InterfaceBlockEntity.java index 61e921fd1..9edacdb05 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/iface/InterfaceBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/iface/InterfaceBlockEntity.java @@ -15,6 +15,7 @@ import com.refinedmods.refinedstorage2.platform.common.block.entity.FilterWithFuzzyMode; import com.refinedmods.refinedstorage2.platform.common.containermenu.InterfaceContainerMenu; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; +import com.refinedmods.refinedstorage2.platform.common.content.ContentNames; import com.refinedmods.refinedstorage2.platform.common.internal.resource.ResourceContainerImpl; import com.refinedmods.refinedstorage2.platform.common.menu.ExtendedMenuProvider; @@ -35,8 +36,6 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.state.BlockState; -import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; - public class InterfaceBlockEntity extends AbstractInternalNetworkNodeContainerBlockEntity implements ExtendedMenuProvider, BlockEntityWithDrops { @@ -157,7 +156,7 @@ public void writeScreenOpeningData(final ServerPlayer player, final FriendlyByte @Override public Component getDisplayName() { - return createTranslation("block", "interface"); + return ContentNames.INTERFACE; } @Override diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/CompositeStorageMonitorExtractionStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/CompositeStorageMonitorExtractionStrategy.java new file mode 100644 index 000000000..48472b1aa --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/CompositeStorageMonitorExtractionStrategy.java @@ -0,0 +1,32 @@ +package com.refinedmods.refinedstorage2.platform.common.block.entity.storagemonitor; + +import com.refinedmods.refinedstorage2.api.network.Network; +import com.refinedmods.refinedstorage2.api.storage.Actor; +import com.refinedmods.refinedstorage2.platform.api.blockentity.storagemonitor.StorageMonitorExtractionStrategy; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.world.entity.player.Player; + +public class CompositeStorageMonitorExtractionStrategy implements StorageMonitorExtractionStrategy { + private final List strategies = new ArrayList<>(); + + public void addStrategy(final StorageMonitorExtractionStrategy strategy) { + strategies.add(strategy); + } + + @Override + public boolean extract(final Object resource, + final boolean fullStack, + final Player player, + final Actor actor, + final Network network) { + for (final StorageMonitorExtractionStrategy strategy : strategies) { + if (strategy.extract(resource, fullStack, player, actor, network)) { + return true; + } + } + return false; + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/CompositeStorageMonitorInsertionStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/CompositeStorageMonitorInsertionStrategy.java new file mode 100644 index 000000000..95e98fdd1 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/CompositeStorageMonitorInsertionStrategy.java @@ -0,0 +1,31 @@ +package com.refinedmods.refinedstorage2.platform.common.block.entity.storagemonitor; + +import com.refinedmods.refinedstorage2.api.network.Network; +import com.refinedmods.refinedstorage2.api.storage.Actor; +import com.refinedmods.refinedstorage2.platform.api.blockentity.storagemonitor.StorageMonitorInsertionStrategy; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import net.minecraft.world.item.ItemStack; + +public class CompositeStorageMonitorInsertionStrategy implements StorageMonitorInsertionStrategy { + private final List strategies = new ArrayList<>(); + + public void addStrategy(final StorageMonitorInsertionStrategy strategy) { + strategies.add(strategy); + } + + @Override + public Optional insert( + final Object configuredResource, + final ItemStack stack, + final Actor actor, + final Network network + ) { + return strategies.stream() + .flatMap(strategy -> strategy.insert(configuredResource, stack, actor, network).stream()) + .findFirst(); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/FluidStorageMonitorExtractionStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/FluidStorageMonitorExtractionStrategy.java new file mode 100644 index 000000000..629dfc662 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/FluidStorageMonitorExtractionStrategy.java @@ -0,0 +1,42 @@ +package com.refinedmods.refinedstorage2.platform.common.block.entity.storagemonitor; + +import com.refinedmods.refinedstorage2.api.network.Network; +import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.storage.Actor; +import com.refinedmods.refinedstorage2.api.storage.TransferHelper; +import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; +import com.refinedmods.refinedstorage2.platform.api.blockentity.storagemonitor.StorageMonitorExtractionStrategy; +import com.refinedmods.refinedstorage2.platform.api.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.common.Platform; +import com.refinedmods.refinedstorage2.platform.common.internal.storage.BucketPlayerInventoryInsertableStorage; +import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; + +import net.minecraft.world.entity.player.Player; + +public class FluidStorageMonitorExtractionStrategy implements StorageMonitorExtractionStrategy { + @Override + public boolean extract(final Object resource, + final boolean fullStack, + final Player player, + final Actor actor, + final Network network) { + if (!(resource instanceof FluidResource fluidResource)) { + return false; + } + final BucketPlayerInventoryInsertableStorage target = new BucketPlayerInventoryInsertableStorage( + player.getInventory(), + network.getComponent(StorageNetworkComponent.class).getStorageChannel(StorageChannelTypes.ITEM), + true + ); + final StorageChannel source = network.getComponent(StorageNetworkComponent.class) + .getStorageChannel(StorageChannelTypes.FLUID); + return TransferHelper.transfer( + fluidResource, + Platform.INSTANCE.getBucketAmount(), + actor, + source, + target, + source + ) > 0; + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/FluidStorageMonitorInsertionStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/FluidStorageMonitorInsertionStrategy.java new file mode 100644 index 000000000..35a7ed952 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/FluidStorageMonitorInsertionStrategy.java @@ -0,0 +1,69 @@ +package com.refinedmods.refinedstorage2.platform.common.block.entity.storagemonitor; + +import com.refinedmods.refinedstorage2.api.core.Action; +import com.refinedmods.refinedstorage2.api.network.Network; +import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; +import com.refinedmods.refinedstorage2.api.storage.Actor; +import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; +import com.refinedmods.refinedstorage2.platform.api.blockentity.storagemonitor.StorageMonitorInsertionStrategy; +import com.refinedmods.refinedstorage2.platform.api.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.common.ContainedFluid; +import com.refinedmods.refinedstorage2.platform.common.Platform; +import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; + +import java.util.Optional; +import javax.annotation.Nullable; + +import net.minecraft.world.item.ItemStack; + +public class FluidStorageMonitorInsertionStrategy implements StorageMonitorInsertionStrategy { + @Override + public Optional insert( + final Object configuredResource, + final ItemStack stack, + final Actor actor, + final Network network + ) { + if (!(configuredResource instanceof FluidResource configuredFluidResource)) { + return Optional.empty(); + } + final StorageChannel fluidStorageChannel = network.getComponent(StorageNetworkComponent.class) + .getStorageChannel(StorageChannelTypes.FLUID); + return Platform.INSTANCE.getContainedFluid(stack) + .map(extracted -> tryInsert(actor, configuredFluidResource, extracted, fluidStorageChannel)) + .map(extracted -> doInsert(actor, extracted, fluidStorageChannel)); + } + + @Nullable + private ContainedFluid tryInsert(final Actor actor, + final FluidResource configuredResource, + final ContainedFluid result, + final StorageChannel storageChannel) { + final ResourceAmount fluid = result.fluid(); + if (!fluid.getResource().equals(configuredResource)) { + return null; + } + final long insertedSimulated = storageChannel.insert( + fluid.getResource(), + fluid.getAmount(), + Action.SIMULATE, + actor + ); + final boolean insertedSuccessfully = insertedSimulated == fluid.getAmount(); + return insertedSuccessfully ? result : null; + } + + private ItemStack doInsert(final Actor actor, + final ContainedFluid extracted, + final StorageChannel storageChannel) { + final ResourceAmount fluid = extracted.fluid(); + storageChannel.insert( + fluid.getResource(), + fluid.getAmount(), + Action.EXECUTE, + actor + ); + return extracted.remainderContainer(); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/InsertTracker.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/InsertTracker.java new file mode 100644 index 000000000..87d42cdee --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/InsertTracker.java @@ -0,0 +1,37 @@ +package com.refinedmods.refinedstorage2.platform.common.block.entity.storagemonitor; + +import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; + +import com.mojang.authlib.GameProfile; +import net.minecraft.world.item.ItemStack; + +class InsertTracker { + private static final long MAX_DELAY = 500; + + private final Map entries = new HashMap<>(); + + public void trackInsertedItem(final GameProfile gameProfile, final ItemStack stack) { + entries.put(gameProfile.getId(), new Entry(System.currentTimeMillis(), ItemResource.ofItemStack(stack))); + } + + public Optional getLastInsertedItem(final GameProfile gameProfile) { + final Entry entry = entries.get(gameProfile.getId()); + if (entry == null) { + return Optional.empty(); + } + final long time = System.currentTimeMillis(); + if (time - entry.time > MAX_DELAY) { + entries.remove(gameProfile.getId()); + return Optional.empty(); + } + return Optional.of(entry.itemResource); + } + + private record Entry(long time, ItemResource itemResource) { + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/ItemStorageMonitorExtractionStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/ItemStorageMonitorExtractionStrategy.java new file mode 100644 index 000000000..4338802e2 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/ItemStorageMonitorExtractionStrategy.java @@ -0,0 +1,36 @@ +package com.refinedmods.refinedstorage2.platform.common.block.entity.storagemonitor; + +import com.refinedmods.refinedstorage2.api.core.Action; +import com.refinedmods.refinedstorage2.api.network.Network; +import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.storage.Actor; +import com.refinedmods.refinedstorage2.platform.api.blockentity.storagemonitor.StorageMonitorExtractionStrategy; +import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; + +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; + +public class ItemStorageMonitorExtractionStrategy implements StorageMonitorExtractionStrategy { + @Override + public boolean extract(final Object resource, + final boolean fullStack, + final Player player, + final Actor actor, + final Network network) { + if (!(resource instanceof ItemResource itemResource)) { + return false; + } + final long extracted = network.getComponent(StorageNetworkComponent.class) + .getStorageChannel(StorageChannelTypes.ITEM) + .extract(itemResource, fullStack ? itemResource.item().getMaxStackSize() : 1, Action.EXECUTE, actor); + if (extracted > 0) { + final ItemStack stack = itemResource.toItemStack(extracted); + if (!player.getInventory().add(stack)) { + player.drop(stack, false); + } + return true; + } + return false; + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/ItemStorageMonitorInsertionStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/ItemStorageMonitorInsertionStrategy.java new file mode 100644 index 000000000..297741a93 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/ItemStorageMonitorInsertionStrategy.java @@ -0,0 +1,37 @@ +package com.refinedmods.refinedstorage2.platform.common.block.entity.storagemonitor; + +import com.refinedmods.refinedstorage2.api.core.Action; +import com.refinedmods.refinedstorage2.api.network.Network; +import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.storage.Actor; +import com.refinedmods.refinedstorage2.platform.api.blockentity.storagemonitor.StorageMonitorInsertionStrategy; +import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; + +import java.util.Optional; + +import net.minecraft.world.item.ItemStack; + +public class ItemStorageMonitorInsertionStrategy implements StorageMonitorInsertionStrategy { + @Override + public Optional insert(final Object configuredResource, + final ItemStack stack, + final Actor actor, + final Network network) { + if (!(configuredResource instanceof ItemResource configuredItemResource)) { + return Optional.empty(); + } + final ItemResource resource = ItemResource.ofItemStack(stack); + if (!configuredItemResource.equals(resource)) { + return Optional.empty(); + } + final long inserted = network.getComponent(StorageNetworkComponent.class) + .getStorageChannel(StorageChannelTypes.ITEM) + .insert(resource, stack.getCount(), Action.EXECUTE, actor); + final long remainder = stack.getCount() - inserted; + if (remainder > 0) { + return Optional.of(resource.toItemStack(remainder)); + } + return Optional.of(ItemStack.EMPTY); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/StorageMonitorBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/StorageMonitorBlockEntity.java new file mode 100644 index 000000000..21586c41c --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/StorageMonitorBlockEntity.java @@ -0,0 +1,317 @@ +package com.refinedmods.refinedstorage2.platform.common.block.entity.storagemonitor; + +import com.refinedmods.refinedstorage2.api.network.Network; +import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.impl.node.SimpleNetworkNode; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; +import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; +import com.refinedmods.refinedstorage2.platform.api.PlatformApi; +import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.api.resource.ResourceAmountTemplate; +import com.refinedmods.refinedstorage2.platform.api.resource.ResourceContainer; +import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; +import com.refinedmods.refinedstorage2.platform.api.storage.channel.FuzzyStorageChannel; +import com.refinedmods.refinedstorage2.platform.common.Platform; +import com.refinedmods.refinedstorage2.platform.common.block.entity.AbstractInternalNetworkNodeContainerBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.block.entity.FilterWithFuzzyMode; +import com.refinedmods.refinedstorage2.platform.common.containermenu.StorageMonitorContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; +import com.refinedmods.refinedstorage2.platform.common.content.ContentNames; +import com.refinedmods.refinedstorage2.platform.common.internal.resource.ResourceContainerImpl; +import com.refinedmods.refinedstorage2.platform.common.menu.ExtendedMenuProvider; + +import javax.annotation.Nullable; + +import com.google.common.util.concurrent.RateLimiter; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class StorageMonitorBlockEntity extends AbstractInternalNetworkNodeContainerBlockEntity + implements ExtendedMenuProvider { + private static final Logger LOGGER = LoggerFactory.getLogger(StorageMonitorBlockEntity.class); + + private static final String TAG_CLIENT_FILTER = "cf"; + private static final String TAG_CLIENT_AMOUNT = "ca"; + private static final String TAG_CLIENT_ACTIVE = "cac"; + + private final FilterWithFuzzyMode filter; + private final RateLimiter displayUpdateRateLimiter = RateLimiter.create(0.25); + private final InsertTracker insertTracker = new InsertTracker(); + + private long currentAmount; + private boolean currentlyActive; + + public StorageMonitorBlockEntity(final BlockPos pos, final BlockState state) { + super(BlockEntities.INSTANCE.getStorageMonitor(), pos, state, new SimpleNetworkNode( + Platform.INSTANCE.getConfig().getStorageMonitor().getEnergyUsage() + )); + final ResourceContainer resourceContainer = ResourceContainerImpl.createForFilter(1); + this.filter = FilterWithFuzzyMode.create(resourceContainer, () -> { + setChanged(); + if (level != null) { + sendDisplayUpdate(level, getAmount(), getNode().isActive()); + } + }); + } + + @Override + public void doWork() { + super.doWork(); + if (level == null) { + return; + } + trySendDisplayUpdate(level); + } + + private void trySendDisplayUpdate(final Level level) { + final long amount = getAmount(); + final boolean active = getNode().isActive(); + if ((amount != currentAmount || active != currentlyActive) && displayUpdateRateLimiter.tryAcquire()) { + sendDisplayUpdate(level, amount, active); + } + } + + private long getAmount() { + final ResourceAmountTemplate template = filter.getFilterContainer().get(0); + if (template == null) { + return 0; + } + final Network network = getNode().getNetwork(); + if (network == null) { + return 0; + } + return getAmount(network, template); + } + + private long getAmount(final Network network, final ResourceAmountTemplate template) { + final StorageChannel storageChannel = network.getComponent(StorageNetworkComponent.class) + .getStorageChannel(template.getStorageChannelType()); + if (!filter.isFuzzyMode() || !(storageChannel instanceof FuzzyStorageChannel fuzzyStorageChannel)) { + return storageChannel.get(template.getResource()).map(ResourceAmount::getAmount).orElse(0L); + } + return fuzzyStorageChannel.getFuzzy(template.getResource()).stream().mapToLong(ResourceAmount::getAmount).sum(); + } + + public void extract(final Player player) { + if (level == null) { + return; + } + final Network network = getNode().getNetwork(); + if (network == null) { + return; + } + final ResourceAmountTemplate template = getFilteredResource(); + if (template == null) { + return; + } + extract(level, player, template.getResource(), network); + } + + private void extract( + final Level level, + final Player player, + final T template, + final Network network + ) { + final boolean success = PlatformApi.INSTANCE.getStorageMonitorExtractionStrategy().extract( + template, + !player.isShiftKeyDown(), + player, + new PlayerActor(player), + network + ); + if (!success) { + return; + } + sendDisplayUpdate(level, getAmount(), getNode().isActive()); + level.playSound( + null, + getBlockPos(), + SoundEvents.ITEM_PICKUP, + SoundSource.PLAYERS, + .2f, + ((level.random.nextFloat() - level.random.nextFloat()) * .7f + 1) * 2 + ); + } + + public void insert(final Player player, final InteractionHand hand) { + if (level != null && doInsert(player, hand)) { + sendDisplayUpdate(level, getAmount(), getNode().isActive()); + } + } + + private boolean doInsert(final Player player, final InteractionHand hand) { + final Network network = getNode().getNetwork(); + if (network == null) { + return false; + } + final ResourceAmountTemplate template = getFilteredResource(); + if (template == null) { + return false; + } + final ItemStack heldStack = player.getItemInHand(hand); + if (heldStack.isEmpty()) { + return doInsertAll(player); + } + return doInsert(player, hand, heldStack, template.getResource(), network); + } + + private boolean doInsert( + final Player player, + final InteractionHand hand, + final ItemStack heldStack, + final T template, + final Network network + ) { + return PlatformApi.INSTANCE.getStorageMonitorInsertionStrategy().insert( + template, + heldStack, + new PlayerActor(player), + network + ).map(result -> { + insertTracker.trackInsertedItem(player.getGameProfile(), heldStack); + player.setItemInHand(hand, result); + return true; + }).orElse(false); + } + + private boolean doInsertAll(final Player player) { + return insertTracker.getLastInsertedItem(player.getGameProfile()).map( + item -> doInsertAll(player, item) + ).orElse(false); + } + + private boolean doInsertAll(final Player player, final ItemResource lastInsertedItem) { + final Network network = getNode().getNetwork(); + if (network == null) { + return false; + } + final ResourceAmountTemplate template = getFilteredResource(); + if (template == null) { + return false; + } + boolean success = false; + for (int i = 0; i < player.getInventory().getContainerSize(); ++i) { + success |= tryInsertSlot(player, lastInsertedItem, i, template.getResource(), network); + } + return success; + } + + private boolean tryInsertSlot( + final Player player, + final ItemResource lastInsertedItem, + final int inventorySlotIndex, + final T template, + final Network network + ) { + final ItemStack slot = player.getInventory().getItem(inventorySlotIndex); + if (slot.isEmpty()) { + return false; + } + final ItemResource itemInSlot = ItemResource.ofItemStack(slot); + if (!itemInSlot.equals(lastInsertedItem)) { + return false; + } + return PlatformApi.INSTANCE.getStorageMonitorInsertionStrategy().insert( + template, + slot, + new PlayerActor(player), + network + ).map(result -> { + player.getInventory().setItem(inventorySlotIndex, result); + return true; + }).orElse(false); + } + + public boolean isFuzzyMode() { + return filter.isFuzzyMode(); + } + + public void setFuzzyMode(final boolean fuzzyMode) { + filter.setFuzzyMode(fuzzyMode); + } + + @Nullable + public ResourceAmountTemplate getFilteredResource() { + return filter.getFilterContainer().get(0); + } + + public long getCurrentAmount() { + return currentAmount; + } + + public boolean isCurrentlyActive() { + return currentlyActive; + } + + @Override + public void saveAdditional(final CompoundTag tag) { + super.saveAdditional(tag); + filter.save(tag); + } + + @Override + public void load(final CompoundTag tag) { + if (tag.contains(TAG_CLIENT_FILTER) && tag.contains(TAG_CLIENT_AMOUNT) && tag.contains(TAG_CLIENT_ACTIVE)) { + filter.getFilterContainer().fromTag(tag.getCompound(TAG_CLIENT_FILTER)); + currentAmount = tag.getLong(TAG_CLIENT_AMOUNT); + currentlyActive = tag.getBoolean(TAG_CLIENT_ACTIVE); + } else { + filter.load(tag); + } + super.load(tag); + } + + @Override + public void writeScreenOpeningData(final ServerPlayer player, final FriendlyByteBuf buf) { + filter.getFilterContainer().writeToUpdatePacket(buf); + } + + @Override + public Component getDisplayName() { + return ContentNames.STORAGE_MONITOR; + } + + @Nullable + @Override + public AbstractContainerMenu createMenu(final int syncId, final Inventory inventory, final Player player) { + return new StorageMonitorContainerMenu(syncId, player, this, filter.getFilterContainer()); + } + + @Override + public ClientboundBlockEntityDataPacket getUpdatePacket() { + return ClientboundBlockEntityDataPacket.create(this); + } + + @Override + public CompoundTag getUpdateTag() { + final CompoundTag tag = new CompoundTag(); + tag.put(TAG_CLIENT_FILTER, filter.getFilterContainer().toTag()); + tag.putLong(TAG_CLIENT_AMOUNT, currentAmount); + tag.putBoolean(TAG_CLIENT_ACTIVE, currentlyActive); + return tag; + } + + private void sendDisplayUpdate(final Level level, final long amount, final boolean active) { + currentAmount = amount; + currentlyActive = active; + level.sendBlockUpdated(worldPosition, getBlockState(), getBlockState(), Block.UPDATE_ALL); + LOGGER.info("Sending display update for storage monitor {} with amount {}", worldPosition, amount); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/package-info.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/package-info.java new file mode 100644 index 000000000..acaf1c2fe --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/package-info.java @@ -0,0 +1,7 @@ +@ParametersAreNonnullByDefault +@FieldsAndMethodsAreNonnullByDefault +package com.refinedmods.refinedstorage2.platform.common.block.entity.storagemonitor; + +import com.refinedmods.refinedstorage2.api.core.FieldsAndMethodsAreNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/StorageMonitorContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/StorageMonitorContainerMenu.java new file mode 100644 index 000000000..ab288c604 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/StorageMonitorContainerMenu.java @@ -0,0 +1,54 @@ +package com.refinedmods.refinedstorage2.platform.common.containermenu; + +import com.refinedmods.refinedstorage2.platform.api.resource.ResourceContainer; +import com.refinedmods.refinedstorage2.platform.common.block.entity.storagemonitor.StorageMonitorBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.containermenu.property.ClientProperty; +import com.refinedmods.refinedstorage2.platform.common.containermenu.property.PropertyTypes; +import com.refinedmods.refinedstorage2.platform.common.containermenu.property.ServerProperty; +import com.refinedmods.refinedstorage2.platform.common.containermenu.slot.ResourceSlot; +import com.refinedmods.refinedstorage2.platform.common.content.Menus; +import com.refinedmods.refinedstorage2.platform.common.internal.resource.ResourceContainerImpl; +import com.refinedmods.refinedstorage2.platform.common.util.RedstoneMode; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; + +import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; + +public class StorageMonitorContainerMenu extends AbstractResourceContainerMenu { + private static final Component FILTER_HELP = createTranslation("gui", "storage_monitor.filter_help"); + + public StorageMonitorContainerMenu(final int syncId, final Inventory playerInventory, final FriendlyByteBuf buf) { + super(Menus.INSTANCE.getStorageMonitor(), syncId); + registerProperty(new ClientProperty<>(PropertyTypes.FUZZY_MODE, false)); + registerProperty(new ClientProperty<>(PropertyTypes.REDSTONE_MODE, RedstoneMode.IGNORE)); + addSlots(playerInventory, ResourceContainerImpl.createForFilter(1)); + initializeResourceSlots(buf); + } + + public StorageMonitorContainerMenu(final int syncId, + final Player player, + final StorageMonitorBlockEntity storageMonitor, + final ResourceContainer resourceContainer) { + super(Menus.INSTANCE.getStorageMonitor(), syncId, player); + registerProperty(new ServerProperty<>( + PropertyTypes.FUZZY_MODE, + storageMonitor::isFuzzyMode, + storageMonitor::setFuzzyMode + )); + registerProperty(new ServerProperty<>( + PropertyTypes.REDSTONE_MODE, + storageMonitor::getRedstoneMode, + storageMonitor::setRedstoneMode + )); + addSlots(player.getInventory(), resourceContainer); + } + + private void addSlots(final Inventory playerInventory, final ResourceContainer resourceContainer) { + addSlot(new ResourceSlot(resourceContainer, 0, FILTER_HELP, 80, 20)); + addPlayerInventory(playerInventory, 8, 55); + transferManager.addFilterTransfer(playerInventory); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/BlockEntities.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/BlockEntities.java index 9ca78ce92..2a0bee746 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/BlockEntities.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/BlockEntities.java @@ -14,6 +14,7 @@ import com.refinedmods.refinedstorage2.platform.common.block.entity.iface.InterfaceBlockEntity; import com.refinedmods.refinedstorage2.platform.common.block.entity.storage.FluidStorageBlockBlockEntity; import com.refinedmods.refinedstorage2.platform.common.block.entity.storage.ItemStorageBlockBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.block.entity.storagemonitor.StorageMonitorBlockEntity; import com.refinedmods.refinedstorage2.platform.common.block.entity.wirelesstransmitter.WirelessTransmitterBlockEntity; import com.refinedmods.refinedstorage2.platform.common.internal.storage.type.FluidStorageType; import com.refinedmods.refinedstorage2.platform.common.internal.storage.type.ItemStorageType; @@ -61,6 +62,8 @@ public final class BlockEntities { private Supplier> constructor; @Nullable private Supplier> wirelessTransmitter; + @Nullable + private Supplier> storageMonitor; private BlockEntities() { } @@ -194,4 +197,12 @@ public BlockEntityType getWirelessTransmitter() public void setWirelessTransmitter(final Supplier> supplier) { this.wirelessTransmitter = supplier; } + + public BlockEntityType getStorageMonitor() { + return Objects.requireNonNull(storageMonitor).get(); + } + + public void setStorageMonitor(final Supplier> supplier) { + this.storageMonitor = supplier; + } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Blocks.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Blocks.java index c4da073cc..18c5e28d4 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Blocks.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Blocks.java @@ -14,6 +14,7 @@ import com.refinedmods.refinedstorage2.platform.common.block.InterfaceBlock; import com.refinedmods.refinedstorage2.platform.common.block.ItemStorageBlock; import com.refinedmods.refinedstorage2.platform.common.block.SimpleBlock; +import com.refinedmods.refinedstorage2.platform.common.block.StorageMonitorBlock; import com.refinedmods.refinedstorage2.platform.common.block.WirelessTransmitterBlock; import com.refinedmods.refinedstorage2.platform.common.block.grid.CraftingGridBlock; import com.refinedmods.refinedstorage2.platform.common.block.grid.GridBlock; @@ -129,6 +130,8 @@ public final class Blocks { new EnumMap<>(FluidStorageType.Variant.class); @Nullable private Supplier iface; + @Nullable + private Supplier storageMonitor; private Blocks() { } @@ -229,4 +232,12 @@ public BlockColorMap getConstructor() { public BlockColorMap getWirelessTransmitter() { return wirelessTransmitter; } + + public void setStorageMonitor(final Supplier supplier) { + this.storageMonitor = supplier; + } + + public StorageMonitorBlock getStorageMonitor() { + return Objects.requireNonNull(storageMonitor).get(); + } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/ContentIds.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/ContentIds.java index 1ea0d646c..cd3f251c8 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/ContentIds.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/ContentIds.java @@ -47,6 +47,7 @@ public final class ContentIds { public static final ResourceLocation WIRELESS_TRANSMITTER = createIdentifier("wireless_transmitter"); public static final ResourceLocation RANGE_UPGRADE = createIdentifier("range_upgrade"); public static final ResourceLocation CREATIVE_RANGE_UPGRADE = createIdentifier("creative_range_upgrade"); + public static final ResourceLocation STORAGE_MONITOR = createIdentifier("storage_monitor"); private ContentIds() { } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/ContentNames.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/ContentNames.java index f4227d9d3..b1ac504ec 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/ContentNames.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/ContentNames.java @@ -18,6 +18,10 @@ public final class ContentNames { public static final MutableComponent CREATIVE_CONTROLLER = createTranslation("block", "creative_controller"); public static final MutableComponent WIRELESS_GRID = createTranslation("item", "wireless_grid"); public static final MutableComponent WIRELESS_TRANSMITTER = createTranslation("block", "wireless_transmitter"); + public static final MutableComponent REGULATOR_UPGRADE = createTranslation("block", "regulator_upgrade"); + public static final MutableComponent STORAGE_MONITOR = createTranslation("block", "storage_monitor"); + public static final MutableComponent INTERFACE = createTranslation("block", "interface"); + public static final MutableComponent DISK_DRIVE = createTranslation("block", "disk_drive"); private ContentNames() { } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/CreativeModeTabItems.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/CreativeModeTabItems.java index a4803c336..5af4cd217 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/CreativeModeTabItems.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/CreativeModeTabItems.java @@ -46,6 +46,7 @@ private static void appendBlocks(final Consumer consumer) { )); itemConsumer.accept(Blocks.INSTANCE.getMachineCasing()); itemConsumer.accept(Blocks.INSTANCE.getQuartzEnrichedIronBlock()); + itemConsumer.accept(Blocks.INSTANCE.getStorageMonitor()); } private static void appendBlockColors(final Consumer consumer, final BlockColorMap map) { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/DefaultEnergyUsage.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/DefaultEnergyUsage.java index 86f47ed85..ba04bd65e 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/DefaultEnergyUsage.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/DefaultEnergyUsage.java @@ -13,6 +13,8 @@ public final class DefaultEnergyUsage { public static final long CONSTRUCTOR = 3; public static final long DESTRUCTOR = 3; public static final long DISK_DRIVE_PER_DISK = 4; + public static final long STORAGE_MONITOR = 4; + public static final long CONTROLLER_CAPACITY = 1000; public static final long ONE_K_STORAGE_BLOCK = 2; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Menus.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Menus.java index 881c21eec..671b2ba41 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Menus.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Menus.java @@ -7,6 +7,7 @@ import com.refinedmods.refinedstorage2.platform.common.containermenu.ImporterContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.InterfaceContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.RegulatorUpgradeContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.containermenu.StorageMonitorContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.WirelessTransmitterContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.detector.DetectorContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.grid.CraftingGridContainerMenu; @@ -58,6 +59,8 @@ public final class Menus { private Supplier> regulatorUpgrade; @Nullable private Supplier> wirelessTransmitter; + @Nullable + private Supplier> storageMonitor; private Menus() { } @@ -189,4 +192,12 @@ public MenuType getWirelessTransmitter() { public void setWirelessTransmitter(final Supplier> supplier) { this.wirelessTransmitter = supplier; } + + public MenuType getStorageMonitor() { + return Objects.requireNonNull(storageMonitor).get(); + } + + public void setStorageMonitor(final Supplier> supplier) { + this.storageMonitor = supplier; + } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/FluidResourceFactory.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/FluidResourceFactory.java index 19b42aecd..ffe9b8705 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/FluidResourceFactory.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/FluidResourceFactory.java @@ -13,8 +13,8 @@ public class FluidResourceFactory implements ResourceFactory { @Override public Optional> create(final ItemStack stack) { - return Platform.INSTANCE.convertToFluid(stack).map(resourceAmount -> new ResourceAmountTemplate<>( - resourceAmount.getResource(), + return Platform.INSTANCE.getContainedFluid(stack).map(result -> new ResourceAmountTemplate<>( + result.fluid().getResource(), Platform.INSTANCE.getBucketAmount(), StorageChannelTypes.FLUID )); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/FluidResourceRendering.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/FluidResourceRendering.java index f01109dbf..d004a4336 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/FluidResourceRendering.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/FluidResourceRendering.java @@ -6,12 +6,18 @@ import java.util.List; +import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.network.chat.Component; +import net.minecraft.world.level.Level; public class FluidResourceRendering implements ResourceRendering { @Override - public String getDisplayedAmount(final long amount) { + public String getDisplayedAmount(final long amount, final boolean withUnits) { + if (!withUnits) { + return Platform.INSTANCE.getBucketAmountFormatter().format(amount); + } return Platform.INSTANCE.getBucketAmountFormatter().formatWithUnits(amount); } @@ -29,4 +35,13 @@ public List getTooltip(final FluidResource resource) { public void render(final FluidResource resource, final GuiGraphics graphics, final int x, final int y) { Platform.INSTANCE.getFluidRenderer().render(graphics.pose(), x, y, resource); } + + @Override + public void render(final FluidResource resource, + final PoseStack poseStack, + final MultiBufferSource renderTypeBuffer, + final int light, + final Level level) { + Platform.INSTANCE.getFluidRenderer().render(poseStack, renderTypeBuffer, light, resource); + } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/ItemResourceRendering.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/ItemResourceRendering.java index 07aac7529..e54703dbc 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/ItemResourceRendering.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/ItemResourceRendering.java @@ -10,13 +10,21 @@ import java.util.List; import java.util.Map; +import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.network.chat.Component; +import net.minecraft.util.Mth; +import net.minecraft.world.item.ItemDisplayContext; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.level.Level; +import org.joml.Matrix4f; public class ItemResourceRendering implements ResourceRendering { + public static final Matrix4f IN_WORLD_SCALE = new Matrix4f().scale(0.3F, 0.3F, 0.001f); private final Map stackCache = new HashMap<>(); private ItemStack getStack(final ItemResource itemResource) { @@ -24,7 +32,10 @@ private ItemStack getStack(final ItemResource itemResource) { } @Override - public String getDisplayedAmount(final long amount) { + public String getDisplayedAmount(final long amount, final boolean withUnits) { + if (!withUnits) { + return AmountFormatting.format(amount); + } if (amount == 1) { return ""; } @@ -51,4 +62,25 @@ public void render(final ItemResource resource, final GuiGraphics graphics, fina graphics.renderItem(stack, x, y); graphics.renderItemDecorations(Minecraft.getInstance().font, stack, x, y); } + + @Override + public void render(final ItemResource resource, + final PoseStack poseStack, + final MultiBufferSource renderTypeBuffer, + final int light, + final Level level) { + final ItemStack itemStack = getStack(resource); + poseStack.mulPoseMatrix(IN_WORLD_SCALE); + poseStack.last().normal().rotateX(Mth.DEG_TO_RAD * -45f); + Minecraft.getInstance().getItemRenderer().renderStatic( + itemStack, + ItemDisplayContext.GUI, + light, + OverlayTexture.NO_OVERLAY, + poseStack, + renderTypeBuffer, + level, + 0 + ); + } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/ResourceContainerImpl.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/ResourceContainerImpl.java index 00f7353ee..944ee6d36 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/ResourceContainerImpl.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/ResourceContainerImpl.java @@ -267,6 +267,7 @@ public void fromTag(final CompoundTag tag) { for (int i = 0; i < size(); ++i) { final String key = "s" + i; if (!tag.contains(key)) { + removeSilently(i); continue; } final CompoundTag item = tag.getCompound(key); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/storage/BucketPlayerInventoryInsertableStorage.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/storage/BucketPlayerInventoryInsertableStorage.java new file mode 100644 index 000000000..f102d74e2 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/storage/BucketPlayerInventoryInsertableStorage.java @@ -0,0 +1,89 @@ +package com.refinedmods.refinedstorage2.platform.common.internal.storage; + +import com.refinedmods.refinedstorage2.api.core.Action; +import com.refinedmods.refinedstorage2.api.storage.Actor; +import com.refinedmods.refinedstorage2.api.storage.InsertableStorage; +import com.refinedmods.refinedstorage2.api.storage.Storage; +import com.refinedmods.refinedstorage2.platform.api.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.common.Platform; + +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; + +public class BucketPlayerInventoryInsertableStorage implements InsertableStorage { + private static final ItemStack EMPTY_BUCKET_STACK = new ItemStack(Items.BUCKET); + private static final ItemResource EMPTY_BUCKET_RESOURCE = ItemResource.ofItemStack(EMPTY_BUCKET_STACK); + + private final Inventory playerInventory; + private final Storage emptyBucketStorage; + private final boolean mayDropFilledBucket; + + public BucketPlayerInventoryInsertableStorage(final Inventory playerInventory, + final Storage emptyBucketStorage, + final boolean mayDropFilledBucket) { + this.playerInventory = playerInventory; + this.emptyBucketStorage = emptyBucketStorage; + this.mayDropFilledBucket = mayDropFilledBucket; + } + + @Override + public long insert(final FluidResource resource, final long amount, final Action action, final Actor actor) { + if (amount != Platform.INSTANCE.getBucketAmount()) { + return 0; + } + return Platform.INSTANCE.convertToBucket(resource).map( + filledBucketStack -> insert(filledBucketStack, amount, action, actor) + ).orElse(0L); + } + + private long insert(final ItemStack filledBucketStack, final long amount, final Action action, final Actor actor) { + if (extractBucketFromInventory(action)) { + return insert(filledBucketStack, amount, action, this::returnBucketToInventory); + } else if (extractBucketFromStorage(action, actor)) { + return insert(filledBucketStack, amount, action, () -> returnBucketToStorage(actor)); + } + return 0L; + } + + private long insert(final ItemStack filledBucketStack, + final long amount, + final Action action, + final Runnable rollbackAction) { + if (action == Action.EXECUTE && !playerInventory.add(filledBucketStack)) { + if (mayDropFilledBucket) { + playerInventory.player.drop(filledBucketStack, false); + } else { + rollbackAction.run(); + return 0; + } + } + return amount; + } + + private boolean extractBucketFromInventory(final Action action) { + for (int i = 0; i < playerInventory.getContainerSize(); ++i) { + final ItemStack stack = playerInventory.getItem(i); + if (stack.getItem() == Items.BUCKET) { + if (action == Action.EXECUTE) { + playerInventory.removeItem(i, 1); + } + return true; + } + } + return false; + } + + private void returnBucketToInventory() { + playerInventory.add(EMPTY_BUCKET_STACK); + } + + private boolean extractBucketFromStorage(final Action action, final Actor actor) { + return emptyBucketStorage.extract(EMPTY_BUCKET_RESOURCE, 1, action, actor) == 1; + } + + private void returnBucketToStorage(final Actor actor) { + emptyBucketStorage.insert(EMPTY_BUCKET_RESOURCE, 1, Action.EXECUTE, actor); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/RegulatorUpgradeItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/RegulatorUpgradeItem.java index 1443590bb..19ec7a354 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/RegulatorUpgradeItem.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/RegulatorUpgradeItem.java @@ -9,6 +9,7 @@ import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.containermenu.AbstractSingleAmountContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.RegulatorUpgradeContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.content.ContentNames; import com.refinedmods.refinedstorage2.platform.common.internal.resource.ResourceContainerImpl; import com.refinedmods.refinedstorage2.platform.common.menu.ExtendedMenuProvider; @@ -139,7 +140,7 @@ public void writeScreenOpeningData(final ServerPlayer player, final FriendlyByte @Override public Component getDisplayName() { - return createTranslation("item", "regulator_upgrade"); + return ContentNames.REGULATOR_UPGRADE; } @Override diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/render/FluidRenderer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/render/FluidRenderer.java index ebf502c26..eb4deace0 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/render/FluidRenderer.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/render/FluidRenderer.java @@ -5,11 +5,14 @@ import java.util.List; import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.network.chat.Component; public interface FluidRenderer { void render(PoseStack poseStack, int x, int y, FluidResource fluidResource); + void render(PoseStack poseStack, MultiBufferSource renderTypeBuffer, int light, FluidResource fluidResource); + List getTooltip(FluidResource fluidResource); Component getDisplayName(FluidResource fluidResource); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/render/entity/StorageMonitorBlockEntityRenderer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/render/entity/StorageMonitorBlockEntityRenderer.java new file mode 100644 index 000000000..b1bf7d150 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/render/entity/StorageMonitorBlockEntityRenderer.java @@ -0,0 +1,137 @@ +package com.refinedmods.refinedstorage2.platform.common.render.entity; + +import com.refinedmods.refinedstorage2.platform.api.PlatformApi; +import com.refinedmods.refinedstorage2.platform.api.resource.ResourceAmountTemplate; +import com.refinedmods.refinedstorage2.platform.api.resource.ResourceRendering; +import com.refinedmods.refinedstorage2.platform.common.block.StorageMonitorBlock; +import com.refinedmods.refinedstorage2.platform.common.block.direction.BiDirectionType; +import com.refinedmods.refinedstorage2.platform.common.block.entity.storagemonitor.StorageMonitorBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.util.BiDirection; + +import javax.annotation.Nullable; + +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Font; +import net.minecraft.client.renderer.LightTexture; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; +import net.minecraft.util.Mth; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; +import org.joml.Quaternionf; + +public class StorageMonitorBlockEntityRenderer implements BlockEntityRenderer { + private static final Quaternionf ROTATE_TO_FRONT = new Quaternionf().rotationY(Mth.DEG_TO_RAD * 180); + private static final float FONT_SPACING = -0.23f; + + @Override + public void render(final StorageMonitorBlockEntity blockEntity, + final float tickDelta, + final PoseStack poseStack, + final MultiBufferSource vertexConsumers, + final int light, + final int overlay) { + final Level level = blockEntity.getLevel(); + if (level == null) { + return; + } + final BiDirection direction = getDirection(blockEntity, level); + if (direction == null) { + return; + } + if (!blockEntity.isCurrentlyActive()) { + return; + } + final ResourceAmountTemplate template = blockEntity.getFilteredResource(); + if (template == null) { + return; + } + doRender( + blockEntity.getLevel(), + poseStack, + vertexConsumers, + direction, + template, + blockEntity.getCurrentAmount() + ); + } + + private void doRender(final Level level, + final PoseStack poseStack, + final MultiBufferSource vertexConsumers, + final BiDirection direction, + final ResourceAmountTemplate template, + final long amount) { + final ResourceRendering resourceRendering = PlatformApi.INSTANCE.getResourceRendering( + template.getResource() + ); + doRender( + poseStack, + vertexConsumers, + direction.getQuaternion(), + resourceRendering.getDisplayedAmount(amount, false), + level, + resourceRendering, + template.getResource() + ); + } + + private void doRender(final PoseStack poseStack, + final MultiBufferSource renderTypeBuffer, + final Quaternionf rotation, + final String amount, + final Level level, + final ResourceRendering resourceRendering, + final T resource) { + poseStack.pushPose(); + + poseStack.translate(0.5, 0.5, 0.5); + poseStack.mulPose(rotation); + poseStack.mulPose(ROTATE_TO_FRONT); + poseStack.translate(0, 0.05, 0.5); + + poseStack.pushPose(); + renderAmount(poseStack, renderTypeBuffer, amount); + poseStack.popPose(); + + poseStack.pushPose(); + poseStack.translate(0, 0, 0.01f); + resourceRendering.render(resource, poseStack, renderTypeBuffer, LightTexture.FULL_BRIGHT, level); + poseStack.popPose(); + + poseStack.popPose(); + } + + private void renderAmount(final PoseStack poseStack, + final MultiBufferSource renderTypeBuffer, + final String amount) { + final Font font = Minecraft.getInstance().font; + final float width = font.width(amount); + poseStack.translate(0.0f, FONT_SPACING, 0.02f); + poseStack.scale(1.0f / 62.0f, -1.0f / 62.0f, 1.0f / 62.0f); + poseStack.scale(0.5f, 0.5f, 0); + poseStack.translate(-0.5f * width, 0.0f, 0.5f); + font.drawInBatch( + amount, + 0, + 0, + 0xFFFFFF, + false, + poseStack.last().pose(), + renderTypeBuffer, + Font.DisplayMode.NORMAL, + 0, + LightTexture.FULL_BRIGHT + ); + } + + @Nullable + private BiDirection getDirection(final StorageMonitorBlockEntity blockEntity, final Level level) { + final BlockState state = level.getBlockState(blockEntity.getBlockPos()); + if (state.getBlock() instanceof StorageMonitorBlock) { + return state.getValue(BiDirectionType.INSTANCE.getProperty()); + } + return null; + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/render/model/AbstractFluidRenderer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/render/model/AbstractFluidRenderer.java index 225fe296e..091d8b592 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/render/model/AbstractFluidRenderer.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/render/model/AbstractFluidRenderer.java @@ -7,8 +7,12 @@ import com.mojang.blaze3d.vertex.DefaultVertexFormat; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.Tesselator; +import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexFormat; import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.client.renderer.texture.TextureAtlasSprite; public abstract class AbstractFluidRenderer implements FluidRenderer { @@ -44,4 +48,47 @@ protected void render(final PoseStack poseStack, .color(r, g, b, 255).endVertex(); tesselator.end(); } + + protected void render(final PoseStack poseStack, + final MultiBufferSource renderTypeBuffer, + final int light, + final int packedRgb, + final TextureAtlasSprite sprite) { + final VertexConsumer buffer = renderTypeBuffer.getBuffer(RenderType.text(sprite.atlasLocation())); + final float scale = 0.3F; + // y is flipped here + final var x0 = -scale / 2; + final var y0 = scale / 2; + final var x1 = scale / 2; + final var y1 = -scale / 2; + final var transform = poseStack.last().pose(); + buffer.vertex(transform, x0, y1, 0) + .color(packedRgb) + .uv(sprite.getU0(), sprite.getV1()) + .overlayCoords(OverlayTexture.NO_OVERLAY) + .uv2(light) + .normal(0, 0, 1) + .endVertex(); + buffer.vertex(transform, x1, y1, 0) + .color(packedRgb) + .uv(sprite.getU1(), sprite.getV1()) + .overlayCoords(OverlayTexture.NO_OVERLAY) + .uv2(light) + .normal(0, 0, 1) + .endVertex(); + buffer.vertex(transform, x1, y0, 0) + .color(packedRgb) + .uv(sprite.getU1(), sprite.getV0()) + .overlayCoords(OverlayTexture.NO_OVERLAY) + .uv2(light) + .normal(0, 0, 1) + .endVertex(); + buffer.vertex(transform, x0, y0, 0) + .color(packedRgb) + .uv(sprite.getU0(), sprite.getV0()) + .overlayCoords(OverlayTexture.NO_OVERLAY) + .uv2(light) + .normal(0, 0, 1) + .endVertex(); + } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/AbstractBaseScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/AbstractBaseScreen.java index e4bbf303d..fee620d19 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/AbstractBaseScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/AbstractBaseScreen.java @@ -134,7 +134,7 @@ private void renderResourceSlotAmount(final GuiGraphics graphics, graphics, x, y, - rendering.getDisplayedAmount(amount), + rendering.getDisplayedAmount(amount, true), Objects.requireNonNullElse(ChatFormatting.WHITE.getColor(), 15), true ); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/StorageMonitorScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/StorageMonitorScreen.java new file mode 100644 index 000000000..47b5cf231 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/StorageMonitorScreen.java @@ -0,0 +1,41 @@ +package com.refinedmods.refinedstorage2.platform.common.screen; + +import com.refinedmods.refinedstorage2.platform.common.containermenu.StorageMonitorContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.containermenu.property.PropertyTypes; +import com.refinedmods.refinedstorage2.platform.common.screen.widget.FuzzyModeSideButtonWidget; +import com.refinedmods.refinedstorage2.platform.common.screen.widget.RedstoneModeSideButtonWidget; + +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Inventory; + +import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; + +public class StorageMonitorScreen extends AbstractBaseScreen { + private static final ResourceLocation TEXTURE = createIdentifier("textures/gui/storage_monitor.png"); + + public StorageMonitorScreen(final StorageMonitorContainerMenu menu, + final Inventory playerInventory, + final Component text) { + super(menu, playerInventory, text); + + this.inventoryLabelY = 43; + this.imageWidth = 211; + this.imageHeight = 137; + } + + @Override + protected void init() { + super.init(); + addSideButton(new RedstoneModeSideButtonWidget(getMenu().getProperty(PropertyTypes.REDSTONE_MODE))); + addSideButton(new FuzzyModeSideButtonWidget( + getMenu().getProperty(PropertyTypes.FUZZY_MODE), + FuzzyModeSideButtonWidget.Type.GENERIC + )); + } + + @Override + protected ResourceLocation getTexture() { + return TEXTURE; + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/amount/DetectorScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/amount/DetectorScreen.java index 0983ec549..f631c035f 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/amount/DetectorScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/amount/DetectorScreen.java @@ -18,7 +18,7 @@ protected void init() { super.init(); addSideButton(new FuzzyModeSideButtonWidget( getMenu().getProperty(PropertyTypes.FUZZY_MODE), - FuzzyModeSideButtonWidget.Type.DETECTOR + FuzzyModeSideButtonWidget.Type.GENERIC )); addSideButton(new DetectorModeSideButtonWidget(getMenu().getProperty(PropertyTypes.DETECTOR_MODE))); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/grid/hint/FluidGridInsertionHint.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/grid/hint/FluidGridInsertionHint.java index a11b1d503..a2f806c31 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/grid/hint/FluidGridInsertionHint.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/grid/hint/FluidGridInsertionHint.java @@ -1,6 +1,7 @@ package com.refinedmods.refinedstorage2.platform.common.screen.grid.hint; import com.refinedmods.refinedstorage2.platform.api.grid.GridInsertionHint; +import com.refinedmods.refinedstorage2.platform.common.ContainedFluid; import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.screen.tooltip.MouseWithIconClientTooltipComponent; @@ -12,17 +13,21 @@ public class FluidGridInsertionHint implements GridInsertionHint { @Override public Optional getHint(final ItemStack carried) { - return Platform.INSTANCE.convertToFluid(carried).map(resourceAmount -> new MouseWithIconClientTooltipComponent( + return Platform.INSTANCE.getContainedFluid(carried).map(this::createComponent); + } + + private MouseWithIconClientTooltipComponent createComponent(final ContainedFluid result) { + return new MouseWithIconClientTooltipComponent( MouseWithIconClientTooltipComponent.Type.RIGHT, (graphics, x, y) -> Platform.INSTANCE.getFluidRenderer().render( graphics.pose(), x, y, - resourceAmount.getResource() + result.fluid().getResource() ), - resourceAmount.getAmount() == Platform.INSTANCE.getBucketAmount() + result.fluid().getAmount() == Platform.INSTANCE.getBucketAmount() ? null - : Platform.INSTANCE.getBucketAmountFormatter().format(resourceAmount.getAmount()) - )); + : Platform.INSTANCE.getBucketAmountFormatter().format(result.fluid().getAmount()) + ); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/tooltip/ResourceClientTooltipComponent.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/tooltip/ResourceClientTooltipComponent.java index 78011bd6e..686af7f05 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/tooltip/ResourceClientTooltipComponent.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/tooltip/ResourceClientTooltipComponent.java @@ -52,7 +52,7 @@ private static Component getNameWithAmount(final ResourceAmountTemplate r final ResourceRendering rendering = PlatformApi.INSTANCE.getResourceRendering( resourceAmount.getResource() ); - final String amount = rendering.getDisplayedAmount(resourceAmount.getAmount()); + final String amount = rendering.getDisplayedAmount(resourceAmount.getAmount(), true); final Component displayName = rendering.getDisplayName(resourceAmount.getResource()); if (amount.isEmpty()) { return displayName; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/widget/FuzzyModeSideButtonWidget.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/widget/FuzzyModeSideButtonWidget.java index 9859b2eac..411ad017e 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/widget/FuzzyModeSideButtonWidget.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/widget/FuzzyModeSideButtonWidget.java @@ -54,7 +54,7 @@ protected Component getHelpText() { public enum Type { STORAGE, - DETECTOR, + GENERIC, EXTRACTING_STORAGE_NETWORK, EXTRACTING_SOURCE; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/util/BiDirection.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/util/BiDirection.java index aea34f2ac..264943074 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/util/BiDirection.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/util/BiDirection.java @@ -9,24 +9,25 @@ import org.joml.Vector3f; public enum BiDirection implements StringRepresentable { - NORTH(new Vector3f(0, 0, 0)), - EAST(new Vector3f(0, -90, 0)), - SOUTH(new Vector3f(0, 180, 0)), - WEST(new Vector3f(0, 90, 0)), - UP_NORTH(new Vector3f(90, 0, 180)), - UP_EAST(new Vector3f(90, 0, -90)), - UP_SOUTH(new Vector3f(90, 0, 0)), - UP_WEST(new Vector3f(90, 0, 90)), - DOWN_NORTH(new Vector3f(-90, 0, 0)), - DOWN_EAST(new Vector3f(-90, 0, -90)), - DOWN_SOUTH(new Vector3f(-90, 0, 180)), - DOWN_WEST(new Vector3f(-90, 0, 90)); + NORTH(new Vector3f(0, 0, 0), Direction.NORTH), + EAST(new Vector3f(0, -90, 0), Direction.EAST), + SOUTH(new Vector3f(0, 180, 0), Direction.SOUTH), + WEST(new Vector3f(0, 90, 0), Direction.WEST), + UP_NORTH(new Vector3f(90, 0, 180), Direction.UP), + UP_EAST(new Vector3f(90, 0, -90), Direction.UP), + UP_SOUTH(new Vector3f(90, 0, 0), Direction.UP), + UP_WEST(new Vector3f(90, 0, 90), Direction.UP), + DOWN_NORTH(new Vector3f(-90, 0, 0), Direction.DOWN), + DOWN_EAST(new Vector3f(-90, 0, -90), Direction.DOWN), + DOWN_SOUTH(new Vector3f(-90, 0, 180), Direction.DOWN), + DOWN_WEST(new Vector3f(-90, 0, 90), Direction.DOWN); private final Vector3f vec; private final String name; private final Quaternionf quaternion; + private final Direction direction; - BiDirection(final Vector3f vec) { + BiDirection(final Vector3f vec, final Direction direction) { this.vec = vec; this.name = name().toLowerCase(Locale.ROOT); this.quaternion = new Quaternionf().rotateXYZ( @@ -34,6 +35,7 @@ public enum BiDirection implements StringRepresentable { vec.y() * Mth.DEG_TO_RAD, vec.z() * Mth.DEG_TO_RAD ); + this.direction = direction; } public static BiDirection forHorizontal(final Direction horizontalDirection) { @@ -95,4 +97,8 @@ public String getSerializedName() { public Quaternionf getQuaternion() { return quaternion; } + + public Direction asDirection() { + return direction; + } } diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/blockstates/storage_monitor.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/blockstates/storage_monitor.json new file mode 100644 index 000000000..01d572529 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/blockstates/storage_monitor.json @@ -0,0 +1,57 @@ +{ + "variants": { + "direction=down_east": { + "model": "refinedstorage2:block/storage_monitor", + "x": 90, + "y": -90 + }, + "direction=down_north": { + "model": "refinedstorage2:block/storage_monitor", + "x": 90 + }, + "direction=down_south": { + "model": "refinedstorage2:block/storage_monitor", + "x": 90, + "y": 180 + }, + "direction=down_west": { + "model": "refinedstorage2:block/storage_monitor", + "x": 90, + "y": 90 + }, + "direction=east": { + "model": "refinedstorage2:block/storage_monitor", + "y": 90 + }, + "direction=north": { + "model": "refinedstorage2:block/storage_monitor" + }, + "direction=south": { + "model": "refinedstorage2:block/storage_monitor", + "y": 180 + }, + "direction=up_east": { + "model": "refinedstorage2:block/storage_monitor", + "x": -90, + "y": -90 + }, + "direction=up_north": { + "model": "refinedstorage2:block/storage_monitor", + "x": -90, + "y": 180 + }, + "direction=up_south": { + "model": "refinedstorage2:block/storage_monitor", + "x": -90 + }, + "direction=up_west": { + "model": "refinedstorage2:block/storage_monitor", + "x": -90, + "y": 90 + }, + "direction=west": { + "model": "refinedstorage2:block/storage_monitor", + "y": 270 + } + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/lang/en_us.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/lang/en_us.json index e02294bde..59ef8d0bb 100644 --- a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/lang/en_us.json +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/lang/en_us.json @@ -27,6 +27,7 @@ "block.refinedstorage2.constructor": "Constructor", "block.refinedstorage2.destructor": "Destructor", "block.refinedstorage2.wireless_transmitter": "Wireless Transmitter", + "block.refinedstorage2.storage_monitor": "Storage Monitor", "gui.refinedstorage2.controller.redstone_mode_help": "When this device is inactive, the storage network will not be able to use this device as an energy source.", "gui.refinedstorage2.disk_drive.disks": "Disks", "gui.refinedstorage2.storage.redstone_mode_help": "When this device is inactive, the contained storage will no longer be accessible from within the storage network.", @@ -83,6 +84,7 @@ "gui.refinedstorage2.importer.filter_mode.allow.help": "Only allow resources into the storage network that are configured in the filters.", "gui.refinedstorage2.importer.filter_mode.block.help": "Disallow resources into the storage network that are configured in the filters.", "gui.refinedstorage2.wireless_transmitter.distance": "%d block(s)", + "gui.refinedstorage2.storage_monitor.filter_help": "The resource to display.", "gui.refinedstorage2.redstone_mode": "Redstone mode", "gui.refinedstorage2.redstone_mode.ignore": "Ignore", "gui.refinedstorage2.redstone_mode.ignore.help": "This device will always be active, regardless of redstone signal.", @@ -108,12 +110,12 @@ "gui.refinedstorage2.fuzzy_mode": "Fuzzy mode", "gui.refinedstorage2.fuzzy_mode.on": "On", "gui.refinedstorage2.fuzzy_mode.on.storage_help": "Match the filters for the allowlist or blocklist exactly.", - "gui.refinedstorage2.fuzzy_mode.on.detector_help": "Match the filter exactly.", + "gui.refinedstorage2.fuzzy_mode.on.generic_help": "Match the filter exactly.", "gui.refinedstorage2.fuzzy_mode.on.extracting_storage_network_help": "Match the filters when extracting from the storage network exactly.", "gui.refinedstorage2.fuzzy_mode.on.extracting_source_help": "Match the filters when extracting from the source exactly.", "gui.refinedstorage2.fuzzy_mode.off": "Off", "gui.refinedstorage2.fuzzy_mode.off.storage_help": "Match the filters for the allowlist or blocklist without comparing NBT tags.", - "gui.refinedstorage2.fuzzy_mode.off.detector_help": "Match the filter without comparing NBT tags.", + "gui.refinedstorage2.fuzzy_mode.off.generic_help": "Match the filter without comparing NBT tags.", "gui.refinedstorage2.fuzzy_mode.off.extracting_storage_network_help": "Match the filters when extracting from the storage network without comparing NBT tags.", "gui.refinedstorage2.fuzzy_mode.off.extracting_source_help": "Match the filters when extracting from the source without comparing NBT tags.", "gui.refinedstorage2.access_mode": "Access mode", @@ -290,6 +292,7 @@ "text.autoconfig.refinedstorage2.option.wirelessTransmitter": "Wireless Transmitter", "text.autoconfig.refinedstorage2.option.wirelessTransmitter.energyUsage": "Energy usage", "text.autoconfig.refinedstorage2.option.wirelessTransmitter.baseRange": "Base range", + "text.autoconfig.refinedstorage2.option.storageMonitor.energyUsage": "Energy usage", "advancements.refinedstorage2.root.description": "Use one or multiple Controllers in a network to provide your network with energy", "advancements.refinedstorage2.connecting": "Connecting", "advancements.refinedstorage2.connecting.description": "Use Cable to connect devices with each other, or place devices against each other", @@ -320,5 +323,7 @@ "advancements.refinedstorage2.destruction": "Destruction", "advancements.refinedstorage2.destruction.description": "Get blocks from in the world into the storage network with a Destructor", "advancements.refinedstorage2.wireless": "Wireless", - "advancements.refinedstorage2.wireless.description": "Access your resources wirelessly with a Wireless Grid." + "advancements.refinedstorage2.wireless.description": "Access your resources wirelessly with a Wireless Grid.", + "advancements.refinedstorage2.better_than_a_barrel": "Better than a barrel", + "advancements.refinedstorage2.better_than_a_barrel.description": "Craft a Storage Monitor to view, insert or extract resources in a storage network" } diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/disk.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/disk.json index 9e2a90de0..3b5925d4b 100644 --- a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/disk.json +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/disk.json @@ -1,6 +1,6 @@ { "textures": { - "base": "refinedstorage2:block/disk" + "base": "refinedstorage2:block/disk_drive/disk" }, "elements": [ { diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/disk_drive_base.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/disk_drive_base.json index c23ba436a..fd97de0e7 100644 --- a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/disk_drive_base.json +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/disk_drive_base.json @@ -1,11 +1,11 @@ { "parent": "block/block", "textures": { - "particle": "refinedstorage2:block/disk_drive", - "front": "refinedstorage2:block/disk_drive", - "bottom": "refinedstorage2:block/disk_drive_bottom", - "top": "refinedstorage2:block/disk_drive_top", - "side": "refinedstorage2:block/disk_drive_side" + "particle": "refinedstorage2:block/disk_drive/front", + "front": "refinedstorage2:block/disk_drive/front", + "bottom": "refinedstorage2:block/disk_drive/bottom", + "top": "refinedstorage2:block/disk_drive/top", + "side": "refinedstorage2:block/disk_drive/side" }, "elements": [ { diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/disk_inactive.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/disk_inactive.json index 773f835f2..ffac12be9 100644 --- a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/disk_inactive.json +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/disk_inactive.json @@ -1,6 +1,6 @@ { "textures": { - "base": "refinedstorage2:block/disk" + "base": "refinedstorage2:block/disk_drive/disk" }, "elements": [ { diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/interface_active.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/interface_active.json index d1e503c0c..d1b902270 100644 --- a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/interface_active.json +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/interface_active.json @@ -1,6 +1,6 @@ { "parent": "block/cube_all", "textures": { - "all": "refinedstorage2:block/interface_active" + "all": "refinedstorage2:block/interface/active" } } \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/interface_inactive.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/interface_inactive.json index 7b07d961a..43d2d258d 100644 --- a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/interface_inactive.json +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/interface_inactive.json @@ -1,6 +1,6 @@ { "parent": "block/cube_all", "textures": { - "all": "refinedstorage2:block/interface_inactive" + "all": "refinedstorage2:block/interface/inactive" } } \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/storage_monitor.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/storage_monitor.json new file mode 100644 index 000000000..422b44501 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/storage_monitor.json @@ -0,0 +1,12 @@ +{ + "parent": "block/cube", + "textures": { + "particle": "refinedstorage2:block/side", + "north": "refinedstorage2:block/storage_monitor/front", + "east": "refinedstorage2:block/storage_monitor/left", + "south": "refinedstorage2:block/storage_monitor/back", + "west": "refinedstorage2:block/storage_monitor/right", + "up": "refinedstorage2:block/storage_monitor/top", + "down": "refinedstorage2:block/bottom" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/storage_monitor.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/storage_monitor.json new file mode 100644 index 000000000..90256ac6c --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/storage_monitor.json @@ -0,0 +1,3 @@ +{ + "parent": "refinedstorage2:block/storage_monitor" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/disk_drive_bottom.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/disk_drive/bottom.png similarity index 100% rename from refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/disk_drive_bottom.png rename to refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/disk_drive/bottom.png diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/disk.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/disk_drive/disk.png similarity index 100% rename from refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/disk.png rename to refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/disk_drive/disk.png diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/disk_drive.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/disk_drive/front.png similarity index 100% rename from refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/disk_drive.png rename to refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/disk_drive/front.png diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/disk_drive_side.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/disk_drive/side.png similarity index 100% rename from refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/disk_drive_side.png rename to refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/disk_drive/side.png diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/disk_drive_top.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/disk_drive/top.png similarity index 100% rename from refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/disk_drive_top.png rename to refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/disk_drive/top.png diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/interface_active.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/interface/active.png similarity index 100% rename from refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/interface_active.png rename to refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/interface/active.png diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/interface_inactive.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/interface/inactive.png similarity index 100% rename from refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/interface_inactive.png rename to refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/interface/inactive.png diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/side.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/side.png new file mode 100644 index 0000000000000000000000000000000000000000..fb581557600370be2d35233c4c00c6690ad6aa6e GIT binary patch literal 15349 zcmeI3e{37&8OPrsKp_)T!lcomF*#RNKsEb*IOo_`$EA%E5>#iEo3trIT`zaKEpE1KBEG_LU%=smabJ`VfR!_gDJg2n%$F4%hXhM zsr{&srRD^bEhEus7?D7>TsP+L-qGBgDNo1kTlAP}B+WbgY-vidaEfj)C|fXq3ftr4 z1*hQcoW|CEwc!Ug9*M{;Qjc8jq1$QUf9AbmyZooY-WvK_+h^lPK z%W}cBi+w^NsXb;|a!i5k!2p`OOV?FN^JqRO_b5&`ukp?vwV}}|ivn~u@(o@eFK9}m zSItavarzSLprH)fg_N^ak+sm++9(J-C$9I3Jm2D3C$#ulMW1iID0)4f25;ULOI>OU z6Z#IQwkC{dW{=0^gbD4f)5PTWPT^3<6+&k7N&3>MX77g!R=%Glsm1$2=KgHAT4|gUcs+}xr_yN6UYq>)25qf{|sT{+w-;$*G+I> zacjOKqAzn{3d@6zG)Y$MV>@8VXmR~)=9tU36>ln=VGooQlv&f|mG6@D%3~z^V9eg` zm9}cuDx<1wVj7y2loN1WFWM2yIf=5ai_NLsv>DdA}U(}Ju3G?HXiHsv&F{ZnEt|Vfz)h7j08H-V8HEX%Qa(J_OF0l z-w2hQDGJ`tE@>;(ciX!^GMLdf3LLu7LkGHYsd#s3>ej2L;@zdG#muglZUuzgXeG^9 zmi<$eg|P`ep22`e6y2hqEp0B%*r=yqq&uji1J$&*3Gd0}ly;O&+*&CS>&PW$O96Y3 z%2Z0W6+Nb*Cq%aJh`6|j3VZV#4vI7ShK+GMItWgK7*kwCM7V(B!f6m=ii?N{7f@U{ z4Ps1j5fR}6iVLSfj43W6B3wXm;WUUb#YIGf3n(s}1~I0%h=_0j#f8%##uOJ35iX#( za2mvz;vyo#1r!%fgBVj>L`1lN;=*YVV~UH22p3RXI1OSar$LObimRsh(j|csl^negJMZ_WtCZRsgF0&>mdZnR?H^_jpI7zP9E3 zb-O>B7}&ny@-2V5vUdI}aNDubEr0yJ_s%Zg(Z6n8b@cb|O&>k};X`S&!@ZIL)%6qi zE!+xfN5{H;I(Bko>^d-a_N+2ucGL}}Qn!!q3-^qC`PRahbN4*Se?He-{qy&q0^3Ih zezk4q!sPI~!?S-m`PJ_G4gUInz542H!ONE~M-Cra{mzQ2zkl+HbNpJc^YEP?fOEU% zer&$|PjBs~pM5qx{aCt31M$F%{fE!Le(3YLx`C%(QZ}GhS1--9r`v*jE3zHs3vF{@^#G;hRRU)J@iaJH~zgJ}@>GRNHT;-xof8gt_^Z$*1|}#I99A z|MMO7*SdG^+I8=Jbps=>ADCFp>`Bk8e0k#I|L#eT@7uR`W@=B+lAhmxY4+T}FV_5W zjeF{t_MG{G>9Xn$O}}}1ef9iXJKC7N;s0H{_~$pD8dFBJ? h_W!Q_<+D}bA7J;u=zs3rY`>V>-qI0#ZT}G literal 0 HcmV?d00001 diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/storage_monitor/back.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/storage_monitor/back.png new file mode 100644 index 0000000000000000000000000000000000000000..ffb76f755fa9a787972cd4c17b1c3dca2b1ab4b1 GIT binary patch literal 1415 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61SBU+%rFB|k|nMYCBgY=CFO}lsSJ)O`AMk? zp1FzXsX?iUDV2pMQ*9U+nDa72B1$5BeXNr6bM+EIYV;~{3xK*A7;Nk-3KEmEQ%e+* zQqwc@Y?a>c-mj#PnPRIHZt82`Ti~3Uk?B!Ylp0*+7m{3+ootz+WN)WnQ(*-(AUCxn zQK2F?C$HG5!d3}vt`(3C64qBz04piUwpD^SD#ABF!8yMuRl!uxOgGuk&``nLQqR!T z!q~`EN5ROz&{W^RQs2-(*TB%q(7?*bKmiJrfVLH-q*(>IxIyg#@@$ndN=gc>^!3Zj z%k|2Q_413-^$jg8E%gnI^o@*kfhu&1EAvVcD|GXUm0>2hq!uR^WfqiV=I1GZOiWD5 zFD#PU%0_}#n6BP2AO_EVu8M)o`HUDF34YC)x{-2sR(CaRb3oXS&*t9 zlv|9-O^tOeQ%y{DEmM*#b&U;;4N_AQ%`FU*4PfSA({E{RVd~;)WME-p4oIBp4nO9trn3tRivpW-LH$<phIbtAf7XZzyuX?y}6TK
    js(5`t?UIDBps zydCLndOza&&3)TX$$#Ntw($~PaQ$RTQ)AU-lRSy4?42*SJ0GsFxmdA9qgk$bnWoZb zMK@VnzIL^xYOW?3hx(5@Uplo(g}2{>{pby*Tuw=v7q4Ll)rDvtlj$EKMOWD+zsT?&%D#q zZSuvzUsL5n%iaGq8`gzspZGIlE89VbhDqlqTc7{@waRx&(7)?D;?{3+O?r`dBOqvk j%+JG(r;1Me=Q3c({@o?*e|U}qsA%+b^>bP0l+XkKE;Id| literal 0 HcmV?d00001 diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/storage_monitor/front.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/storage_monitor/front.png new file mode 100644 index 0000000000000000000000000000000000000000..d7a267815296bbeb4a5fa9a3f4bff269b0b43590 GIT binary patch literal 1273 zcmbVMZEO=|96#|TrWrcX4-U{A2aYXrZ@pgIyY!e_uN#f)+)8C-WXSdI>3ZAluDyFk z+etzqbEdv!ATe_x1U>-CG-&vuvJj^v5>e0~zJw*ZEEpwxz$_$u7%x88wbKs^AH3xL z&&&OO|M&luIy>4{dRBWd3|kr9BFE8M>%Nb!Kyqw<#*dad7)ipdRvP9N8(__vl>&Iw zQ2Ia|C|WW14G3Y_gS+)a5+-BqqG}nG;$oBE=kkPjc+hFT(M?xJQPz8->+Kh(^B2r)gsNe--&~(ItM3nW4XzyOr1YU-~ z0f|_2DjDmBtno*(S%BYG@bQT4Ki?4ThBt>GI3X< zlCp-NL?BNWLol+j*pgz?sU!-ej4miynxz=pFx@Ix`luoQ##l!{Kt(@rG{Q)U3SI=$2_QY8lx2ZlJZ=mVuY^ zEb7bnAOsi^4CFHH(6r;#WsR$v5;1DckjyUp^S=BZwxj&!$6 zqks-e!vst;K{gtdbyxSsFzkW4sN9?=T!9C!d-gFkug~;Yvs~ld%iTB6?5S1GPA&8& z8{T~;d12zvh7%=Y=I5TN8wuG~KQ=P|SZ;3o z$mCa4?8nQur1lRQ-cz2~{>k6dZ*oqeQxdrT8|96#|@napPDHr?xXFb5gES6kX%D5msUD6}k#Sy1na8#<1Rgh$ z{bpoBRH?H7whAJE^=O91Ll6XPFrkFrs3rC3Fo_d-3^!o}uE7b4z$p@kCm%%dCbC|t zh_+AqQdVZfC(A(!!$P4D8q%VIxEdo&CKHB}7)fdr3yoCE%S>3qOUZEt8b}_I3(B0p z!!bt2Ev%8vh@y1j3W1>0IYrD%lYvq~hJ~3RMxZzr2*mC+ZY{}0;9nWjT1&3lAi#=% zB&-oVN~ocDr%_LL{3QxQ%wt=H37iO4%&<;Cn(FYl$&(B39nYC(QEZu zjS1-V8WZa_X|#kE2P|VS5*|FxGaX*1H<1KxH`qy?l^|>xmTZ!+8w|8wYalGNO&`ZP zcu8h>4~YBb6yKBBj7MTAs|Xlb5M6>$9j}4{pCAj8PYA+R>v-1T)Dn(og^-jMOVh-y zX&`cM0@f}H0eC#l6gQ0qqb);=XV`5<9chp0&n9fPY@I&aK;l-DK}#c(SazD&O=9i; zi^UW%Sgc6?Q#A1{r4nP)sTNQcQ%wYTrE^53MHbvZqYyOXyo0v5!k1QTKGJprS8r(U z8ve$1r~pn)RWI6lct-U2!dpvkUvQ~jY*4Fw=$YQ(VI;qwzLFmqi z_lvSX@2c76SsMqE+dSWYy#rTeeu4~Rt<5L?tUL0s6?u9?Zeh|u(D-rjdm!)A^r(Np z(Ry}gi6P?C-G6G}82yo^{+VZI|9Y`)X2)m#Enr!+nSDqX?x}$KK5yaF)*A2pujZ}Y z+tZKsocZqZ`6Tj9)Ic|#%4&@`tm zb?=G0EtOSOYIA4g)a|hc5f|Eb^2)J4#&XaniQ=8tcdh?<-O)YKcV^6iK73f&>Y*NA Q75jZUZ29!Q?8?S}0J$~}(*OVf literal 0 HcmV?d00001 diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/storage_monitor/right.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/storage_monitor/right.png new file mode 100644 index 0000000000000000000000000000000000000000..8a7d7d2c5163a961f5894538593765666c83c340 GIT binary patch literal 1443 zcmaJ>eNYr-9A1?WP0S%Q4RV%+;lsGwkNe zEktb;YesBzz=mczC!L`Qh-fIvQDK~9Gz^O&aGGSawD_8$h7=sz1CIKG+?n0?>-Rjr z=ly-`5nKLq(QBVx3qeq{WxLTXjT=I5)Jo}ltii38hApDWAr^3@qMzmgq-QuMfGr-n z4A=q9?5XSnSrD|!%N9CBhc%CMaUMAxvXKWoJ_!v$Svdh8?J5T%>;z@3SBFe}c^-jT zMu!xsteDkD0XMt7h6e>T`Gu~Ua+j7tasRuF@z7RXR*yxC+IzD2~Z6oWwDbz~IFPk-YIt zDQP#F7kx=99pV;6ABm!VzhCZG$T_|Y#kE>3iV-M5$RrDyu*WOX0hw1w3^N#k;Nn@I z$Z}pd#7H~2Dp7|>N*Au+@mZ})#9m=BP*TXy0PRC@Ifi;Xp?l3+3!)wTD`Qz}p>U56 zpmrc|RlG~eM`>ahEXD58jzWf#8geJkN=czBjGU{=1H7Wes6(U^Im0rflW;omQiW2c zQm7O%El{dtTE?lBDR2b_7&=3PyRb0Na(D%$RO>Sg1~Z|gaNMLeXiRE~FyR?`gULu? ziZIsV6-3(W0%6~*SP5p1V z8xDQf+`n_|a^9pt95w8X?5h9!{p_PtH|@noqPF#%&{$HE`-jptCm#!Tcjq@341W0H zM=BB*$12A-ufV+vsm7BW1{9bXc1v@ew8nJ2o76Ww$A4jaEFp4B&uq@MU4uPw zrl0yhd;Vfwdoa~T#IL7eYnLZZ+~?v8^I5Inl#+x?wpU3%`=nKcRP zdd~{CH}*HwVlg9=is02%b+yMGLGch3zq=}__@(m7PUcDk*A=&GPHAm=Vx0r+ZM-u* zJT=pY*J^yLE6C=$r`qrSa+u0L38Gwv+UNwi`n~9E|KYiPg#P|yX5*WhVBV?Tz1e4> z;p?@3=B`1KF8gL?&!w1R#vgW!2eSTfbT;gJgZO!T?Adp2T`b8>85-NzjwZzQ+-Z4@ zXo`4d)L+z=x+5oeX1^zE>yxWb-vh7S)yA(U4nz*7jwR=}{V;v+ZFS4+D>YeLiO+{C zl3%}cx;-(u{z5@x)NS}db^4~qn+|*xc_|Q4LIlqrm1RCmya3&gFGd*Q>dnw^(_+du Jwi-(6{sCeM}Q)96o_%LPA!FOvR5J$C5dqy{}&F-CCgZ=;)wGY9n>(#Mh59TFz@7M2n ze$V^+xaRV*S5i|lQXmLQwHLEab<{-P)d}kN_z9mu9X2RMZe@p5rGz*cKo(x|0NC#5 zs(}-5eEt3*V1l4TQE<5xx1*HtN`4&|wb6zB0Tm5Fru=Y#^VR?b_JC?ZG$Rkc97JG& zHzO6419Jqdz$X+p$Y4i9nakTyjcdbRkkF$<-)M(=>_^C_!jd3vIAoRJgEK3}(d{SP=BeLO>BD z5sor)9;r?-BdXG+EBFHr$1<@Pj0H*!85-sSD6Yd$zdw4fMeCsA1pmrd(K_g=4*=8& zf>NFARr67m6$h)ad%B~jp{j=2E(>Z>xLQ{7*7<>`*jY28p6GaiXFP<*gIAGyEk#nK zmIiuCOYg0Soi4Y4x>#-^AgY}st1Yr{a%~R;t!lHg7FYO3(}%;|O_=7$`>iwW z{lDweb`JbuZdAsvMp~MiYxcIU?wC6`%?`ld-a1R(zj^#@*+t=WtMgX>3-&AXkzJ?W z8XVU<`uBZe*G^_mbUhg8y!`OVg{__8;zOC>*xgqTZ2HDD((}WmcYZxM*anjE)=_uO z!j1Ix9g)gCroRHl-{zm(lap^ptVaTghd+8eyKuGm((J;fxi#i39}HJzMHEfROgh;& z=I62-aORXdZXnlTfyJV+n+jz&j}jk`wO}2BU2+e z?cO=(hR&q<2Y({xduH-RdP8F~`Stgk3Oh8jjd{rv*SVBcyOT!0n4a1rO^-LU+}Zaz zvEO)eB5az}l)8VqC!eqk_5SkQ#f=pU4n8~K@w!Ur4X5SMn>ps(=r7P-RK|7}RyO?u Dom}%M literal 0 HcmV?d00001 diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/gui/storage_monitor.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/gui/storage_monitor.png new file mode 100644 index 0000000000000000000000000000000000000000..df26907155a169347a8fd3871468a1eb4eabe30c GIT binary patch literal 1816 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K58911MRQ8&P5D>38$lZxy-8q?;Kn_c~qpu?a z!^VE@KZ&di49pAxJ|V6^adUI?(9qEC?(Sp9j{X1tA1E>kMnhnPgh10{aTQRmDGBlm z1}6TI3>bpHv#SE5owL9rvY3H^?=T269?xHq0u+=iag8Vm&QB{TPb^AhC`ioAE78kK zEm1JhGte_Ma%RbX!@$5);OXKRQW5v|)@v_jM*-G{rqjRIKe;-i$o)YSnS}kX5%)Ru!e(x3T8s?Z~C00|p?=V#SYG4s?V0afhje&_n zfx%yX0+2qi_q31$1EUwCot*V&M^9mfbNo~7Vi_1&9^6aiRA^ve`tW5E%Y*NBLJj<0 zAcZ^1Bbhh?xC{3E*FL`f$ATq{40}P!?(EiK1Q|ZhP60?aR8Ln0YUMa^nf(gK0sAd$ z&b@gx-+vclMQeFU?RH_XN+e|(2&0mfwQYvfFonmNiInDma)OSjn2O z+qT^2D?_}!O|?@r`+>L721|c0)y}SXvW6ugS-7Fsm%+@8@y3mz$JtW*pJgLkYbfg( R)+A72<>~6@vd$@?2>`Z}7mNS^ literal 0 HcmV?d00001 diff --git a/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/advancements/better_than_a_barrel.json b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/advancements/better_than_a_barrel.json new file mode 100644 index 000000000..a05321c59 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/advancements/better_than_a_barrel.json @@ -0,0 +1,28 @@ +{ + "display": { + "icon": { + "item": "refinedstorage2:storage_monitor" + }, + "title": { + "translate": "advancements.refinedstorage2.better_than_a_barrel" + }, + "description": { + "translate": "advancements.refinedstorage2.better_than_a_barrel.description" + } + }, + "parent": "refinedstorage2:root", + "criteria": { + "storage_monitor_in_inventory": { + "trigger": "minecraft:inventory_changed", + "conditions": { + "items": [ + { + "items": [ + "refinedstorage2:storage_monitor" + ] + } + ] + } + } + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/loot_tables/blocks/storage_monitor.json b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/loot_tables/blocks/storage_monitor.json new file mode 100644 index 000000000..f097506cd --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/loot_tables/blocks/storage_monitor.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "refinedstorage2:storage_monitor" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/storage_monitor.json b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/storage_monitor.json new file mode 100644 index 000000000..ac7b229d1 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/storage_monitor.json @@ -0,0 +1,31 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "PCG", + "EMG", + "PDG" + ], + "key": { + "P": { + "item": "refinedstorage2:basic_processor" + }, + "C": { + "item": "refinedstorage2:construction_core" + }, + "G": { + "item": "minecraft:glass" + }, + "E": { + "item": "refinedstorage2:quartz_enriched_iron" + }, + "M": { + "item": "refinedstorage2:machine_casing" + }, + "D": { + "item": "refinedstorage2:destruction_core" + } + }, + "result": { + "item": "refinedstorage2:storage_monitor" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ClientModInitializerImpl.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ClientModInitializerImpl.java index 88b9851f9..1073aec9e 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ClientModInitializerImpl.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ClientModInitializerImpl.java @@ -12,6 +12,7 @@ import com.refinedmods.refinedstorage2.platform.common.content.KeyMappings; import com.refinedmods.refinedstorage2.platform.common.item.RegulatorUpgradeItem; import com.refinedmods.refinedstorage2.platform.common.render.NetworkItemItemPropertyFunction; +import com.refinedmods.refinedstorage2.platform.common.render.entity.StorageMonitorBlockEntityRenderer; import com.refinedmods.refinedstorage2.platform.common.render.model.ControllerModelPredicateProvider; import com.refinedmods.refinedstorage2.platform.common.screen.tooltip.CompositeClientTooltipComponent; import com.refinedmods.refinedstorage2.platform.common.screen.tooltip.HelpClientTooltipComponent; @@ -239,6 +240,10 @@ private void registerBlockEntityRenderers() { BlockEntities.INSTANCE.getDiskDrive(), ctx -> new DiskDriveBlockEntityRendererImpl<>() ); + BlockEntityRenderers.register( + BlockEntities.INSTANCE.getStorageMonitor(), + ctx -> new StorageMonitorBlockEntityRenderer() + ); } private void registerCustomModels() { diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ConfigImpl.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ConfigImpl.java index b65a123ac..49f8c4428 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ConfigImpl.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ConfigImpl.java @@ -70,6 +70,11 @@ public class ConfigImpl implements ConfigData, com.refinedmods.refinedstorage2.p @ConfigEntry.Gui.CollapsibleObject private WirelessTransmitterEntryImpl wirelessTransmitter = new WirelessTransmitterEntryImpl(); + @ConfigEntry.Gui.CollapsibleObject + private SimpleEnergyUsageEntryImpl storageMonitor = new SimpleEnergyUsageEntryImpl( + DefaultEnergyUsage.STORAGE_MONITOR + ); + public static ConfigImpl get() { return AutoConfig.getConfigHolder(ConfigImpl.class).getConfig(); } @@ -159,6 +164,11 @@ public WirelessTransmitterEntry getWirelessTransmitter() { return wirelessTransmitter; } + @Override + public SimpleEnergyUsageEntry getStorageMonitor() { + return storageMonitor; + } + private static class GridEntryImpl implements GridEntry { private boolean largeFont = false; diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/PlatformImpl.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/PlatformImpl.java index 877849b91..273f7e10f 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/PlatformImpl.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/PlatformImpl.java @@ -8,6 +8,7 @@ import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.AbstractPlatform; import com.refinedmods.refinedstorage2.platform.common.Config; +import com.refinedmods.refinedstorage2.platform.common.ContainedFluid; import com.refinedmods.refinedstorage2.platform.common.containermenu.transfer.TransferManager; import com.refinedmods.refinedstorage2.platform.common.util.BucketAmountFormatting; import com.refinedmods.refinedstorage2.platform.common.util.CustomBlockPlaceContext; @@ -22,8 +23,7 @@ import com.refinedmods.refinedstorage2.platform.fabric.packet.c2s.ClientToServerCommunicationsImpl; import com.refinedmods.refinedstorage2.platform.fabric.packet.s2c.ServerToClientCommunicationsImpl; import com.refinedmods.refinedstorage2.platform.fabric.render.FluidVariantFluidRenderer; -import com.refinedmods.refinedstorage2.platform.fabric.util.BucketSingleStackStorage; -import com.refinedmods.refinedstorage2.platform.fabric.util.VariantUtil; +import com.refinedmods.refinedstorage2.platform.fabric.util.SingleStackStorageImpl; import java.util.List; import java.util.Optional; @@ -88,6 +88,7 @@ import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.Vec3; +import static com.refinedmods.refinedstorage2.platform.fabric.util.VariantUtil.ofFluidVariant; import static com.refinedmods.refinedstorage2.platform.fabric.util.VariantUtil.toFluidVariant; import static com.refinedmods.refinedstorage2.platform.fabric.util.VariantUtil.toItemVariant; @@ -147,11 +148,24 @@ public GridResourceFactory getFluidGridResourceFactory() { } @Override - public Optional> convertToFluid(final ItemStack stack) { + public Optional getContainedFluid(final ItemStack stack) { if (stack.isEmpty()) { return Optional.empty(); } - return convertNonEmptyToFluid(stack); + final SingleStackStorageImpl interceptingStorage = new SingleStackStorageImpl(stack); + final Storage storage = FluidStorage.ITEM.find(stack, ContainerItemContext.ofSingleSlot( + interceptingStorage + )); + try (Transaction tx = Transaction.openOuter()) { + final var extracted = StorageUtil.extractAny(storage, Long.MAX_VALUE, tx); + if (extracted == null) { + return Optional.empty(); + } + return Optional.of(new ContainedFluid( + interceptingStorage.getStack(), + new ResourceAmount<>(ofFluidVariant(extracted.resource()), extracted.amount()) + )); + } } @Override @@ -167,7 +181,7 @@ public Optional convertJeiIngredientToFluid(final Object ingredie @Override public Optional convertToBucket(final FluidResource fluidResource) { - final BucketSingleStackStorage interceptingStorage = new BucketSingleStackStorage(); + final SingleStackStorageImpl interceptingStorage = SingleStackStorageImpl.forEmptyBucket(); final Storage destination = FluidStorage.ITEM.find( interceptingStorage.getStack(), ContainerItemContext.ofSingleSlot(interceptingStorage) @@ -181,18 +195,6 @@ public Optional convertToBucket(final FluidResource fluidResource) { } } - private Optional> convertNonEmptyToFluid(final ItemStack stack) { - final Storage storage = FluidStorage.ITEM.find( - stack, - new ConstantContainerItemContext(ItemVariant.of(stack), 1) - ); - return Optional.ofNullable(StorageUtil.findExtractableContent(storage, null)) - .map(content -> new ResourceAmount<>( - VariantUtil.ofFluidVariant(content.resource()), - content.amount() - )); - } - @Override public TransferManager createTransferManager(final AbstractContainerMenu containerMenu) { return new TransferManager(containerMenu, ContainerTransferDestination::new); diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/internal/grid/FluidGridExtractionStrategy.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/internal/grid/FluidGridExtractionStrategy.java index a38915a68..074b53eec 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/internal/grid/FluidGridExtractionStrategy.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/internal/grid/FluidGridExtractionStrategy.java @@ -12,7 +12,7 @@ import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; -import com.refinedmods.refinedstorage2.platform.fabric.util.BucketSingleStackStorage; +import com.refinedmods.refinedstorage2.platform.fabric.util.SingleStackStorageImpl; import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext; import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorage; @@ -65,7 +65,7 @@ public boolean onExtract(final PlatformStorageChannelType storageChannelT private void extractWithBucketInStorage(final FluidResource fluidResource, final GridExtractMode mode, final boolean cursor) { - final BucketSingleStackStorage interceptingStorage = new BucketSingleStackStorage(); + final SingleStackStorageImpl interceptingStorage = SingleStackStorageImpl.forEmptyBucket(); final net.fabricmc.fabric.api.transfer.v1.storage.Storage destination = FluidStorage.ITEM.find( interceptingStorage.getStack(), ContainerItemContext.ofSingleSlot(interceptingStorage) @@ -94,7 +94,7 @@ private void extractWithBucketInInventory(final FluidResource fluidResource, final boolean cursor) { try (Transaction tx = Transaction.openOuter()) { playerInventoryStorage.extract(BUCKET_ITEM_VARIANT, 1, tx); - final BucketSingleStackStorage interceptingStorage = new BucketSingleStackStorage(); + final SingleStackStorageImpl interceptingStorage = SingleStackStorageImpl.forEmptyBucket(); final net.fabricmc.fabric.api.transfer.v1.storage.Storage dest = FluidStorage.ITEM.find( interceptingStorage.getStack(), ContainerItemContext.ofSingleSlot(interceptingStorage) @@ -123,7 +123,7 @@ private void extractWithBucketInInventory(final FluidResource fluidResource, } } - private boolean insertResultingBucketIntoInventory(final BucketSingleStackStorage interceptingStorage, + private boolean insertResultingBucketIntoInventory(final SingleStackStorageImpl interceptingStorage, final boolean cursor, final Transaction innerTx) { final net.fabricmc.fabric.api.transfer.v1.storage.Storage relevantStorage = cursor diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/render/FluidVariantFluidRenderer.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/render/FluidVariantFluidRenderer.java index 4852d21a6..85d9db524 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/render/FluidVariantFluidRenderer.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/render/FluidVariantFluidRenderer.java @@ -13,6 +13,7 @@ import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariantAttributes; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.network.chat.Component; import net.minecraft.world.item.TooltipFlag; @@ -31,10 +32,25 @@ public void render(final PoseStack poseStack, final FluidResource fluidResource) { final FluidVariant fluidVariant = getFluidVariantFromCache(fluidResource); final TextureAtlasSprite sprite = FluidVariantRendering.getSprite(fluidVariant); - if (sprite != null) { - final int packedRgb = FluidVariantRendering.getColor(fluidVariant); - render(poseStack, x, y, packedRgb, sprite); + if (sprite == null) { + return; } + final int packedRgb = FluidVariantRendering.getColor(fluidVariant); + render(poseStack, x, y, packedRgb, sprite); + } + + @Override + public void render(final PoseStack poseStack, + final MultiBufferSource renderTypeBuffer, + final int light, + final FluidResource fluidResource) { + final FluidVariant fluidVariant = getFluidVariantFromCache(fluidResource); + final TextureAtlasSprite sprite = FluidVariantRendering.getSprite(fluidVariant); + if (sprite == null) { + return; + } + final int packedRgb = FluidVariantRendering.getColor(fluidVariant); + render(poseStack, renderTypeBuffer, light, packedRgb, sprite); } @Override diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/util/BucketSingleStackStorage.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/util/SingleStackStorageImpl.java similarity index 54% rename from refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/util/BucketSingleStackStorage.java rename to refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/util/SingleStackStorageImpl.java index eee423e36..34289db78 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/util/BucketSingleStackStorage.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/util/SingleStackStorageImpl.java @@ -4,8 +4,16 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -public class BucketSingleStackStorage extends SingleStackStorage { - private ItemStack stack = new ItemStack(Items.BUCKET); +public final class SingleStackStorageImpl extends SingleStackStorage { + private ItemStack stack; + + public SingleStackStorageImpl(final ItemStack stack) { + this.stack = stack; + } + + public static SingleStackStorageImpl forEmptyBucket() { + return new SingleStackStorageImpl(new ItemStack(Items.BUCKET)); + } @Override public ItemStack getStack() { diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ClientModInitializer.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ClientModInitializer.java index 8005d9c8c..49d796b16 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ClientModInitializer.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ClientModInitializer.java @@ -10,6 +10,7 @@ import com.refinedmods.refinedstorage2.platform.common.content.KeyMappings; import com.refinedmods.refinedstorage2.platform.common.item.RegulatorUpgradeItem; import com.refinedmods.refinedstorage2.platform.common.render.NetworkItemItemPropertyFunction; +import com.refinedmods.refinedstorage2.platform.common.render.entity.StorageMonitorBlockEntityRenderer; import com.refinedmods.refinedstorage2.platform.common.render.model.ControllerModelPredicateProvider; import com.refinedmods.refinedstorage2.platform.common.screen.tooltip.CompositeClientTooltipComponent; import com.refinedmods.refinedstorage2.platform.common.screen.tooltip.HelpClientTooltipComponent; @@ -141,6 +142,10 @@ private static void registerBlockEntityRenderer() { BlockEntities.INSTANCE.getDiskDrive(), ctx -> new DiskDriveBlockEntityRendererImpl<>() ); + BlockEntityRenderers.register( + BlockEntities.INSTANCE.getStorageMonitor(), + ctx -> new StorageMonitorBlockEntityRenderer() + ); } private static void registerGridSynchronizers() { diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ConfigImpl.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ConfigImpl.java index e249e5ae6..782b8fd36 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ConfigImpl.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ConfigImpl.java @@ -35,6 +35,7 @@ public class ConfigImpl implements Config { private final SimpleEnergyUsageEntry constructor; private final WirelessGridEntry wirelessGrid; private final WirelessTransmitterEntry wirelessTransmitter; + private final SimpleEnergyUsageEntry storageMonitor; public ConfigImpl() { cable = new SimpleEnergyUsageEntryImpl("cable", "Cable", DefaultEnergyUsage.CABLE); @@ -58,6 +59,11 @@ public ConfigImpl() { constructor = new SimpleEnergyUsageEntryImpl("constructor", "Constructor", DefaultEnergyUsage.CONSTRUCTOR); wirelessGrid = new WirelessGridEntryImpl(); wirelessTransmitter = new WirelessTransmitterEntryImpl(); + storageMonitor = new SimpleEnergyUsageEntryImpl( + "storageMonitor", + "Storage Monitor", + DefaultEnergyUsage.STORAGE_MONITOR + ); spec = builder.build(); } @@ -150,6 +156,11 @@ public WirelessTransmitterEntry getWirelessTransmitter() { return wirelessTransmitter; } + @Override + public SimpleEnergyUsageEntry getStorageMonitor() { + return storageMonitor; + } + private class SimpleEnergyUsageEntryImpl implements SimpleEnergyUsageEntry { private final ForgeConfigSpec.LongValue energyUsage; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/PlatformImpl.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/PlatformImpl.java index 56ea8b0f1..29213daac 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/PlatformImpl.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/PlatformImpl.java @@ -8,6 +8,7 @@ import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.AbstractPlatform; import com.refinedmods.refinedstorage2.platform.common.Config; +import com.refinedmods.refinedstorage2.platform.common.ContainedFluid; import com.refinedmods.refinedstorage2.platform.common.containermenu.transfer.TransferManager; import com.refinedmods.refinedstorage2.platform.common.util.BucketAmountFormatting; import com.refinedmods.refinedstorage2.platform.common.util.CustomBlockPlaceContext; @@ -69,6 +70,7 @@ import net.minecraftforge.common.util.FakePlayerFactory; import net.minecraftforge.event.ForgeEventFactory; import net.minecraftforge.event.level.BlockEvent; +import net.minecraftforge.fluids.FluidActionResult; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidType; import net.minecraftforge.fluids.FluidUtil; @@ -142,14 +144,22 @@ public GridResourceFactory getFluidGridResourceFactory() { } @Override - public Optional> convertToFluid(final ItemStack stack) { - return stack - .getCapability(ForgeCapabilities.FLUID_HANDLER_ITEM, null) - .map(handler -> handler.getFluidInTank(0)) - .map(contents -> contents.isEmpty() ? null : new ResourceAmount<>( - new FluidResource(contents.getFluid(), contents.getTag()), - contents.getAmount()) - ); + public Optional getContainedFluid(final ItemStack stack) { + final FluidTank tank = new FluidTank(Integer.MAX_VALUE); + final FluidActionResult result = FluidUtil.tryEmptyContainer( + stack, + tank, + Integer.MAX_VALUE, + null, + true + ); + if (!result.isSuccess() || tank.isEmpty()) { + return Optional.empty(); + } + return Optional.of(new ContainedFluid( + result.getResult(), + new ResourceAmount<>(ofFluidStack(tank.getFluid()), tank.getFluidAmount()) + )); } @Override diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/render/FluidStackFluidRenderer.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/render/FluidStackFluidRenderer.java index 00a597c67..64bf8246e 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/render/FluidStackFluidRenderer.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/render/FluidStackFluidRenderer.java @@ -10,6 +10,7 @@ import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; @@ -42,6 +43,22 @@ public void render(final PoseStack poseStack, final int x, final int y, final Fl render(poseStack, x, y, packedRgb, sprite); } + @Override + public void render(final PoseStack poseStack, + final MultiBufferSource renderTypeBuffer, + final int light, + final FluidResource fluidResource) { + final FluidStack stack = getFluidStackFromCache(fluidResource); + final Fluid fluid = fluidResource.fluid(); + + final IClientFluidTypeExtensions renderProperties = IClientFluidTypeExtensions.of(fluid); + + final int packedRgb = renderProperties.getTintColor(stack); + final TextureAtlasSprite sprite = getStillFluidSprite(renderProperties, stack); + + render(poseStack, renderTypeBuffer, light, packedRgb, sprite); + } + @Override public Component getDisplayName(final FluidResource fluidResource) { return fluidResource.fluid().getFluidType().getDescription(); diff --git a/refinedstorage2-platform-forge/src/main/resources/assets/refinedstorage2/textures/slot/curios.png b/refinedstorage2-platform-forge/src/main/resources/assets/refinedstorage2/textures/slot/curios.png index 90fb5ee2eb92322229c786daabac7a9df8483bd7..e48e77d76e78650f34caaa5a2dbaac6061ebb668 100644 GIT binary patch delta 192 zcmV;x06+hQ0)YaMNq@os01m?r3`KR>puu;3jdoS+vI)O%4LMa7ej0X)xLI_~3rO^c@xXn4Y z6a-`Vnw|U|TB4jYP`9CKfWh3zJ@8pXH362vjoc$#kZB-+F*$rqca7R(d6H6Unuxcc ui6)(J&|s#xG&g*vRT=#F$bY|4#+Vbt;AiHq<4^kl00007#FJ-i_uz>P_0Av6RODZT43=ohSWIb5D08)evL#0sw z&M