diff --git a/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageApi.java b/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageApi.java index 585eaa5f4..9c470730f 100644 --- a/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageApi.java +++ b/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageApi.java @@ -7,14 +7,10 @@ import com.refinedmods.refinedstorage.api.network.energy.EnergyStorage; import com.refinedmods.refinedstorage.api.network.node.NetworkNode; import com.refinedmods.refinedstorage.api.network.security.SecurityPolicy; -import com.refinedmods.refinedstorage.api.resource.ResourceAmount; -import com.refinedmods.refinedstorage.api.resource.ResourceKey; import com.refinedmods.refinedstorage.common.api.constructordestructor.ConstructorStrategyFactory; import com.refinedmods.refinedstorage.common.api.constructordestructor.DestructorStrategyFactory; import com.refinedmods.refinedstorage.common.api.exporter.ExporterTransferStrategyFactory; import com.refinedmods.refinedstorage.common.api.grid.Grid; -import com.refinedmods.refinedstorage.common.api.grid.GridInsertionHint; -import com.refinedmods.refinedstorage.common.api.grid.GridInsertionHints; import com.refinedmods.refinedstorage.common.api.grid.GridSynchronizer; import com.refinedmods.refinedstorage.common.api.grid.strategy.GridExtractionStrategy; import com.refinedmods.refinedstorage.common.api.grid.strategy.GridExtractionStrategyFactory; @@ -24,6 +20,8 @@ import com.refinedmods.refinedstorage.common.api.grid.strategy.GridScrollingStrategyFactory; import com.refinedmods.refinedstorage.common.api.importer.ImporterTransferStrategyFactory; import com.refinedmods.refinedstorage.common.api.security.PlatformPermission; +import com.refinedmods.refinedstorage.common.api.storage.StorageBlockData; +import com.refinedmods.refinedstorage.common.api.storage.StorageBlockProvider; import com.refinedmods.refinedstorage.common.api.storage.StorageContainerItemHelper; import com.refinedmods.refinedstorage.common.api.storage.StorageRepository; import com.refinedmods.refinedstorage.common.api.storage.StorageType; @@ -31,6 +29,7 @@ import com.refinedmods.refinedstorage.common.api.storagemonitor.StorageMonitorExtractionStrategy; import com.refinedmods.refinedstorage.common.api.storagemonitor.StorageMonitorInsertionStrategy; import com.refinedmods.refinedstorage.common.api.support.energy.EnergyItemHelper; +import com.refinedmods.refinedstorage.common.api.support.network.AbstractNetworkNodeContainerBlockEntity; import com.refinedmods.refinedstorage.common.api.support.network.InWorldNetworkNodeContainer; import com.refinedmods.refinedstorage.common.api.support.network.NetworkNodeContainerProvider; import com.refinedmods.refinedstorage.common.api.support.network.item.NetworkItemHelper; @@ -38,7 +37,6 @@ import com.refinedmods.refinedstorage.common.api.support.resource.RecipeModIngredientConverter; import com.refinedmods.refinedstorage.common.api.support.resource.ResourceContainerInsertStrategy; import com.refinedmods.refinedstorage.common.api.support.resource.ResourceFactory; -import com.refinedmods.refinedstorage.common.api.support.resource.ResourceRendering; import com.refinedmods.refinedstorage.common.api.support.resource.ResourceType; import com.refinedmods.refinedstorage.common.api.support.slotreference.SlotReference; import com.refinedmods.refinedstorage.common.api.support.slotreference.SlotReferenceFactory; @@ -47,21 +45,24 @@ import com.refinedmods.refinedstorage.common.api.wirelesstransmitter.WirelessTransmitterRangeModifier; import java.util.Collection; -import java.util.List; import java.util.Optional; import java.util.Set; import javax.annotation.Nullable; import net.minecraft.core.BlockPos; +import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.chat.Component; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MenuType; import net.minecraft.world.item.Item; 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.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; @@ -133,10 +134,6 @@ GridInsertionStrategy createGridInsertionStrategy(AbstractContainerMenu containe Collection getResourceContainerInsertStrategies(); - void addAlternativeGridInsertionHint(GridInsertionHint hint); - - GridInsertionHints getGridInsertionHints(); - GridExtractionStrategy createGridExtractionStrategy(AbstractContainerMenu containerMenu, ServerPlayer player, Grid grid); @@ -161,10 +158,6 @@ GridScrollingStrategy createGridScrollingStrategy(AbstractContainerMenu containe Set getAlternativeResourceFactories(); - void registerResourceRendering(Class resourceClass, ResourceRendering rendering); - - ResourceRendering getResourceRendering(Class resourceClass); - void addIngredientConverter(RecipeModIngredientConverter converter); RecipeModIngredientConverter getIngredientConverter(); @@ -207,7 +200,19 @@ EnergyStorage asBlockItemEnergyStorage( Optional getPattern(ItemStack stack, Level level); - void openAutocraftingPreview(List requests, @Nullable Object parentScreen); - ResourceLocation getCreativeModeTabId(); + + AbstractNetworkNodeContainerBlockEntity createStorageBlockEntity(BlockPos pos, + BlockState state, + StorageBlockProvider provider); + + Block createStorageBlock(Block.Properties properties, StorageBlockProvider provider); + + AbstractContainerMenu createStorageBlockContainerMenu(int syncId, + Player player, + StorageBlockData data, + ResourceFactory resourceFactory, + MenuType menuType); + + StreamCodec getStorageBlockDataStreamCodec(); } diff --git a/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageApiProxy.java b/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageApiProxy.java index f33b6d74b..f917a941a 100644 --- a/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageApiProxy.java +++ b/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageApiProxy.java @@ -7,14 +7,10 @@ import com.refinedmods.refinedstorage.api.network.energy.EnergyStorage; import com.refinedmods.refinedstorage.api.network.node.NetworkNode; import com.refinedmods.refinedstorage.api.network.security.SecurityPolicy; -import com.refinedmods.refinedstorage.api.resource.ResourceAmount; -import com.refinedmods.refinedstorage.api.resource.ResourceKey; import com.refinedmods.refinedstorage.common.api.constructordestructor.ConstructorStrategyFactory; import com.refinedmods.refinedstorage.common.api.constructordestructor.DestructorStrategyFactory; import com.refinedmods.refinedstorage.common.api.exporter.ExporterTransferStrategyFactory; import com.refinedmods.refinedstorage.common.api.grid.Grid; -import com.refinedmods.refinedstorage.common.api.grid.GridInsertionHint; -import com.refinedmods.refinedstorage.common.api.grid.GridInsertionHints; import com.refinedmods.refinedstorage.common.api.grid.GridSynchronizer; import com.refinedmods.refinedstorage.common.api.grid.strategy.GridExtractionStrategy; import com.refinedmods.refinedstorage.common.api.grid.strategy.GridExtractionStrategyFactory; @@ -24,6 +20,8 @@ import com.refinedmods.refinedstorage.common.api.grid.strategy.GridScrollingStrategyFactory; import com.refinedmods.refinedstorage.common.api.importer.ImporterTransferStrategyFactory; import com.refinedmods.refinedstorage.common.api.security.PlatformPermission; +import com.refinedmods.refinedstorage.common.api.storage.StorageBlockData; +import com.refinedmods.refinedstorage.common.api.storage.StorageBlockProvider; import com.refinedmods.refinedstorage.common.api.storage.StorageContainerItemHelper; import com.refinedmods.refinedstorage.common.api.storage.StorageRepository; import com.refinedmods.refinedstorage.common.api.storage.StorageType; @@ -31,6 +29,7 @@ import com.refinedmods.refinedstorage.common.api.storagemonitor.StorageMonitorExtractionStrategy; import com.refinedmods.refinedstorage.common.api.storagemonitor.StorageMonitorInsertionStrategy; import com.refinedmods.refinedstorage.common.api.support.energy.EnergyItemHelper; +import com.refinedmods.refinedstorage.common.api.support.network.AbstractNetworkNodeContainerBlockEntity; import com.refinedmods.refinedstorage.common.api.support.network.InWorldNetworkNodeContainer; import com.refinedmods.refinedstorage.common.api.support.network.NetworkNodeContainerProvider; import com.refinedmods.refinedstorage.common.api.support.network.item.NetworkItemHelper; @@ -38,7 +37,6 @@ import com.refinedmods.refinedstorage.common.api.support.resource.RecipeModIngredientConverter; import com.refinedmods.refinedstorage.common.api.support.resource.ResourceContainerInsertStrategy; import com.refinedmods.refinedstorage.common.api.support.resource.ResourceFactory; -import com.refinedmods.refinedstorage.common.api.support.resource.ResourceRendering; import com.refinedmods.refinedstorage.common.api.support.resource.ResourceType; import com.refinedmods.refinedstorage.common.api.support.slotreference.SlotReference; import com.refinedmods.refinedstorage.common.api.support.slotreference.SlotReferenceFactory; @@ -47,21 +45,24 @@ import com.refinedmods.refinedstorage.common.api.wirelesstransmitter.WirelessTransmitterRangeModifier; import java.util.Collection; -import java.util.List; import java.util.Optional; import java.util.Set; import javax.annotation.Nullable; import net.minecraft.core.BlockPos; +import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.chat.Component; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MenuType; import net.minecraft.world.item.Item; 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.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; @@ -229,16 +230,6 @@ public Collection getResourceContainerInsertStr return ensureLoaded().getResourceContainerInsertStrategies(); } - @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 ServerPlayer player, @@ -293,17 +284,6 @@ 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 Class resourceClass) { - return ensureLoaded().getResourceRendering(resourceClass); - } - @Override public void addIngredientConverter(final RecipeModIngredientConverter converter) { ensureLoaded().addIngredientConverter(converter); @@ -405,13 +385,34 @@ public Optional getPattern(final ItemStack stack, final Level level) { } @Override - public void openAutocraftingPreview(final List requests, @Nullable final Object parentScreen) { - ensureLoaded().openAutocraftingPreview(requests, parentScreen); + public ResourceLocation getCreativeModeTabId() { + return ensureLoaded().getCreativeModeTabId(); } @Override - public ResourceLocation getCreativeModeTabId() { - return ensureLoaded().getCreativeModeTabId(); + public AbstractNetworkNodeContainerBlockEntity createStorageBlockEntity(final BlockPos pos, + final BlockState state, + final StorageBlockProvider provider) { + return ensureLoaded().createStorageBlockEntity(pos, state, provider); + } + + @Override + public Block createStorageBlock(final Block.Properties properties, final StorageBlockProvider provider) { + return ensureLoaded().createStorageBlock(properties, provider); + } + + @Override + public AbstractContainerMenu createStorageBlockContainerMenu(final int syncId, + final Player player, + final StorageBlockData data, + final ResourceFactory resourceFactory, + final MenuType menuType) { + return ensureLoaded().createStorageBlockContainerMenu(syncId, player, data, resourceFactory, menuType); + } + + @Override + public StreamCodec getStorageBlockDataStreamCodec() { + return ensureLoaded().getStorageBlockDataStreamCodec(); } private RefinedStorageApi ensureLoaded() { diff --git a/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageClientApi.java b/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageClientApi.java new file mode 100644 index 000000000..eb6cd7151 --- /dev/null +++ b/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageClientApi.java @@ -0,0 +1,49 @@ +package com.refinedmods.refinedstorage.common.api; + +import com.refinedmods.refinedstorage.api.resource.ResourceAmount; +import com.refinedmods.refinedstorage.api.resource.ResourceKey; +import com.refinedmods.refinedstorage.common.api.grid.GridInsertionHint; +import com.refinedmods.refinedstorage.common.api.grid.GridInsertionHints; +import com.refinedmods.refinedstorage.common.api.support.resource.ResourceRendering; + +import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.annotation.Nullable; + +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.item.Item; +import org.apiguardian.api.API; + +@API(status = API.Status.STABLE, since = "2.0.0-milestone.4.11") +public interface RefinedStorageClientApi { + RefinedStorageClientApi INSTANCE = new RefinedStorageClientApiProxy(); + + AbstractContainerScreen createStorageBlockScreen( + AbstractContainerMenu menu, + Inventory inventory, + Component title, + Class resourceClass + ); + + void openAutocraftingPreview(List requests, @Nullable Screen parentScreen); + + void registerResourceRendering(Class resourceClass, ResourceRendering rendering); + + ResourceRendering getResourceRendering(Class resourceClass); + + void addAlternativeGridInsertionHint(GridInsertionHint hint); + + GridInsertionHints getGridInsertionHints(); + + void registerDiskModel(Item item, ResourceLocation model); + + Set getDiskModels(); + + Map getDiskModelsByItem(); +} diff --git a/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageClientApiProxy.java b/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageClientApiProxy.java new file mode 100644 index 000000000..6adafab42 --- /dev/null +++ b/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageClientApiProxy.java @@ -0,0 +1,90 @@ +package com.refinedmods.refinedstorage.common.api; + +import com.refinedmods.refinedstorage.api.resource.ResourceAmount; +import com.refinedmods.refinedstorage.api.resource.ResourceKey; +import com.refinedmods.refinedstorage.common.api.grid.GridInsertionHint; +import com.refinedmods.refinedstorage.common.api.grid.GridInsertionHints; +import com.refinedmods.refinedstorage.common.api.support.resource.ResourceRendering; + +import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.annotation.Nullable; + +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.item.Item; + +public class RefinedStorageClientApiProxy implements RefinedStorageClientApi { + @Nullable + private RefinedStorageClientApi delegate; + + public void setDelegate(final RefinedStorageClientApi delegate) { + if (this.delegate != null) { + throw new IllegalStateException("Client API already injected"); + } + this.delegate = delegate; + } + + @Override + public AbstractContainerScreen createStorageBlockScreen( + final AbstractContainerMenu menu, + final Inventory inventory, + final Component title, + final Class resourceClass + ) { + return ensureLoaded().createStorageBlockScreen(menu, inventory, title, resourceClass); + } + + @Override + public void openAutocraftingPreview(final List requests, @Nullable final Screen parentScreen) { + ensureLoaded().openAutocraftingPreview(requests, parentScreen); + } + + @Override + public void registerResourceRendering(final Class resourceClass, + final ResourceRendering rendering) { + ensureLoaded().registerResourceRendering(resourceClass, rendering); + } + + @Override + public ResourceRendering getResourceRendering(final Class resourceClass) { + return ensureLoaded().getResourceRendering(resourceClass); + } + + @Override + public void addAlternativeGridInsertionHint(final GridInsertionHint hint) { + ensureLoaded().addAlternativeGridInsertionHint(hint); + } + + @Override + public GridInsertionHints getGridInsertionHints() { + return ensureLoaded().getGridInsertionHints(); + } + + @Override + public void registerDiskModel(final Item item, final ResourceLocation model) { + ensureLoaded().registerDiskModel(item, model); + } + + @Override + public Set getDiskModels() { + return ensureLoaded().getDiskModels(); + } + + @Override + public Map getDiskModelsByItem() { + return ensureLoaded().getDiskModelsByItem(); + } + + private RefinedStorageClientApi ensureLoaded() { + if (delegate == null) { + throw new IllegalStateException("API not loaded yet"); + } + return delegate; + } +} diff --git a/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/storage/StorageBlockData.java b/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/storage/StorageBlockData.java new file mode 100644 index 000000000..df3bf828f --- /dev/null +++ b/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/storage/StorageBlockData.java @@ -0,0 +1,9 @@ +package com.refinedmods.refinedstorage.common.api.storage; + +import com.refinedmods.refinedstorage.api.resource.ResourceAmount; + +import java.util.List; +import java.util.Optional; + +public record StorageBlockData(long stored, long capacity, List> resources) { +} diff --git a/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/storage/StorageBlockProvider.java b/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/storage/StorageBlockProvider.java new file mode 100644 index 000000000..7146b1b7f --- /dev/null +++ b/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/storage/StorageBlockProvider.java @@ -0,0 +1,23 @@ +package com.refinedmods.refinedstorage.common.api.storage; + +import com.refinedmods.refinedstorage.common.api.support.resource.ResourceFactory; + +import net.minecraft.network.chat.Component; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.level.block.entity.BlockEntityType; +import org.apiguardian.api.API; + +@API(status = API.Status.STABLE, since = "2.0.0-milestone.4.11") +public interface StorageBlockProvider { + SerializableStorage createStorage(Runnable listener); + + Component getDisplayName(); + + long getEnergyUsage(); + + ResourceFactory getResourceFactory(); + + BlockEntityType getBlockEntityType(); + + MenuType getMenuType(); +} diff --git a/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/storage/StorageContainerItemHelper.java b/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/storage/StorageContainerItemHelper.java index ff50d513d..63c7f7385 100644 --- a/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/storage/StorageContainerItemHelper.java +++ b/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/storage/StorageContainerItemHelper.java @@ -1,19 +1,15 @@ package com.refinedmods.refinedstorage.common.api.storage; import java.util.List; -import java.util.Map; import java.util.Optional; -import java.util.Set; import java.util.function.Function; import java.util.function.LongFunction; import javax.annotation.Nullable; import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.level.Level; @@ -52,11 +48,5 @@ void appendToTooltip(ItemStack stack, void transferFromBlockEntity(ItemStack stack, StorageBlockEntity blockEntity); - void registerDiskModel(Item item, ResourceLocation model); - - Set getDiskModels(); - - Map getDiskModelsByItem(); - void markAsToTransfer(ItemStack from, ItemStack to); } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/AbstractClientModInitializer.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/AbstractClientModInitializer.java index bbc1b946b..9c1d5a454 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/AbstractClientModInitializer.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/AbstractClientModInitializer.java @@ -2,6 +2,8 @@ import com.refinedmods.refinedstorage.api.resource.ResourceAmount; import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.RefinedStorageClientApi; +import com.refinedmods.refinedstorage.common.api.RefinedStorageClientApiProxy; import com.refinedmods.refinedstorage.common.api.upgrade.UpgradeMapping; import com.refinedmods.refinedstorage.common.autocrafting.autocrafter.AutocrafterScreen; import com.refinedmods.refinedstorage.common.autocrafting.autocraftermanager.AutocrafterManagerScreen; @@ -36,8 +38,6 @@ import com.refinedmods.refinedstorage.common.storage.diskinterface.DiskInterfaceScreen; import com.refinedmods.refinedstorage.common.storage.externalstorage.ExternalStorageScreen; import com.refinedmods.refinedstorage.common.storage.portablegrid.PortableGridScreen; -import com.refinedmods.refinedstorage.common.storage.storageblock.FluidStorageBlockScreen; -import com.refinedmods.refinedstorage.common.storage.storageblock.ItemStorageBlockScreen; import com.refinedmods.refinedstorage.common.storagemonitor.StorageMonitorScreen; import com.refinedmods.refinedstorage.common.support.resource.FluidResource; import com.refinedmods.refinedstorage.common.support.resource.FluidResourceRendering; @@ -57,6 +57,7 @@ import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.gui.screens.inventory.MenuAccess; import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; import net.minecraft.network.chat.Component; @@ -65,10 +66,17 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.Item; import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createIdentifier; public abstract class AbstractClientModInitializer { + public static void initializeClientPlatformApi() { + ((RefinedStorageClientApiProxy) RefinedStorageClientApi.INSTANCE).setDelegate( + new RefinedStorageClientApiImpl() + ); + } + protected static void registerScreens(final ScreenRegistration registration) { registration.register(Menus.INSTANCE.getDiskDrive(), DiskDriveScreen::new); registration.register(Menus.INSTANCE.getGrid(), GridScreen::new); @@ -76,8 +84,26 @@ protected static void registerScreens(final ScreenRegistration registration) { registration.register(Menus.INSTANCE.getPatternGrid(), PatternGridScreen::new); registration.register(Menus.INSTANCE.getWirelessGrid(), GridScreen::new); registration.register(Menus.INSTANCE.getController(), ControllerScreen::new); - registration.register(Menus.INSTANCE.getItemStorage(), ItemStorageBlockScreen::new); - registration.register(Menus.INSTANCE.getFluidStorage(), FluidStorageBlockScreen::new); + registration.register(Menus.INSTANCE.getItemStorage(), + new ScreenConstructor>() { + @Override + public AbstractContainerScreen create(final AbstractContainerMenu menu, + final Inventory inventory, + final Component title) { + return RefinedStorageClientApi.INSTANCE.createStorageBlockScreen(menu, inventory, title, + ItemResource.class); + } + }); + registration.register(Menus.INSTANCE.getFluidStorage(), + new ScreenConstructor>() { + @Override + public AbstractContainerScreen create(final AbstractContainerMenu menu, + final Inventory inventory, + final Component title) { + return RefinedStorageClientApi.INSTANCE.createStorageBlockScreen(menu, inventory, title, + FluidResource.class); + } + }); registration.register(Menus.INSTANCE.getImporter(), ImporterScreen::new); registration.register(Menus.INSTANCE.getExporter(), ExporterScreen::new); registration.register(Menus.INSTANCE.getInterface(), InterfaceScreen::new); @@ -112,12 +138,12 @@ public AutocraftingPreviewScreen create(final AutocraftingPreviewContainerMenu m } protected static void registerAlternativeGridHints() { - RefinedStorageApi.INSTANCE.addAlternativeGridInsertionHint(new FluidGridInsertionHint()); + RefinedStorageClientApi.INSTANCE.addAlternativeGridInsertionHint(new FluidGridInsertionHint()); } protected static void registerResourceRendering() { - RefinedStorageApi.INSTANCE.registerResourceRendering(ItemResource.class, new ItemResourceRendering()); - RefinedStorageApi.INSTANCE.registerResourceRendering(FluidResource.class, new FluidResourceRendering( + RefinedStorageClientApi.INSTANCE.registerResourceRendering(ItemResource.class, ItemResourceRendering.INSTANCE); + RefinedStorageClientApi.INSTANCE.registerResourceRendering(FluidResource.class, new FluidResourceRendering( Platform.INSTANCE.getBucketAmount() )); } @@ -156,18 +182,13 @@ protected static void handleInputEvents() { protected static void registerDiskModels() { final ResourceLocation diskModel = createIdentifier("block/disk/disk"); for (final ItemStorageVariant variant : ItemStorageVariant.values()) { - RefinedStorageApi.INSTANCE.getStorageContainerItemHelper().registerDiskModel( - Items.INSTANCE.getItemStorageDisk(variant), - diskModel - ); + final Item item = Items.INSTANCE.getItemStorageDisk(variant); + RefinedStorageClientApi.INSTANCE.registerDiskModel(item, diskModel); } - final ResourceLocation fluidDiskModel = createIdentifier("block/disk/fluid_disk"); for (final FluidStorageVariant variant : FluidStorageVariant.values()) { - RefinedStorageApi.INSTANCE.getStorageContainerItemHelper().registerDiskModel( - Items.INSTANCE.getFluidStorageDisk(variant), - fluidDiskModel - ); + final Item item = Items.INSTANCE.getFluidStorageDisk(variant); + RefinedStorageClientApi.INSTANCE.registerDiskModel(item, fluidDiskModel); } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/AbstractModInitializer.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/AbstractModInitializer.java index e3ee5c201..63d5aeb23 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/AbstractModInitializer.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/AbstractModInitializer.java @@ -44,6 +44,7 @@ import com.refinedmods.refinedstorage.common.constructordestructor.PlaceBlockConstructorStrategy; import com.refinedmods.refinedstorage.common.constructordestructor.PlaceFireworksConstructorStrategy; import com.refinedmods.refinedstorage.common.constructordestructor.PlaceFluidConstructorStrategy; +import com.refinedmods.refinedstorage.common.content.BlockConstants; import com.refinedmods.refinedstorage.common.content.BlockEntities; import com.refinedmods.refinedstorage.common.content.BlockEntityProviders; import com.refinedmods.refinedstorage.common.content.BlockEntityTypeFactory; @@ -116,15 +117,10 @@ import com.refinedmods.refinedstorage.common.storage.portablegrid.PortableGridItemContainerMenu; import com.refinedmods.refinedstorage.common.storage.portablegrid.PortableGridLootItemFunction; import com.refinedmods.refinedstorage.common.storage.portablegrid.PortableGridType; -import com.refinedmods.refinedstorage.common.storage.storageblock.FluidStorageBlock; -import com.refinedmods.refinedstorage.common.storage.storageblock.FluidStorageBlockBlockEntity; import com.refinedmods.refinedstorage.common.storage.storageblock.FluidStorageBlockBlockItem; -import com.refinedmods.refinedstorage.common.storage.storageblock.FluidStorageBlockContainerMenu; -import com.refinedmods.refinedstorage.common.storage.storageblock.ItemStorageBlock; -import com.refinedmods.refinedstorage.common.storage.storageblock.ItemStorageBlockBlockEntity; +import com.refinedmods.refinedstorage.common.storage.storageblock.FluidStorageBlockProvider; import com.refinedmods.refinedstorage.common.storage.storageblock.ItemStorageBlockBlockItem; -import com.refinedmods.refinedstorage.common.storage.storageblock.ItemStorageBlockContainerMenu; -import com.refinedmods.refinedstorage.common.storage.storageblock.StorageBlockData; +import com.refinedmods.refinedstorage.common.storage.storageblock.ItemStorageBlockProvider; import com.refinedmods.refinedstorage.common.storage.storageblock.StorageBlockLootItemFunction; import com.refinedmods.refinedstorage.common.storage.storagedisk.FluidStorageDiskItem; import com.refinedmods.refinedstorage.common.storage.storagedisk.ItemStorageDiskItem; @@ -308,13 +304,19 @@ protected final void registerBlocks(final RegistryCallback callback, for (final ItemStorageVariant variant : ItemStorageVariant.values()) { Blocks.INSTANCE.setItemStorageBlock(variant, callback.register( ContentIds.forItemStorageBlock(variant), - () -> new ItemStorageBlock(variant) + () -> RefinedStorageApi.INSTANCE.createStorageBlock( + BlockConstants.PROPERTIES, + new ItemStorageBlockProvider(variant) + ) )); } for (final FluidStorageVariant variant : FluidStorageVariant.values()) { Blocks.INSTANCE.setFluidStorageBlock(variant, callback.register( ContentIds.forFluidStorageBlock(variant), - () -> new FluidStorageBlock(variant) + () -> RefinedStorageApi.INSTANCE.createStorageBlock( + BlockConstants.PROPERTIES, + new FluidStorageBlockProvider(variant) + ) )); } Blocks.INSTANCE.getController().registerBlocks(callback); @@ -573,7 +575,9 @@ protected final void registerBlockEntities( BlockEntities.INSTANCE.setItemStorageBlock(variant, callback.register( ContentIds.forItemStorageBlock(variant), () -> typeFactory.create( - (pos, state) -> new ItemStorageBlockBlockEntity(pos, state, variant), + (pos, state) -> RefinedStorageApi.INSTANCE.createStorageBlockEntity( + pos, state, new ItemStorageBlockProvider(variant) + ), Blocks.INSTANCE.getItemStorageBlock(variant) ) )); @@ -582,7 +586,9 @@ protected final void registerBlockEntities( BlockEntities.INSTANCE.setFluidStorageBlock(variant, callback.register( ContentIds.forFluidStorageBlock(variant), () -> typeFactory.create( - (pos, state) -> new FluidStorageBlockBlockEntity(pos, state, variant), + (pos, state) -> RefinedStorageApi.INSTANCE.createStorageBlockEntity( + pos, state, new FluidStorageBlockProvider(variant) + ), Blocks.INSTANCE.getFluidStorageBlock(variant) ) )); @@ -709,12 +715,22 @@ protected final void registerMenus(final RegistryCallback> callback, )); Menus.INSTANCE.setItemStorage(callback.register( ContentIds.ITEM_STORAGE_BLOCK, - () -> extendedMenuTypeFactory.create(ItemStorageBlockContainerMenu::new, StorageBlockData.STREAM_CODEC) - )); + () -> extendedMenuTypeFactory.create((syncId, playerInventory, data) -> + RefinedStorageApi.INSTANCE.createStorageBlockContainerMenu( + syncId, + playerInventory.player, + data, + RefinedStorageApi.INSTANCE.getItemResourceFactory(), + Menus.INSTANCE.getItemStorage()), RefinedStorageApi.INSTANCE.getStorageBlockDataStreamCodec()))); Menus.INSTANCE.setFluidStorage(callback.register( ContentIds.FLUID_STORAGE_BLOCK, - () -> extendedMenuTypeFactory.create(FluidStorageBlockContainerMenu::new, StorageBlockData.STREAM_CODEC) - )); + () -> extendedMenuTypeFactory.create((syncId, playerInventory, data) -> + RefinedStorageApi.INSTANCE.createStorageBlockContainerMenu( + syncId, + playerInventory.player, + data, + RefinedStorageApi.INSTANCE.getFluidResourceFactory(), + Menus.INSTANCE.getFluidStorage()), RefinedStorageApi.INSTANCE.getStorageBlockDataStreamCodec()))); Menus.INSTANCE.setImporter(callback.register( ContentIds.IMPORTER, () -> extendedMenuTypeFactory.create(ImporterContainerMenu::new, ResourceContainerData.STREAM_CODEC) @@ -817,10 +833,8 @@ protected final void registerMenus(final RegistryCallback> callback, )); Menus.INSTANCE.setWirelessAutocraftingMonitor(callback.register( ContentIds.WIRELESS_AUTOCRAFTING_MONITOR, - () -> extendedMenuTypeFactory.create( - WirelessAutocraftingMonitorContainerMenu::new, - AutocraftingMonitorData.STREAM_CODEC - ) + () -> extendedMenuTypeFactory.create(WirelessAutocraftingMonitorContainerMenu::new, + AutocraftingMonitorData.STREAM_CODEC) )); } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/RefinedStorageApiImpl.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/RefinedStorageApiImpl.java index 0f328fcc4..e732baff6 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/RefinedStorageApiImpl.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/RefinedStorageApiImpl.java @@ -10,16 +10,12 @@ import com.refinedmods.refinedstorage.api.network.impl.NetworkFactory; import com.refinedmods.refinedstorage.api.network.node.NetworkNode; import com.refinedmods.refinedstorage.api.network.security.SecurityPolicy; -import com.refinedmods.refinedstorage.api.resource.ResourceAmount; -import com.refinedmods.refinedstorage.api.resource.ResourceKey; import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; import com.refinedmods.refinedstorage.common.api.autocrafting.PatternProviderItem; import com.refinedmods.refinedstorage.common.api.constructordestructor.ConstructorStrategyFactory; import com.refinedmods.refinedstorage.common.api.constructordestructor.DestructorStrategyFactory; import com.refinedmods.refinedstorage.common.api.exporter.ExporterTransferStrategyFactory; import com.refinedmods.refinedstorage.common.api.grid.Grid; -import com.refinedmods.refinedstorage.common.api.grid.GridInsertionHint; -import com.refinedmods.refinedstorage.common.api.grid.GridInsertionHints; import com.refinedmods.refinedstorage.common.api.grid.GridSynchronizer; import com.refinedmods.refinedstorage.common.api.grid.strategy.GridExtractionStrategy; import com.refinedmods.refinedstorage.common.api.grid.strategy.GridExtractionStrategyFactory; @@ -29,6 +25,8 @@ import com.refinedmods.refinedstorage.common.api.grid.strategy.GridScrollingStrategyFactory; import com.refinedmods.refinedstorage.common.api.importer.ImporterTransferStrategyFactory; import com.refinedmods.refinedstorage.common.api.security.PlatformPermission; +import com.refinedmods.refinedstorage.common.api.storage.StorageBlockData; +import com.refinedmods.refinedstorage.common.api.storage.StorageBlockProvider; import com.refinedmods.refinedstorage.common.api.storage.StorageContainerItemHelper; import com.refinedmods.refinedstorage.common.api.storage.StorageRepository; import com.refinedmods.refinedstorage.common.api.storage.StorageType; @@ -36,6 +34,7 @@ import com.refinedmods.refinedstorage.common.api.storagemonitor.StorageMonitorExtractionStrategy; import com.refinedmods.refinedstorage.common.api.storagemonitor.StorageMonitorInsertionStrategy; import com.refinedmods.refinedstorage.common.api.support.energy.EnergyItemHelper; +import com.refinedmods.refinedstorage.common.api.support.network.AbstractNetworkNodeContainerBlockEntity; import com.refinedmods.refinedstorage.common.api.support.network.InWorldNetworkNodeContainer; import com.refinedmods.refinedstorage.common.api.support.network.NetworkNodeContainerProvider; import com.refinedmods.refinedstorage.common.api.support.network.item.NetworkItemHelper; @@ -43,7 +42,6 @@ import com.refinedmods.refinedstorage.common.api.support.resource.RecipeModIngredientConverter; import com.refinedmods.refinedstorage.common.api.support.resource.ResourceContainerInsertStrategy; import com.refinedmods.refinedstorage.common.api.support.resource.ResourceFactory; -import com.refinedmods.refinedstorage.common.api.support.resource.ResourceRendering; import com.refinedmods.refinedstorage.common.api.support.resource.ResourceType; import com.refinedmods.refinedstorage.common.api.support.slotreference.SlotReference; import com.refinedmods.refinedstorage.common.api.support.slotreference.SlotReferenceFactory; @@ -52,9 +50,6 @@ import com.refinedmods.refinedstorage.common.api.wirelesstransmitter.WirelessTransmitterRangeModifier; import com.refinedmods.refinedstorage.common.content.ContentIds; import com.refinedmods.refinedstorage.common.grid.NoopGridSynchronizer; -import com.refinedmods.refinedstorage.common.grid.screen.hint.GridInsertionHintsImpl; -import com.refinedmods.refinedstorage.common.grid.screen.hint.ItemGridInsertionHint; -import com.refinedmods.refinedstorage.common.grid.screen.hint.SingleItemGridInsertionHint; import com.refinedmods.refinedstorage.common.grid.strategy.CompositeGridExtractionStrategy; import com.refinedmods.refinedstorage.common.grid.strategy.CompositeGridInsertionStrategy; import com.refinedmods.refinedstorage.common.grid.strategy.CompositeGridScrollingStrategy; @@ -63,6 +58,10 @@ import com.refinedmods.refinedstorage.common.storage.StorageContainerItemHelperImpl; import com.refinedmods.refinedstorage.common.storage.StorageRepositoryImpl; import com.refinedmods.refinedstorage.common.storage.StorageTypes; +import com.refinedmods.refinedstorage.common.storage.storageblock.StorageBlock; +import com.refinedmods.refinedstorage.common.storage.storageblock.StorageBlockBlockEntity; +import com.refinedmods.refinedstorage.common.storage.storageblock.StorageBlockCodecs; +import com.refinedmods.refinedstorage.common.storage.storageblock.StorageBlockContainerMenu; import com.refinedmods.refinedstorage.common.storagemonitor.CompositeStorageMonitorExtractionStrategy; import com.refinedmods.refinedstorage.common.storagemonitor.CompositeStorageMonitorInsertionStrategy; import com.refinedmods.refinedstorage.common.support.energy.EnergyItemHelperImpl; @@ -81,7 +80,6 @@ import com.refinedmods.refinedstorage.common.support.slotreference.CompositeSlotReferenceProvider; import com.refinedmods.refinedstorage.common.support.slotreference.InventorySlotReference; import com.refinedmods.refinedstorage.common.upgrade.UpgradeRegistryImpl; -import com.refinedmods.refinedstorage.common.util.ClientPlatformUtil; import com.refinedmods.refinedstorage.common.util.IdentifierUtil; import com.refinedmods.refinedstorage.common.util.ServerEventQueue; @@ -104,16 +102,20 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.chat.Component; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MenuType; import net.minecraft.world.item.Item; 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.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; @@ -155,16 +157,11 @@ public class RefinedStorageApiImpl implements RefinedStorageApi { new CompositeRecipeModIngredientConverter(); 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(); @@ -381,16 +378,6 @@ public Collection getResourceContainerInsertStr return Collections.unmodifiableList(resourceExtractStrategies); } - @Override - public void addAlternativeGridInsertionHint(final GridInsertionHint hint) { - gridInsertionHints.addAlternativeHint(hint); - } - - @Override - public GridInsertionHints getGridInsertionHints() { - return gridInsertionHints; - } - @Override public GridExtractionStrategy createGridExtractionStrategy(final AbstractContainerMenu containerMenu, final ServerPlayer player, @@ -453,17 +440,6 @@ public Set getAlternativeResourceFactories() { return resourceFactories; } - @Override - public void registerResourceRendering(final Class resourceClass, - final ResourceRendering rendering) { - resourceRenderingMap.put(resourceClass, rendering); - } - - @Override - public ResourceRendering getResourceRendering(final Class resourceClass) { - return resourceRenderingMap.get(resourceClass); - } - @Override public void addIngredientConverter(final RecipeModIngredientConverter converter) { ingredientConverter.addConverter(converter); @@ -601,15 +577,39 @@ public Optional getPattern(final ItemStack stack, final Level level) { } @Override - public void openAutocraftingPreview(final List requests, @Nullable final Object parentScreen) { - if (requests.isEmpty()) { - return; - } - ClientPlatformUtil.openCraftingPreview(requests, parentScreen); + public ResourceLocation getCreativeModeTabId() { + return ContentIds.CREATIVE_MODE_TAB; } @Override - public ResourceLocation getCreativeModeTabId() { - return ContentIds.CREATIVE_MODE_TAB; + public AbstractNetworkNodeContainerBlockEntity createStorageBlockEntity(final BlockPos pos, + final BlockState state, + final StorageBlockProvider provider) { + return new StorageBlockBlockEntity(pos, state, provider); + } + + @Override + public Block createStorageBlock(final Block.Properties properties, final StorageBlockProvider provider) { + return new StorageBlock<>(properties, provider); + } + + @Override + public AbstractContainerMenu createStorageBlockContainerMenu(final int syncId, + final Player player, + final StorageBlockData data, + final ResourceFactory resourceFactory, + final MenuType menuType) { + return new StorageBlockContainerMenu( + menuType, + syncId, + player, + data, + resourceFactory + ); + } + + @Override + public StreamCodec getStorageBlockDataStreamCodec() { + return StorageBlockCodecs.STREAM_CODEC; } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/RefinedStorageClientApiImpl.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/RefinedStorageClientApiImpl.java new file mode 100644 index 000000000..fc9fa7afb --- /dev/null +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/RefinedStorageClientApiImpl.java @@ -0,0 +1,107 @@ +package com.refinedmods.refinedstorage.common; + +import com.refinedmods.refinedstorage.api.resource.ResourceAmount; +import com.refinedmods.refinedstorage.api.resource.ResourceKey; +import com.refinedmods.refinedstorage.common.api.RefinedStorageClientApi; +import com.refinedmods.refinedstorage.common.api.grid.GridInsertionHint; +import com.refinedmods.refinedstorage.common.api.grid.GridInsertionHints; +import com.refinedmods.refinedstorage.common.api.support.resource.ResourceRendering; +import com.refinedmods.refinedstorage.common.grid.screen.hint.GridInsertionHintsImpl; +import com.refinedmods.refinedstorage.common.grid.screen.hint.ItemGridInsertionHint; +import com.refinedmods.refinedstorage.common.grid.screen.hint.SingleItemGridInsertionHint; +import com.refinedmods.refinedstorage.common.storage.storageblock.StorageBlockContainerMenu; +import com.refinedmods.refinedstorage.common.storage.storageblock.StorageBlockScreen; +import com.refinedmods.refinedstorage.common.support.resource.ItemResource; +import com.refinedmods.refinedstorage.common.support.resource.ItemResourceRendering; +import com.refinedmods.refinedstorage.common.util.ClientPlatformUtil; + +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.annotation.Nullable; + +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.item.Item; + +public class RefinedStorageClientApiImpl implements RefinedStorageClientApi { + private final Map, ResourceRendering> resourceRenderingMap = new HashMap<>(); + private final Map diskModelsByItem = new HashMap<>(); + private final Set diskModels = new HashSet<>(); + private final GridInsertionHintsImpl gridInsertionHints = new GridInsertionHintsImpl( + new ItemGridInsertionHint(), + new SingleItemGridInsertionHint() + ); + + @Override + @SuppressWarnings({"unchecked", "rawtypes"}) + public AbstractContainerScreen createStorageBlockScreen( + final AbstractContainerMenu menu, + final Inventory inventory, + final Component title, + final Class resourceClass + ) { + return (AbstractContainerScreen) new StorageBlockScreen( + (StorageBlockContainerMenu) menu, + inventory, + title, + getResourceRendering(resourceClass) + ); + } + + @Override + public void openAutocraftingPreview(final List requests, @Nullable final Screen parentScreen) { + if (requests.isEmpty()) { + return; + } + ClientPlatformUtil.openCraftingPreview(requests, parentScreen); + } + + @Override + public void addAlternativeGridInsertionHint(final GridInsertionHint hint) { + gridInsertionHints.addAlternativeHint(hint); + } + + @Override + public GridInsertionHints getGridInsertionHints() { + return gridInsertionHints; + } + + @Override + public void registerDiskModel(final Item item, final ResourceLocation model) { + diskModelsByItem.put(item, model); + diskModels.add(model); + } + + @Override + public Set getDiskModels() { + return diskModels; + } + + @Override + public Map getDiskModelsByItem() { + return Collections.unmodifiableMap(diskModelsByItem); + } + + @Override + public void registerResourceRendering(final Class resourceClass, + final ResourceRendering rendering) { + resourceRenderingMap.put(resourceClass, rendering); + } + + @Override + public ResourceRendering getResourceRendering(final Class resourceClass) { + // fast path for items + if (resourceClass == ItemResource.class) { + return ItemResourceRendering.INSTANCE; + } + return resourceRenderingMap.get(resourceClass); + } +} diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/CraftingPatternClientTooltipComponent.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/CraftingPatternClientTooltipComponent.java index b431f29ce..56be06912 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/CraftingPatternClientTooltipComponent.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/CraftingPatternClientTooltipComponent.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage.common.autocrafting; -import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.RefinedStorageClientApi; import com.refinedmods.refinedstorage.common.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage.common.support.resource.ItemResource; @@ -99,7 +99,7 @@ private void renderInputSlot(final int x, final int y, final GuiGraphics graphic if (!inputs.isEmpty()) { final int idx = currentCycle % inputs.size(); final PlatformResourceKey resource = inputs.get(idx); - RefinedStorageApi.INSTANCE.getResourceRendering(resource.getClass()).render( + RefinedStorageClientApi.INSTANCE.getResourceRendering(resource.getClass()).render( resource, graphics, x + sx * 18 + 1, diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/ProcessingPatternClientTooltipComponent.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/ProcessingPatternClientTooltipComponent.java index 06afaf280..7b76bfdb8 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/ProcessingPatternClientTooltipComponent.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/ProcessingPatternClientTooltipComponent.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage.common.autocrafting; import com.refinedmods.refinedstorage.api.resource.ResourceAmount; -import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.RefinedStorageClientApi; import com.refinedmods.refinedstorage.common.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage.common.api.support.resource.ResourceRendering; import com.refinedmods.refinedstorage.common.support.ResourceSlotRendering; @@ -75,7 +75,7 @@ private static List getOutputText(final ProcessingPatternState state) } private static Component getOutputText(final ResourceAmount resourceAmount) { - final ResourceRendering rendering = RefinedStorageApi.INSTANCE.getResourceRendering( + final ResourceRendering rendering = RefinedStorageClientApi.INSTANCE.getResourceRendering( resourceAmount.resource().getClass() ); final String displayAmount = rendering.formatAmount(resourceAmount.amount()); @@ -147,7 +147,7 @@ private void renderMatrixSlot( return; } final ResourceAmount resourceAmount = possibilities.get(currentCycle % possibilities.size()); - final ResourceRendering rendering = RefinedStorageApi.INSTANCE.getResourceRendering( + final ResourceRendering rendering = RefinedStorageClientApi.INSTANCE.getResourceRendering( resourceAmount.resource().getClass() ); rendering.render(resourceAmount.resource(), graphics, slotX + 1, slotY + 1); diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/SmithingTablePatternClientTooltipComponent.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/SmithingTablePatternClientTooltipComponent.java index 71ad06504..3383aedcc 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/SmithingTablePatternClientTooltipComponent.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/SmithingTablePatternClientTooltipComponent.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage.common.autocrafting; -import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.RefinedStorageClientApi; import com.refinedmods.refinedstorage.common.api.support.resource.ResourceRendering; import com.refinedmods.refinedstorage.common.support.Sprites; import com.refinedmods.refinedstorage.common.support.resource.ItemResource; @@ -31,7 +31,7 @@ public void renderImage(final Font font, final int x, final int y, final GuiGrap graphics.drawString(font, outputText, x, y, 0xAAAAAA); final int slotsY = y + 9 + 2; graphics.blitSprite(Sprites.SLOT, x, slotsY, 18, 18); - final ResourceRendering rendering = RefinedStorageApi.INSTANCE.getResourceRendering(ItemResource.class); + final ResourceRendering rendering = RefinedStorageClientApi.INSTANCE.getResourceRendering(ItemResource.class); rendering.render(pattern.getTemplate(), graphics, x + 1, slotsY + 1); graphics.blitSprite(Sprites.SLOT, x + 18, slotsY, 18, 18); rendering.render(pattern.getBase(), graphics, x + 18 + 1, slotsY + 1); @@ -63,7 +63,7 @@ public int getWidth(final Font font) { } private static Component getOutputText(final ItemResource output) { - final ResourceRendering rendering = RefinedStorageApi.INSTANCE.getResourceRendering(ItemResource.class); + final ResourceRendering rendering = RefinedStorageClientApi.INSTANCE.getResourceRendering(ItemResource.class); return Component.literal("1x ") .append(rendering.getDisplayName(output)) .withStyle(ChatFormatting.GRAY); diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/StonecutterPatternClientTooltipComponent.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/StonecutterPatternClientTooltipComponent.java index 5e32c883c..5a1c32daf 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/StonecutterPatternClientTooltipComponent.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/StonecutterPatternClientTooltipComponent.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage.common.autocrafting; -import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.RefinedStorageClientApi; import com.refinedmods.refinedstorage.common.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage.common.api.support.resource.ResourceRendering; import com.refinedmods.refinedstorage.common.support.resource.ItemResource; @@ -33,7 +33,7 @@ class StonecutterPatternClientTooltipComponent implements ClientTooltipComponent public void renderImage(final Font font, final int x, final int y, final GuiGraphics graphics) { graphics.drawString(font, outputText, x, y, 0xAAAAAA); graphics.blitSprite(SLOT, x, y + 9 + 2, 18, 18); - final ResourceRendering rendering = RefinedStorageApi.INSTANCE.getResourceRendering(ItemResource.class); + final ResourceRendering rendering = RefinedStorageClientApi.INSTANCE.getResourceRendering(ItemResource.class); rendering.render(input, graphics, x + 1, y + 9 + 2 + 1); graphics.blitSprite( LIGHT_ARROW, @@ -58,7 +58,7 @@ public void renderImage(final Font font, final int x, final int y, final GuiGrap } private static Component getOutputText(final ItemResource output) { - final ResourceRendering rendering = RefinedStorageApi.INSTANCE.getResourceRendering(ItemResource.class); + final ResourceRendering rendering = RefinedStorageClientApi.INSTANCE.getResourceRendering(ItemResource.class); return Component.literal("1x ") .append(rendering.getDisplayName(output)) .withStyle(ChatFormatting.GRAY); diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocraftermanager/AutocrafterManagerContainerMenu.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocraftermanager/AutocrafterManagerContainerMenu.java index 869eb7e2d..9ce99fd5c 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocraftermanager/AutocrafterManagerContainerMenu.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocraftermanager/AutocrafterManagerContainerMenu.java @@ -3,6 +3,7 @@ import com.refinedmods.refinedstorage.api.resource.ResourceKey; import com.refinedmods.refinedstorage.common.Platform; import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.RefinedStorageClientApi; import com.refinedmods.refinedstorage.common.autocrafting.PatternInventory; import com.refinedmods.refinedstorage.common.content.Menus; import com.refinedmods.refinedstorage.common.support.AbstractBaseContainerMenu; @@ -274,7 +275,7 @@ boolean hasPatternOutput(final Level level, final String normalizedQuery, final private static boolean hasResource(final Set resources, final String normalizedQuery) { return resources.stream().anyMatch(key -> - RefinedStorageApi.INSTANCE.getResourceRendering(key.getClass()) + RefinedStorageClientApi.INSTANCE.getResourceRendering(key.getClass()) .getDisplayName(key) .getString() .toLowerCase(Locale.ROOT) diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AutocraftingMonitorScreen.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AutocraftingMonitorScreen.java index 9ac2e2d80..0a0e1fe51 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AutocraftingMonitorScreen.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AutocraftingMonitorScreen.java @@ -2,7 +2,7 @@ import com.refinedmods.refinedstorage.api.autocrafting.TaskId; import com.refinedmods.refinedstorage.api.autocrafting.status.TaskStatus; -import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.RefinedStorageClientApi; import com.refinedmods.refinedstorage.common.api.support.resource.ResourceRendering; import com.refinedmods.refinedstorage.common.support.AbstractBaseScreen; import com.refinedmods.refinedstorage.common.support.containermenu.PropertyTypes; @@ -276,7 +276,9 @@ private void renderItem(final GuiGraphics graphics, renderItemErrorIcon(graphics, x, y); } int xx = x + 2; - final ResourceRendering rendering = RefinedStorageApi.INSTANCE.getResourceRendering(item.resource().getClass()); + final ResourceRendering rendering = RefinedStorageClientApi.INSTANCE.getResourceRendering( + item.resource().getClass() + ); int yy = y + 7; rendering.render(item.resource(), graphics, xx, yy); if (isHovering(x - leftPos, y - topPos, 73, 29, mouseX, mouseY) diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AutocraftingTaskButton.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AutocraftingTaskButton.java index cf6036ada..8e2bee898 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AutocraftingTaskButton.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AutocraftingTaskButton.java @@ -3,7 +3,7 @@ import com.refinedmods.refinedstorage.api.autocrafting.TaskId; import com.refinedmods.refinedstorage.api.autocrafting.status.TaskStatus; import com.refinedmods.refinedstorage.api.resource.ResourceKey; -import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.RefinedStorageClientApi; import com.refinedmods.refinedstorage.common.api.support.resource.ResourceRendering; import com.refinedmods.refinedstorage.common.support.ResourceSlotRendering; import com.refinedmods.refinedstorage.common.support.tooltip.SmallText; @@ -36,7 +36,7 @@ class AutocraftingTaskButton extends AbstractButton { super(x, y, TASK_BUTTON_WIDTH, TASK_BUTTON_HEIGHT, Component.empty()); this.task = task; final ResourceKey resource = task.resource(); - final ResourceRendering rendering = RefinedStorageApi.INSTANCE.getResourceRendering(resource.getClass()); + final ResourceRendering rendering = RefinedStorageClientApi.INSTANCE.getResourceRendering(resource.getClass()); this.text = new TextMarquee( rendering.getDisplayName(resource), TASK_BUTTON_WIDTH - 16 - 4 - 4 - 4, @@ -72,7 +72,7 @@ protected void renderWidget(final GuiGraphics graphics, private void renderResourceIcon(final GuiGraphics graphics) { final ResourceKey resource = task.resource(); - final ResourceRendering rendering = RefinedStorageApi.INSTANCE.getResourceRendering(resource.getClass()); + final ResourceRendering rendering = RefinedStorageClientApi.INSTANCE.getResourceRendering(resource.getClass()); final int resourceX = getX() + 3; final int resourceY = getY() + 4; rendering.render(resource, graphics, resourceX, resourceY); diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/patterngrid/PatternGridBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/patterngrid/PatternGridBlockEntity.java index a978db09e..73e51b010 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/patterngrid/PatternGridBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/patterngrid/PatternGridBlockEntity.java @@ -592,7 +592,7 @@ static ProcessingMatrixInputResourceContainer createProcessingMatrixInputContain static ProcessingMatrixInputResourceContainer createProcessingMatrixInputContainer(final ProcessingInputData data) { final ProcessingMatrixInputResourceContainer filterContainer = createProcessingMatrixInputContainer(); - setResourceContainerData(data.resourceContainerData(), filterContainer); + setResourceContainerData(data.resourceContainerData().resources(), filterContainer); for (int i = 0; i < data.allowedTagIds().size(); ++i) { filterContainer.setAllowedTagIds(i, data.allowedTagIds().get(i)); } @@ -610,7 +610,7 @@ static ResourceContainer createProcessingMatrixOutputContainer() { static ResourceContainer createProcessingMatrixOutputContainer(final ResourceContainerData data) { final ResourceContainer filterContainer = createProcessingMatrixOutputContainer(); - setResourceContainerData(data, filterContainer); + setResourceContainerData(data.resources(), filterContainer); return filterContainer; } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/patterngrid/ProcessingMatrixInputClientTooltipComponent.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/patterngrid/ProcessingMatrixInputClientTooltipComponent.java index 00a3cd0ff..c02f40ff0 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/patterngrid/ProcessingMatrixInputClientTooltipComponent.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/patterngrid/ProcessingMatrixInputClientTooltipComponent.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage.common.autocrafting.patterngrid; -import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.RefinedStorageClientApi; import com.refinedmods.refinedstorage.common.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage.common.api.support.resource.ResourceRendering; import com.refinedmods.refinedstorage.common.api.support.resource.ResourceTag; @@ -69,7 +69,9 @@ public void renderImage(final Font font, final int x, final int y, final GuiGrap final PlatformResourceKey resource = alternative.resources().get( currentCycle % alternative.resources().size() ); - final ResourceRendering rendering = RefinedStorageApi.INSTANCE.getResourceRendering(resource.getClass()); + final ResourceRendering rendering = RefinedStorageClientApi.INSTANCE.getResourceRendering( + resource.getClass() + ); rendering.render(resource, graphics, x, y + 9 + PADDING + i * 18); graphics.drawString( font, diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewScreen.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewScreen.java index 80e1b91db..9e83b6bad 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewScreen.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewScreen.java @@ -3,7 +3,7 @@ import com.refinedmods.refinedstorage.api.autocrafting.preview.Preview; import com.refinedmods.refinedstorage.api.autocrafting.preview.PreviewItem; import com.refinedmods.refinedstorage.api.autocrafting.preview.PreviewType; -import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.RefinedStorageClientApi; import com.refinedmods.refinedstorage.common.api.support.resource.ResourceRendering; import com.refinedmods.refinedstorage.common.support.amount.AbstractAmountScreen; import com.refinedmods.refinedstorage.common.support.amount.AmountScreenConfiguration; @@ -294,7 +294,9 @@ private void renderCell(final GuiGraphics graphics, graphics.fill(x, y, x + 73, y + 29, 0xFFF2DEDE); } int xx = x + 2; - final ResourceRendering rendering = RefinedStorageApi.INSTANCE.getResourceRendering(item.resource().getClass()); + final ResourceRendering rendering = RefinedStorageClientApi.INSTANCE.getResourceRendering( + item.resource().getClass() + ); int yy = y + 7; rendering.render(item.resource(), graphics, xx, yy); if (isHovering(xx - leftPos, yy - topPos, 16, 16, mouseX, mouseY) diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingRequestButton.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingRequestButton.java index dadb6d171..2ca23d851 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingRequestButton.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingRequestButton.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage.common.autocrafting.preview; import com.refinedmods.refinedstorage.api.resource.ResourceKey; -import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.RefinedStorageClientApi; import com.refinedmods.refinedstorage.common.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage.common.api.support.resource.ResourceRendering; import com.refinedmods.refinedstorage.common.support.ResourceSlotRendering; @@ -31,7 +31,7 @@ class AutocraftingRequestButton extends AbstractButton { super(x, y, REQUEST_BUTTON_WIDTH, REQUEST_BUTTON_HEIGHT, Component.empty()); this.request = request; final ResourceKey resource = request.getResource(); - final ResourceRendering rendering = RefinedStorageApi.INSTANCE.getResourceRendering(resource.getClass()); + final ResourceRendering rendering = RefinedStorageClientApi.INSTANCE.getResourceRendering(resource.getClass()); this.text = new TextMarquee( rendering.getDisplayName(resource), REQUEST_BUTTON_WIDTH - 16 - 4 - 4 - 4, @@ -59,7 +59,7 @@ protected void renderWidget(final GuiGraphics graphics, private void renderResourceIcon(final GuiGraphics graphics) { final ResourceKey resource = request.getResource(); - final ResourceRendering rendering = RefinedStorageApi.INSTANCE.getResourceRendering(resource.getClass()); + final ResourceRendering rendering = RefinedStorageClientApi.INSTANCE.getResourceRendering(resource.getClass()); final int resourceX = getX() + 3; final int resourceY = getY() + 4; rendering.render(resource, graphics, resourceX, resourceY); diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/content/BlockEntities.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/content/BlockEntities.java index bad5dcbf5..38d2e7fbb 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/content/BlockEntities.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/content/BlockEntities.java @@ -1,5 +1,6 @@ package com.refinedmods.refinedstorage.common.content; +import com.refinedmods.refinedstorage.common.api.support.network.AbstractNetworkNodeContainerBlockEntity; import com.refinedmods.refinedstorage.common.autocrafting.autocrafter.AutocrafterBlockEntity; import com.refinedmods.refinedstorage.common.autocrafting.autocraftermanager.AutocrafterManagerBlockEntity; import com.refinedmods.refinedstorage.common.autocrafting.monitor.AutocraftingMonitorBlockEntity; @@ -25,8 +26,6 @@ import com.refinedmods.refinedstorage.common.storage.diskinterface.AbstractDiskInterfaceBlockEntity; import com.refinedmods.refinedstorage.common.storage.externalstorage.AbstractExternalStorageBlockEntity; import com.refinedmods.refinedstorage.common.storage.portablegrid.AbstractPortableGridBlockEntity; -import com.refinedmods.refinedstorage.common.storage.storageblock.FluidStorageBlockBlockEntity; -import com.refinedmods.refinedstorage.common.storage.storageblock.ItemStorageBlockBlockEntity; import com.refinedmods.refinedstorage.common.storagemonitor.StorageMonitorBlockEntity; import java.util.EnumMap; @@ -55,9 +54,9 @@ public final class BlockEntities { private Supplier> controller; @Nullable private Supplier> creativeController; - private final Map>> + private final Map>>> itemStorageBlocks = new EnumMap<>(ItemStorageVariant.class); - private final Map>> + private final Map>>> fluidStorageBlocks = new EnumMap<>(FluidStorageVariant.class); @Nullable private Supplier> importer; @@ -157,21 +156,28 @@ public void setCreativeController(final Supplier> supplier) { + public void setItemStorageBlock( + final ItemStorageVariant variant, + final Supplier>> supplier + ) { itemStorageBlocks.put(variant, supplier); } - public BlockEntityType getItemStorageBlock(final ItemStorageVariant variant) { + public BlockEntityType> getItemStorageBlock( + final ItemStorageVariant variant + ) { return itemStorageBlocks.get(variant).get(); } - public void setFluidStorageBlock(final FluidStorageVariant variant, - final Supplier> supplier) { + public void setFluidStorageBlock( + final FluidStorageVariant variant, + final Supplier>> supplier + ) { fluidStorageBlocks.put(variant, supplier); } - public BlockEntityType getFluidStorageBlock(final FluidStorageVariant variant) { + public BlockEntityType> getFluidStorageBlock( + final FluidStorageVariant variant) { return fluidStorageBlocks.get(variant).get(); } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/content/Blocks.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/content/Blocks.java index 2b3bc9a50..b0dc7e784 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/content/Blocks.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/content/Blocks.java @@ -37,8 +37,6 @@ import com.refinedmods.refinedstorage.common.storage.externalstorage.AbstractExternalStorageBlockEntity; import com.refinedmods.refinedstorage.common.storage.externalstorage.ExternalStorageBlock; import com.refinedmods.refinedstorage.common.storage.portablegrid.PortableGridBlock; -import com.refinedmods.refinedstorage.common.storage.storageblock.FluidStorageBlock; -import com.refinedmods.refinedstorage.common.storage.storageblock.ItemStorageBlock; import com.refinedmods.refinedstorage.common.storagemonitor.StorageMonitorBlock; import com.refinedmods.refinedstorage.common.support.BaseBlockItem; import com.refinedmods.refinedstorage.common.support.SimpleBlock; @@ -49,6 +47,7 @@ import javax.annotation.Nullable; import net.minecraft.world.item.DyeColor; +import net.minecraft.world.level.block.Block; import static java.util.Objects.requireNonNull; @@ -170,9 +169,8 @@ public final class Blocks { private Supplier diskDrive; @Nullable private Supplier machineCasing; - private final Map> itemStorageBlocks = - new EnumMap<>(ItemStorageVariant.class); - private final Map> fluidStorageBlocks = + private final Map> itemStorageBlocks = new EnumMap<>(ItemStorageVariant.class); + private final Map> fluidStorageBlocks = new EnumMap<>(FluidStorageVariant.class); @Nullable private Supplier iface; @@ -239,20 +237,19 @@ public void setMachineCasing(final Supplier machineCasingSupplier) this.machineCasing = machineCasingSupplier; } - public void setItemStorageBlock(final ItemStorageVariant variant, final Supplier supplier) { + public void setItemStorageBlock(final ItemStorageVariant variant, final Supplier supplier) { itemStorageBlocks.put(variant, supplier); } - public ItemStorageBlock getItemStorageBlock(final ItemStorageVariant variant) { + public Block getItemStorageBlock(final ItemStorageVariant variant) { return itemStorageBlocks.get(variant).get(); } - public void setFluidStorageBlock(final FluidStorageVariant variant, - final Supplier supplier) { + public void setFluidStorageBlock(final FluidStorageVariant variant, final Supplier supplier) { fluidStorageBlocks.put(variant, supplier); } - public FluidStorageBlock getFluidStorageBlock(final FluidStorageVariant variant) { + public Block getFluidStorageBlock(final FluidStorageVariant variant) { return fluidStorageBlocks.get(variant).get(); } @@ -310,7 +307,7 @@ public BlockColorMap setExternalStorage( } public BlockColorMap getExternalStorage() { - return externalStorage; + return requireNonNull(externalStorage); } public BlockColorMap getDetector() { diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/content/Menus.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/content/Menus.java index 6984f5744..f0d0e6477 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/content/Menus.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/content/Menus.java @@ -27,14 +27,13 @@ import com.refinedmods.refinedstorage.common.storage.externalstorage.ExternalStorageContainerMenu; import com.refinedmods.refinedstorage.common.storage.portablegrid.PortableGridBlockContainerMenu; import com.refinedmods.refinedstorage.common.storage.portablegrid.PortableGridItemContainerMenu; -import com.refinedmods.refinedstorage.common.storage.storageblock.FluidStorageBlockContainerMenu; -import com.refinedmods.refinedstorage.common.storage.storageblock.ItemStorageBlockContainerMenu; import com.refinedmods.refinedstorage.common.storagemonitor.StorageMonitorContainerMenu; import com.refinedmods.refinedstorage.common.upgrade.RegulatorUpgradeContainerMenu; import java.util.function.Supplier; import javax.annotation.Nullable; +import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.MenuType; import static java.util.Objects.requireNonNull; @@ -55,9 +54,9 @@ public final class Menus { @Nullable private Supplier> controller; @Nullable - private Supplier> itemStorage; + private Supplier> itemStorage; @Nullable - private Supplier> fluidStorage; + private Supplier> fluidStorage; @Nullable private Supplier> importer; @Nullable @@ -156,19 +155,19 @@ public void setController(final Supplier> supp this.controller = supplier; } - public MenuType getItemStorage() { + public MenuType getItemStorage() { return requireNonNull(itemStorage).get(); } - public void setItemStorage(final Supplier> supplier) { + public void setItemStorage(final Supplier> supplier) { this.itemStorage = supplier; } - public MenuType getFluidStorage() { + public MenuType getFluidStorage() { return requireNonNull(fluidStorage).get(); } - public void setFluidStorage(final Supplier> supplier) { + public void setFluidStorage(final Supplier> supplier) { this.fluidStorage = supplier; } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/AbstractGridScreen.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/AbstractGridScreen.java index e9d570941..3523a5716 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/AbstractGridScreen.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/AbstractGridScreen.java @@ -9,6 +9,7 @@ import com.refinedmods.refinedstorage.api.storage.tracked.TrackedResource; import com.refinedmods.refinedstorage.common.Platform; import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.RefinedStorageClientApi; import com.refinedmods.refinedstorage.common.api.grid.GridScrollMode; import com.refinedmods.refinedstorage.common.api.grid.view.PlatformGridResource; import com.refinedmods.refinedstorage.common.grid.AbstractGridContainerMenu; @@ -420,7 +421,8 @@ private void renderOverStorageAreaTooltip(final GuiGraphics graphics, final int if (carried.isEmpty()) { return; } - final List hints = RefinedStorageApi.INSTANCE.getGridInsertionHints().getHints(carried); + final List hints = RefinedStorageClientApi.INSTANCE.getGridInsertionHints() + .getHints(carried); Platform.INSTANCE.renderTooltip(graphics, hints, x, y); } @@ -541,7 +543,7 @@ private boolean tryStartAutocrafting(final PlatformGridResource resource) { if (request == null) { return false; } - RefinedStorageApi.INSTANCE.openAutocraftingPreview(List.of(request), this); + RefinedStorageClientApi.INSTANCE.openAutocraftingPreview(List.of(request), this); return true; } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/hint/FluidGridInsertionHint.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/hint/FluidGridInsertionHint.java index e0f04b3e7..b44bf7229 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/hint/FluidGridInsertionHint.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/hint/FluidGridInsertionHint.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage.common.grid.screen.hint; import com.refinedmods.refinedstorage.common.Platform; -import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.RefinedStorageClientApi; import com.refinedmods.refinedstorage.common.api.grid.GridInsertionHint; import com.refinedmods.refinedstorage.common.api.support.resource.FluidOperationResult; import com.refinedmods.refinedstorage.common.support.resource.FluidResource; @@ -22,9 +22,8 @@ private ClientTooltipComponent createComponent(final FluidOperationResult result return MouseClientTooltipComponent.fluid( MouseClientTooltipComponent.Type.RIGHT, (FluidResource) result.fluid(), - result.amount() == Platform.INSTANCE.getBucketAmount() - ? null - : RefinedStorageApi.INSTANCE.getResourceRendering(FluidResource.class).formatAmount(result.amount()) + result.amount() == Platform.INSTANCE.getBucketAmount() ? null : RefinedStorageClientApi.INSTANCE + .getResourceRendering(FluidResource.class).formatAmount(result.amount()) ); } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/view/FluidGridResource.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/view/FluidGridResource.java index b197dd9c6..c88f4ee23 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/view/FluidGridResource.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/view/FluidGridResource.java @@ -5,7 +5,7 @@ import com.refinedmods.refinedstorage.api.grid.view.GridView; import com.refinedmods.refinedstorage.api.resource.ResourceAmount; import com.refinedmods.refinedstorage.common.Platform; -import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.RefinedStorageClientApi; import com.refinedmods.refinedstorage.common.api.grid.GridScrollMode; import com.refinedmods.refinedstorage.common.api.grid.strategy.GridExtractionStrategy; import com.refinedmods.refinedstorage.common.api.grid.strategy.GridScrollingStrategy; @@ -43,7 +43,7 @@ public FluidGridResource(final FluidResource resource, final boolean autocraftable) { super(resource, name, attributes, autocraftable); this.id = BuiltInRegistries.FLUID.getId(resource.fluid()); - this.rendering = RefinedStorageApi.INSTANCE.getResourceRendering(FluidResource.class); + this.rendering = RefinedStorageClientApi.INSTANCE.getResourceRendering(FluidResource.class); } @Override diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/StorageContainerItemHelperImpl.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/StorageContainerItemHelperImpl.java index 85d8f9fc3..a5fb6d244 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/StorageContainerItemHelperImpl.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/StorageContainerItemHelperImpl.java @@ -10,13 +10,8 @@ import com.refinedmods.refinedstorage.common.api.storage.StorageRepository; import com.refinedmods.refinedstorage.common.content.DataComponents; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Optional; -import java.util.Set; import java.util.UUID; import java.util.function.Function; import java.util.function.LongFunction; @@ -25,13 +20,11 @@ import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; -import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.level.Level; @@ -41,9 +34,6 @@ public class StorageContainerItemHelperImpl implements StorageContainerItemHelper { private static final Logger LOGGER = LoggerFactory.getLogger(StorageContainerItemHelperImpl.class); - private final Map diskModelsByItem = new HashMap<>(); - private final Set diskModels = new HashSet<>(); - @Override public Optional resolveStorage(final StorageRepository storageRepository, final ItemStack stack) { @@ -200,22 +190,6 @@ public void transferFromBlockEntity(final ItemStack stack, final StorageBlockEnt } } - @Override - public void registerDiskModel(final Item item, final ResourceLocation model) { - diskModelsByItem.put(item, model); - diskModels.add(model); - } - - @Override - public Set getDiskModels() { - return diskModels; - } - - @Override - public Map getDiskModelsByItem() { - return Collections.unmodifiableMap(diskModelsByItem); - } - @Override public void markAsToTransfer(final ItemStack from, final ItemStack to) { getId(from).ifPresent(id -> to.set(DataComponents.INSTANCE.getStorageReferenceToBeTransferred(), id)); diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/AbstractStorageBlock.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/AbstractStorageBlock.java deleted file mode 100644 index f70618188..000000000 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/AbstractStorageBlock.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.refinedmods.refinedstorage.common.storage.storageblock; - -import com.refinedmods.refinedstorage.common.support.AbstractBaseBlock; -import com.refinedmods.refinedstorage.common.support.AbstractBlockEntityTicker; - -import javax.annotation.Nullable; - -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; - -abstract class AbstractStorageBlock extends AbstractBaseBlock - implements EntityBlock { - private final AbstractBlockEntityTicker ticker; - - protected AbstractStorageBlock(final Properties properties, final AbstractBlockEntityTicker ticker) { - super(properties); - this.ticker = ticker; - } - - @Nullable - @Override - public BlockEntityTicker getTicker(final Level level, - final BlockState blockState, - final BlockEntityType type) { - return ticker.get(level, type); - } -} diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/AbstractStorageBlockScreen.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/AbstractStorageBlockScreen.java deleted file mode 100644 index 19f05616e..000000000 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/AbstractStorageBlockScreen.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.refinedmods.refinedstorage.common.storage.storageblock; - -import com.refinedmods.refinedstorage.common.storage.AbstractProgressStorageScreen; - -import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.player.Inventory; - -import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createIdentifier; - -abstract class AbstractStorageBlockScreen extends AbstractProgressStorageScreen { - private static final ResourceLocation TEXTURE = createIdentifier("textures/gui/storage.png"); - - protected AbstractStorageBlockScreen(final AbstractStorageBlockContainerMenu menu, - final Inventory inventory, - final Component title) { - super(menu, inventory, title, 80); - } - - @Override - protected ResourceLocation getTexture() { - return TEXTURE; - } -} diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/FluidStorageBlock.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/FluidStorageBlock.java deleted file mode 100644 index 1c0261f2c..000000000 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/FluidStorageBlock.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.refinedmods.refinedstorage.common.storage.storageblock; - -import com.refinedmods.refinedstorage.common.content.BlockConstants; -import com.refinedmods.refinedstorage.common.content.BlockEntities; -import com.refinedmods.refinedstorage.common.storage.FluidStorageVariant; -import com.refinedmods.refinedstorage.common.support.network.NetworkNodeBlockEntityTicker; - -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.state.BlockState; - -public class FluidStorageBlock extends AbstractStorageBlock { - private final FluidStorageVariant variant; - - public FluidStorageBlock(final FluidStorageVariant variant) { - super( - BlockConstants.PROPERTIES, - new NetworkNodeBlockEntityTicker<>(() -> BlockEntities.INSTANCE.getFluidStorageBlock(variant)) - ); - this.variant = variant; - } - - @Override - public BlockEntity newBlockEntity(final BlockPos pos, final BlockState state) { - return new FluidStorageBlockBlockEntity(pos, state, variant); - } -} diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/FluidStorageBlockBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/FluidStorageBlockBlockEntity.java deleted file mode 100644 index 6e66013db..000000000 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/FluidStorageBlockBlockEntity.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.refinedmods.refinedstorage.common.storage.storageblock; - -import com.refinedmods.refinedstorage.api.network.impl.node.storage.StorageNetworkNode; -import com.refinedmods.refinedstorage.common.Platform; -import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; -import com.refinedmods.refinedstorage.common.api.storage.SerializableStorage; -import com.refinedmods.refinedstorage.common.content.BlockEntities; -import com.refinedmods.refinedstorage.common.storage.FluidStorageVariant; - -import net.minecraft.core.BlockPos; -import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.player.Inventory; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.level.block.state.BlockState; - -import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createTranslation; - -public class FluidStorageBlockBlockEntity extends AbstractStorageBlockBlockEntity { - private final FluidStorageVariant variant; - private final Component displayName; - - public FluidStorageBlockBlockEntity(final BlockPos pos, - final BlockState state, - final FluidStorageVariant variant) { - super( - BlockEntities.INSTANCE.getFluidStorageBlock(variant), - pos, - state, - new StorageNetworkNode(getEnergyUsage(variant), 0, 1), - RefinedStorageApi.INSTANCE.getFluidResourceFactory() - ); - this.variant = variant; - this.displayName = createTranslation( - "block", - String.format("%s_fluid_storage_block", variant.getName()) - ); - } - - private static long getEnergyUsage(final FluidStorageVariant variant) { - return switch (variant) { - case SIXTY_FOUR_B -> Platform.INSTANCE.getConfig().getFluidStorageBlock().get64bEnergyUsage(); - case TWO_HUNDRED_FIFTY_SIX_B -> Platform.INSTANCE.getConfig().getFluidStorageBlock().get256bEnergyUsage(); - case THOUSAND_TWENTY_FOUR_B -> Platform.INSTANCE.getConfig().getFluidStorageBlock().get1024bEnergyUsage(); - case FOUR_THOUSAND_NINETY_SIX_B -> - Platform.INSTANCE.getConfig().getFluidStorageBlock().get4096bEnergyUsage(); - case CREATIVE -> Platform.INSTANCE.getConfig().getFluidStorageBlock().getCreativeEnergyUsage(); - }; - } - - @Override - protected SerializableStorage createStorage(final Runnable listener) { - return FluidStorageBlockBlockItem.createStorage(variant, listener); - } - - @Override - public Component getName() { - return overrideName(displayName); - } - - @Override - public AbstractContainerMenu createMenu(final int syncId, final Inventory inventory, final Player player) { - return new FluidStorageBlockContainerMenu( - syncId, - player, - getFilterContainer(), - configContainer - ); - } -} diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/FluidStorageBlockBlockItem.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/FluidStorageBlockBlockItem.java index 253ede466..af786590b 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/FluidStorageBlockBlockItem.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/FluidStorageBlockBlockItem.java @@ -1,6 +1,7 @@ package com.refinedmods.refinedstorage.common.storage.storageblock; import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.RefinedStorageClientApi; import com.refinedmods.refinedstorage.common.api.storage.AbstractStorageContainerBlockItem; import com.refinedmods.refinedstorage.common.api.storage.SerializableStorage; import com.refinedmods.refinedstorage.common.api.storage.StorageRepository; @@ -60,7 +61,7 @@ protected Long getCapacity() { @Override protected String formatAmount(final long amount) { - return RefinedStorageApi.INSTANCE.getResourceRendering(FluidResource.class).formatAmount(amount); + return RefinedStorageClientApi.INSTANCE.getResourceRendering(FluidResource.class).formatAmount(amount); } @Override diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/FluidStorageBlockContainerMenu.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/FluidStorageBlockContainerMenu.java deleted file mode 100644 index bc34a5dd2..000000000 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/FluidStorageBlockContainerMenu.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.refinedmods.refinedstorage.common.storage.storageblock; - -import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; -import com.refinedmods.refinedstorage.common.api.support.resource.ResourceContainer; -import com.refinedmods.refinedstorage.common.content.Menus; -import com.refinedmods.refinedstorage.common.storage.StorageConfigurationContainer; - -import net.minecraft.world.entity.player.Inventory; -import net.minecraft.world.entity.player.Player; - -public class FluidStorageBlockContainerMenu extends AbstractStorageBlockContainerMenu { - public FluidStorageBlockContainerMenu(final int syncId, - final Inventory playerInventory, - final StorageBlockData storageBlockData) { - super( - Menus.INSTANCE.getFluidStorage(), - syncId, - playerInventory.player, - storageBlockData, - RefinedStorageApi.INSTANCE.getFluidResourceFactory() - ); - } - - FluidStorageBlockContainerMenu(final int syncId, - final Player player, - final ResourceContainer resourceContainer, - final StorageConfigurationContainer configContainer) { - super(Menus.INSTANCE.getFluidStorage(), syncId, player, resourceContainer, configContainer); - } - - @Override - public boolean hasCapacity() { - return getCapacity() > 0; - } -} diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/FluidStorageBlockProvider.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/FluidStorageBlockProvider.java new file mode 100644 index 000000000..f487160bc --- /dev/null +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/FluidStorageBlockProvider.java @@ -0,0 +1,64 @@ +package com.refinedmods.refinedstorage.common.storage.storageblock; + +import com.refinedmods.refinedstorage.common.Platform; +import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.storage.SerializableStorage; +import com.refinedmods.refinedstorage.common.api.storage.StorageBlockProvider; +import com.refinedmods.refinedstorage.common.api.support.resource.ResourceFactory; +import com.refinedmods.refinedstorage.common.content.BlockEntities; +import com.refinedmods.refinedstorage.common.content.Menus; +import com.refinedmods.refinedstorage.common.storage.FluidStorageVariant; +import com.refinedmods.refinedstorage.common.storage.StorageTypes; + +import net.minecraft.network.chat.Component; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.level.block.entity.BlockEntityType; + +import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createTranslation; + +public class FluidStorageBlockProvider implements StorageBlockProvider { + private final FluidStorageVariant variant; + private final Component displayName; + + public FluidStorageBlockProvider(final FluidStorageVariant variant) { + this.variant = variant; + this.displayName = createTranslation("block", String.format("%s_fluid_storage_block", variant.getName())); + } + + @Override + public SerializableStorage createStorage(final Runnable listener) { + return StorageTypes.FLUID.create(variant.getCapacity(), listener); + } + + @Override + public Component getDisplayName() { + return displayName; + } + + @Override + public long getEnergyUsage() { + return switch (variant) { + case SIXTY_FOUR_B -> Platform.INSTANCE.getConfig().getFluidStorageBlock().get64bEnergyUsage(); + case TWO_HUNDRED_FIFTY_SIX_B -> Platform.INSTANCE.getConfig().getFluidStorageBlock().get256bEnergyUsage(); + case THOUSAND_TWENTY_FOUR_B -> Platform.INSTANCE.getConfig().getFluidStorageBlock().get1024bEnergyUsage(); + case FOUR_THOUSAND_NINETY_SIX_B -> + Platform.INSTANCE.getConfig().getFluidStorageBlock().get4096bEnergyUsage(); + case CREATIVE -> Platform.INSTANCE.getConfig().getFluidStorageBlock().getCreativeEnergyUsage(); + }; + } + + @Override + public ResourceFactory getResourceFactory() { + return RefinedStorageApi.INSTANCE.getFluidResourceFactory(); + } + + @Override + public BlockEntityType getBlockEntityType() { + return BlockEntities.INSTANCE.getFluidStorageBlock(variant); + } + + @Override + public MenuType getMenuType() { + return Menus.INSTANCE.getFluidStorage(); + } +} diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/FluidStorageBlockScreen.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/FluidStorageBlockScreen.java deleted file mode 100644 index 75493ff6c..000000000 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/FluidStorageBlockScreen.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.refinedmods.refinedstorage.common.storage.storageblock; - -import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; -import com.refinedmods.refinedstorage.common.support.resource.FluidResource; - -import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.player.Inventory; - -public class FluidStorageBlockScreen extends AbstractStorageBlockScreen { - public FluidStorageBlockScreen(final AbstractStorageBlockContainerMenu menu, - final Inventory inventory, - final Component title) { - super(menu, inventory, title); - } - - @Override - protected String formatAmount(final long amount) { - return RefinedStorageApi.INSTANCE.getResourceRendering(FluidResource.class).formatAmount(amount); - } -} diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/ItemStorageBlock.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/ItemStorageBlock.java deleted file mode 100644 index 4b7e9a36d..000000000 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/ItemStorageBlock.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.refinedmods.refinedstorage.common.storage.storageblock; - -import com.refinedmods.refinedstorage.common.content.BlockConstants; -import com.refinedmods.refinedstorage.common.content.BlockEntities; -import com.refinedmods.refinedstorage.common.storage.ItemStorageVariant; -import com.refinedmods.refinedstorage.common.support.network.NetworkNodeBlockEntityTicker; - -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.state.BlockState; - -public class ItemStorageBlock extends AbstractStorageBlock { - private final ItemStorageVariant variant; - - public ItemStorageBlock(final ItemStorageVariant variant) { - super( - BlockConstants.PROPERTIES, - new NetworkNodeBlockEntityTicker<>(() -> BlockEntities.INSTANCE.getItemStorageBlock(variant)) - ); - this.variant = variant; - } - - @Override - public BlockEntity newBlockEntity(final BlockPos pos, final BlockState state) { - return new ItemStorageBlockBlockEntity(pos, state, variant); - } -} diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/ItemStorageBlockBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/ItemStorageBlockBlockEntity.java deleted file mode 100644 index 8073f8831..000000000 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/ItemStorageBlockBlockEntity.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.refinedmods.refinedstorage.common.storage.storageblock; - -import com.refinedmods.refinedstorage.api.network.impl.node.storage.StorageNetworkNode; -import com.refinedmods.refinedstorage.common.Platform; -import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; -import com.refinedmods.refinedstorage.common.api.storage.SerializableStorage; -import com.refinedmods.refinedstorage.common.content.BlockEntities; -import com.refinedmods.refinedstorage.common.storage.ItemStorageVariant; - -import net.minecraft.core.BlockPos; -import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.player.Inventory; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.level.block.state.BlockState; - -import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createTranslation; - -public class ItemStorageBlockBlockEntity extends AbstractStorageBlockBlockEntity { - private final ItemStorageVariant variant; - private final Component displayName; - - public ItemStorageBlockBlockEntity(final BlockPos pos, - final BlockState state, - final ItemStorageVariant variant) { - super( - BlockEntities.INSTANCE.getItemStorageBlock(variant), - pos, - state, - new StorageNetworkNode(getEnergyUsage(variant), 0, 1), - RefinedStorageApi.INSTANCE.getItemResourceFactory() - ); - this.variant = variant; - this.displayName = createTranslation("block", String.format("%s_storage_block", variant.getName())); - } - - private static long getEnergyUsage(final ItemStorageVariant variant) { - return switch (variant) { - case ONE_K -> Platform.INSTANCE.getConfig().getStorageBlock().get1kEnergyUsage(); - case FOUR_K -> Platform.INSTANCE.getConfig().getStorageBlock().get4kEnergyUsage(); - case SIXTEEN_K -> Platform.INSTANCE.getConfig().getStorageBlock().get16kEnergyUsage(); - case SIXTY_FOUR_K -> Platform.INSTANCE.getConfig().getStorageBlock().get64kEnergyUsage(); - case CREATIVE -> Platform.INSTANCE.getConfig().getStorageBlock().getCreativeEnergyUsage(); - }; - } - - @Override - protected SerializableStorage createStorage(final Runnable listener) { - return ItemStorageBlockBlockItem.createStorage(variant, listener); - } - - @Override - public Component getName() { - return overrideName(displayName); - } - - @Override - public AbstractContainerMenu createMenu(final int syncId, final Inventory inventory, final Player player) { - return new ItemStorageBlockContainerMenu( - syncId, - player, - getFilterContainer(), - configContainer - ); - } -} diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/ItemStorageBlockContainerMenu.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/ItemStorageBlockContainerMenu.java deleted file mode 100644 index b192a82b2..000000000 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/ItemStorageBlockContainerMenu.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.refinedmods.refinedstorage.common.storage.storageblock; - -import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; -import com.refinedmods.refinedstorage.common.api.support.resource.ResourceContainer; -import com.refinedmods.refinedstorage.common.content.Menus; -import com.refinedmods.refinedstorage.common.storage.StorageConfigurationContainer; - -import net.minecraft.world.entity.player.Inventory; -import net.minecraft.world.entity.player.Player; - -public class ItemStorageBlockContainerMenu extends AbstractStorageBlockContainerMenu { - public ItemStorageBlockContainerMenu(final int syncId, - final Inventory playerInventory, - final StorageBlockData storageBlockData) { - super( - Menus.INSTANCE.getItemStorage(), - syncId, - playerInventory.player, - storageBlockData, - RefinedStorageApi.INSTANCE.getItemResourceFactory() - ); - } - - ItemStorageBlockContainerMenu(final int syncId, - final Player player, - final ResourceContainer resourceContainer, - final StorageConfigurationContainer configContainer) { - super(Menus.INSTANCE.getItemStorage(), syncId, player, resourceContainer, configContainer); - } - - @Override - public boolean hasCapacity() { - return getCapacity() > 0; - } -} diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/ItemStorageBlockProvider.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/ItemStorageBlockProvider.java new file mode 100644 index 000000000..f5f54f91e --- /dev/null +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/ItemStorageBlockProvider.java @@ -0,0 +1,63 @@ +package com.refinedmods.refinedstorage.common.storage.storageblock; + +import com.refinedmods.refinedstorage.common.Platform; +import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.storage.SerializableStorage; +import com.refinedmods.refinedstorage.common.api.storage.StorageBlockProvider; +import com.refinedmods.refinedstorage.common.api.support.resource.ResourceFactory; +import com.refinedmods.refinedstorage.common.content.BlockEntities; +import com.refinedmods.refinedstorage.common.content.Menus; +import com.refinedmods.refinedstorage.common.storage.ItemStorageVariant; +import com.refinedmods.refinedstorage.common.storage.StorageTypes; + +import net.minecraft.network.chat.Component; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.level.block.entity.BlockEntityType; + +import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createTranslation; + +public class ItemStorageBlockProvider implements StorageBlockProvider { + private final ItemStorageVariant variant; + private final Component displayName; + + public ItemStorageBlockProvider(final ItemStorageVariant variant) { + this.variant = variant; + this.displayName = createTranslation("block", String.format("%s_storage_block", variant.getName())); + } + + @Override + public SerializableStorage createStorage(final Runnable listener) { + return StorageTypes.ITEM.create(variant.getCapacity(), listener); + } + + @Override + public Component getDisplayName() { + return displayName; + } + + @Override + public long getEnergyUsage() { + return switch (variant) { + case ONE_K -> Platform.INSTANCE.getConfig().getStorageBlock().get1kEnergyUsage(); + case FOUR_K -> Platform.INSTANCE.getConfig().getStorageBlock().get4kEnergyUsage(); + case SIXTEEN_K -> Platform.INSTANCE.getConfig().getStorageBlock().get16kEnergyUsage(); + case SIXTY_FOUR_K -> Platform.INSTANCE.getConfig().getStorageBlock().get64kEnergyUsage(); + case CREATIVE -> Platform.INSTANCE.getConfig().getStorageBlock().getCreativeEnergyUsage(); + }; + } + + @Override + public ResourceFactory getResourceFactory() { + return RefinedStorageApi.INSTANCE.getItemResourceFactory(); + } + + @Override + public BlockEntityType getBlockEntityType() { + return BlockEntities.INSTANCE.getItemStorageBlock(variant); + } + + @Override + public MenuType getMenuType() { + return Menus.INSTANCE.getItemStorage(); + } +} diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/ItemStorageBlockScreen.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/ItemStorageBlockScreen.java deleted file mode 100644 index fbae1c186..000000000 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/ItemStorageBlockScreen.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.refinedmods.refinedstorage.common.storage.storageblock; - -import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.player.Inventory; - -public class ItemStorageBlockScreen extends AbstractStorageBlockScreen { - public ItemStorageBlockScreen(final AbstractStorageBlockContainerMenu menu, - final Inventory inventory, - final Component title) { - super(menu, inventory, title); - } -} diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/StorageBlock.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/StorageBlock.java new file mode 100644 index 000000000..5d12b3ba5 --- /dev/null +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/StorageBlock.java @@ -0,0 +1,53 @@ +package com.refinedmods.refinedstorage.common.storage.storageblock; + +import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.storage.StorageBlockProvider; +import com.refinedmods.refinedstorage.common.support.AbstractBaseBlock; +import com.refinedmods.refinedstorage.common.support.AbstractBlockEntityTicker; +import com.refinedmods.refinedstorage.common.support.network.AbstractBaseNetworkNodeContainerBlockEntity; + +import javax.annotation.Nullable; + +import net.minecraft.core.BlockPos; +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; + +public class StorageBlock extends AbstractBaseBlock implements EntityBlock { + private final AbstractBlockEntityTicker ticker; + private final StorageBlockProvider provider; + + @SuppressWarnings("unchecked") + public StorageBlock(final Properties properties, final StorageBlockProvider provider) { + super(properties); + this.ticker = new AbstractBlockEntityTicker<>(() -> (BlockEntityType) provider.getBlockEntityType()) { + @Override + public void tick(final Level level, + final BlockPos blockPos, + final BlockState blockState, + final BlockEntity blockEntity) { + if (blockEntity instanceof AbstractBaseNetworkNodeContainerBlockEntity networkNode) { + networkNode.updateActiveness(blockState, null); + networkNode.doWork(); + } + } + }; + this.provider = provider; + } + + @Override + public BlockEntity newBlockEntity(final BlockPos pos, final BlockState state) { + return RefinedStorageApi.INSTANCE.createStorageBlockEntity(pos, state, provider); + } + + @Nullable + @Override + public BlockEntityTicker getTicker(final Level level, + final BlockState blockState, + final BlockEntityType type) { + return ticker.get(level, type); + } +} diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/AbstractStorageBlockBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/StorageBlockBlockEntity.java similarity index 78% rename from refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/AbstractStorageBlockBlockEntity.java rename to refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/StorageBlockBlockEntity.java index df59512f3..33c3d811d 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/AbstractStorageBlockBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/StorageBlockBlockEntity.java @@ -5,10 +5,11 @@ import com.refinedmods.refinedstorage.api.storage.Storage; import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; import com.refinedmods.refinedstorage.common.api.storage.SerializableStorage; +import com.refinedmods.refinedstorage.common.api.storage.StorageBlockData; import com.refinedmods.refinedstorage.common.api.storage.StorageBlockEntity; +import com.refinedmods.refinedstorage.common.api.storage.StorageBlockProvider; import com.refinedmods.refinedstorage.common.api.storage.StorageRepository; import com.refinedmods.refinedstorage.common.api.support.resource.ResourceContainer; -import com.refinedmods.refinedstorage.common.api.support.resource.ResourceFactory; import com.refinedmods.refinedstorage.common.storage.StorageConfigurationContainerImpl; import com.refinedmods.refinedstorage.common.support.FilterWithFuzzyMode; import com.refinedmods.refinedstorage.common.support.containermenu.NetworkNodeExtendedMenuProvider; @@ -24,35 +25,37 @@ import net.minecraft.core.HolderLookup; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.chat.Component; import net.minecraft.network.codec.StreamEncoder; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -abstract class AbstractStorageBlockBlockEntity - extends AbstractBaseNetworkNodeContainerBlockEntity +public class StorageBlockBlockEntity extends AbstractBaseNetworkNodeContainerBlockEntity implements NetworkNodeExtendedMenuProvider, StorageBlockEntity, AbstractStorageContainerNetworkNode.Provider { - private static final Logger LOGGER = LoggerFactory.getLogger(AbstractStorageBlockBlockEntity.class); + private static final Logger LOGGER = LoggerFactory.getLogger(StorageBlockBlockEntity.class); private static final String TAG_STORAGE_ID = "sid"; protected final StorageConfigurationContainerImpl configContainer; private final FilterWithFuzzyMode filter; + private final Component displayName; + private final StorageBlockProvider storageBlockProvider; @Nullable private UUID storageId; - protected AbstractStorageBlockBlockEntity(final BlockEntityType type, - final BlockPos pos, - final BlockState state, - final StorageNetworkNode node, - final ResourceFactory resourceFactory) { - super(type, pos, state, node); + public StorageBlockBlockEntity(final BlockPos pos, + final BlockState state, + final StorageBlockProvider provider) { + super(provider.getBlockEntityType(), pos, state, new StorageNetworkNode(provider.getEnergyUsage(), 0, 1)); this.filter = FilterWithFuzzyMode.createAndListenForUniqueFilters( - ResourceContainerImpl.createForFilter(resourceFactory), + ResourceContainerImpl.createForFilter(provider.getResourceFactory()), this::setChanged, mainNetworkNode.getStorageConfiguration()::setFilters ); @@ -64,10 +67,10 @@ protected AbstractStorageBlockBlockEntity(final BlockEntityType type, this::setRedstoneMode ); mainNetworkNode.getStorageConfiguration().setNormalizer(filter.createNormalizer()); + this.displayName = provider.getDisplayName(); + this.storageBlockProvider = provider; } - protected abstract SerializableStorage createStorage(Runnable listener); - @Override public void setLevel(final Level level) { super.setLevel(level); @@ -83,7 +86,7 @@ public void setLevel(final Level level) { // In both cases listed above we need to clean up the storage we create here. storageId = UUID.randomUUID(); final StorageRepository storageRepository = RefinedStorageApi.INSTANCE.getStorageRepository(level); - final SerializableStorage storage = createStorage(storageRepository::markAsChanged); + final SerializableStorage storage = storageBlockProvider.createStorage(storageRepository::markAsChanged); storageRepository.set(storageId, storage); } mainNetworkNode.setProvider(this); @@ -156,13 +159,13 @@ public StorageBlockData getMenuData() { return new StorageBlockData( mainNetworkNode.getStored(), mainNetworkNode.getCapacity(), - ResourceContainerData.of(filter.getFilterContainer()) + ResourceContainerData.of(filter.getFilterContainer()).resources() ); } @Override public StreamEncoder getMenuCodec() { - return StorageBlockData.STREAM_CODEC; + return RefinedStorageApi.INSTANCE.getStorageBlockDataStreamCodec(); } @Override @@ -173,4 +176,20 @@ public Optional resolve(final int index) { final StorageRepository storageRepository = RefinedStorageApi.INSTANCE.getStorageRepository(level); return storageRepository.get(storageId).map(Storage.class::cast); } + + @Override + public Component getName() { + return overrideName(displayName); + } + + @Override + public AbstractContainerMenu createMenu(final int syncId, final Inventory inventory, final Player player) { + return new StorageBlockContainerMenu( + storageBlockProvider.getMenuType(), + syncId, + player, + filter.getFilterContainer(), + configContainer + ); + } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/StorageBlockCodecs.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/StorageBlockCodecs.java new file mode 100644 index 000000000..d40ab0294 --- /dev/null +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/StorageBlockCodecs.java @@ -0,0 +1,27 @@ +package com.refinedmods.refinedstorage.common.storage.storageblock; + +import com.refinedmods.refinedstorage.api.resource.ResourceAmount; +import com.refinedmods.refinedstorage.common.api.storage.StorageBlockData; +import com.refinedmods.refinedstorage.common.support.resource.ResourceCodecs; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; + +public final class StorageBlockCodecs { + private static final StreamCodec>> RESOURCES_STREAM_CODEC = + ByteBufCodecs.collection(ArrayList::new, ByteBufCodecs.optional(ResourceCodecs.AMOUNT_STREAM_CODEC)); + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + ByteBufCodecs.VAR_LONG, StorageBlockData::stored, + ByteBufCodecs.VAR_LONG, StorageBlockData::capacity, + RESOURCES_STREAM_CODEC, StorageBlockData::resources, + StorageBlockData::new + ); + + private StorageBlockCodecs() { + } +} diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/AbstractStorageBlockContainerMenu.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/StorageBlockContainerMenu.java similarity index 72% rename from refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/AbstractStorageBlockContainerMenu.java rename to refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/StorageBlockContainerMenu.java index e315bd92a..d15eb586a 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/AbstractStorageBlockContainerMenu.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/StorageBlockContainerMenu.java @@ -1,5 +1,6 @@ package com.refinedmods.refinedstorage.common.storage.storageblock; +import com.refinedmods.refinedstorage.common.api.storage.StorageBlockData; import com.refinedmods.refinedstorage.common.api.support.resource.ResourceContainer; import com.refinedmods.refinedstorage.common.api.support.resource.ResourceFactory; import com.refinedmods.refinedstorage.common.storage.AbstractStorageContainerMenu; @@ -15,33 +16,32 @@ import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createTranslation; -public abstract class AbstractStorageBlockContainerMenu extends AbstractStorageContainerMenu - implements StorageAccessor { +public class StorageBlockContainerMenu extends AbstractStorageContainerMenu implements StorageAccessor { private static final int FILTER_SLOT_X = 8; private static final int FILTER_SLOT_Y = 20; private long stored; private long capacity; - protected AbstractStorageBlockContainerMenu(final MenuType type, - final int syncId, - final Player player, - final StorageBlockData storageBlockData, - final ResourceFactory resourceFactory) { + public StorageBlockContainerMenu(final MenuType type, + final int syncId, + final Player player, + final StorageBlockData storageBlockData, + final ResourceFactory resourceFactory) { super(type, syncId); this.stored = storageBlockData.stored(); this.capacity = storageBlockData.capacity(); addSlots( player, - ResourceContainerImpl.createForFilter(resourceFactory, storageBlockData.resourceContainerData()) + ResourceContainerImpl.createForFilter(resourceFactory, storageBlockData.resources()) ); } - protected AbstractStorageBlockContainerMenu(final MenuType type, - final int syncId, - final Player player, - final ResourceContainer resourceContainer, - final StorageConfigurationContainer configContainer) { + public StorageBlockContainerMenu(final MenuType type, + final int syncId, + final Player player, + final ResourceContainer resourceContainer, + final StorageConfigurationContainer configContainer) { super(type, syncId, player, configContainer); addSlots(player, resourceContainer); } @@ -75,6 +75,11 @@ public double getProgress() { return (double) getStored() / (double) getCapacity(); } + @Override + public boolean hasCapacity() { + return capacity > 0; + } + @Override public long getCapacity() { return capacity; diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/StorageBlockData.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/StorageBlockData.java deleted file mode 100644 index fbaf7ea16..000000000 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/StorageBlockData.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.refinedmods.refinedstorage.common.storage.storageblock; - -import com.refinedmods.refinedstorage.common.support.resource.ResourceContainerData; - -import net.minecraft.network.RegistryFriendlyByteBuf; -import net.minecraft.network.codec.ByteBufCodecs; -import net.minecraft.network.codec.StreamCodec; - -public record StorageBlockData(long stored, long capacity, ResourceContainerData resourceContainerData) { - public static final StreamCodec STREAM_CODEC = StreamCodec.composite( - ByteBufCodecs.VAR_LONG, StorageBlockData::stored, - ByteBufCodecs.VAR_LONG, StorageBlockData::capacity, - ResourceContainerData.STREAM_CODEC, StorageBlockData::resourceContainerData, - StorageBlockData::new - ); -} diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/StorageBlockScreen.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/StorageBlockScreen.java new file mode 100644 index 000000000..ed2d700f3 --- /dev/null +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/StorageBlockScreen.java @@ -0,0 +1,34 @@ +package com.refinedmods.refinedstorage.common.storage.storageblock; + +import com.refinedmods.refinedstorage.common.api.support.resource.ResourceRendering; +import com.refinedmods.refinedstorage.common.storage.AbstractProgressStorageScreen; + +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Inventory; + +import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createIdentifier; + +public class StorageBlockScreen extends AbstractProgressStorageScreen { + private static final ResourceLocation TEXTURE = createIdentifier("textures/gui/storage.png"); + + private final ResourceRendering resourceRendering; + + public StorageBlockScreen(final StorageBlockContainerMenu menu, + final Inventory inventory, + final Component title, + final ResourceRendering resourceRendering) { + super(menu, inventory, title, 80); + this.resourceRendering = resourceRendering; + } + + @Override + protected ResourceLocation getTexture() { + return TEXTURE; + } + + @Override + protected String formatAmount(final long qty) { + return resourceRendering.formatAmount(qty); + } +} diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storagedisk/FluidStorageDiskItem.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storagedisk/FluidStorageDiskItem.java index c26266938..769648d4c 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storagedisk/FluidStorageDiskItem.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storagedisk/FluidStorageDiskItem.java @@ -1,6 +1,7 @@ package com.refinedmods.refinedstorage.common.storage.storagedisk; import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.RefinedStorageClientApi; import com.refinedmods.refinedstorage.common.api.storage.AbstractStorageContainerItem; import com.refinedmods.refinedstorage.common.api.storage.SerializableStorage; import com.refinedmods.refinedstorage.common.api.storage.StorageRepository; @@ -53,7 +54,7 @@ protected Long getCapacity() { @Override protected String formatAmount(final long amount) { - return RefinedStorageApi.INSTANCE.getResourceRendering(FluidResource.class).formatAmount(amount); + return RefinedStorageClientApi.INSTANCE.getResourceRendering(FluidResource.class).formatAmount(amount); } @Override diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storagemonitor/StorageMonitorBlockEntityRenderer.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storagemonitor/StorageMonitorBlockEntityRenderer.java index 582990291..0c38b518e 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storagemonitor/StorageMonitorBlockEntityRenderer.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storagemonitor/StorageMonitorBlockEntityRenderer.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage.common.storagemonitor; import com.refinedmods.refinedstorage.api.resource.ResourceKey; -import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.RefinedStorageClientApi; import com.refinedmods.refinedstorage.common.api.support.resource.ResourceRendering; import com.refinedmods.refinedstorage.common.support.direction.BiDirection; import com.refinedmods.refinedstorage.common.support.direction.BiDirectionType; @@ -61,7 +61,7 @@ private void doRender(final Level level, final BiDirection direction, final ResourceKey resource, final long amount) { - final ResourceRendering rendering = RefinedStorageApi.INSTANCE.getResourceRendering(resource.getClass()); + final ResourceRendering rendering = RefinedStorageClientApi.INSTANCE.getResourceRendering(resource.getClass()); doRender( poseStack, vertexConsumers, diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/AbstractBaseScreen.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/AbstractBaseScreen.java index 72e200b35..63c90187a 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/AbstractBaseScreen.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/AbstractBaseScreen.java @@ -3,6 +3,7 @@ import com.refinedmods.refinedstorage.api.resource.ResourceKey; import com.refinedmods.refinedstorage.common.Platform; import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.RefinedStorageClientApi; import com.refinedmods.refinedstorage.common.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage.common.api.support.resource.ResourceFactory; import com.refinedmods.refinedstorage.common.api.upgrade.UpgradeMapping; @@ -208,7 +209,7 @@ public final List getResourceSlotTooltip(final ItemStack } protected List getResourceSlotTooltip(final ResourceKey resource, final ResourceSlot slot) { - final List tooltip = RefinedStorageApi.INSTANCE + final List tooltip = RefinedStorageClientApi.INSTANCE .getResourceRendering(resource.getClass()) .getTooltip(resource) .stream() diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/ResourceSlotRendering.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/ResourceSlotRendering.java index 4c4d8d604..8be478e1e 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/ResourceSlotRendering.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/ResourceSlotRendering.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage.common.support; import com.refinedmods.refinedstorage.api.resource.ResourceKey; -import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.RefinedStorageClientApi; import com.refinedmods.refinedstorage.common.api.support.resource.ResourceRendering; import com.refinedmods.refinedstorage.common.support.containermenu.ResourceSlot; @@ -38,7 +38,7 @@ private static void render(final GuiGraphics graphics, final ResourceKey resource, final long amount, final boolean renderAmount) { - final ResourceRendering rendering = RefinedStorageApi.INSTANCE.getResourceRendering(resource.getClass()); + final ResourceRendering rendering = RefinedStorageClientApi.INSTANCE.getResourceRendering(resource.getClass()); rendering.render(resource, graphics, x, y); if (renderAmount) { renderAmount(graphics, x, y, amount, rendering); diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/resource/FluidResourceRendering.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/resource/FluidResourceRendering.java index 57506c10b..f4ed420e6 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/resource/FluidResourceRendering.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/resource/FluidResourceRendering.java @@ -18,10 +18,14 @@ import net.minecraft.world.level.Level; public class FluidResourceRendering implements ResourceRendering { - private static final DecimalFormat LESS_THAN_1_BUCKET_FORMATTER = - new DecimalFormat("0.#", DecimalFormatSymbols.getInstance(Locale.US)); - private static final DecimalFormat FORMATTER = - new DecimalFormat("#,###.#", DecimalFormatSymbols.getInstance(Locale.US)); + private static final DecimalFormat LESS_THAN_1_BUCKET_FORMATTER = new DecimalFormat( + "0.#", + DecimalFormatSymbols.getInstance(Locale.US) + ); + private static final DecimalFormat FORMATTER = new DecimalFormat( + "#,###.#", + DecimalFormatSymbols.getInstance(Locale.US) + ); private final long bucketAmount; diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/resource/ItemResourceRendering.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/resource/ItemResourceRendering.java index d4b107f7c..da2c6a27b 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/resource/ItemResourceRendering.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/resource/ItemResourceRendering.java @@ -25,8 +25,11 @@ import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.format; import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.formatWithUnits; -public class ItemResourceRendering implements ResourceRendering { - public static final Matrix4f IN_WORLD_SCALE = new Matrix4f().scale(0.3F, 0.3F, 0.001f); +public enum ItemResourceRendering implements ResourceRendering { + INSTANCE; + + 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) { diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/resource/ResourceContainerImpl.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/resource/ResourceContainerImpl.java index cea778c36..8bb92e80a 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/resource/ResourceContainerImpl.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/resource/ResourceContainerImpl.java @@ -14,6 +14,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Optional; import java.util.Set; import java.util.function.ToLongFunction; import javax.annotation.Nullable; @@ -381,7 +382,7 @@ public static ResourceContainer createForFilter() { public static ResourceContainer createForFilter(final ResourceContainerData data) { final ResourceContainer resourceContainer = createForFilter(data.resources().size()); - setResourceContainerData(data, resourceContainer); + setResourceContainerData(data.resources(), resourceContainer); return resourceContainer; } @@ -410,15 +411,22 @@ public static ResourceContainer createForFilter(final ResourceFactory resourceFa public static ResourceContainer createForFilter(final ResourceFactory resourceFactory, final ResourceContainerData data) { final ResourceContainer resourceContainer = createForFilter(resourceFactory, data.resources().size()); - setResourceContainerData(data, resourceContainer); + setResourceContainerData(data.resources(), resourceContainer); return resourceContainer; } - public static void setResourceContainerData(final ResourceContainerData data, + public static ResourceContainer createForFilter(final ResourceFactory resourceFactory, + final List> resources) { + final ResourceContainer resourceContainer = createForFilter(resourceFactory, resources.size()); + setResourceContainerData(resources, resourceContainer); + return resourceContainer; + } + + public static void setResourceContainerData(final List> resources, final ResourceContainer resourceContainer) { - for (int i = 0; i < data.resources().size(); ++i) { + for (int i = 0; i < resources.size(); ++i) { final int ii = i; - data.resources().get(i).ifPresent(resource -> resourceContainer.set(ii, resource)); + resources.get(i).ifPresent(resource -> resourceContainer.set(ii, resource)); } } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/tooltip/MouseClientTooltipComponent.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/tooltip/MouseClientTooltipComponent.java index 8ddf14d05..1c0bdf4a5 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/tooltip/MouseClientTooltipComponent.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/tooltip/MouseClientTooltipComponent.java @@ -2,7 +2,7 @@ import com.refinedmods.refinedstorage.api.resource.ResourceKey; import com.refinedmods.refinedstorage.common.Platform; -import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.RefinedStorageClientApi; import com.refinedmods.refinedstorage.common.support.resource.FluidResource; import javax.annotation.Nullable; @@ -102,7 +102,7 @@ public static ClientTooltipComponent resource(final Type type, @Nullable final String amount) { return new MouseClientTooltipComponent( type, - (graphics, x, y) -> RefinedStorageApi.INSTANCE.getResourceRendering(resource.getClass()) + (graphics, x, y) -> RefinedStorageClientApi.INSTANCE.getResourceRendering(resource.getClass()) .render(resource, graphics, x, y), amount ); diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/tooltip/ResourceClientTooltipComponent.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/tooltip/ResourceClientTooltipComponent.java index 526fa8153..151fa2601 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/tooltip/ResourceClientTooltipComponent.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/tooltip/ResourceClientTooltipComponent.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage.common.support.tooltip; import com.refinedmods.refinedstorage.api.resource.ResourceAmount; -import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.RefinedStorageClientApi; import com.refinedmods.refinedstorage.common.api.support.resource.ResourceRendering; import net.minecraft.client.gui.Font; @@ -30,7 +30,7 @@ public int getWidth(final Font font) { @Override public void renderImage(final Font font, final int x, final int y, final GuiGraphics graphics) { - RefinedStorageApi.INSTANCE.getResourceRendering(resourceAmount.resource().getClass()).render( + RefinedStorageClientApi.INSTANCE.getResourceRendering(resourceAmount.resource().getClass()).render( resourceAmount.resource(), graphics, x, @@ -46,7 +46,7 @@ public void renderImage(final Font font, final int x, final int y, final GuiGrap } private static Component getNameWithAmount(final ResourceAmount resourceAmount) { - final ResourceRendering rendering = RefinedStorageApi.INSTANCE.getResourceRendering( + final ResourceRendering rendering = RefinedStorageClientApi.INSTANCE.getResourceRendering( resourceAmount.resource().getClass() ); final String amount = rendering.formatAmount(resourceAmount.amount()); diff --git a/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/ClientModInitializerImpl.java b/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/ClientModInitializerImpl.java index 17796cf06..27d301f9a 100644 --- a/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/ClientModInitializerImpl.java +++ b/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/ClientModInitializerImpl.java @@ -72,6 +72,7 @@ import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.blockentity.BlockEntityRenderers; import net.minecraft.client.renderer.item.ItemProperties; +import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.inventory.AbstractContainerMenu; @@ -88,6 +89,7 @@ public class ClientModInitializerImpl extends AbstractClientModInitializer imple @Override public void onInitializeClient() { + initializeClientPlatformApi(); setRenderLayers(); registerEmissiveModels(); registerPacketHandlers(); @@ -460,27 +462,27 @@ private void registerCustomPatternModel(final ModelLoadingPlugin.Context pluginC } private void registerCustomTooltips() { - TooltipComponentCallback.EVENT.register(data -> { - if (data instanceof AbstractUpgradeItem.UpgradeDestinationTooltipComponent component) { + TooltipComponentCallback.EVENT.register(d -> { + if (d instanceof AbstractUpgradeItem.UpgradeDestinationTooltipComponent(var destinations, var helpText)) { return new CompositeClientTooltipComponent(List.of( - new UpgradeDestinationClientTooltipComponent(component.destinations()), - HelpClientTooltipComponent.create(component.helpText()) + new UpgradeDestinationClientTooltipComponent(destinations), + HelpClientTooltipComponent.create(helpText) )); } return null; }); TooltipComponentCallback.EVENT.register(data -> { - if (data instanceof HelpTooltipComponent component) { - return HelpClientTooltipComponent.create(component.text()); + if (data instanceof HelpTooltipComponent(Component text)) { + return HelpClientTooltipComponent.create(text); } return null; }); - TooltipComponentCallback.EVENT.register(data -> { - if (data instanceof RegulatorUpgradeItem.RegulatorTooltipComponent component) { + TooltipComponentCallback.EVENT.register(d -> { + if (d instanceof RegulatorUpgradeItem.RegulatorTooltipComponent(var destinations, var helpText, var r)) { return createRegulatorUpgradeClientTooltipComponent( - component.destinations(), - component.configuredResource(), - component.helpText() + destinations, + r, + helpText ); } return null; diff --git a/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/storage/diskdrive/DiskDriveUnbakedModel.java b/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/storage/diskdrive/DiskDriveUnbakedModel.java index a6e02f845..a72c0206a 100644 --- a/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/storage/diskdrive/DiskDriveUnbakedModel.java +++ b/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/storage/diskdrive/DiskDriveUnbakedModel.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage.fabric.storage.diskdrive; -import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.RefinedStorageClientApi; import com.refinedmods.refinedstorage.fabric.support.render.QuadRotators; import java.util.Collection; @@ -38,14 +38,14 @@ public Collection getDependencies() { final Set dependencies = new HashSet<>(); dependencies.add(BASE_MODEL); dependencies.add(LED_INACTIVE_MODEL); - dependencies.addAll(RefinedStorageApi.INSTANCE.getStorageContainerItemHelper().getDiskModels()); + dependencies.addAll(RefinedStorageClientApi.INSTANCE.getDiskModels()); return dependencies; } @Override public void resolveParents(final Function modelGetter) { modelGetter.apply(BASE_MODEL).resolveParents(modelGetter); - RefinedStorageApi.INSTANCE.getStorageContainerItemHelper().getDiskModels().forEach( + RefinedStorageClientApi.INSTANCE.getDiskModels().forEach( diskModel -> modelGetter.apply(diskModel).resolveParents(modelGetter) ); modelGetter.apply(LED_INACTIVE_MODEL).resolveParents(modelGetter); @@ -56,8 +56,7 @@ public void resolveParents(final Function modelG public BakedModel bake(final ModelBaker baker, final Function spriteGetter, final ModelState state) { - final Map diskModels = RefinedStorageApi.INSTANCE.getStorageContainerItemHelper() - .getDiskModelsByItem() + final Map diskModels = RefinedStorageClientApi.INSTANCE.getDiskModelsByItem() .entrySet() .stream() .collect(Collectors.toMap( diff --git a/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/storage/diskinterface/DiskInterfaceUnbakedModel.java b/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/storage/diskinterface/DiskInterfaceUnbakedModel.java index ef4d4b1f3..f964fe61b 100644 --- a/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/storage/diskinterface/DiskInterfaceUnbakedModel.java +++ b/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/storage/diskinterface/DiskInterfaceUnbakedModel.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage.fabric.storage.diskinterface; -import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.RefinedStorageClientApi; import com.refinedmods.refinedstorage.fabric.support.render.QuadRotators; import java.util.Collection; @@ -44,7 +44,7 @@ public Collection getDependencies() { dependencies.add(baseModel); dependencies.add(INACTIVE_MODEL); dependencies.add(LED_INACTIVE_MODEL); - dependencies.addAll(RefinedStorageApi.INSTANCE.getStorageContainerItemHelper().getDiskModels()); + dependencies.addAll(RefinedStorageClientApi.INSTANCE.getDiskModels()); return dependencies; } @@ -52,7 +52,7 @@ public Collection getDependencies() { public void resolveParents(final Function modelGetter) { modelGetter.apply(baseModel).resolveParents(modelGetter); modelGetter.apply(INACTIVE_MODEL).resolveParents(modelGetter); - RefinedStorageApi.INSTANCE.getStorageContainerItemHelper().getDiskModels().forEach( + RefinedStorageClientApi.INSTANCE.getDiskModels().forEach( diskModel -> modelGetter.apply(diskModel).resolveParents(modelGetter) ); modelGetter.apply(LED_INACTIVE_MODEL).resolveParents(modelGetter); @@ -63,7 +63,7 @@ public void resolveParents(final Function modelG public BakedModel bake(final ModelBaker baker, final Function spriteGetter, final ModelState state) { - final Map diskModels = RefinedStorageApi.INSTANCE.getStorageContainerItemHelper() + final Map diskModels = RefinedStorageClientApi.INSTANCE .getDiskModelsByItem() .entrySet() .stream() diff --git a/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/storage/portablegrid/PortableGridUnbakedModel.java b/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/storage/portablegrid/PortableGridUnbakedModel.java index 1cafd0d1a..a94087748 100644 --- a/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/storage/portablegrid/PortableGridUnbakedModel.java +++ b/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/storage/portablegrid/PortableGridUnbakedModel.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage.fabric.storage.portablegrid; -import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.RefinedStorageClientApi; import com.refinedmods.refinedstorage.fabric.support.render.QuadRotators; import java.util.Collection; @@ -48,7 +48,7 @@ public void resolveParents(final Function modelG modelGetter.apply(NORMAL_LED_MODEL).resolveParents(modelGetter); modelGetter.apply(NEAR_CAPACITY_LED_MODEL).resolveParents(modelGetter); modelGetter.apply(FULL_LED_MODEL).resolveParents(modelGetter); - RefinedStorageApi.INSTANCE.getStorageContainerItemHelper().getDiskModels().forEach( + RefinedStorageClientApi.INSTANCE.getDiskModels().forEach( diskModel -> modelGetter.apply(diskModel).resolveParents(modelGetter) ); } @@ -57,7 +57,7 @@ public void resolveParents(final Function modelG public BakedModel bake(final ModelBaker baker, final Function spriteGetter, final ModelState state) { - final Map diskModels = RefinedStorageApi.INSTANCE.getStorageContainerItemHelper() + final Map diskModels = RefinedStorageClientApi.INSTANCE .getDiskModelsByItem() .entrySet() .stream() diff --git a/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/ModInitializer.java b/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/ModInitializer.java index de22470b2..8a823eed4 100644 --- a/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/ModInitializer.java +++ b/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/ModInitializer.java @@ -1,5 +1,6 @@ package com.refinedmods.refinedstorage.neoforge; +import com.refinedmods.refinedstorage.common.AbstractClientModInitializer; import com.refinedmods.refinedstorage.common.AbstractModInitializer; import com.refinedmods.refinedstorage.common.Platform; import com.refinedmods.refinedstorage.common.PlatformProxy; @@ -215,6 +216,7 @@ public ModInitializer(final IEventBus eventBus, final ModContainer modContainer) registerTickHandler(); if (FMLEnvironment.dist == Dist.CLIENT) { + AbstractClientModInitializer.initializeClientPlatformApi(); eventBus.addListener(ClientModInitializer::onClientSetup); eventBus.addListener(ClientModInitializer::onRegisterCustomModels); eventBus.addListener(ClientModInitializer::onRegisterMenuScreens); diff --git a/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/storage/diskdrive/DiskDriveUnbakedGeometry.java b/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/storage/diskdrive/DiskDriveUnbakedGeometry.java index f50a5a1fb..af9a85aca 100644 --- a/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/storage/diskdrive/DiskDriveUnbakedGeometry.java +++ b/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/storage/diskdrive/DiskDriveUnbakedGeometry.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage.neoforge.storage.diskdrive; -import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.RefinedStorageClientApi; import com.refinedmods.refinedstorage.neoforge.support.render.DiskModelBaker; import com.refinedmods.refinedstorage.neoforge.support.render.RotationTranslationModelBaker; @@ -31,7 +31,7 @@ public class DiskDriveUnbakedGeometry implements IUnbakedGeometry modelGetter, final IGeometryBakingContext context) { modelGetter.apply(BASE_MODEL).resolveParents(modelGetter); - RefinedStorageApi.INSTANCE.getStorageContainerItemHelper().getDiskModels().forEach( + RefinedStorageClientApi.INSTANCE.getDiskModels().forEach( diskModel -> modelGetter.apply(diskModel).resolveParents(modelGetter) ); modelGetter.apply(LED_INACTIVE_MODEL).resolveParents(modelGetter); diff --git a/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/storage/diskinterface/DiskInterfaceUnbakedGeometry.java b/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/storage/diskinterface/DiskInterfaceUnbakedGeometry.java index af3d01e45..0216822af 100644 --- a/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/storage/diskinterface/DiskInterfaceUnbakedGeometry.java +++ b/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/storage/diskinterface/DiskInterfaceUnbakedGeometry.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage.neoforge.storage.diskinterface; -import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.RefinedStorageClientApi; import com.refinedmods.refinedstorage.neoforge.support.render.DiskModelBaker; import com.refinedmods.refinedstorage.neoforge.support.render.RotationTranslationModelBaker; @@ -36,7 +36,7 @@ public void resolveParents(final Function modelG final IGeometryBakingContext context) { modelGetter.apply(baseModel).resolveParents(modelGetter); modelGetter.apply(INACTIVE_MODEL).resolveParents(modelGetter); - RefinedStorageApi.INSTANCE.getStorageContainerItemHelper().getDiskModels().forEach( + RefinedStorageClientApi.INSTANCE.getDiskModels().forEach( diskModel -> modelGetter.apply(diskModel).resolveParents(modelGetter) ); modelGetter.apply(LED_INACTIVE_MODEL).resolveParents(modelGetter); diff --git a/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/storage/portablegrid/PortableGridUnbakedGeometry.java b/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/storage/portablegrid/PortableGridUnbakedGeometry.java index 38531d03e..c1e78dced 100644 --- a/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/storage/portablegrid/PortableGridUnbakedGeometry.java +++ b/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/storage/portablegrid/PortableGridUnbakedGeometry.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage.neoforge.storage.portablegrid; -import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.RefinedStorageClientApi; import com.refinedmods.refinedstorage.neoforge.support.render.DiskModelBaker; import com.refinedmods.refinedstorage.neoforge.support.render.RotationTranslationModelBaker; @@ -40,7 +40,7 @@ public void resolveParents(final Function modelG modelGetter.apply(NORMAL_LED_MODEL).resolveParents(modelGetter); modelGetter.apply(NEAR_CAPACITY_LED_MODEL).resolveParents(modelGetter); modelGetter.apply(FULL_LED_MODEL).resolveParents(modelGetter); - RefinedStorageApi.INSTANCE.getStorageContainerItemHelper().getDiskModels().forEach( + RefinedStorageClientApi.INSTANCE.getDiskModels().forEach( diskModel -> modelGetter.apply(diskModel).resolveParents(modelGetter) ); } diff --git a/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/support/render/DiskModelBaker.java b/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/support/render/DiskModelBaker.java index 6f7a5afad..abf563af9 100644 --- a/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/support/render/DiskModelBaker.java +++ b/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/support/render/DiskModelBaker.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage.neoforge.support.render; -import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; +import com.refinedmods.refinedstorage.common.api.RefinedStorageClientApi; import java.util.Map; import java.util.function.Function; @@ -19,8 +19,7 @@ public class DiskModelBaker { public DiskModelBaker(final ModelState state, final ModelBaker baker, final Function spriteGetter) { - this.bakers = RefinedStorageApi.INSTANCE.getStorageContainerItemHelper() - .getDiskModelsByItem() + this.bakers = RefinedStorageClientApi.INSTANCE.getDiskModelsByItem() .entrySet() .stream() .collect(Collectors.toMap(