From 3a19ccd700cbfdd43ad269c6afe396255363e995 Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Sun, 28 Jan 2024 12:35:33 +0100 Subject: [PATCH] feat: port to minecraft 1.20.4 --- .github/workflows/build.yml | 2 +- .github/workflows/draft-release.yml | 2 +- .../issue-for-unsupported-version.yml | 2 +- .github/workflows/publish-release.yml | 2 +- .github/workflows/resolved-issue-locking.yml | 2 +- .github/workflows/validate-branch-name.yml | 2 +- .github/workflows/validate-changelog.yml | 2 +- .../workflows/validate-commit-messages.yml | 2 +- CHANGELOG.md | 1 + LICENSE.md | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 +- .../energy/AbstractEnergyBlockItem.java | 2 +- .../support/energy/AbstractEnergyItem.java | 2 +- .../api/support/energy/EnergyItem.java | 17 - ...ava => TransferableBlockEntityEnergy.java} | 6 +- .../api/support/resource/FluidResource.java | 2 - .../api/support/resource/ItemResource.java | 2 - .../common/AbstractModInitializer.java | 13 +- .../platform/common/Platform.java | 4 +- .../platform/common/PlatformApiImpl.java | 18 +- .../platform/common/PlatformProxy.java | 4 +- .../ConfigurationCardItem.java | 5 - .../AbstractConstructorDestructorBlock.java | 10 +- .../ConstructorBlock.java | 10 +- .../DestructorBlock.java | 10 +- .../ItemDropConstructorStrategy.java | 4 +- .../common/content/BlockColorMap.java | 6 +- .../platform/common/content/Blocks.java | 96 +- .../common/content/CreativeModeTabItems.java | 7 +- .../platform/common/content/Items.java | 71 +- .../controller/AbstractControllerBlock.java | 84 ++ .../common/controller/ControllerBlock.java | 86 +- .../controller/ControllerBlockEntity.java | 8 +- .../controller/ControllerBlockItem.java | 7 +- .../controller/CreativeControllerBlock.java | 27 + .../CreativeControllerBlockItem.java | 2 +- .../common/detector/DetectorBlock.java | 8 +- .../common/exporter/ExporterBlock.java | 9 +- .../common/grid/AbstractGridBlock.java | 5 +- .../grid/AbstractGridContainerMenu.java | 33 + .../common/grid/CraftingGridBlock.java | 8 +- .../common/grid/CraftingGridBlockEntity.java | 2 + .../common/grid/CraftingGridResultSlot.java | 4 +- .../platform/common/grid/GridBlock.java | 9 +- .../common/grid/WirelessGridItem.java | 10 +- .../grid/screen/AbstractGridScreen.java | 44 +- .../grid/screen/CraftingGridScreen.java | 36 +- .../AbstractFluidGridResourceFactory.java | 2 - .../view/AbstractItemGridResourceFactory.java | 1 - .../common/grid/view/FluidGridResource.java | 1 - .../common/importer/ImporterBlock.java | 7 +- .../common/networking/CableBlock.java | 6 +- .../networking/NetworkReceiverBlock.java | 3 +- .../networking/NetworkTransmitterBlock.java | 3 +- .../CraftingGridRecipeTransferHandler.java | 8 +- .../common/storage/DiskInventory.java | 2 - .../externalstorage/ExternalStorageBlock.java | 7 +- .../AbstractPortableGridBlockEntity.java | 4 +- .../PortableGridLootItemFunction.java | 2 +- ...ortableGridLootItemFunctionSerializer.java | 22 - .../StorageBlockLootItemFunction.java | 2 +- ...torageBlockLootItemFunctionSerializer.java | 22 - .../ItemStorageMonitorExtractionStrategy.java | 1 - .../common/support/AbstractBaseBlock.java | 5 +- .../common/support/AbstractBaseScreen.java | 2 +- .../common/support/AbstractColoredBlock.java | 7 +- .../common/support/BlockItemProvider.java | 4 +- .../common/support/ColorableBlock.java | 5 +- .../support/amount/AbstractAmountScreen.java | 4 +- .../support/energy/EnergyItemHelperImpl.java | 19 +- .../energy/EnergyLootItemFunction.java | 6 +- .../EnergyLootItemFunctionSerializer.java | 22 - .../NetworkNodeContainerBlockEntityImpl.java | 8 +- .../common/support}/packet/PacketIds.java | 2 +- .../common/support/packet}/package-info.java | 2 +- .../support/widget/HoveredImageButton.java | 26 + .../support/widget/ScrollbarWidget.java | 4 +- .../UpgradeWithEnchantedBookRecipe.java | 69 +- ...radeWithEnchantedBookRecipeSerializer.java | 42 +- .../platform/common/util/PacketUtil.java | 2 - .../WirelessTransmitterBlock.java | 8 +- .../block/constructor_destructor/active.json | 2 +- .../models/block/detector/powered.json | 8 +- .../models/block/emissive_all_cutout.json | 12 +- .../models/block/emissive_north_cutout.json | 2 +- .../block/wireless_transmitter/active.json | 12 +- .../models/item/constructor/base.json | 2 +- .../models/item/destructor/base.json | 2 +- .../textures/gui/crafting_grid.png | Bin 2556 -> 2163 bytes .../textures/gui/sprites/widget/move_down.png | Bin 0 -> 143 bytes .../gui/sprites/widget/move_down_disabled.png | Bin 0 -> 142 bytes .../gui/sprites/widget/move_down_focused.png | Bin 0 -> 143 bytes .../textures/gui/sprites/widget/move_up.png | Bin 0 -> 140 bytes .../gui/sprites/widget/move_up_disabled.png | Bin 0 -> 141 bytes .../gui/sprites/widget/move_up_focused.png | Bin 0 -> 140 bytes .../recipes/fortune_1_upgrade.json | 5 +- .../recipes/fortune_2_upgrade.json | 6 +- .../recipes/fortune_3_upgrade.json | 6 +- .../recipes/silk_touch_upgrade.json | 4 +- .../platform/common/TestPlatform.java | 4 +- refinedstorage2-platform-fabric/build.gradle | 4 +- .../fabric/ClientModInitializerImpl.java | 4 +- .../platform/fabric/ModInitializerImpl.java | 52 +- .../platform/fabric/PlatformImpl.java | 7 +- .../c2s/ClientToServerCommunicationsImpl.java | 2 +- .../s2c/ServerToClientCommunicationsImpl.java | 2 +- .../rei/RefinedStorageREIClientPlugin.java | 14 +- .../src/main/resources/fabric.mod.json | 2 +- refinedstorage2-platform-forge/.gitignore | 2 +- refinedstorage2-platform-forge/build.gradle | 22 +- .../platform/forge/ClientModInitializer.java | 50 +- .../platform/forge/ConfigImpl.java | 106 +- .../platform/forge/ModInitializer.java | 914 ++++++++++-------- .../platform/forge/PlatformImpl.java | 71 +- .../forge/datagen/BlockModelProvider.java | 6 +- .../forge/datagen/BlockStateProvider.java | 24 +- .../forge/datagen/DataGenerators.java | 8 +- .../forge/datagen/ItemModelProvider.java | 21 +- .../recipe/RecoloringRecipeProvider.java | 32 +- .../forge/datagen/tag/BlockTagsProvider.java | 2 +- .../forge/datagen/tag/ItemTagGenerator.java | 13 +- ...andlerExporterTransferStrategyFactory.java | 6 +- ...andlerExporterTransferStrategyFactory.java | 4 +- .../grid/strategy/CursorItemHandler.java | 4 +- .../strategy/FluidGridExtractionStrategy.java | 13 +- .../strategy/FluidGridInsertionStrategy.java | 9 +- .../strategy/ItemGridExtractionStrategy.java | 8 +- .../strategy/ItemGridInsertionStrategy.java | 10 +- .../strategy/ItemGridScrollingStrategy.java | 14 +- .../view/ForgeFluidGridResourceFactory.java | 4 +- .../view/ForgeItemGridResourceFactory.java | 2 +- .../importer/FluidHandlerImporterSource.java | 14 +- ...andlerImporterTransferStrategyFactory.java | 6 +- .../importer/ItemHandlerImporterSource.java | 14 +- ...andlerImporterTransferStrategyFactory.java | 4 +- .../platform/forge/packet/NetworkManager.java | 195 ---- .../packet/c2s/CraftingGridClearPacket.java | 33 - .../forge/packet/c2s/GridInsertPacket.java | 45 - .../packet/c2s/PropertyChangePacket.java | 44 - .../c2s/ResourceFilterSlotChangePacket.java | 78 -- .../c2s/ResourceSlotAmountChangePacket.java | 43 - .../packet/c2s/ResourceSlotChangePacket.java | 44 - .../packet/c2s/SingleAmountChangePacket.java | 40 - .../packet/c2s/StorageInfoRequestPacket.java | 44 - .../forge/packet/s2c/ClientProxy.java | 16 - .../forge/packet/s2c/EnergyInfoPacket.java | 41 - .../forge/packet/s2c/GridActivePacket.java | 38 - .../forge/packet/s2c/GridClearPacket.java | 23 - .../forge/packet/s2c/GridUpdatePacket.java | 75 -- .../s2c/NetworkTransmitterStatusPacket.java | 43 - .../packet/s2c/StorageInfoResponsePacket.java | 44 - .../s2c/WirelessTransmitterRangePacket.java | 38 - .../rei/RefinedStorageREIClientPlugin.java | 13 +- ...nCoordinates.java => CapabilityCache.java} | 26 +- .../forge/storage/CapabilityCacheImpl.java | 31 + .../FluidHandlerExtractableStorage.java | 10 +- .../FluidHandlerInsertableStorage.java | 12 +- .../forge/storage/ForgeHandlerUtil.java | 6 +- .../storage/InteractionCoordinatesImpl.java | 40 - .../ItemHandlerExtractableStorage.java | 10 +- .../storage/ItemHandlerInsertableStorage.java | 12 +- .../diskdrive/DiskDriveBakedModel.java | 4 +- .../diskdrive/DiskDriveGeometryLoader.java | 2 +- .../diskdrive/DiskDriveUnbakedGeometry.java | 4 +- .../diskdrive/ForgeDiskDriveBlockEntity.java | 4 +- .../FluidHandlerExternalStorageProvider.java | 14 +- ...latformExternalStorageProviderFactory.java | 58 +- .../ItemHandlerExternalStorageProvider.java | 14 +- ...latformExternalStorageProviderFactory.java | 58 +- .../ForgePortableGridBlockEntity.java | 4 +- .../portablegrid/PortableGridBakedModel.java | 4 +- .../PortableGridGeometryLoader.java | 2 +- .../PortableGridUnbakedGeometry.java | 4 +- .../ContainerTransferDestination.java | 4 +- .../support/containermenu/MenuOpenerImpl.java | 7 +- .../support/energy/EnergyStorageAdapter.java | 2 +- .../bounditem/CuriosSlotReference.java | 1 - .../CuriosSlotReferenceProvider.java | 3 +- .../c2s/ClientToServerCommunicationsImpl.java | 39 +- .../packet/c2s/CraftingGridClearPacket.java | 33 + .../c2s/CraftingGridRecipeTransferPacket.java | 44 +- .../packet/c2s/GridExtractPacket.java | 79 +- .../support/packet/c2s/GridInsertPacket.java | 38 + .../packet/c2s/GridScrollPacket.java | 79 +- .../packet/c2s/PropertyChangePacket.java | 28 + .../c2s/ResourceFilterSlotChangePacket.java | 65 ++ .../c2s/ResourceSlotAmountChangePacket.java | 34 + .../packet/c2s/ResourceSlotChangePacket.java | 35 + .../packet/c2s/SingleAmountChangePacket.java | 33 + .../packet/c2s/StorageInfoRequestPacket.java | 43 + .../packet/c2s/UseNetworkBoundItemPacket.java | 46 +- .../packet/c2s/package-info.java | 2 +- .../support/packet/s2c/EnergyInfoPacket.java | 36 + .../support/packet/s2c/GridActivePacket.java | 35 + .../support/packet/s2c/GridClearPacket.java | 31 + .../support/packet/s2c/GridUpdatePacket.java | 61 ++ .../s2c/NetworkTransmitterStatusPacket.java | 38 + .../packet/s2c/ResourceSlotUpdatePacket.java | 64 +- .../s2c/ServerToClientCommunicationsImpl.java | 29 +- .../packet/s2c/StorageInfoResponsePacket.java | 38 + .../s2c/WirelessTransmitterRangePacket.java | 33 + .../packet/s2c}/package-info.java | 2 +- .../render/FluidStackFluidRenderer.java | 6 +- .../forge/support/render/ItemBakedModel.java | 2 +- .../render/RotationTranslationModelBaker.java | 2 +- .../ResourceContainerFluidHandlerAdapter.java | 4 +- .../forge/support/resource/VariantUtil.java | 4 +- .../resources/META-INF/accesstransformer.cfg | 4 +- .../src/main/resources/META-INF/mods.toml | 2 +- .../src/main/resources/pack.mcmeta | 2 +- settings.gradle | 2 +- 211 files changed, 2229 insertions(+), 2556 deletions(-) delete mode 100644 refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/energy/EnergyItem.java rename refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/energy/{EnergyBlockEntity.java => TransferableBlockEntityEnergy.java} (59%) create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/controller/AbstractControllerBlock.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/controller/CreativeControllerBlock.java delete mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridLootItemFunctionSerializer.java delete mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storageblock/StorageBlockLootItemFunctionSerializer.java delete mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/energy/EnergyLootItemFunctionSerializer.java rename {refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric => refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support}/packet/PacketIds.java (96%) rename {refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c => refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/packet}/package-info.java (74%) create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/HoveredImageButton.java create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/gui/sprites/widget/move_down.png create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/gui/sprites/widget/move_down_disabled.png create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/gui/sprites/widget/move_down_focused.png create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/gui/sprites/widget/move_up.png create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/gui/sprites/widget/move_up_disabled.png create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/gui/sprites/widget/move_up_focused.png delete mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/NetworkManager.java delete mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/CraftingGridClearPacket.java delete mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/GridInsertPacket.java delete mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/PropertyChangePacket.java delete mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ResourceFilterSlotChangePacket.java delete mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ResourceSlotAmountChangePacket.java delete mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ResourceSlotChangePacket.java delete mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/SingleAmountChangePacket.java delete mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/StorageInfoRequestPacket.java delete mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/ClientProxy.java delete mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/EnergyInfoPacket.java delete mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/GridActivePacket.java delete mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/GridClearPacket.java delete mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/GridUpdatePacket.java delete mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/NetworkTransmitterStatusPacket.java delete mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/StorageInfoResponsePacket.java delete mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/WirelessTransmitterRangePacket.java rename refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/{InteractionCoordinates.java => CapabilityCache.java} (86%) create mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/CapabilityCacheImpl.java delete mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/InteractionCoordinatesImpl.java rename refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/{ => support}/packet/c2s/ClientToServerCommunicationsImpl.java (70%) create mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/CraftingGridClearPacket.java rename refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/{ => support}/packet/c2s/CraftingGridRecipeTransferPacket.java (51%) rename refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/{ => support}/packet/c2s/GridExtractPacket.java (50%) create mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/GridInsertPacket.java rename refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/{ => support}/packet/c2s/GridScrollPacket.java (53%) create mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/PropertyChangePacket.java create mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/ResourceFilterSlotChangePacket.java create mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/ResourceSlotAmountChangePacket.java create mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/ResourceSlotChangePacket.java create mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/SingleAmountChangePacket.java create mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/StorageInfoRequestPacket.java rename refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/{ => support}/packet/c2s/UseNetworkBoundItemPacket.java (53%) rename refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/{ => support}/packet/c2s/package-info.java (73%) create mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/EnergyInfoPacket.java create mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/GridActivePacket.java create mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/GridClearPacket.java create mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/GridUpdatePacket.java create mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/NetworkTransmitterStatusPacket.java rename refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/{ => support}/packet/s2c/ResourceSlotUpdatePacket.java (50%) rename refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/{ => support}/packet/s2c/ServerToClientCommunicationsImpl.java (72%) create mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/StorageInfoResponsePacket.java create mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/WirelessTransmitterRangePacket.java rename refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/{packet => support/packet/s2c}/package-info.java (73%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7bf568ea5..dcb54fa06 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,5 +8,5 @@ on: types: [ opened, synchronize, reopened ] jobs: build: - uses: refinedmods/refinedarchitect/.github/workflows/build.yml@v0.9.0 + uses: refinedmods/refinedarchitect/.github/workflows/build.yml@v0.11.2 secrets: inherit diff --git a/.github/workflows/draft-release.yml b/.github/workflows/draft-release.yml index e7027dbde..5114b7cbb 100644 --- a/.github/workflows/draft-release.yml +++ b/.github/workflows/draft-release.yml @@ -17,7 +17,7 @@ on: type: string jobs: draft: - uses: refinedmods/refinedarchitect/.github/workflows/draft-release.yml@v0.9.0 + uses: refinedmods/refinedarchitect/.github/workflows/draft-release.yml@v0.11.2 with: release-type: ${{ inputs.release-type }} version-number-override: ${{ inputs.version-number-override }} diff --git a/.github/workflows/issue-for-unsupported-version.yml b/.github/workflows/issue-for-unsupported-version.yml index 27fdc3297..bd2b4f188 100644 --- a/.github/workflows/issue-for-unsupported-version.yml +++ b/.github/workflows/issue-for-unsupported-version.yml @@ -4,4 +4,4 @@ on: types: [ labeled, unlabeled, reopened ] jobs: unsupported-labeler: - uses: refinedmods/refinedarchitect/.github/workflows/issue-for-unsupported-version.yml@v0.9.0 \ No newline at end of file + uses: refinedmods/refinedarchitect/.github/workflows/issue-for-unsupported-version.yml@v0.11.2 \ No newline at end of file diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 39ec95967..7a3eb0338 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -7,7 +7,7 @@ on: - closed jobs: publish-release: - uses: refinedmods/refinedarchitect/.github/workflows/publish-release.yml@v0.9.0 + uses: refinedmods/refinedarchitect/.github/workflows/publish-release.yml@v0.11.2 secrets: inherit with: project-name: 'Refined Storage' diff --git a/.github/workflows/resolved-issue-locking.yml b/.github/workflows/resolved-issue-locking.yml index 050b0b699..89652e7a7 100644 --- a/.github/workflows/resolved-issue-locking.yml +++ b/.github/workflows/resolved-issue-locking.yml @@ -4,4 +4,4 @@ on: - cron: '0 0 * * *' jobs: lock: - uses: refinedmods/refinedarchitect/.github/workflows/resolved-issue-locking.yml@v0.9.0 \ No newline at end of file + uses: refinedmods/refinedarchitect/.github/workflows/resolved-issue-locking.yml@v0.11.2 \ No newline at end of file diff --git a/.github/workflows/validate-branch-name.yml b/.github/workflows/validate-branch-name.yml index 6f09baf29..6ab945cb8 100644 --- a/.github/workflows/validate-branch-name.yml +++ b/.github/workflows/validate-branch-name.yml @@ -2,4 +2,4 @@ name: Validate branch name on: [ pull_request ] jobs: validate-branch-name: - uses: refinedmods/refinedarchitect/.github/workflows/validate-branch-name.yml@v0.9.0 \ No newline at end of file + uses: refinedmods/refinedarchitect/.github/workflows/validate-branch-name.yml@v0.11.2 \ No newline at end of file diff --git a/.github/workflows/validate-changelog.yml b/.github/workflows/validate-changelog.yml index b7b83f9f3..4174999a9 100644 --- a/.github/workflows/validate-changelog.yml +++ b/.github/workflows/validate-changelog.yml @@ -4,4 +4,4 @@ on: types: [ opened, synchronize, reopened, ready_for_review, labeled, unlabeled ] jobs: validate-changelog: - uses: refinedmods/refinedarchitect/.github/workflows/validate-changelog.yml@v0.9.0 \ No newline at end of file + uses: refinedmods/refinedarchitect/.github/workflows/validate-changelog.yml@v0.11.2 \ No newline at end of file diff --git a/.github/workflows/validate-commit-messages.yml b/.github/workflows/validate-commit-messages.yml index 918f1807b..557417578 100644 --- a/.github/workflows/validate-commit-messages.yml +++ b/.github/workflows/validate-commit-messages.yml @@ -2,4 +2,4 @@ name: Validate commit messages on: [ pull_request ] jobs: validate-commit-messages: - uses: refinedmods/refinedarchitect/.github/workflows/validate-commit-messages.yml@v0.9.0 \ No newline at end of file + uses: refinedmods/refinedarchitect/.github/workflows/validate-commit-messages.yml@v0.11.2 \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 91c7f619d..83ee18f31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ### Added +- Ported to Minecraft 1.20.4. - Custom disk models. Fluid disks now have a different model. - Portable Grid diff --git a/LICENSE.md b/LICENSE.md index 94967f8d3..adfbd606c 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ # The MIT License (MIT) -Copyright © 2020 - 2023 Refined Mods +Copyright © 2020 - 2024 Refined Mods Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index fae08049a..1af9e0930 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/energy/AbstractEnergyBlockItem.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/energy/AbstractEnergyBlockItem.java index f89cf8afd..af084eaf1 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/energy/AbstractEnergyBlockItem.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/energy/AbstractEnergyBlockItem.java @@ -15,7 +15,7 @@ import org.apiguardian.api.API; @API(status = API.Status.STABLE, since = "2.0.0-milestone.3.1") -public abstract class AbstractEnergyBlockItem extends BlockItem implements EnergyItem { +public abstract class AbstractEnergyBlockItem extends BlockItem { private final EnergyItemHelper helper; protected AbstractEnergyBlockItem(final Block block, final Properties properties, final EnergyItemHelper helper) { diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/energy/AbstractEnergyItem.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/energy/AbstractEnergyItem.java index 98ec52e94..0d3c846b6 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/energy/AbstractEnergyItem.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/energy/AbstractEnergyItem.java @@ -11,7 +11,7 @@ import org.apiguardian.api.API; @API(status = API.Status.STABLE, since = "2.0.0-milestone.3.1") -public abstract class AbstractEnergyItem extends Item implements EnergyItem { +public abstract class AbstractEnergyItem extends Item { private final EnergyItemHelper helper; protected AbstractEnergyItem(final Properties properties, final EnergyItemHelper helper) { diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/energy/EnergyItem.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/energy/EnergyItem.java deleted file mode 100644 index 6c0901f3a..000000000 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/energy/EnergyItem.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.api.support.energy; - -import com.refinedmods.refinedstorage2.api.network.energy.EnergyStorage; - -import java.util.Optional; - -import net.minecraft.world.item.ItemStack; -import org.apiguardian.api.API; - -/** - * Implement this on items that can contain energy. - * At runtime, Refined Storage will attach an energy storage adapter for the platform on the given {@link ItemStack}. - */ -@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.1") -public interface EnergyItem { - Optional createEnergyStorage(ItemStack stack); -} diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/energy/EnergyBlockEntity.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/energy/TransferableBlockEntityEnergy.java similarity index 59% rename from refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/energy/EnergyBlockEntity.java rename to refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/energy/TransferableBlockEntityEnergy.java index c231e5006..94b4fe065 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/energy/EnergyBlockEntity.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/energy/TransferableBlockEntityEnergy.java @@ -4,11 +4,7 @@ import org.apiguardian.api.API; -/** - * Implement this on block entities that can contain energy. - * At runtime, Refined Storage will attach an energy storage adapter for the platform. - */ @API(status = API.Status.STABLE, since = "2.0.0-milestone.3.1") -public interface EnergyBlockEntity { +public interface TransferableBlockEntityEnergy { EnergyStorage getEnergyStorage(); } diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/FluidResource.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/FluidResource.java index e71622db8..36dd326a3 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/FluidResource.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/FluidResource.java @@ -29,7 +29,6 @@ public FluidResource normalize() { return new FluidResource(fluid, null); } - @SuppressWarnings({"deprecation", "RedundantSuppression"}) // forge deprecates Registry access public static CompoundTag toTag(final FluidResource fluidResource) { final CompoundTag tag = new CompoundTag(); if (fluidResource.tag() != null) { @@ -45,7 +44,6 @@ public static CompoundTag toTagWithAmount(final ResourceAmount re return tag; } - @SuppressWarnings({"deprecation", "RedundantSuppression"}) // forge deprecates Registry access public static Optional fromTag(final CompoundTag tag) { final ResourceLocation id = new ResourceLocation(tag.getString(TAG_ID)); final Fluid fluid = BuiltInRegistries.FLUID.get(id); diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/ItemResource.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/ItemResource.java index 8fd372aae..558390206 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/ItemResource.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/ItemResource.java @@ -53,7 +53,6 @@ public static ItemResource ofItemStack(final ItemStack itemStack) { return new ItemResource(itemStack.getItem(), itemStack.getTag()); } - @SuppressWarnings({"deprecation", "RedundantSuppression"}) // forge deprecates Registry access public static CompoundTag toTag(final ItemResource itemResource) { final CompoundTag tag = new CompoundTag(); if (itemResource.tag() != null) { @@ -69,7 +68,6 @@ public static CompoundTag toTagWithAmount(final ResourceAmount res return tag; } - @SuppressWarnings({"deprecation", "RedundantSuppression"}) // forge deprecates Registry access public static Optional fromTag(final CompoundTag tag) { final ResourceLocation id = new ResourceLocation(tag.getString(TAG_ID)); final Item item = BuiltInRegistries.ITEM.get(id); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractModInitializer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractModInitializer.java index 30a6c6061..915c51450 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractModInitializer.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractModInitializer.java @@ -68,7 +68,7 @@ import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridBlock; import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridContainerMenu; import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridItem; -import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridLootItemFunctionSerializer; +import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridLootItemFunction; import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridType; import com.refinedmods.refinedstorage2.platform.common.storage.storageblock.FluidStorageBlock; import com.refinedmods.refinedstorage2.platform.common.storage.storageblock.FluidStorageBlockBlockEntity; @@ -78,7 +78,7 @@ import com.refinedmods.refinedstorage2.platform.common.storage.storageblock.ItemStorageBlockBlockEntity; import com.refinedmods.refinedstorage2.platform.common.storage.storageblock.ItemStorageBlockBlockItem; import com.refinedmods.refinedstorage2.platform.common.storage.storageblock.ItemStorageBlockContainerMenu; -import com.refinedmods.refinedstorage2.platform.common.storage.storageblock.StorageBlockLootItemFunctionSerializer; +import com.refinedmods.refinedstorage2.platform.common.storage.storageblock.StorageBlockLootItemFunction; import com.refinedmods.refinedstorage2.platform.common.storage.storagedisk.FluidStorageDiskItem; import com.refinedmods.refinedstorage2.platform.common.storage.storagedisk.ItemStorageDiskItem; import com.refinedmods.refinedstorage2.platform.common.storagemonitor.FluidStorageMonitorExtractionStrategy; @@ -91,7 +91,7 @@ import com.refinedmods.refinedstorage2.platform.common.support.SimpleBlock; import com.refinedmods.refinedstorage2.platform.common.support.SimpleBlockItem; import com.refinedmods.refinedstorage2.platform.common.support.SimpleItem; -import com.refinedmods.refinedstorage2.platform.common.support.energy.EnergyLootItemFunctionSerializer; +import com.refinedmods.refinedstorage2.platform.common.support.energy.EnergyLootItemFunction; import com.refinedmods.refinedstorage2.platform.common.support.network.NetworkNodeContainerBlockEntityImpl; import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResourceFactory; import com.refinedmods.refinedstorage2.platform.common.upgrade.FortuneUpgradeItem; @@ -111,6 +111,7 @@ import java.util.function.BiFunction; import java.util.function.Supplier; +import com.mojang.serialization.Codec; import net.minecraft.core.BlockPos; import net.minecraft.sounds.SoundEvent; import net.minecraft.world.inventory.MenuType; @@ -714,15 +715,15 @@ protected final void registerMenus(final RegistryCallback> callback, protected final void registerLootFunctions(final RegistryCallback callback) { LootFunctions.INSTANCE.setStorageBlock(callback.register( STORAGE_BLOCK, - () -> new LootItemFunctionType(new StorageBlockLootItemFunctionSerializer()) + () -> new LootItemFunctionType(Codec.unit(new StorageBlockLootItemFunction())) )); LootFunctions.INSTANCE.setPortableGrid(callback.register( PORTABLE_GRID, - () -> new LootItemFunctionType(new PortableGridLootItemFunctionSerializer()) + () -> new LootItemFunctionType(Codec.unit(new PortableGridLootItemFunction())) )); LootFunctions.INSTANCE.setEnergy(callback.register( createIdentifier("energy"), - () -> new LootItemFunctionType(new EnergyLootItemFunctionSerializer()) + () -> new LootItemFunctionType(Codec.unit(new EnergyLootItemFunction())) )); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/Platform.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/Platform.java index 3e332eae3..6b4953556 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/Platform.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/Platform.java @@ -37,8 +37,8 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.CraftingRecipe; -import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.state.BlockState; @@ -100,7 +100,7 @@ NonNullList getRemainingCraftingItems(Player player, ItemStack getBlockAsItemStack(Block block, BlockState state, Direction direction, - BlockGetter level, + LevelReader level, BlockPos pos, Player player); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java index 844abecfc..de8798b0a 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java @@ -44,8 +44,8 @@ import com.refinedmods.refinedstorage2.platform.api.upgrade.BuiltinUpgradeDestinations; import com.refinedmods.refinedstorage2.platform.api.upgrade.UpgradeRegistry; import com.refinedmods.refinedstorage2.platform.api.wirelesstransmitter.WirelessTransmitterRangeModifier; +import com.refinedmods.refinedstorage2.platform.common.grid.AbstractGridContainerMenu; import com.refinedmods.refinedstorage2.platform.common.grid.NoopGridSynchronizer; -import com.refinedmods.refinedstorage2.platform.common.grid.screen.AbstractGridScreen; import com.refinedmods.refinedstorage2.platform.common.grid.screen.hint.GridInsertionHintsImpl; import com.refinedmods.refinedstorage2.platform.common.grid.screen.hint.ItemGridInsertionHint; import com.refinedmods.refinedstorage2.platform.common.grid.screen.hint.SingleItemGridInsertionHint; @@ -101,6 +101,7 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; +import net.minecraft.world.level.saveddata.SavedData; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; @@ -168,19 +169,18 @@ public PlatformRegistry> getStorageTypeRegistry() { return storageTypeRegistry; } + @SuppressWarnings("DataFlowIssue") // NeoForge makes null datafixer safe @Override public StorageRepository getStorageRepository(final Level level) { if (level.getServer() == null) { return clientStorageRepository; } final ServerLevel serverLevel = Objects.requireNonNull(level.getServer().getLevel(Level.OVERWORLD)); - return serverLevel - .getDataStorage() - .computeIfAbsent( - this::createStorageRepository, - this::createStorageRepository, - StorageRepositoryImpl.NAME - ); + return serverLevel.getDataStorage().computeIfAbsent(new SavedData.Factory<>( + this::createStorageRepository, + this::createStorageRepository, + null + ), StorageRepositoryImpl.NAME); } @Override @@ -280,7 +280,7 @@ public PlatformRegistry getGridSynchronizerRegistry() { @Override public void writeGridScreenOpeningData(final Grid grid, final FriendlyByteBuf buf) { - AbstractGridScreen.writeScreenOpeningData(storageChannelTypeRegistry, grid, buf); + AbstractGridContainerMenu.writeScreenOpeningData(storageChannelTypeRegistry, grid, buf); } @Override diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformProxy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformProxy.java index e70c7e17f..9ef09ac11 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformProxy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformProxy.java @@ -36,8 +36,8 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.CraftingRecipe; -import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.state.BlockState; @@ -195,7 +195,7 @@ public boolean placeFluid(final Level level, public ItemStack getBlockAsItemStack(final Block block, final BlockState state, final Direction direction, - final BlockGetter level, + final LevelReader level, final BlockPos pos, final Player player) { return ensureLoaded().getBlockAsItemStack(block, state, direction, level, pos, player); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/configurationcard/ConfigurationCardItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/configurationcard/ConfigurationCardItem.java index 8a89d6e5d..c61da30ab 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/configurationcard/ConfigurationCardItem.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/configurationcard/ConfigurationCardItem.java @@ -82,7 +82,6 @@ private InteractionResult applyConfiguration( return InteractionResult.SUCCESS; } - @SuppressWarnings("deprecation") // Forge deprecates registry access this way private void tryTransferUpgrades(final Player player, final ConfigurationCardTarget target, final CompoundTag tag) { final ListTag upgradesTag = tag.getList(TAG_UPGRADES, Tag.TAG_STRING); for (final Tag upgradeItemTag : upgradesTag) { @@ -111,7 +110,6 @@ private InteractionResult configurationCardIsConfiguredForDifferentType( return InteractionResult.CONSUME; } - @SuppressWarnings("deprecation") // Forge deprecates registry access this way private void writeConfiguration(final ItemStack stack, final Player player, final ConfigurationCardTarget target, @@ -130,7 +128,6 @@ private CompoundTag createConfigTag(final ConfigurationCardTarget target) { return tag; } - @SuppressWarnings("deprecation") // Forge deprecates registry access this way private ListTag createUpgradesTag(final ConfigurationCardTarget target) { final ListTag tag = new ListTag(); target.getUpgradeItems().forEach(item -> { @@ -184,13 +181,11 @@ public void appendHoverText(final ItemStack stack, } @Nullable - @SuppressWarnings("deprecation") // Forge deprecates registry access this way private BlockEntityType getConfiguredType(final CompoundTag tag) { final ResourceLocation type = new ResourceLocation(tag.getString(TAG_TYPE)); return BuiltInRegistries.BLOCK_ENTITY_TYPE.get(type); } - @SuppressWarnings("deprecation") // Forge deprecates registry access this way private MutableComponent getConfiguredTypeTranslation(final BlockEntityType type) { final ResourceLocation typeId = BuiltInRegistries.BLOCK_ENTITY_TYPE.getKey(type); if (typeId == null) { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/AbstractConstructorDestructorBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/AbstractConstructorDestructorBlock.java index 9144a29a4..3e29246be 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/AbstractConstructorDestructorBlock.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/AbstractConstructorDestructorBlock.java @@ -12,6 +12,7 @@ import net.minecraft.core.Direction; import net.minecraft.network.chat.MutableComponent; +import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.DyeColor; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; @@ -24,9 +25,10 @@ import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.phys.shapes.VoxelShape; -public abstract class AbstractConstructorDestructorBlock +public abstract class AbstractConstructorDestructorBlock, + B extends BlockEntity, I extends BlockItem> extends AbstractDirectionalCableBlock - implements ColorableBlock, EntityBlock { + implements ColorableBlock, EntityBlock { public static final BooleanProperty ACTIVE = BooleanProperty.create("active"); private static final Map SHAPE_CACHE = new HashMap<>(); @@ -79,9 +81,9 @@ public MutableComponent getName() { @Nullable @Override - public BlockEntityTicker getTicker(final Level level, + public BlockEntityTicker getTicker(final Level level, final BlockState blockState, - final BlockEntityType type) { + final BlockEntityType type) { return ticker.get(level, type); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/ConstructorBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/ConstructorBlock.java index 571c67293..e8c9ea21f 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/ConstructorBlock.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/ConstructorBlock.java @@ -12,7 +12,6 @@ import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; -import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.Item; import net.minecraft.world.level.block.entity.BlockEntity; @@ -20,8 +19,9 @@ import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; -public class ConstructorBlock extends AbstractConstructorDestructorBlock - implements BlockItemProvider { +public class ConstructorBlock extends AbstractConstructorDestructorBlock< + ConstructorBlock, ConstructorBlockEntity, NamedBlockItem + > implements BlockItemProvider { private static final Component HELP = createTranslation("item", "constructor.help"); public ConstructorBlock(final DyeColor color, final MutableComponent name) { @@ -32,7 +32,7 @@ public ConstructorBlock(final DyeColor color, final MutableComponent name) { } @Override - public BlockColorMap getBlockColorMap() { + public BlockColorMap getBlockColorMap() { return Blocks.INSTANCE.getConstructor(); } @@ -43,7 +43,7 @@ public BlockEntity newBlockEntity(final BlockPos blockPos, final BlockState bloc } @Override - public BlockItem createBlockItem() { + public NamedBlockItem createBlockItem() { return new NamedBlockItem(this, new Item.Properties(), getName(), HELP); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/DestructorBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/DestructorBlock.java index 87f40f864..eb95d5e00 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/DestructorBlock.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/DestructorBlock.java @@ -12,7 +12,6 @@ import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; -import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.Item; import net.minecraft.world.level.block.entity.BlockEntity; @@ -20,8 +19,9 @@ import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; -public class DestructorBlock extends AbstractConstructorDestructorBlock - implements BlockItemProvider { +public class DestructorBlock extends AbstractConstructorDestructorBlock< + DestructorBlock, DestructorBlockEntity, NamedBlockItem + > implements BlockItemProvider { private static final Component HELP = createTranslation("item", "destructor.help"); public DestructorBlock(final DyeColor color, final MutableComponent name) { @@ -32,7 +32,7 @@ public DestructorBlock(final DyeColor color, final MutableComponent name) { } @Override - public BlockColorMap getBlockColorMap() { + public BlockColorMap getBlockColorMap() { return Blocks.INSTANCE.getDestructor(); } @@ -43,7 +43,7 @@ public BlockEntity newBlockEntity(final BlockPos blockPos, final BlockState bloc } @Override - public BlockItem createBlockItem() { + public NamedBlockItem createBlockItem() { return new NamedBlockItem(this, new Item.Properties(), getName(), HELP); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/ItemDropConstructorStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/ItemDropConstructorStrategy.java index d80763679..74a92fa58 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/ItemDropConstructorStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/ItemDropConstructorStrategy.java @@ -5,11 +5,11 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.core.PositionImpl; import net.minecraft.core.dispenser.DefaultDispenseItemBehavior; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.phys.Vec3; class ItemDropConstructorStrategy extends AbstractItemConstructorStrategy { private final long amount; @@ -36,7 +36,7 @@ protected boolean apply( final Actor actor, final Player actingPlayer ) { - final PositionImpl position = new PositionImpl( + final Vec3 position = new Vec3( getDispensePositionX(), getDispensePositionY(), getDispensePositionZ() diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/BlockColorMap.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/BlockColorMap.java index 2d52bb6d0..3732ec934 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/BlockColorMap.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/BlockColorMap.java @@ -25,7 +25,7 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.Property; -public class BlockColorMap extends ColorMap { +public class BlockColorMap, I extends BlockItem> extends ColorMap { private final BlockFactory blockFactory; private final MutableComponent baseName; @@ -101,9 +101,9 @@ public void registerItems(final RegistryCallback callback) { }); } - public void registerItems(final RegistryCallback callback, final Consumer> acceptor) { + public void registerItems(final RegistryCallback callback, final Consumer> acceptor) { forEach((color, id, block) -> { - final Supplier itemSupplier = () -> block.get().createBlockItem(); + final Supplier itemSupplier = () -> block.get().createBlockItem(); acceptor.accept(callback.register(id, itemSupplier)); }); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Blocks.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Blocks.java index b7bac5c9b..b13f8e159 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Blocks.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Blocks.java @@ -2,9 +2,12 @@ import com.refinedmods.refinedstorage2.platform.common.constructordestructor.ConstructorBlock; import com.refinedmods.refinedstorage2.platform.common.constructordestructor.DestructorBlock; +import com.refinedmods.refinedstorage2.platform.common.controller.AbstractControllerBlock; import com.refinedmods.refinedstorage2.platform.common.controller.ControllerBlock; import com.refinedmods.refinedstorage2.platform.common.controller.ControllerBlockEntityTicker; -import com.refinedmods.refinedstorage2.platform.common.controller.ControllerType; +import com.refinedmods.refinedstorage2.platform.common.controller.ControllerBlockItem; +import com.refinedmods.refinedstorage2.platform.common.controller.CreativeControllerBlock; +import com.refinedmods.refinedstorage2.platform.common.controller.CreativeControllerBlockItem; import com.refinedmods.refinedstorage2.platform.common.detector.DetectorBlock; import com.refinedmods.refinedstorage2.platform.common.exporter.ExporterBlock; import com.refinedmods.refinedstorage2.platform.common.grid.CraftingGridBlock; @@ -22,6 +25,7 @@ import com.refinedmods.refinedstorage2.platform.common.storage.storageblock.FluidStorageBlock; import com.refinedmods.refinedstorage2.platform.common.storage.storageblock.ItemStorageBlock; import com.refinedmods.refinedstorage2.platform.common.storagemonitor.StorageMonitorBlock; +import com.refinedmods.refinedstorage2.platform.common.support.NamedBlockItem; import com.refinedmods.refinedstorage2.platform.common.support.SimpleBlock; import com.refinedmods.refinedstorage2.platform.common.wirelesstransmitter.WirelessTransmitterBlock; @@ -39,95 +43,95 @@ public final class Blocks { public static final DyeColor CABLE_LIKE_COLOR = DyeColor.GRAY; public static final Blocks INSTANCE = new Blocks(); - private final BlockColorMap cable = new BlockColorMap<>( + private final BlockColorMap cable = new BlockColorMap<>( CableBlock::new, ContentIds.CABLE, ContentNames.CABLE, CABLE_LIKE_COLOR ); - private final BlockColorMap grid = new BlockColorMap<>( + private final BlockColorMap grid = new BlockColorMap<>( GridBlock::new, ContentIds.GRID, ContentNames.GRID, COLOR ); - private final BlockColorMap craftingGrid = new BlockColorMap<>( + private final BlockColorMap craftingGrid = new BlockColorMap<>( CraftingGridBlock::new, ContentIds.CRAFTING_GRID, ContentNames.CRAFTING_GRID, COLOR ); - private final BlockColorMap detector = new BlockColorMap<>( + private final BlockColorMap detector = new BlockColorMap<>( DetectorBlock::new, ContentIds.DETECTOR, ContentNames.DETECTOR, COLOR ); - private final BlockColorMap controller = new BlockColorMap<>( - (color, name) -> new ControllerBlock( - ControllerType.NORMAL, - name, - new ControllerBlockEntityTicker(BlockEntities.INSTANCE::getController), - color - ), - ContentIds.CONTROLLER, - ContentNames.CONTROLLER, - COLOR - ); - private final BlockColorMap creativeController = new BlockColorMap<>( - (color, name) -> new ControllerBlock( - ControllerType.CREATIVE, + private final BlockColorMap, ControllerBlockItem> controller = + new BlockColorMap<>( + (color, name) -> new ControllerBlock( + name, + new ControllerBlockEntityTicker(BlockEntities.INSTANCE::getController), + color + ), + ContentIds.CONTROLLER, + ContentNames.CONTROLLER, + COLOR + ); + private final BlockColorMap + , CreativeControllerBlockItem> creativeController = + new BlockColorMap<>((color, name) -> new CreativeControllerBlock( name, new ControllerBlockEntityTicker(BlockEntities.INSTANCE::getCreativeController), color ), - ContentIds.CREATIVE_CONTROLLER, - ContentNames.CREATIVE_CONTROLLER, - COLOR - ); - private final BlockColorMap exporter = new BlockColorMap<>( + ContentIds.CREATIVE_CONTROLLER, + ContentNames.CREATIVE_CONTROLLER, + COLOR + ); + private final BlockColorMap exporter = new BlockColorMap<>( ExporterBlock::new, ContentIds.EXPORTER, ContentNames.EXPORTER, CABLE_LIKE_COLOR ); - private final BlockColorMap importer = new BlockColorMap<>( + private final BlockColorMap importer = new BlockColorMap<>( ImporterBlock::new, ContentIds.IMPORTER, ContentNames.IMPORTER, CABLE_LIKE_COLOR ); - private final BlockColorMap externalStorage = new BlockColorMap<>( + private final BlockColorMap externalStorage = new BlockColorMap<>( ExternalStorageBlock::new, ContentIds.EXTERNAL_STORAGE, ContentNames.EXTERNAL_STORAGE, CABLE_LIKE_COLOR ); - private final BlockColorMap destructor = new BlockColorMap<>( + private final BlockColorMap destructor = new BlockColorMap<>( DestructorBlock::new, ContentIds.DESTRUCTOR, ContentNames.DESTRUCTOR, CABLE_LIKE_COLOR ); - private final BlockColorMap constructor = new BlockColorMap<>( + private final BlockColorMap constructor = new BlockColorMap<>( ConstructorBlock::new, ContentIds.CONSTRUCTOR, ContentNames.CONSTRUCTOR, CABLE_LIKE_COLOR ); - private final BlockColorMap wirelessTransmitter = new BlockColorMap<>( + private final BlockColorMap wirelessTransmitter = new BlockColorMap<>( WirelessTransmitterBlock::new, ContentIds.WIRELESS_TRANSMITTER, ContentNames.WIRELESS_TRANSMITTER, COLOR ); - private final BlockColorMap networkReceiver = new BlockColorMap<>( + private final BlockColorMap networkReceiver = new BlockColorMap<>( NetworkReceiverBlock::new, ContentIds.NETWORK_RECEIVER, ContentNames.NETWORK_RECEIVER, COLOR ); - private final BlockColorMap networkTransmitter = new BlockColorMap<>( + private final BlockColorMap networkTransmitter = new BlockColorMap<>( NetworkTransmitterBlock::new, ContentIds.NETWORK_TRANSMITTER, ContentNames.NETWORK_TRANSMITTER, @@ -156,7 +160,7 @@ public final class Blocks { private Blocks() { } - public BlockColorMap getCable() { + public BlockColorMap getCable() { return cable; } @@ -172,19 +176,21 @@ public SimpleBlock getMachineCasing() { return requireNonNull(machineCasing).get(); } - public BlockColorMap getGrid() { + public BlockColorMap getGrid() { return grid; } - public BlockColorMap getCraftingGrid() { + public BlockColorMap getCraftingGrid() { return craftingGrid; } - public BlockColorMap getController() { + public BlockColorMap, ControllerBlockItem> getController() { return controller; } - public BlockColorMap getCreativeController() { + public BlockColorMap< + AbstractControllerBlock, + CreativeControllerBlockItem> getCreativeController() { return creativeController; } @@ -217,11 +223,11 @@ public FluidStorageBlock getFluidStorageBlock(final FluidStorageType.Variant var return fluidStorageBlocks.get(variant).get(); } - public BlockColorMap getImporter() { + public BlockColorMap getImporter() { return importer; } - public BlockColorMap getExporter() { + public BlockColorMap getExporter() { return exporter; } @@ -233,23 +239,23 @@ public InterfaceBlock getInterface() { return requireNonNull(iface).get(); } - public BlockColorMap getExternalStorage() { + public BlockColorMap getExternalStorage() { return externalStorage; } - public BlockColorMap getDetector() { + public BlockColorMap getDetector() { return detector; } - public BlockColorMap getDestructor() { + public BlockColorMap getDestructor() { return destructor; } - public BlockColorMap getConstructor() { + public BlockColorMap getConstructor() { return constructor; } - public BlockColorMap getWirelessTransmitter() { + public BlockColorMap getWirelessTransmitter() { return wirelessTransmitter; } @@ -261,11 +267,11 @@ public StorageMonitorBlock getStorageMonitor() { return requireNonNull(storageMonitor).get(); } - public BlockColorMap getNetworkReceiver() { + public BlockColorMap getNetworkReceiver() { return networkReceiver; } - public BlockColorMap getNetworkTransmitter() { + public BlockColorMap getNetworkTransmitter() { return networkTransmitter; } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/CreativeModeTabItems.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/CreativeModeTabItems.java index 3922cecbd..b7ea19476 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/CreativeModeTabItems.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/CreativeModeTabItems.java @@ -3,7 +3,6 @@ import com.refinedmods.refinedstorage2.platform.common.misc.ProcessorItem; import com.refinedmods.refinedstorage2.platform.common.storage.FluidStorageType; import com.refinedmods.refinedstorage2.platform.common.storage.ItemStorageType; -import com.refinedmods.refinedstorage2.platform.common.support.energy.EnergyItemHelperImpl; import java.util.Arrays; import java.util.function.Consumer; @@ -24,7 +23,9 @@ public static void append(final Consumer consumer) { private static void appendBlocks(final Consumer consumer) { final Consumer itemConsumer = item -> consumer.accept(new ItemStack(item)); Items.INSTANCE.getControllers().stream().map(Supplier::get).forEach(itemConsumer); - EnergyItemHelperImpl.createAllAtEnergyCapacity(Items.INSTANCE.getControllers()).forEach(consumer); + Items.INSTANCE.getControllers().forEach(controllerItem -> consumer.accept( + controllerItem.get().createAtEnergyCapacity() + )); Items.INSTANCE.getCreativeControllers().stream().map(Supplier::get).forEach(itemConsumer); Items.INSTANCE.getCables().stream().map(Supplier::get).forEach(itemConsumer); Items.INSTANCE.getImporters().stream().map(Supplier::get).forEach(itemConsumer); @@ -53,7 +54,7 @@ private static void appendBlocks(final Consumer consumer) { Items.INSTANCE.getNetworkReceivers().stream().map(Supplier::get).forEach(itemConsumer); } - private static void appendBlockColors(final Consumer consumer, final BlockColorMap map) { + private static void appendBlockColors(final Consumer consumer, final BlockColorMap map) { map.values().forEach(block -> consumer.accept(new ItemStack(block))); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Items.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Items.java index 0c70f63b7..392c091c4 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Items.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Items.java @@ -1,6 +1,7 @@ package com.refinedmods.refinedstorage2.platform.common.content; import com.refinedmods.refinedstorage2.platform.api.upgrade.AbstractUpgradeItem; +import com.refinedmods.refinedstorage2.platform.common.controller.ControllerBlockItem; import com.refinedmods.refinedstorage2.platform.common.grid.WirelessGridItem; import com.refinedmods.refinedstorage2.platform.common.misc.ProcessorItem; import com.refinedmods.refinedstorage2.platform.common.storage.FluidStorageType; @@ -30,18 +31,18 @@ public final class Items { = new EnumMap<>(ItemStorageType.Variant.class); private final Map> fluidStorageDisks = new EnumMap<>(FluidStorageType.Variant.class); - private final List> allControllers = new ArrayList<>(); - private final List> allCreativeControllers = new ArrayList<>(); - private final List> allCables = new ArrayList<>(); - private final List> allExporters = new ArrayList<>(); - private final List> allImporters = new ArrayList<>(); - private final List> allExternalStorages = new ArrayList<>(); - private final List> allDetectors = new ArrayList<>(); - private final List> allDestructors = new ArrayList<>(); - private final List> allConstructors = new ArrayList<>(); - private final List> allWirelessTransmitters = new ArrayList<>(); - private final List> allNetworkReceivers = new ArrayList<>(); - private final List> allNetworkTransmitters = new ArrayList<>(); + private final List> allControllers = new ArrayList<>(); + private final List> allCreativeControllers = new ArrayList<>(); + private final List> allCables = new ArrayList<>(); + private final List> allExporters = new ArrayList<>(); + private final List> allImporters = new ArrayList<>(); + private final List> allExternalStorages = new ArrayList<>(); + private final List> allDetectors = new ArrayList<>(); + private final List> allDestructors = new ArrayList<>(); + private final List> allConstructors = new ArrayList<>(); + private final List> allWirelessTransmitters = new ArrayList<>(); + private final List> allNetworkReceivers = new ArrayList<>(); + private final List> allNetworkTransmitters = new ArrayList<>(); @Nullable private Supplier quartzEnrichedIron; @Nullable @@ -181,7 +182,7 @@ public Item getDestructionCore() { return requireNonNull(destructionCore).get(); } - public void addCreativeController(final Supplier supplier) { + public void addCreativeController(final Supplier supplier) { allCreativeControllers.add(supplier); } @@ -189,75 +190,75 @@ public List> getCreativeControllers() { return Collections.unmodifiableList(allCreativeControllers); } - public void addController(final Supplier supplier) { + public void addController(final Supplier supplier) { allControllers.add(supplier); } - public List> getControllers() { + public List> getControllers() { return Collections.unmodifiableList(allControllers); } - public void addCable(final Supplier supplier) { + public void addCable(final Supplier supplier) { allCables.add(supplier); } - public List> getCables() { + public List> getCables() { return Collections.unmodifiableList(allCables); } - public void addExporter(final Supplier supplier) { + public void addExporter(final Supplier supplier) { allExporters.add(supplier); } - public List> getExporters() { + public List> getExporters() { return Collections.unmodifiableList(allExporters); } - public void addImporter(final Supplier supplier) { + public void addImporter(final Supplier supplier) { allImporters.add(supplier); } - public List> getImporters() { + public List> getImporters() { return Collections.unmodifiableList(allImporters); } - public void addExternalStorage(final Supplier supplier) { + public void addExternalStorage(final Supplier supplier) { allExternalStorages.add(supplier); } - public List> getExternalStorages() { + public List> getExternalStorages() { return Collections.unmodifiableList(allExternalStorages); } - public void addDetector(final Supplier supplier) { + public void addDetector(final Supplier supplier) { allDetectors.add(supplier); } - public List> getDetectors() { + public List> getDetectors() { return Collections.unmodifiableList(allDetectors); } - public void addDestructor(final Supplier supplier) { + public void addDestructor(final Supplier supplier) { allDestructors.add(supplier); } - public List> getDestructors() { + public List> getDestructors() { return Collections.unmodifiableList(allDestructors); } - public void addConstructor(final Supplier supplier) { + public void addConstructor(final Supplier supplier) { allConstructors.add(supplier); } - public List> getConstructors() { + public List> getConstructors() { return Collections.unmodifiableList(allConstructors); } - public void addWirelessTransmitter(final Supplier supplier) { + public void addWirelessTransmitter(final Supplier supplier) { allWirelessTransmitters.add(supplier); } - public List> getWirelessTransmitters() { + public List> getWirelessTransmitters() { return Collections.unmodifiableList(allWirelessTransmitters); } @@ -373,19 +374,19 @@ public void setConfigurationCard(final Supplier supplier) { this.configurationCard = supplier; } - public void addNetworkReceiver(final Supplier supplier) { + public void addNetworkReceiver(final Supplier supplier) { allNetworkReceivers.add(supplier); } - public List> getNetworkReceivers() { + public List> getNetworkReceivers() { return Collections.unmodifiableList(allNetworkReceivers); } - public void addNetworkTransmitter(final Supplier supplier) { + public void addNetworkTransmitter(final Supplier supplier) { allNetworkTransmitters.add(supplier); } - public List> getNetworkTransmitters() { + public List> getNetworkTransmitters() { return Collections.unmodifiableList(allNetworkTransmitters); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/controller/AbstractControllerBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/controller/AbstractControllerBlock.java new file mode 100644 index 000000000..7e5b47049 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/controller/AbstractControllerBlock.java @@ -0,0 +1,84 @@ +package com.refinedmods.refinedstorage2.platform.common.controller; + +import com.refinedmods.refinedstorage2.platform.common.content.BlockConstants; +import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseBlock; +import com.refinedmods.refinedstorage2.platform.common.support.BlockItemProvider; +import com.refinedmods.refinedstorage2.platform.common.support.ColorableBlock; + +import net.minecraft.core.BlockPos; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.DyeColor; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.EntityBlock; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityTicker; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.EnumProperty; + +public abstract class AbstractControllerBlock + extends AbstractBaseBlock + implements ColorableBlock, I>, EntityBlock, BlockItemProvider { + public static final EnumProperty ENERGY_TYPE = EnumProperty.create( + "energy_type", + ControllerEnergyType.class + ); + + protected final MutableComponent name; + + private final ControllerType type; + private final ControllerBlockEntityTicker ticker; + private final DyeColor color; + + public AbstractControllerBlock(final ControllerType type, + final MutableComponent name, + final ControllerBlockEntityTicker ticker, + final DyeColor color) { + super(BlockConstants.PROPERTIES); + this.type = type; + this.name = name; + this.ticker = ticker; + this.color = color; + } + + @Override + protected BlockState getDefaultState() { + return super.getDefaultState().setValue(ENERGY_TYPE, ControllerEnergyType.OFF); + } + + @Override + public MutableComponent getName() { + return name; + } + + @Override + protected void createBlockStateDefinition(final StateDefinition.Builder builder) { + super.createBlockStateDefinition(builder); + builder.add(ENERGY_TYPE); + } + + @Override + public BlockEntity newBlockEntity(final BlockPos pos, final BlockState state) { + return new ControllerBlockEntity(type, pos, state); + } + + @Override + public BlockEntityTicker getTicker(final Level level, + final BlockState state, + final BlockEntityType blockEntityType) { + return ticker.get(level, blockEntityType); + } + + @Override + public DyeColor getColor() { + return color; + } + + @Override + public boolean canAlwaysConnect() { + return true; + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/controller/ControllerBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/controller/ControllerBlock.java index be41270c2..68f216341 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/controller/ControllerBlock.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/controller/ControllerBlock.java @@ -1,99 +1,25 @@ package com.refinedmods.refinedstorage2.platform.common.controller; import com.refinedmods.refinedstorage2.platform.common.content.BlockColorMap; -import com.refinedmods.refinedstorage2.platform.common.content.BlockConstants; import com.refinedmods.refinedstorage2.platform.common.content.Blocks; -import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseBlock; -import com.refinedmods.refinedstorage2.platform.common.support.BlockItemProvider; -import com.refinedmods.refinedstorage2.platform.common.support.ColorableBlock; -import net.minecraft.core.BlockPos; import net.minecraft.network.chat.MutableComponent; -import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.DyeColor; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.EntityBlock; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.entity.BlockEntityTicker; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.world.level.block.state.properties.EnumProperty; -public class ControllerBlock extends AbstractBaseBlock implements ColorableBlock, EntityBlock, - BlockItemProvider { - public static final EnumProperty ENERGY_TYPE = EnumProperty.create( - "energy_type", - ControllerEnergyType.class - ); - - private final ControllerType type; - private final MutableComponent name; - private final ControllerBlockEntityTicker ticker; - private final DyeColor color; - - public ControllerBlock(final ControllerType type, - final MutableComponent name, +public class ControllerBlock extends AbstractControllerBlock { + public ControllerBlock(final MutableComponent name, final ControllerBlockEntityTicker ticker, final DyeColor color) { - super(BlockConstants.PROPERTIES); - this.type = type; - this.name = name; - this.ticker = ticker; - this.color = color; - } - - @Override - protected BlockState getDefaultState() { - return super.getDefaultState().setValue(ENERGY_TYPE, ControllerEnergyType.OFF); - } - - @Override - public MutableComponent getName() { - return name; - } - - @Override - protected void createBlockStateDefinition(final StateDefinition.Builder builder) { - super.createBlockStateDefinition(builder); - builder.add(ENERGY_TYPE); - } - - @Override - public BlockEntity newBlockEntity(final BlockPos pos, final BlockState state) { - return new ControllerBlockEntity(type, pos, state); - } - - @Override - public BlockEntityTicker getTicker(final Level level, - final BlockState state, - final BlockEntityType blockEntityType) { - return ticker.get(level, blockEntityType); - } - - @Override - public BlockColorMap getBlockColorMap() { - return type == ControllerType.CREATIVE - ? Blocks.INSTANCE.getCreativeController() - : Blocks.INSTANCE.getController(); - } - - @Override - public DyeColor getColor() { - return color; + super(ControllerType.NORMAL, name, ticker, color); } @Override - public boolean canAlwaysConnect() { - return true; + public BlockColorMap, ControllerBlockItem> getBlockColorMap() { + return Blocks.INSTANCE.getController(); } @Override - public BlockItem createBlockItem() { - if (type == ControllerType.CREATIVE) { - return new CreativeControllerBlockItem(this, name); - } + public ControllerBlockItem createBlockItem() { return new ControllerBlockItem(this, name); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/controller/ControllerBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/controller/ControllerBlockEntity.java index b7e8d79ed..fc7d3e72d 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/controller/ControllerBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/controller/ControllerBlockEntity.java @@ -3,7 +3,7 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.network.energy.EnergyStorage; import com.refinedmods.refinedstorage2.api.network.impl.node.controller.ControllerNetworkNode; -import com.refinedmods.refinedstorage2.platform.api.support.energy.EnergyBlockEntity; +import com.refinedmods.refinedstorage2.platform.api.support.energy.TransferableBlockEntityEnergy; import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; import com.refinedmods.refinedstorage2.platform.common.content.ContentNames; @@ -28,7 +28,7 @@ import org.slf4j.LoggerFactory; public class ControllerBlockEntity extends AbstractRedstoneModeNetworkNodeContainerBlockEntity - implements ExtendedMenuProvider, EnergyBlockEntity { + implements ExtendedMenuProvider, TransferableBlockEntityEnergy { private static final Logger LOGGER = LoggerFactory.getLogger(ControllerBlockEntity.class); private static final String TAG_STORED = "stored"; @@ -62,7 +62,7 @@ private static BlockEntityType getBlockEntityType(final C } public void updateEnergyTypeInLevel(final BlockState state) { - final ControllerEnergyType currentEnergyType = state.getValue(ControllerBlock.ENERGY_TYPE); + final ControllerEnergyType currentEnergyType = state.getValue(AbstractControllerBlock.ENERGY_TYPE); final ControllerEnergyType newEnergyType = ControllerEnergyType.ofState(getNode().getState()); if (newEnergyType != currentEnergyType && level != null && energyStateChangeRateLimiter.tryAcquire()) { LOGGER.debug( @@ -71,7 +71,7 @@ public void updateEnergyTypeInLevel(final BlockState state) { currentEnergyType, newEnergyType ); - level.setBlockAndUpdate(getBlockPos(), state.setValue(ControllerBlock.ENERGY_TYPE, newEnergyType)); + level.setBlockAndUpdate(getBlockPos(), state.setValue(AbstractControllerBlock.ENERGY_TYPE, newEnergyType)); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/controller/ControllerBlockItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/controller/ControllerBlockItem.java index 034a7f446..752f57d1e 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/controller/ControllerBlockItem.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/controller/ControllerBlockItem.java @@ -20,7 +20,7 @@ public class ControllerBlockItem extends AbstractEnergyBlockItem { private final Component name; - public ControllerBlockItem(final Block block, final Component displayName) { + ControllerBlockItem(final Block block, final Component displayName) { super(block, new Item.Properties().stacksTo(1), PlatformApi.INSTANCE.getEnergyItemHelper()); this.name = displayName; } @@ -40,11 +40,10 @@ public Optional getTooltipImage(final ItemStack stack) { return Optional.of(new HelpTooltipComponent(createTranslation("item", "controller.help"))); } - @Override - public Optional createEnergyStorage(final ItemStack stack) { + public EnergyStorage createEnergyStorage(final ItemStack stack) { final EnergyStorage energyStorage = new EnergyStorageImpl( Platform.INSTANCE.getConfig().getController().getEnergyCapacity() ); - return Optional.of(PlatformApi.INSTANCE.asItemEnergyStorage(energyStorage, stack)); + return PlatformApi.INSTANCE.asItemEnergyStorage(energyStorage, stack); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/controller/CreativeControllerBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/controller/CreativeControllerBlock.java new file mode 100644 index 000000000..a2b071dca --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/controller/CreativeControllerBlock.java @@ -0,0 +1,27 @@ +package com.refinedmods.refinedstorage2.platform.common.controller; + +import com.refinedmods.refinedstorage2.platform.common.content.BlockColorMap; +import com.refinedmods.refinedstorage2.platform.common.content.Blocks; + +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.world.item.DyeColor; + +public class CreativeControllerBlock extends AbstractControllerBlock { + public CreativeControllerBlock(final MutableComponent name, + final ControllerBlockEntityTicker ticker, + final DyeColor color) { + super(ControllerType.CREATIVE, name, ticker, color); + } + + @Override + public BlockColorMap< + AbstractControllerBlock, + CreativeControllerBlockItem> getBlockColorMap() { + return Blocks.INSTANCE.getCreativeController(); + } + + @Override + public CreativeControllerBlockItem createBlockItem() { + return new CreativeControllerBlockItem(this, name); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/controller/CreativeControllerBlockItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/controller/CreativeControllerBlockItem.java index 6315648cf..026576d86 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/controller/CreativeControllerBlockItem.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/controller/CreativeControllerBlockItem.java @@ -8,7 +8,7 @@ import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; -class CreativeControllerBlockItem extends NamedBlockItem { +public class CreativeControllerBlockItem extends NamedBlockItem { CreativeControllerBlockItem(final Block block, final Component name) { super(block, new Item.Properties().stacksTo(1), name, createTranslation("item", "creative_controller.help")); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/detector/DetectorBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/detector/DetectorBlock.java index bfd2e98d8..195db2cc0 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/detector/DetectorBlock.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/detector/DetectorBlock.java @@ -17,7 +17,6 @@ import net.minecraft.core.Direction; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; -import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.Item; import net.minecraft.world.level.BlockGetter; @@ -37,7 +36,8 @@ import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; public class DetectorBlock extends AbstractDirectionalBlock - implements ColorableBlock, SimpleWaterloggedBlock, EntityBlock, BlockItemProvider { + implements ColorableBlock, SimpleWaterloggedBlock, EntityBlock, + BlockItemProvider { public static final BooleanProperty POWERED = BooleanProperty.create("powered"); private static final Component HELP = createTranslation("item", "detector.help"); @@ -75,7 +75,7 @@ protected void createBlockStateDefinition(final StateDefinition.Builder getBlockColorMap() { + public BlockColorMap getBlockColorMap() { return Blocks.INSTANCE.getDetector(); } @@ -137,7 +137,7 @@ public int getSignal(final BlockState state, } @Override - public BlockItem createBlockItem() { + public NamedBlockItem createBlockItem() { return new NamedBlockItem(this, new Item.Properties(), name, HELP); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/exporter/ExporterBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/exporter/ExporterBlock.java index 2d16dcafd..b7d004666 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/exporter/ExporterBlock.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/exporter/ExporterBlock.java @@ -19,7 +19,6 @@ import net.minecraft.core.Direction; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; -import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.Item; import net.minecraft.world.level.Level; @@ -32,8 +31,8 @@ import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; -public class ExporterBlock extends AbstractDirectionalCableBlock implements ColorableBlock, EntityBlock, - BlockItemProvider { +public class ExporterBlock extends AbstractDirectionalCableBlock + implements ColorableBlock, EntityBlock, BlockItemProvider { private static final Component HELP = createTranslation("item", "exporter.help"); private static final Map SHAPE_CACHE = new HashMap<>(); private static final AbstractBlockEntityTicker TICKER = @@ -66,7 +65,7 @@ public BlockEntityTicker getTicker(final Level level, } @Override - public BlockColorMap getBlockColorMap() { + public BlockColorMap getBlockColorMap() { return Blocks.INSTANCE.getExporter(); } @@ -88,7 +87,7 @@ public MutableComponent getName() { } @Override - public BlockItem createBlockItem() { + public NamedBlockItem createBlockItem() { return new NamedBlockItem(this, new Item.Properties(), name, HELP); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/AbstractGridBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/AbstractGridBlock.java index 7719cb5bc..8a15592c9 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/AbstractGridBlock.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/AbstractGridBlock.java @@ -9,6 +9,7 @@ import com.refinedmods.refinedstorage2.platform.common.support.direction.DirectionType; import net.minecraft.network.chat.MutableComponent; +import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.DyeColor; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.EntityBlock; @@ -16,9 +17,9 @@ import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BooleanProperty; -public abstract class AbstractGridBlock & BlockItemProvider> +public abstract class AbstractGridBlock & BlockItemProvider, I extends BlockItem> extends AbstractDirectionalBlock - implements EntityBlock, ColorableBlock { + implements EntityBlock, ColorableBlock { public static final BooleanProperty ACTIVE = BooleanProperty.create("active"); private final MutableComponent name; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/AbstractGridContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/AbstractGridContainerMenu.java index 4482e60f7..ccc677826 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/AbstractGridContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/AbstractGridContainerMenu.java @@ -10,6 +10,7 @@ import com.refinedmods.refinedstorage2.api.grid.view.GridViewBuilder; import com.refinedmods.refinedstorage2.api.grid.view.GridViewBuilderImpl; import com.refinedmods.refinedstorage2.api.grid.watcher.GridWatcher; +import com.refinedmods.refinedstorage2.api.storage.TrackedResourceAmount; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; @@ -34,6 +35,7 @@ import com.refinedmods.refinedstorage2.query.lexer.LexerTokenMappings; import com.refinedmods.refinedstorage2.query.parser.ParserOperatorMappings; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.function.Predicate; @@ -459,4 +461,35 @@ private static void readStorageChannelFromBuffer(final PlatformStorageChanne public void onClear() { view.clear(); } + + public static void writeScreenOpeningData(final PlatformRegistry> + storageChannelTypeRegistry, + final Grid grid, + final FriendlyByteBuf buf) { + buf.writeBoolean(grid.isGridActive()); + final List> types = storageChannelTypeRegistry.getAll(); + buf.writeInt(types.size()); + types.forEach(type -> writeStorageChannel(storageChannelTypeRegistry, type, grid, buf)); + } + + private static void writeStorageChannel( + final PlatformRegistry> storageChannelTypeRegistry, + final PlatformStorageChannelType storageChannelType, + final Grid grid, + final FriendlyByteBuf buf + ) { + final ResourceLocation id = storageChannelTypeRegistry.getId(storageChannelType).orElseThrow(); + buf.writeResourceLocation(id); + final List> resources = grid.getResources(storageChannelType, PlayerActor.class); + buf.writeInt(resources.size()); + resources.forEach(resource -> writeGridResource(storageChannelType, resource, buf)); + } + + private static void writeGridResource(final PlatformStorageChannelType storageChannelType, + final TrackedResourceAmount resource, + final FriendlyByteBuf buf) { + storageChannelType.toBuffer(resource.resourceAmount().getResource(), buf); + buf.writeLong(resource.resourceAmount().getAmount()); + PacketUtil.writeTrackedResource(buf, resource.trackedResource()); + } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridBlock.java index a22c8e193..ea5be5efe 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridBlock.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridBlock.java @@ -13,7 +13,6 @@ import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; -import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.Item; import net.minecraft.world.level.Level; @@ -24,7 +23,8 @@ import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; -public class CraftingGridBlock extends AbstractGridBlock implements BlockItemProvider { +public class CraftingGridBlock extends AbstractGridBlock + implements BlockItemProvider { private static final Component HELP = createTranslation("item", "crafting_grid.help"); private static final AbstractBlockEntityTicker TICKER = new NetworkNodeBlockEntityTicker<>( BlockEntities.INSTANCE::getCraftingGrid, @@ -36,7 +36,7 @@ public CraftingGridBlock(final DyeColor color, final MutableComponent name) { } @Override - public BlockColorMap getBlockColorMap() { + public BlockColorMap getBlockColorMap() { return Blocks.INSTANCE.getCraftingGrid(); } @@ -55,7 +55,7 @@ public BlockEntityTicker getTicker(final Level level, } @Override - public BlockItem createBlockItem() { + public NamedBlockItem createBlockItem() { return new NamedBlockItem(this, new Item.Properties(), getName(), HELP); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridBlockEntity.java index bc2381b2f..91fe16574 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridBlockEntity.java @@ -25,6 +25,7 @@ import net.minecraft.world.inventory.ResultContainer; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.CraftingRecipe; +import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; @@ -78,6 +79,7 @@ private CraftingRecipe loadRecipe(final Level level) { return level .getRecipeManager() .getRecipeFor(RecipeType.CRAFTING, craftingMatrix, level) + .map(RecipeHolder::value) .orElse(null); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridResultSlot.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridResultSlot.java index f229f191b..59495bcf2 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridResultSlot.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridResultSlot.java @@ -7,7 +7,7 @@ import net.minecraft.core.NonNullList; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.RecipeHolder; +import net.minecraft.world.inventory.RecipeCraftingHolder; import net.minecraft.world.inventory.ResultSlot; import net.minecraft.world.item.ItemStack; @@ -96,7 +96,7 @@ private void fireCraftingEvents(final Player player, final ItemStack crafted) { // reimplementation of checkTakeAchievements crafted.onCraftedBy(player.level(), player, crafted.getCount()); Platform.INSTANCE.onItemCrafted(player, crafted, source.getCraftingMatrix()); - if (container instanceof RecipeHolder recipeHolder) { + if (container instanceof RecipeCraftingHolder recipeHolder) { recipeHolder.awardUsedRecipes(player, List.of(crafted)); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/GridBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/GridBlock.java index 55a7c9ca8..d33ef786e 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/GridBlock.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/GridBlock.java @@ -13,7 +13,6 @@ import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; -import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.Item; import net.minecraft.world.level.Level; @@ -24,7 +23,8 @@ import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; -public class GridBlock extends AbstractGridBlock implements BlockItemProvider { +public class GridBlock extends AbstractGridBlock + implements BlockItemProvider { private static final Component HELP = createTranslation("item", "grid.help"); private static final AbstractBlockEntityTicker TICKER = new NetworkNodeBlockEntityTicker<>( BlockEntities.INSTANCE::getGrid, @@ -35,8 +35,9 @@ public GridBlock(final DyeColor color, final MutableComponent name) { super(name, color); } + @Override - public BlockColorMap getBlockColorMap() { + public BlockColorMap getBlockColorMap() { return Blocks.INSTANCE.getGrid(); } @@ -55,7 +56,7 @@ public BlockEntityTicker getTicker(final Level level, } @Override - public BlockItem createBlockItem() { + public NamedBlockItem createBlockItem() { return new NamedBlockItem(this, new Item.Properties(), getName(), HELP); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/WirelessGridItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/WirelessGridItem.java index e0388c756..d1a538ee6 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/WirelessGridItem.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/WirelessGridItem.java @@ -9,8 +9,6 @@ import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.SlotReference; import com.refinedmods.refinedstorage2.platform.common.Platform; -import java.util.Optional; - import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -27,15 +25,11 @@ public WirelessGridItem(final boolean creative) { this.creative = creative; } - @Override - public Optional createEnergyStorage(final ItemStack stack) { - if (creative) { - return Optional.empty(); - } + public EnergyStorage createEnergyStorage(final ItemStack stack) { final EnergyStorage energyStorage = new EnergyStorageImpl( Platform.INSTANCE.getConfig().getWirelessGrid().getEnergyCapacity() ); - return Optional.of(PlatformApi.INSTANCE.asItemEnergyStorage(energyStorage, stack)); + return PlatformApi.INSTANCE.asItemEnergyStorage(energyStorage, stack); } @Override diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/AbstractGridScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/AbstractGridScreen.java index 4394a64de..4ac595f8d 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/AbstractGridScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/AbstractGridScreen.java @@ -4,15 +4,11 @@ import com.refinedmods.refinedstorage2.api.grid.operations.GridInsertMode; import com.refinedmods.refinedstorage2.api.grid.view.GridResource; import com.refinedmods.refinedstorage2.api.grid.view.GridView; -import com.refinedmods.refinedstorage2.api.storage.TrackedResourceAmount; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.grid.Grid; import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollMode; import com.refinedmods.refinedstorage2.platform.api.grid.GridSynchronizer; import com.refinedmods.refinedstorage2.platform.api.grid.view.PlatformGridResource; -import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; import com.refinedmods.refinedstorage2.platform.api.support.registry.PlatformRegistry; import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.Platform; @@ -26,7 +22,6 @@ import com.refinedmods.refinedstorage2.platform.common.support.widget.History; import com.refinedmods.refinedstorage2.platform.common.support.widget.RedstoneModeSideButtonWidget; import com.refinedmods.refinedstorage2.platform.common.support.widget.ScrollbarWidget; -import com.refinedmods.refinedstorage2.platform.common.util.PacketUtil; import com.refinedmods.refinedstorage2.query.lexer.SyntaxHighlighter; import com.refinedmods.refinedstorage2.query.lexer.SyntaxHighlighterColors; @@ -39,10 +34,8 @@ import net.minecraft.ChatFormatting; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; -import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; @@ -525,7 +518,7 @@ public boolean mouseReleased(final double mx, final double my, final int button) } @Override - public boolean mouseScrolled(final double x, final double y, final double delta) { + public boolean mouseScrolled(final double x, final double y, final double z, final double delta) { final boolean up = delta > 0; if (isOverStorageArea((int) x, (int) y)) { @@ -538,8 +531,8 @@ public boolean mouseScrolled(final double x, final double y, final double delta) } final boolean didScrollbar = - scrollbar != null && !hasShiftDown() && !hasControlDown() && scrollbar.mouseScrolled(x, y, delta); - return didScrollbar || super.mouseScrolled(x, y, delta); + scrollbar != null && !hasShiftDown() && !hasControlDown() && scrollbar.mouseScrolled(x, y, z, delta); + return didScrollbar || super.mouseScrolled(x, y, z, delta); } private void mouseScrolledInInventory(final boolean up, final Slot slot) { @@ -639,35 +632,4 @@ public boolean keyReleased(final int key, final int scanCode, final int modifier return super.keyReleased(key, scanCode, modifiers); } - - public static void writeScreenOpeningData(final PlatformRegistry> - storageChannelTypeRegistry, - final Grid grid, - final FriendlyByteBuf buf) { - buf.writeBoolean(grid.isGridActive()); - final List> types = storageChannelTypeRegistry.getAll(); - buf.writeInt(types.size()); - types.forEach(type -> writeStorageChannel(storageChannelTypeRegistry, type, grid, buf)); - } - - private static void writeStorageChannel( - final PlatformRegistry> storageChannelTypeRegistry, - final PlatformStorageChannelType storageChannelType, - final Grid grid, - final FriendlyByteBuf buf - ) { - final ResourceLocation id = storageChannelTypeRegistry.getId(storageChannelType).orElseThrow(); - buf.writeResourceLocation(id); - final List> resources = grid.getResources(storageChannelType, PlayerActor.class); - buf.writeInt(resources.size()); - resources.forEach(resource -> writeGridResource(storageChannelType, resource, buf)); - } - - private static void writeGridResource(final PlatformStorageChannelType storageChannelType, - final TrackedResourceAmount resource, - final FriendlyByteBuf buf) { - storageChannelType.toBuffer(resource.resourceAmount().getResource(), buf); - buf.writeLong(resource.resourceAmount().getAmount()); - PacketUtil.writeTrackedResource(buf, resource.trackedResource()); - } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/CraftingGridScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/CraftingGridScreen.java index ca4f0e6cb..f2221282a 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/CraftingGridScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/CraftingGridScreen.java @@ -3,6 +3,7 @@ import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.content.KeyMappings; import com.refinedmods.refinedstorage2.platform.common.grid.CraftingGridContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.support.widget.HoveredImageButton; import javax.annotation.Nullable; @@ -11,6 +12,7 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.ImageButton; import net.minecraft.client.gui.components.Tooltip; +import net.minecraft.client.gui.components.WidgetSprites; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; @@ -24,6 +26,19 @@ public class CraftingGridScreen extends AbstractGridScreen getMenu().clear(toPlayerInventory), text ); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/AbstractFluidGridResourceFactory.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/AbstractFluidGridResourceFactory.java index bf38d4884..cfc6399ba 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/AbstractFluidGridResourceFactory.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/AbstractFluidGridResourceFactory.java @@ -35,7 +35,6 @@ public Optional apply(final ResourceAmount resourceAmount) { )); } - @SuppressWarnings({"deprecation", "RedundantSuppression"}) // forge deprecates Registry access private Set getTags(final Fluid fluid) { return BuiltInRegistries.FLUID.getResourceKey(fluid) .flatMap(BuiltInRegistries.FLUID::getHolder) @@ -45,7 +44,6 @@ private Set getTags(final Fluid fluid) { .collect(Collectors.toSet()); } - @SuppressWarnings({"deprecation", "RedundantSuppression"}) // forge deprecates Registry access private String getModId(final FluidResource fluid) { return BuiltInRegistries.FLUID.getKey(fluid.fluid()).getNamespace(); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/AbstractItemGridResourceFactory.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/AbstractItemGridResourceFactory.java index 10dd7cf6d..8adcd47c3 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/AbstractItemGridResourceFactory.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/AbstractItemGridResourceFactory.java @@ -49,7 +49,6 @@ private String getTooltip(final ItemStack itemStack) { .collect(Collectors.joining("\n")); } - @SuppressWarnings({"deprecation", "RedundantSuppression"}) // forge deprecates Registry access private Set getTags(final Item item) { return BuiltInRegistries.ITEM.getResourceKey(item) .flatMap(BuiltInRegistries.ITEM::getHolder) diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/FluidGridResource.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/FluidGridResource.java index 5d9be6361..0e1986d59 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/FluidGridResource.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/FluidGridResource.java @@ -28,7 +28,6 @@ public class FluidGridResource extends AbstractPlatformGridResource resourceAmount, final String name, final String modId, diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/importer/ImporterBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/importer/ImporterBlock.java index 06e521f87..061634789 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/importer/ImporterBlock.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/importer/ImporterBlock.java @@ -19,7 +19,6 @@ import net.minecraft.core.Direction; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; -import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.Item; import net.minecraft.world.level.Level; @@ -33,7 +32,7 @@ import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; public class ImporterBlock extends AbstractDirectionalCableBlock implements - ColorableBlock, EntityBlock, BlockItemProvider { + ColorableBlock, EntityBlock, BlockItemProvider { private static final Component HELP = createTranslation("item", "importer.help"); private static final Map SHAPE_CACHE = new HashMap<>(); private static final AbstractBlockEntityTicker TICKER = @@ -66,7 +65,7 @@ public BlockEntityTicker getTicker(final Level level, } @Override - public BlockColorMap getBlockColorMap() { + public BlockColorMap getBlockColorMap() { return Blocks.INSTANCE.getImporter(); } @@ -88,7 +87,7 @@ public MutableComponent getName() { } @Override - public BlockItem createBlockItem() { + public NamedBlockItem createBlockItem() { return new NamedBlockItem(this, new Item.Properties(), name, HELP); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/CableBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/CableBlock.java index 4932e6704..d49d16772 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/CableBlock.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/CableBlock.java @@ -8,10 +8,10 @@ import com.refinedmods.refinedstorage2.platform.common.content.Blocks; import com.refinedmods.refinedstorage2.platform.common.support.AbstractBlockEntityTicker; import com.refinedmods.refinedstorage2.platform.common.support.AbstractColoredBlock; -import com.refinedmods.refinedstorage2.platform.common.support.BlockItemProvider; import com.refinedmods.refinedstorage2.platform.common.support.CableBlockSupport; import com.refinedmods.refinedstorage2.platform.common.support.CableShapeCacheKey; import com.refinedmods.refinedstorage2.platform.common.support.ColorableBlock; +import com.refinedmods.refinedstorage2.platform.common.support.NamedBlockItem; import com.refinedmods.refinedstorage2.platform.common.support.network.NetworkNodeBlockEntityTicker; import com.refinedmods.refinedstorage2.platform.common.support.network.NetworkNodeContainerBlockEntityImpl; @@ -41,7 +41,7 @@ import net.minecraft.world.phys.shapes.VoxelShape; public class CableBlock extends AbstractColoredBlock - implements ColorableBlock, SimpleWaterloggedBlock, EntityBlock, BlockItemProvider { + implements ColorableBlock, SimpleWaterloggedBlock, EntityBlock { private static final AbstractBlockEntityTicker> TICKER = new NetworkNodeBlockEntityTicker<>(BlockEntities.INSTANCE::getCable); @@ -119,7 +119,7 @@ public BlockEntity newBlockEntity(final BlockPos pos, final BlockState state) { } @Override - public BlockColorMap getBlockColorMap() { + public BlockColorMap getBlockColorMap() { return Blocks.INSTANCE.getCable(); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/NetworkReceiverBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/NetworkReceiverBlock.java index 4bb7ea7c3..94db2f415 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/NetworkReceiverBlock.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/NetworkReceiverBlock.java @@ -6,6 +6,7 @@ import com.refinedmods.refinedstorage2.platform.common.content.Blocks; import com.refinedmods.refinedstorage2.platform.common.support.AbstractBlockEntityTicker; import com.refinedmods.refinedstorage2.platform.common.support.AbstractColoredBlock; +import com.refinedmods.refinedstorage2.platform.common.support.NamedBlockItem; import com.refinedmods.refinedstorage2.platform.common.support.network.NetworkNodeBlockEntityTicker; import javax.annotation.Nullable; @@ -45,7 +46,7 @@ protected void createBlockStateDefinition(final StateDefinition.Builder getBlockColorMap() { + public BlockColorMap getBlockColorMap() { return Blocks.INSTANCE.getNetworkReceiver(); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/NetworkTransmitterBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/NetworkTransmitterBlock.java index 95798f579..44f7184f7 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/NetworkTransmitterBlock.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/NetworkTransmitterBlock.java @@ -5,6 +5,7 @@ import com.refinedmods.refinedstorage2.platform.common.content.Blocks; import com.refinedmods.refinedstorage2.platform.common.support.AbstractBlockEntityTicker; import com.refinedmods.refinedstorage2.platform.common.support.AbstractColoredBlock; +import com.refinedmods.refinedstorage2.platform.common.support.NamedBlockItem; import javax.annotation.Nullable; @@ -46,7 +47,7 @@ protected void createBlockStateDefinition(final StateDefinition.Builder getBlockColorMap() { + public BlockColorMap getBlockColorMap() { return Blocks.INSTANCE.getNetworkTransmitter(); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/CraftingGridRecipeTransferHandler.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/CraftingGridRecipeTransferHandler.java index 90fba8272..be8f2ae6a 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/CraftingGridRecipeTransferHandler.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/CraftingGridRecipeTransferHandler.java @@ -21,8 +21,10 @@ import net.minecraft.world.inventory.MenuType; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.CraftingRecipe; +import net.minecraft.world.item.crafting.RecipeHolder; -class CraftingGridRecipeTransferHandler implements IRecipeTransferHandler { +class CraftingGridRecipeTransferHandler implements + IRecipeTransferHandler> { @Override public Class getContainerClass() { return CraftingGridContainerMenu.class; @@ -34,14 +36,14 @@ public Optional> getMenuType() { } @Override - public RecipeType getRecipeType() { + public RecipeType> getRecipeType() { return RecipeTypes.CRAFTING; } @Override @Nullable public IRecipeTransferError transferRecipe(final CraftingGridContainerMenu containerMenu, - final CraftingRecipe recipe, + final RecipeHolder recipe, final IRecipeSlotsView recipeSlots, final Player player, final boolean maxTransfer, diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/DiskInventory.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/DiskInventory.java index f08864058..79d8f182b 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/DiskInventory.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/DiskInventory.java @@ -72,7 +72,6 @@ private Optional validateAndGetStack(final int slot) { return Optional.of(stack); } - @SuppressWarnings("deprecation") // Forge deprecates registry access this way public ListTag toSyncTag(final IntFunction stateProvider) { final ListTag list = new ListTag(); for (int i = 0; i < getContainerSize(); ++i) { @@ -87,7 +86,6 @@ public ListTag toSyncTag(final IntFunction stateProvider) { return list; } - @SuppressWarnings("deprecation") // Forge deprecates registry access this way public Disk[] fromSyncTag(final ListTag list) { final Disk[] disks = new Disk[list.size()]; for (int i = 0; i < list.size(); ++i) { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/externalstorage/ExternalStorageBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/externalstorage/ExternalStorageBlock.java index ef3f47bc4..4cbcd239f 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/externalstorage/ExternalStorageBlock.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/externalstorage/ExternalStorageBlock.java @@ -20,7 +20,6 @@ import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.Item; import net.minecraft.world.level.Level; @@ -37,7 +36,7 @@ import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; public class ExternalStorageBlock extends AbstractDirectionalCableBlock - implements ColorableBlock, EntityBlock, BlockItemProvider { + implements ColorableBlock, EntityBlock, BlockItemProvider { private static final Component HELP = createTranslation("item", "external_storage.help"); private static final Map SHAPE_CACHE = new HashMap<>(); private static final AbstractBlockEntityTicker TICKER = @@ -88,7 +87,7 @@ public void neighborChanged(final BlockState state, } @Override - public BlockColorMap getBlockColorMap() { + public BlockColorMap getBlockColorMap() { return Blocks.INSTANCE.getExternalStorage(); } @@ -110,7 +109,7 @@ public MutableComponent getName() { } @Override - public BlockItem createBlockItem() { + public NamedBlockItem createBlockItem() { return new NamedBlockItem(this, new Item.Properties(), name, HELP); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/AbstractPortableGridBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/AbstractPortableGridBlockEntity.java index 2797de37a..7bbc7851a 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/AbstractPortableGridBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/AbstractPortableGridBlockEntity.java @@ -20,7 +20,7 @@ import com.refinedmods.refinedstorage2.platform.api.configurationcard.ConfigurationCardTarget; import com.refinedmods.refinedstorage2.platform.api.grid.Grid; import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; -import com.refinedmods.refinedstorage2.platform.api.support.energy.EnergyBlockEntity; +import com.refinedmods.refinedstorage2.platform.api.support.energy.TransferableBlockEntityEnergy; import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; @@ -63,7 +63,7 @@ import org.slf4j.LoggerFactory; public abstract class AbstractPortableGridBlockEntity extends BlockEntity implements Grid, ExtendedMenuProvider, - EnergyBlockEntity, ConfigurationCardTarget, GridStorageChannelProvider { + ConfigurationCardTarget, GridStorageChannelProvider, TransferableBlockEntityEnergy { private static final Logger LOGGER = LoggerFactory.getLogger(AbstractPortableGridBlockEntity.class); private static final String TAG_DISK_INVENTORY = "inv"; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridLootItemFunction.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridLootItemFunction.java index de9c1fc5b..441449776 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridLootItemFunction.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridLootItemFunction.java @@ -7,7 +7,7 @@ import net.minecraft.world.level.storage.loot.functions.LootItemFunction; import net.minecraft.world.level.storage.loot.functions.LootItemFunctionType; -class PortableGridLootItemFunction implements LootItemFunction { +public class PortableGridLootItemFunction implements LootItemFunction { @Override public LootItemFunctionType getType() { return LootFunctions.INSTANCE.getPortableGrid(); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridLootItemFunctionSerializer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridLootItemFunctionSerializer.java deleted file mode 100644 index 19e1c12cf..000000000 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridLootItemFunctionSerializer.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.common.storage.portablegrid; - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonObject; -import com.google.gson.JsonSerializationContext; -import net.minecraft.world.level.storage.loot.Serializer; -import net.minecraft.world.level.storage.loot.functions.LootItemFunction; - -public class PortableGridLootItemFunctionSerializer implements Serializer { - @Override - public void serialize(final JsonObject jsonObject, - final LootItemFunction lootItemFunction, - final JsonSerializationContext jsonSerializationContext) { - // no op - } - - @Override - public LootItemFunction deserialize(final JsonObject jsonObject, - final JsonDeserializationContext jsonDeserializationContext) { - return new PortableGridLootItemFunction(); - } -} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storageblock/StorageBlockLootItemFunction.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storageblock/StorageBlockLootItemFunction.java index 950cd926a..126792210 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storageblock/StorageBlockLootItemFunction.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storageblock/StorageBlockLootItemFunction.java @@ -11,7 +11,7 @@ import net.minecraft.world.level.storage.loot.functions.LootItemFunctionType; import net.minecraft.world.level.storage.loot.parameters.LootContextParams; -class StorageBlockLootItemFunction implements LootItemFunction { +public class StorageBlockLootItemFunction implements LootItemFunction { @Override public LootItemFunctionType getType() { return LootFunctions.INSTANCE.getStorageBlock(); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storageblock/StorageBlockLootItemFunctionSerializer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storageblock/StorageBlockLootItemFunctionSerializer.java deleted file mode 100644 index d66b00ee4..000000000 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storageblock/StorageBlockLootItemFunctionSerializer.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.common.storage.storageblock; - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonObject; -import com.google.gson.JsonSerializationContext; -import net.minecraft.world.level.storage.loot.Serializer; -import net.minecraft.world.level.storage.loot.functions.LootItemFunction; - -public class StorageBlockLootItemFunctionSerializer implements Serializer { - @Override - public void serialize(final JsonObject jsonObject, - final LootItemFunction lootItemFunction, - final JsonSerializationContext jsonSerializationContext) { - // no op - } - - @Override - public LootItemFunction deserialize(final JsonObject jsonObject, - final JsonDeserializationContext jsonDeserializationContext) { - return new StorageBlockLootItemFunction(); - } -} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/ItemStorageMonitorExtractionStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/ItemStorageMonitorExtractionStrategy.java index b068f7895..0cf8a8c9a 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/ItemStorageMonitorExtractionStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/ItemStorageMonitorExtractionStrategy.java @@ -13,7 +13,6 @@ public class ItemStorageMonitorExtractionStrategy implements StorageMonitorExtractionStrategy { @Override - @SuppressWarnings("deprecation") // Forge deprecates accessing max stack size this way public boolean extract(final Object resource, final boolean fullStack, final Player player, diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractBaseBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractBaseBlock.java index e05925b0d..30ba76a33 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractBaseBlock.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractBaseBlock.java @@ -171,7 +171,6 @@ private boolean rotate(final BlockState state, final Level level, final BlockPos return !state.equals(rotated); } - @SuppressWarnings("deprecation") // Forge deprecates rotation this way protected BlockState getRotatedBlockState(final BlockState state, final Level level, final BlockPos pos) { return state.rotate(Rotation.CLOCKWISE_90); } @@ -206,14 +205,14 @@ public final Optional tryUpdateColor(final BlockState state, final BlockPos pos, final Player player, final InteractionHand hand) { - if (this instanceof ColorableBlock colorableBlock) { + if (this instanceof ColorableBlock colorableBlock) { return tryUpdateColor(colorableBlock.getBlockColorMap(), state, level, pos, player, hand); } return Optional.empty(); } private Optional tryUpdateColor( - final BlockColorMap blockColorMap, + final BlockColorMap blockColorMap, final BlockState state, final Level level, final BlockPos pos, diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractBaseScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractBaseScreen.java index 95cb62ed7..02575acb7 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractBaseScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractBaseScreen.java @@ -87,7 +87,7 @@ protected void renderBg(final GuiGraphics graphics, final float delta, final int @Override public void render(final GuiGraphics graphics, final int mouseX, final int mouseY, final float delta) { - renderBackground(graphics); + renderBackground(graphics, mouseX, mouseY, delta); super.render(graphics, mouseX, mouseY, delta); renderTooltip(graphics, mouseX, mouseY); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractColoredBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractColoredBlock.java index 7a6e06ac5..08754b8b1 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractColoredBlock.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractColoredBlock.java @@ -1,13 +1,12 @@ package com.refinedmods.refinedstorage2.platform.common.support; import net.minecraft.network.chat.MutableComponent; -import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; -public abstract class AbstractColoredBlock - extends AbstractBaseBlock implements ColorableBlock, BlockItemProvider { +public abstract class AbstractColoredBlock> + extends AbstractBaseBlock implements ColorableBlock, BlockItemProvider { private final DyeColor color; private final MutableComponent name; @@ -28,7 +27,7 @@ public DyeColor getColor() { } @Override - public BlockItem createBlockItem() { + public NamedBlockItem createBlockItem() { return new NamedBlockItem(this, new Item.Properties(), name); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/BlockItemProvider.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/BlockItemProvider.java index a437fbbdb..3078955b4 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/BlockItemProvider.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/BlockItemProvider.java @@ -3,6 +3,6 @@ import net.minecraft.world.item.BlockItem; @FunctionalInterface -public interface BlockItemProvider { - BlockItem createBlockItem(); +public interface BlockItemProvider { + T createBlockItem(); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/ColorableBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/ColorableBlock.java index a3128725e..7bc68f39e 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/ColorableBlock.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/ColorableBlock.java @@ -2,11 +2,12 @@ import com.refinedmods.refinedstorage2.platform.common.content.BlockColorMap; +import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.DyeColor; import net.minecraft.world.level.block.Block; -public interface ColorableBlock { - BlockColorMap getBlockColorMap(); +public interface ColorableBlock, I extends BlockItem> { + BlockColorMap getBlockColorMap(); DyeColor getColor(); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/amount/AbstractAmountScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/amount/AbstractAmountScreen.java index 049f9649c..16b43127d 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/amount/AbstractAmountScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/amount/AbstractAmountScreen.java @@ -165,13 +165,13 @@ private void changeAmount(final int delta) { } @Override - public boolean mouseScrolled(final double x, final double y, final double delta) { + public boolean mouseScrolled(final double x, final double y, final double z, final double delta) { if (delta > 0) { changeAmount(1); } else { changeAmount(-1); } - return super.mouseScrolled(x, y, delta); + return super.mouseScrolled(x, y, z, delta); } @Override diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/energy/EnergyItemHelperImpl.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/energy/EnergyItemHelperImpl.java index f53a35ea6..4e80efdaf 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/energy/EnergyItemHelperImpl.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/energy/EnergyItemHelperImpl.java @@ -2,19 +2,15 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.support.energy.AbstractEnergyBlockItem; -import com.refinedmods.refinedstorage2.platform.api.support.energy.EnergyBlockEntity; import com.refinedmods.refinedstorage2.platform.api.support.energy.EnergyItemHelper; +import com.refinedmods.refinedstorage2.platform.api.support.energy.TransferableBlockEntityEnergy; import java.util.List; -import java.util.function.Supplier; -import java.util.stream.Stream; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; import net.minecraft.util.Mth; -import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; @@ -65,18 +61,13 @@ public ItemStack createAtEnergyCapacity(final Item item) { @Override public void passEnergyToBlockEntity(final BlockPos pos, final Level level, final ItemStack stack) { - if (level.isClientSide() || !(level.getBlockEntity(pos) instanceof EnergyBlockEntity energyBlockEntity)) { + if (level.isClientSide() + || !(level.getBlockEntity(pos) instanceof TransferableBlockEntityEnergy transferableBlockEntityEnergy)) { return; } PlatformApi.INSTANCE.getEnergyStorage(stack).ifPresent( - energyStorage -> energyBlockEntity.getEnergyStorage().receive(energyStorage.getStored(), Action.EXECUTE) + energyStorage -> transferableBlockEntityEnergy.getEnergyStorage() + .receive(energyStorage.getStored(), Action.EXECUTE) ); } - - public static Stream createAllAtEnergyCapacity(final List> items) { - return items.stream().map(Supplier::get) - .filter(AbstractEnergyBlockItem.class::isInstance) - .map(AbstractEnergyBlockItem.class::cast) - .map(AbstractEnergyBlockItem::createAtEnergyCapacity); - } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/energy/EnergyLootItemFunction.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/energy/EnergyLootItemFunction.java index f5476b195..59c6157ea 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/energy/EnergyLootItemFunction.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/energy/EnergyLootItemFunction.java @@ -2,7 +2,7 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.support.energy.EnergyBlockEntity; +import com.refinedmods.refinedstorage2.platform.api.support.energy.TransferableBlockEntityEnergy; import com.refinedmods.refinedstorage2.platform.common.content.LootFunctions; import net.minecraft.world.item.ItemStack; @@ -21,8 +21,8 @@ public LootItemFunctionType getType() { @Override public ItemStack apply(final ItemStack stack, final LootContext lootContext) { final BlockEntity blockEntity = lootContext.getParam(LootContextParams.BLOCK_ENTITY); - if (blockEntity instanceof EnergyBlockEntity energyBlockEntity) { - final long stored = energyBlockEntity.getEnergyStorage().getStored(); + if (blockEntity instanceof TransferableBlockEntityEnergy transferableBlockEntityEnergy) { + final long stored = transferableBlockEntityEnergy.getEnergyStorage().getStored(); PlatformApi.INSTANCE.getEnergyStorage(stack).ifPresent( energyStorage -> energyStorage.receive(stored, Action.EXECUTE) ); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/energy/EnergyLootItemFunctionSerializer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/energy/EnergyLootItemFunctionSerializer.java deleted file mode 100644 index bb5dd73a3..000000000 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/energy/EnergyLootItemFunctionSerializer.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.common.support.energy; - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonObject; -import com.google.gson.JsonSerializationContext; -import net.minecraft.world.level.storage.loot.Serializer; -import net.minecraft.world.level.storage.loot.functions.LootItemFunction; - -public class EnergyLootItemFunctionSerializer implements Serializer { - @Override - public void serialize(final JsonObject jsonObject, - final LootItemFunction lootItemFunction, - final JsonSerializationContext jsonSerializationContext) { - // no op - } - - @Override - public LootItemFunction deserialize(final JsonObject jsonObject, - final JsonDeserializationContext jsonDeserializationContext) { - return new EnergyLootItemFunction(); - } -} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/NetworkNodeContainerBlockEntityImpl.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/NetworkNodeContainerBlockEntityImpl.java index 14ada3bcd..8c5e0ec63 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/NetworkNodeContainerBlockEntityImpl.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/NetworkNodeContainerBlockEntityImpl.java @@ -107,10 +107,10 @@ public boolean canAcceptIncomingConnection(final Direction incomingDirection, fi } protected final boolean colorsAllowConnecting(final BlockState connectingState) { - if (!(connectingState.getBlock() instanceof ColorableBlock otherColorableBlock)) { + if (!(connectingState.getBlock() instanceof ColorableBlock otherColorableBlock)) { return true; } - final ColorableBlock colorableBlock = getColor(); + final ColorableBlock colorableBlock = getColor(); if (colorableBlock == null) { return true; } @@ -120,8 +120,8 @@ protected final boolean colorsAllowConnecting(final BlockState connectingState) } @Nullable - private ColorableBlock getColor() { - if (!(getBlockState().getBlock() instanceof ColorableBlock colorableBlock)) { + private ColorableBlock getColor() { + if (!(getBlockState().getBlock() instanceof ColorableBlock colorableBlock)) { return null; } return colorableBlock; diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/PacketIds.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/packet/PacketIds.java similarity index 96% rename from refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/PacketIds.java rename to refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/packet/PacketIds.java index bb84ba954..bf476c452 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/PacketIds.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/packet/PacketIds.java @@ -1,4 +1,4 @@ -package com.refinedmods.refinedstorage2.platform.fabric.packet; +package com.refinedmods.refinedstorage2.platform.common.support.packet; import net.minecraft.resources.ResourceLocation; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/package-info.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/packet/package-info.java similarity index 74% rename from refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/package-info.java rename to refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/packet/package-info.java index 837b198e4..71ad17d0f 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/package-info.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/packet/package-info.java @@ -1,6 +1,6 @@ @ParametersAreNonnullByDefault @FieldsAndMethodsAreNonnullByDefault -package com.refinedmods.refinedstorage2.platform.forge.packet.s2c; +package com.refinedmods.refinedstorage2.platform.common.support.packet; import com.refinedmods.refinedstorage2.api.core.FieldsAndMethodsAreNonnullByDefault; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/HoveredImageButton.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/HoveredImageButton.java new file mode 100644 index 000000000..9a723d0c4 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/HoveredImageButton.java @@ -0,0 +1,26 @@ +package com.refinedmods.refinedstorage2.platform.common.support.widget; + +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.ImageButton; +import net.minecraft.client.gui.components.WidgetSprites; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; + +public class HoveredImageButton extends ImageButton { + public HoveredImageButton(final int x, + final int y, + final int width, + final int height, + final WidgetSprites sprites, + final OnPress onPress, + final Component component) { + super(x, y, width, height, sprites, onPress, component); + } + + @Override + public void renderWidget(final GuiGraphics graphics, final int x, final int y, final float partialTicks) { + // only takes isHovered in account, not isFocused + final ResourceLocation location = sprites.get(isActive(), isHovered()); + graphics.blitSprite(location, getX(), getY(), width, height); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/ScrollbarWidget.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/ScrollbarWidget.java index 835d6149c..2925c0a8a 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/ScrollbarWidget.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/ScrollbarWidget.java @@ -124,9 +124,9 @@ public boolean mouseReleased(final double mouseX, final double mouseY, final int } @Override - public boolean mouseScrolled(final double mouseX, final double mouseY, final double scrollDelta) { + public boolean mouseScrolled(final double x, final double y, final double z, final double delta) { if (enabled) { - final int scrollDirection = Math.max(Math.min(-(int) scrollDelta, 1), -1); + final int scrollDirection = Math.max(Math.min(-(int) delta, 1), -1); if (scrollAnimation) { startScrollAnimation(scrollDirection); } else { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/upgrade/UpgradeWithEnchantedBookRecipe.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/upgrade/UpgradeWithEnchantedBookRecipe.java index 4d0af11d8..6121ada6f 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/upgrade/UpgradeWithEnchantedBookRecipe.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/upgrade/UpgradeWithEnchantedBookRecipe.java @@ -3,19 +3,27 @@ import com.refinedmods.refinedstorage2.platform.common.content.Items; import java.util.Objects; +import java.util.Optional; import javax.annotation.Nullable; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.core.Holder; import net.minecraft.core.NonNullList; -import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; +import net.minecraft.resources.RegistryFixedCodec; +import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.inventory.CraftingContainer; import net.minecraft.world.item.EnchantedBookItem; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.CraftingBookCategory; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.ShapedRecipe; +import net.minecraft.world.item.crafting.ShapedRecipePattern; import net.minecraft.world.item.enchantment.Enchantment; import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.item.enchantment.EnchantmentInstance; @@ -23,19 +31,28 @@ import net.minecraft.world.level.block.Blocks; public class UpgradeWithEnchantedBookRecipe extends ShapedRecipe { - private final EnchantmentInstance enchantment; - private final ItemStack theResult; + public static final Codec CODEC = RecordCodecBuilder.create( + instance -> instance.group( + RegistryFixedCodec.create(Registries.ENCHANTMENT).fieldOf("enchantment") + .forGetter(UpgradeWithEnchantedBookRecipe::getEnchantment), + Codec.INT.fieldOf("level").orElse(1) + .forGetter(UpgradeWithEnchantedBookRecipe::getEnchantmentLevel), + RegistryFixedCodec.create(Registries.ITEM).fieldOf("result") + .forGetter(UpgradeWithEnchantedBookRecipe::getResultItem) + ).apply(instance, UpgradeWithEnchantedBookRecipe::new) + ); - UpgradeWithEnchantedBookRecipe(final ResourceLocation recipeId, - final Enchantment enchantment, - final int enchantmentLevel, - final ItemStack theResult) { - super(recipeId, "", CraftingBookCategory.MISC, 3, 3, NonNullList.of( + private final Holder enchantment; + private final int level; + private final Holder resultItem; + + UpgradeWithEnchantedBookRecipe(final Holder enchantment, + final int level, + final Holder resultItem) { + super("", CraftingBookCategory.MISC, new ShapedRecipePattern(3, 3, NonNullList.of( Ingredient.EMPTY, Ingredient.of(new ItemStack(Items.INSTANCE.getQuartzEnrichedIron())), - Ingredient.of(EnchantedBookItem.createForEnchantment( - new EnchantmentInstance(enchantment, enchantmentLevel) - )), + Ingredient.of(EnchantedBookItem.createForEnchantment(new EnchantmentInstance(enchantment.value(), level))), Ingredient.of(new ItemStack(Items.INSTANCE.getQuartzEnrichedIron())), Ingredient.of(new ItemStack(Blocks.BOOKSHELF)), Ingredient.of(new ItemStack(Items.INSTANCE.getUpgrade())), @@ -43,36 +60,40 @@ public class UpgradeWithEnchantedBookRecipe extends ShapedRecipe { Ingredient.of(new ItemStack(Items.INSTANCE.getQuartzEnrichedIron())), Ingredient.of(new ItemStack(Items.INSTANCE.getQuartzEnrichedIron())), Ingredient.of(new ItemStack(Items.INSTANCE.getQuartzEnrichedIron())) - ), theResult); - this.enchantment = new EnchantmentInstance(enchantment, enchantmentLevel); - this.theResult = theResult; + ), Optional.empty()), new ItemStack(resultItem.value())); + this.enchantment = enchantment; + this.level = level; + this.resultItem = resultItem; + } + + public Holder getResultItem() { + return resultItem; } - public ItemStack getResult() { - return theResult; + public Holder getEnchantment() { + return enchantment; } @Nullable - @SuppressWarnings("deprecation") // Forge deprecates BuiltinRegistries public ResourceLocation getEnchantmentId() { - return BuiltInRegistries.ENCHANTMENT.getKey(enchantment.enchantment); + return enchantment.unwrapKey().map(ResourceKey::location).orElse(null); } public int getEnchantmentLevel() { - return enchantment.level; + return level; } @Override - public boolean matches(final CraftingContainer craftingContainer, final Level level) { - if (!super.matches(craftingContainer, level)) { + public boolean matches(final CraftingContainer craftingContainer, final Level theLevel) { + if (!super.matches(craftingContainer, theLevel)) { return false; } final ListTag enchantments = EnchantedBookItem.getEnchantments(craftingContainer.getItem(1)); for (int i = 0; i < enchantments.size(); ++i) { final CompoundTag tag = enchantments.getCompound(i); - final int lvl = EnchantmentHelper.getEnchantmentLevel(tag); - final ResourceLocation enchantmentId = EnchantmentHelper.getEnchantmentId(tag); - if (Objects.equals(enchantmentId, getEnchantmentId()) && lvl == enchantment.level) { + final int containerLevel = EnchantmentHelper.getEnchantmentLevel(tag); + final ResourceLocation containerEnchantment = EnchantmentHelper.getEnchantmentId(tag); + if (Objects.equals(containerEnchantment, getEnchantmentId()) && containerLevel == level) { return true; } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/upgrade/UpgradeWithEnchantedBookRecipeSerializer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/upgrade/UpgradeWithEnchantedBookRecipeSerializer.java index 09a98fa06..8fcc1e445 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/upgrade/UpgradeWithEnchantedBookRecipeSerializer.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/upgrade/UpgradeWithEnchantedBookRecipeSerializer.java @@ -2,45 +2,39 @@ import java.util.Objects; -import com.google.gson.JsonObject; +import com.mojang.serialization.Codec; +import net.minecraft.core.Holder; import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.resources.ResourceKey; import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.enchantment.Enchantment; public class UpgradeWithEnchantedBookRecipeSerializer implements RecipeSerializer { @Override - @SuppressWarnings("deprecation") // Forge deprecates BuiltinRegistries - public UpgradeWithEnchantedBookRecipe fromJson(final ResourceLocation recipeId, final JsonObject json) { - final JsonObject enchantmentInfo = json.getAsJsonObject("enchantment"); - final Item resultItem = BuiltInRegistries.ITEM.get( - new ResourceLocation(json.getAsJsonPrimitive("result").getAsString()) - ); - final Enchantment enchantment = Objects.requireNonNull(BuiltInRegistries.ENCHANTMENT.get( - new ResourceLocation(enchantmentInfo.getAsJsonPrimitive("id").getAsString()) - )); - int level = 1; - if (enchantmentInfo.has("level")) { - level = enchantmentInfo.getAsJsonPrimitive("level").getAsInt(); - } - return new UpgradeWithEnchantedBookRecipe(recipeId, enchantment, level, new ItemStack(resultItem)); + public Codec codec() { + return UpgradeWithEnchantedBookRecipe.CODEC; } @Override - @SuppressWarnings("deprecation") // Forge deprecates BuiltinRegistries - public UpgradeWithEnchantedBookRecipe fromNetwork(final ResourceLocation recipeId, final FriendlyByteBuf buffer) { - final ItemStack result = buffer.readItem(); - final Enchantment enchantment = BuiltInRegistries.ENCHANTMENT.get(buffer.readResourceLocation()); - final int level = buffer.readInt(); - return new UpgradeWithEnchantedBookRecipe(recipeId, Objects.requireNonNull(enchantment), level, result); + public UpgradeWithEnchantedBookRecipe fromNetwork(final FriendlyByteBuf buf) { + final Holder result = BuiltInRegistries.ITEM.getHolder(ResourceKey.create( + Registries.ITEM, + buf.readResourceLocation() + )).orElseThrow(); + final Holder enchantment = BuiltInRegistries.ENCHANTMENT.getHolder(ResourceKey.create( + Registries.ENCHANTMENT, + buf.readResourceLocation() + )).orElseThrow(); + final int level = buf.readInt(); + return new UpgradeWithEnchantedBookRecipe(enchantment, level, result); } @Override public void toNetwork(final FriendlyByteBuf buf, final UpgradeWithEnchantedBookRecipe recipe) { - buf.writeItem(recipe.getResult()); + buf.writeResourceLocation(recipe.getResultItem().unwrapKey().orElseThrow().location()); buf.writeResourceLocation(Objects.requireNonNull(recipe.getEnchantmentId())); buf.writeInt(recipe.getEnchantmentLevel()); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/util/PacketUtil.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/util/PacketUtil.java index 22af8955c..791d2e55c 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/util/PacketUtil.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/util/PacketUtil.java @@ -26,13 +26,11 @@ public static ItemResource readItemResource(final FriendlyByteBuf buf) { return new ItemResource(Item.byId(id), nbt); } - @SuppressWarnings({"deprecation", "RedundantSuppression"}) // forge deprecates Registry access public static void writeFluidResource(final FriendlyByteBuf buf, final FluidResource itemResource) { buf.writeVarInt(BuiltInRegistries.FLUID.getId(itemResource.fluid())); buf.writeNbt(itemResource.tag()); } - @SuppressWarnings({"deprecation", "RedundantSuppression"}) // forge deprecates Registry access public static FluidResource readFluidResource(final FriendlyByteBuf buf) { final int id = buf.readVarInt(); final CompoundTag nbt = buf.readNbt(); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/wirelesstransmitter/WirelessTransmitterBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/wirelesstransmitter/WirelessTransmitterBlock.java index 9e3860f68..4cca430bf 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/wirelesstransmitter/WirelessTransmitterBlock.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/wirelesstransmitter/WirelessTransmitterBlock.java @@ -19,7 +19,6 @@ import net.minecraft.core.Direction; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; -import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.Item; import net.minecraft.world.level.BlockGetter; @@ -39,7 +38,8 @@ import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; public class WirelessTransmitterBlock extends AbstractDirectionalBlock - implements ColorableBlock, BlockItemProvider, EntityBlock { + implements ColorableBlock, BlockItemProvider, + EntityBlock { public static final BooleanProperty ACTIVE = BooleanProperty.create("active"); private static final AbstractBlockEntityTicker TICKER = @@ -99,7 +99,7 @@ public VoxelShape getShape(final BlockState state, } @Override - public BlockColorMap getBlockColorMap() { + public BlockColorMap getBlockColorMap() { return Blocks.INSTANCE.getWirelessTransmitter(); } @@ -128,7 +128,7 @@ public MutableComponent getName() { } @Override - public BlockItem createBlockItem() { + public NamedBlockItem createBlockItem() { return new NamedBlockItem(this, new Item.Properties(), getName(), HELP); } } diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/constructor_destructor/active.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/constructor_destructor/active.json index 8cc04e132..f98ac8e7c 100644 --- a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/constructor_destructor/active.json +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/constructor_destructor/active.json @@ -154,7 +154,7 @@ 16.0, 16.0 ], - "forge_data": { + "neoforge_data": { "block_light": 15, "sky_light": 15 } diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/detector/powered.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/detector/powered.json index 53bed43b2..fc0713fa4 100644 --- a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/detector/powered.json +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/detector/powered.json @@ -154,7 +154,7 @@ 12 ], "texture": "#torch", - "forge_data": { + "neoforge_data": { "block_light": 15, "sky_light": 15 } @@ -167,7 +167,7 @@ 12 ], "texture": "#torch", - "forge_data": { + "neoforge_data": { "block_light": 15, "sky_light": 15 } @@ -196,7 +196,7 @@ 12 ], "texture": "#torch", - "forge_data": { + "neoforge_data": { "block_light": 15, "sky_light": 15 } @@ -209,7 +209,7 @@ 12 ], "texture": "#torch", - "forge_data": { + "neoforge_data": { "block_light": 15, "sky_light": 15 } diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/emissive_all_cutout.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/emissive_all_cutout.json index 51f4c9c36..1cf87e323 100644 --- a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/emissive_all_cutout.json +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/emissive_all_cutout.json @@ -55,7 +55,7 @@ "down": { "texture": "#cutout", "cullface": "down", - "forge_data": { + "neoforge_data": { "block_light": 15, "sky_light": 15 } @@ -63,7 +63,7 @@ "up": { "texture": "#cutout", "cullface": "up", - "forge_data": { + "neoforge_data": { "block_light": 15, "sky_light": 15 } @@ -71,7 +71,7 @@ "north": { "texture": "#cutout", "cullface": "north", - "forge_data": { + "neoforge_data": { "block_light": 15, "sky_light": 15 } @@ -79,7 +79,7 @@ "south": { "texture": "#cutout", "cullface": "south", - "forge_data": { + "neoforge_data": { "block_light": 15, "sky_light": 15 } @@ -87,7 +87,7 @@ "west": { "texture": "#cutout", "cullface": "west", - "forge_data": { + "neoforge_data": { "block_light": 15, "sky_light": 15 } @@ -95,7 +95,7 @@ "east": { "texture": "#cutout", "cullface": "east", - "forge_data": { + "neoforge_data": { "block_light": 15, "sky_light": 15 } diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/emissive_north_cutout.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/emissive_north_cutout.json index d8d358153..94c3d668e 100644 --- a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/emissive_north_cutout.json +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/emissive_north_cutout.json @@ -55,7 +55,7 @@ "north": { "texture": "#cutout", "cullface": "north", - "forge_data": { + "neoforge_data": { "block_light": 15, "sky_light": 15 } diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/wireless_transmitter/active.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/wireless_transmitter/active.json index d0a6a83b2..e1d2695ea 100644 --- a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/wireless_transmitter/active.json +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/wireless_transmitter/active.json @@ -127,7 +127,7 @@ 15 ], "texture": "#cutout", - "forge_data": { + "neoforge_data": { "block_light": 15, "sky_light": 15 } @@ -140,7 +140,7 @@ 8 ], "texture": "#cutout", - "forge_data": { + "neoforge_data": { "block_light": 15, "sky_light": 15 } @@ -168,7 +168,7 @@ 16 ], "texture": "#cutout", - "forge_data": { + "neoforge_data": { "block_light": 15, "sky_light": 15 } @@ -181,7 +181,7 @@ 16 ], "texture": "#cutout", - "forge_data": { + "neoforge_data": { "block_light": 15, "sky_light": 15 } @@ -209,7 +209,7 @@ 16 ], "texture": "#cutout", - "forge_data": { + "neoforge_data": { "block_light": 15, "sky_light": 15 } @@ -222,7 +222,7 @@ 16 ], "texture": "#cutout", - "forge_data": { + "neoforge_data": { "block_light": 15, "sky_light": 15 } diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/constructor/base.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/constructor/base.json index 71bf5fba9..757e6bc49 100644 --- a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/constructor/base.json +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/constructor/base.json @@ -381,7 +381,7 @@ 16.0, 16.0 ], - "forge_data": { + "neoforge_data": { "block_light": 15, "sky_light": 15 } diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/destructor/base.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/destructor/base.json index 05e17fc49..d381c276f 100644 --- a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/destructor/base.json +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/destructor/base.json @@ -381,7 +381,7 @@ 16.0, 16.0 ], - "forge_data": { + "neoforge_data": { "block_light": 15, "sky_light": 15 } diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/gui/crafting_grid.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/gui/crafting_grid.png index 9a4c5e0181e78ac784fe366bf9450eacc8fee611..2a76f3627116bc1402f225100a01a261d290f4df 100644 GIT binary patch literal 2163 zcmd5+Yg7~F8U7M33!q5Qijx#vY-P{`lqwJif|pPrQdgoNWF(ep+0{~(?LIBL%=%P|9;*8FedLZN|%xLFeCz$}iTtYDWk7jVy zf2&Qhm%Yb$Mb%tw@D>Dfyk|}RaQ(`uJ6;n{m|%uF`C-H6?5~`0<`1u^-+2Dj{HeK@ z=W^NAI@yxTAKR{Ba7wL<{cUS;jzZZ@QGDBGSY-HhHG9i#q6|A1ht-DhFl?Spb_G%C z^!2i4Bnb8Tifyr(T$H;>JGeaq86O`Hho{i#4%b$K@9F2g)99V2YBd{CaZ(M^k9Xt7 zjYxikcKCAqArR;5<0D(%Cqv?O~54^UQ}Pl=EdiL$9{TwVIam zm(&b*(0GcET=b?|f;>y6)&8H2o7c zsY*JXmE7@&LIx3);pbLnU)^son`!Hr5T(2uXo_1@q^51Q?%p-z6h>8?y$>R?otql;5k?{kD7r-G3s&w9rG0 z_7F=h?c1%0oVZO=ZU-MIB4VR9hlB!VU*g19yPV7ax2=f_+!0)b!Dxg*m<;6Q5=vUy zRybU#RKhs{B2}mJ&)L2K{xpQk<4Ne*DG1UdSpi8Rp+;2pseFc1EUOEb$57K|{nKYo zd)ZUFWoOxETpaR`{FpocM5LbxlA<@oBE*q3(no|g1QiwfAu?057dh%}XQ>%}5vHFg<;qC-#lcl+=$MbO?pcSd(z=ypOLKP z=q|KYzoKC|j+PfAu|fkqL-&3QEu6ldITy!~x+f1mnHodQ%nJj4TO*x&qaOTN%#Bvw z#HE_c9S!TmRb{}fn&!3F_lmT=!X8B^SX(e zXO4zhZKL3co`2{9B){s@7x=*wwT~m+IK_$lBm8;}Zf(zJo=7a&bt|hqknEbs7uH8$ zomtGu-aW3!*QrvD9T=$b-*C`AhlqFM3=+4M;oX1pi`&mm!RG;bBF~=YY&Lqs?W=EiOht;O#Yc)mxfY#tU9EPiqJ%t zwp31EJV!2Sw6X%KZgQbAhrkV?6Kh>i&m9- zl>DXW<4}J6@#zeUch9Q*=LHMZL-@);b=tNZqD!fU3m^=WFlyv2a*2zpwwLiVUDY`vNaZYIHZESdPOQ7N>ey zmHDQm!m`YzFoIer#ghg8xG(s9EEenQ`UYmRR%ZeQv==2}alRwr7H-W5-Px=lx%uR$wju#CDOjOkfLW7;OZu~rm_bT^Zm+4{y7gOY^7xQaN< l`eXQf=H%RSDY`{}9`d-Mbs$FnwCL>?h6EnQR3C`F@OPN{shI!( literal 2556 zcmd6oc~DbX7Kd*_*wG*esL0X|jjbSxq67m5A~et-3J3%dg3zFVKu}p^36W`AN!X?U zSsEoGiX&=>z<>ly8ie#<*hEG;VKb3M!X7X{An9kdHI6maUETB7ysBI8oqKMbbMJS~ z@4oaCZjKvNwy6LBHaI)kdjJ4~K4Cyf0eYRja6j~ebUz=8p+F8! zy^2cbBSI2qhMAarkq1!Q&Om?*n?Oz>AU#I_BV%A_4g=}Rz{wTZ2El=b$eE@6UMzlb z{DHau5oMGOoRo)Pkz9b&!x)9C+FGyLz$1q&EoF-qBSzz+6DTN0u-wQ$b9Z_nLuXf) zggb8)xOZ2Wub#XOwh)y6GqC1w=lp+gH3gw}=iP(|7f85LskD7vBCgcuIQoo_&Y}Jd z++A_kK?PuH0^2vD0W>s0xhGR1&>+e8d2M1S?)xj~=W-vM%H<6Voc@`|t4z!lUMR`T z%zVH$-6fsjn1ZrE?sdkqy6E8}o`OR24)#wQ8V`Bsq!N%M2OS6NcQDn5725sc18pA-#wL8cz8qBqd2) zGlLc8gdEU$ugD)>qqXzC)|Gol!P|q?;9OE#tMXfYmM!OggPH*>ryvQa?#2SH22gcX z>b?PR1T5(gf~BDjcl`#KDu2N;La??w^te4)ckMMtr32i4EU8x=xU`j;2rNFh=$~8~ zFByQM^$IgEl2^ z$0cjNBHQ+U0TzmVL5M<9dMfc%~;KSb^|fiKM*86PRv; zb?X)U!8W58S*v~PVA$~X40VQM1gI{*0{dJHpMn1`7fv8x%{$ug$e8A*b#*>V#%D`H zUs!jxwSC>EJBK2~w<*}J$<_3X;spmgyY`4scgF96i7ZG;AEoyD(LV|FDGo`!L?95( zCoRvNi7nR?SR8Px?h!2vH6@K|kI#&34)uVz<-`=nT4g~+Ws_|+_q$b_vFSUy7wZ-O zv<7vAu)ME*0_Yyc4hSrS;Uztymt@;PDA;!yy$@f+JXEr<`7E8y|8yXWh6Qqdc=6T> zUmrontpabvq?;hkkf80WUjCtRKf*pgRYr|$Ez9w4TDKBdP+}gcSla~48A@T?s>w)b zd%w#I1T8I3930~D{4US)TgB1|^Da0`BOPuql-*xi(P*hSKR?NZnSrN7x#rkvvV+ZFfw##0CMr@w zZ0wRBf^}6@r+u2=O2K!QVq}l{S6k`CMauNWrfk}yf6y>v@*R^W?u+dJD_KuVULV$- z9b`t9MNHjU-s|76Szc!K-a!^Ymu-Hde${~HfJysHJCo>`y(csz7Hy%Y3HJFwjPqs} z9L}&!smZTtLn}yOT%&%0!u+Y8tk>TO(mhuOgYsYLY6lobccmwfQRD+DOftN1&6hb3`9?s{3)4~cXe;@Waj(g4)dA|2+C zkX^C%K#J=NIr^RLE5hu%-U<_1K+|fkHgh)murUbiEGw+U9?9n?@jXT)@~rB!UG0(e z{>)z46m%z8QNohXdx;C|=XDZCJ6dkfHYSN@=<6sr7&9eXMNOovEQCDjXLmG-=BdXU zwf)w}`&RqnjyyAtg10eb1VV=PIswCNd2^yp9&kL}Sq^si>wM|ryWYFv**7A)Gu(JtQxdUBE#~0_op>5)uTYk^tZ~fnzAF-@>~i(9HrL diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/gui/sprites/widget/move_down.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/gui/sprites/widget/move_down.png new file mode 100644 index 0000000000000000000000000000000000000000..57e9a4199651ba94f1bf40de32641b0e1816801b GIT binary patch literal 143 zcmeAS@N?(olHy`uVBq!ia0vp^>>$j+1|*LJg*>X`HF;Rh!UzR4;)tF-pyGAJl*Q}0ZV+WMxg^!wJF nD?iyE94{*n(=~Q2`tye&=%tLFsUY_upot8gu6{1-oD!M<$a*d! literal 0 HcmV?d00001 diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/gui/sprites/widget/move_down_disabled.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/gui/sprites/widget/move_down_disabled.png new file mode 100644 index 0000000000000000000000000000000000000000..81a7ed7ad513ea20ac8974a0139d0451bb2b6376 GIT binary patch literal 142 zcmeAS@N?(olHy`uVBq!ia0vp^>>$j+1|*LJg>$j+1|*LJgX`HF;Rh!UzR4;)tF-pyG90+OUA;3sYU`V}-j1y~ oSAMcTI9^sDrfck4^yd%5!kx+tcV*@j08M1@boFyt=akR{02fCvH2?qr literal 0 HcmV?d00001 diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/gui/sprites/widget/move_up.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/gui/sprites/widget/move_up.png new file mode 100644 index 0000000000000000000000000000000000000000..c6621f7b6138747faaacce6efb5cb7f7db8a728f GIT binary patch literal 140 zcmeAS@N?(olHy`uVBq!ia0vp^>>$j+1|*LJg_JBFY5pR literal 0 HcmV?d00001 diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/gui/sprites/widget/move_up_disabled.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/gui/sprites/widget/move_up_disabled.png new file mode 100644 index 0000000000000000000000000000000000000000..5e0f17dbbe678b26e2d1c39f2a29a884e62ba24c GIT binary patch literal 141 zcmeAS@N?(olHy`uVBq!ia0vp^>>$j+1|*LJglidzcwie7Bu7HdD>$j+1|*LJglc*X36J7BS*tQ($BdbY&gI4HnG{~W-L~^u@Fji5M@!D0 l*(~;Bi}j*a$G(--Fr1K5C~s4dd;m0#!PC{xWt~$(699;+FLD3? literal 0 HcmV?d00001 diff --git a/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/fortune_1_upgrade.json b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/fortune_1_upgrade.json index e3610d9ac..8c7a4bf15 100644 --- a/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/fortune_1_upgrade.json +++ b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/fortune_1_upgrade.json @@ -1,7 +1,6 @@ { "type": "refinedstorage2:upgrade_with_enchanted_book", - "enchantment": { - "id": "minecraft:fortune" - }, + "enchantment": "minecraft:fortune", + "level": 1, "result": "refinedstorage2:fortune_1_upgrade" } \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/fortune_2_upgrade.json b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/fortune_2_upgrade.json index a5496355c..68a36dd30 100644 --- a/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/fortune_2_upgrade.json +++ b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/fortune_2_upgrade.json @@ -1,8 +1,6 @@ { "type": "refinedstorage2:upgrade_with_enchanted_book", - "enchantment": { - "level": 2, - "id": "minecraft:fortune" - }, + "enchantment": "minecraft:fortune", + "level": 2, "result": "refinedstorage2:fortune_2_upgrade" } \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/fortune_3_upgrade.json b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/fortune_3_upgrade.json index ed5f27ccd..51a503666 100644 --- a/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/fortune_3_upgrade.json +++ b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/fortune_3_upgrade.json @@ -1,8 +1,6 @@ { "type": "refinedstorage2:upgrade_with_enchanted_book", - "enchantment": { - "level": 3, - "id": "minecraft:fortune" - }, + "enchantment": "minecraft:fortune", + "level": 3, "result": "refinedstorage2:fortune_3_upgrade" } \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/silk_touch_upgrade.json b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/silk_touch_upgrade.json index 826ad49f3..c2f8c20fb 100644 --- a/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/silk_touch_upgrade.json +++ b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/silk_touch_upgrade.json @@ -1,7 +1,5 @@ { "type": "refinedstorage2:upgrade_with_enchanted_book", - "enchantment": { - "id": "minecraft:silk_touch" - }, + "enchantment": "minecraft:silk_touch", "result": "refinedstorage2:silk_touch_upgrade" } \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/TestPlatform.java b/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/TestPlatform.java index cde1aed42..9dc2cf9c9 100644 --- a/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/TestPlatform.java +++ b/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/TestPlatform.java @@ -36,8 +36,8 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.CraftingRecipe; -import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.state.BlockState; @@ -177,7 +177,7 @@ public boolean placeFluid(final Level level, final BlockPos pos, final Direction @Override public ItemStack getBlockAsItemStack(final Block block, final BlockState state, final Direction direction, - final BlockGetter level, + final LevelReader level, final BlockPos pos, final Player player) { throw new UnsupportedOperationException(); } diff --git a/refinedstorage2-platform-fabric/build.gradle b/refinedstorage2-platform-fabric/build.gradle index 9f1ed55e3..3b0b5bbb4 100644 --- a/refinedstorage2-platform-fabric/build.gradle +++ b/refinedstorage2-platform-fabric/build.gradle @@ -63,7 +63,9 @@ dependencies { modRuntimeOnly fabric.wthit // https://www.curseforge.com/minecraft/mc-mods/trinkets/files - modImplementation "dev.emi:trinkets:3.7.1" + modImplementation "dev.emi:trinkets:3.8.0" + modImplementation "dev.onyxstudios.cardinal-components-api:cardinal-components-base:5.4.0" + modImplementation "dev.onyxstudios.cardinal-components-api:cardinal-components-entity:5.4.0" } enablePublishing() diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ClientModInitializerImpl.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ClientModInitializerImpl.java index 15a13e0d4..8e919c6e7 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ClientModInitializerImpl.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ClientModInitializerImpl.java @@ -15,13 +15,13 @@ import com.refinedmods.refinedstorage2.platform.common.networking.NetworkCardItemPropertyFunction; import com.refinedmods.refinedstorage2.platform.common.storagemonitor.StorageMonitorBlockEntityRenderer; import com.refinedmods.refinedstorage2.platform.common.support.network.bounditem.NetworkBoundItemItemPropertyFunction; +import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; import com.refinedmods.refinedstorage2.platform.common.support.tooltip.CompositeClientTooltipComponent; import com.refinedmods.refinedstorage2.platform.common.support.tooltip.HelpClientTooltipComponent; import com.refinedmods.refinedstorage2.platform.common.support.tooltip.ResourceClientTooltipComponent; import com.refinedmods.refinedstorage2.platform.common.upgrade.RegulatorUpgradeItem; import com.refinedmods.refinedstorage2.platform.common.upgrade.UpgradeDestinationClientTooltipComponent; import com.refinedmods.refinedstorage2.platform.fabric.mixin.ItemPropertiesAccessor; -import com.refinedmods.refinedstorage2.platform.fabric.packet.PacketIds; import com.refinedmods.refinedstorage2.platform.fabric.packet.s2c.EnergyInfoPacket; import com.refinedmods.refinedstorage2.platform.fabric.packet.s2c.GridActivePacket; import com.refinedmods.refinedstorage2.platform.fabric.packet.s2c.GridClearPacket; @@ -119,7 +119,7 @@ private void setRenderLayers() { setCutout(Blocks.INSTANCE.getCreativePortableGrid()); } - private void setCutout(final BlockColorMap blockMap) { + private void setCutout(final BlockColorMap blockMap) { blockMap.values().forEach(this::setCutout); } diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ModInitializerImpl.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ModInitializerImpl.java index 3f30879be..c5fbfe0f0 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ModInitializerImpl.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ModInitializerImpl.java @@ -1,8 +1,6 @@ package com.refinedmods.refinedstorage2.platform.fabric; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.support.energy.EnergyBlockEntity; -import com.refinedmods.refinedstorage2.platform.api.support.energy.EnergyItem; import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.AbstractModInitializer; @@ -12,6 +10,7 @@ import com.refinedmods.refinedstorage2.platform.common.content.Blocks; import com.refinedmods.refinedstorage2.platform.common.content.CreativeModeTabItems; import com.refinedmods.refinedstorage2.platform.common.content.DirectRegistryCallback; +import com.refinedmods.refinedstorage2.platform.common.content.Items; import com.refinedmods.refinedstorage2.platform.common.content.MenuTypeFactory; import com.refinedmods.refinedstorage2.platform.common.grid.WirelessGridItem; import com.refinedmods.refinedstorage2.platform.common.iface.InterfaceBlockEntity; @@ -20,6 +19,7 @@ import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.AbstractDiskDriveBlockEntity; import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridType; import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseBlock; +import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; import com.refinedmods.refinedstorage2.platform.common.upgrade.RegulatorUpgradeItem; import com.refinedmods.refinedstorage2.platform.common.util.ServerEventQueue; import com.refinedmods.refinedstorage2.platform.fabric.exporter.FabricStorageExporterTransferStrategyFactory; @@ -28,7 +28,6 @@ import com.refinedmods.refinedstorage2.platform.fabric.grid.strategy.ItemGridExtractionStrategy; import com.refinedmods.refinedstorage2.platform.fabric.grid.strategy.ItemGridScrollingStrategy; import com.refinedmods.refinedstorage2.platform.fabric.importer.FabricStorageImporterTransferStrategyFactory; -import com.refinedmods.refinedstorage2.platform.fabric.packet.PacketIds; import com.refinedmods.refinedstorage2.platform.fabric.packet.c2s.CraftingGridClearPacket; import com.refinedmods.refinedstorage2.platform.fabric.packet.c2s.CraftingGridRecipeTransferPacket; import com.refinedmods.refinedstorage2.platform.fabric.packet.c2s.GridExtractPacket; @@ -55,24 +54,18 @@ import java.util.Optional; import java.util.function.Function; import java.util.function.Predicate; -import javax.annotation.Nullable; import me.shedaniel.autoconfig.AutoConfig; import me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; import net.fabricmc.fabric.api.event.player.UseBlockCallback; -import net.fabricmc.fabric.api.lookup.v1.block.BlockApiLookup; -import net.fabricmc.fabric.api.lookup.v1.item.ItemApiLookup; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerType; -import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext; import net.fabricmc.fabric.api.transfer.v1.fluid.FluidConstants; import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorage; import net.fabricmc.fabric.api.transfer.v1.item.InventoryStorage; import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; import net.minecraft.core.Registry; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.world.Container; @@ -83,7 +76,6 @@ import net.minecraft.world.inventory.MenuType; import net.minecraft.world.item.CreativeModeTab; 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; @@ -339,33 +331,25 @@ private void registerItemStorage(final Predicate() { - @Override - @Nullable - public EnergyStorage find(final Level world, - final BlockPos pos, - final BlockState state, - @Nullable final BlockEntity blockEntity, - final Direction context) { - if (blockEntity instanceof EnergyBlockEntity energyBlockEntity) { - return new EnergyStorageAdapter(energyBlockEntity.getEnergyStorage()); - } - return null; - } - }); + EnergyStorage.SIDED.registerForBlockEntity( + (blockEntity, context) -> new EnergyStorageAdapter(blockEntity.getEnergyStorage()), + BlockEntities.INSTANCE.getController() + ); + EnergyStorage.SIDED.registerForBlockEntity( + (blockEntity, context) -> new EnergyStorageAdapter(blockEntity.getEnergyStorage()), + BlockEntities.INSTANCE.getPortableGrid() + ); } private void registerEnergyItemProviders() { - EnergyStorage.ITEM.registerFallback(new ItemApiLookup.ItemApiProvider<>() { - @Override - @Nullable - public EnergyStorage find(final ItemStack itemStack, final ContainerItemContext context) { - if (itemStack.getItem() instanceof EnergyItem energyItem) { - return energyItem.createEnergyStorage(itemStack).map(EnergyStorageAdapter::new).orElse(null); - } - return null; - } - }); + EnergyStorage.ITEM.registerForItems( + (stack, context) -> new EnergyStorageAdapter(Items.INSTANCE.getWirelessGrid().createEnergyStorage(stack)), + Items.INSTANCE.getWirelessGrid() + ); + Items.INSTANCE.getControllers().forEach(controller -> EnergyStorage.ITEM.registerForItems( + (stack, context) -> new EnergyStorageAdapter(controller.get().createEnergyStorage(stack)), + controller.get() + )); } private void registerTickHandler() { diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/PlatformImpl.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/PlatformImpl.java index b366bcfb3..b604fe442 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/PlatformImpl.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/PlatformImpl.java @@ -72,9 +72,9 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.item.crafting.CraftingRecipe; -import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.LiquidBlockContainer; @@ -289,7 +289,8 @@ public boolean placeFluid( final boolean replaceable = blockState.canBeReplaced(content); final boolean canPlace = blockState.isAir() || replaceable - || (block instanceof LiquidBlockContainer lbc && lbc.canPlaceLiquid(level, pos, blockState, content)); + || (block instanceof LiquidBlockContainer lbc + && lbc.canPlaceLiquid(player, level, pos, blockState, content)); if (!canPlace || blockState.getFluidState().isSource()) { return false; } else if (block instanceof LiquidBlockContainer lbc && content == Fluids.WATER) { @@ -332,7 +333,7 @@ private void playEmptySound(final Fluid content, final Player player, final Leve public ItemStack getBlockAsItemStack(final Block block, final BlockState state, final Direction direction, - final BlockGetter level, + final LevelReader level, final BlockPos position, final Player player) { return block.getCloneItemStack(level, position, state); diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/ClientToServerCommunicationsImpl.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/ClientToServerCommunicationsImpl.java index 8ca5e7363..d208274f4 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/ClientToServerCommunicationsImpl.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/ClientToServerCommunicationsImpl.java @@ -9,8 +9,8 @@ import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.support.ClientToServerCommunications; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.PropertyType; +import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; import com.refinedmods.refinedstorage2.platform.common.util.PacketUtil; -import com.refinedmods.refinedstorage2.platform.fabric.packet.PacketIds; import java.util.List; import java.util.UUID; diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/s2c/ServerToClientCommunicationsImpl.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/s2c/ServerToClientCommunicationsImpl.java index dcc73b274..35cc62353 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/s2c/ServerToClientCommunicationsImpl.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/s2c/ServerToClientCommunicationsImpl.java @@ -7,8 +7,8 @@ import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceAmountTemplate; import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterStatus; import com.refinedmods.refinedstorage2.platform.common.support.ServerToClientCommunications; +import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; import com.refinedmods.refinedstorage2.platform.common.util.PacketUtil; -import com.refinedmods.refinedstorage2.platform.fabric.packet.PacketIds; import java.util.UUID; import java.util.function.Consumer; diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/RefinedStorageREIClientPlugin.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/RefinedStorageREIClientPlugin.java index a1dc1c257..5e52837ab 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/RefinedStorageREIClientPlugin.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/RefinedStorageREIClientPlugin.java @@ -7,9 +7,8 @@ import com.refinedmods.refinedstorage2.platform.common.content.ContentIds; import com.refinedmods.refinedstorage2.platform.common.content.Items; import com.refinedmods.refinedstorage2.platform.common.content.Tags; +import com.refinedmods.refinedstorage2.platform.common.controller.ControllerBlockItem; import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseScreen; -import com.refinedmods.refinedstorage2.platform.common.support.ColorableBlock; -import com.refinedmods.refinedstorage2.platform.common.support.energy.EnergyItemHelperImpl; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -27,7 +26,6 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; import net.minecraft.world.item.Item; -import net.minecraft.world.level.block.Block; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; @@ -73,8 +71,12 @@ public void registerCollapsibleEntries(final CollapsibleEntryRegistry registry) registry.group( createIdentifier("fully_charged_controller"), createTranslation("block", "controller.rei_fully_charged"), - EnergyItemHelperImpl.createAllAtEnergyCapacity(Items.INSTANCE.getControllers()) - .map(EntryStacks::of).collect(Collectors.toList()) + Items.INSTANCE.getControllers() + .stream() + .map(Supplier::get) + .map(ControllerBlockItem::createAtEnergyCapacity) + .map(EntryStacks::of) + .collect(Collectors.toList()) ); groupItems( registry, @@ -105,7 +107,7 @@ public void registerExclusionZones(final ExclusionZones zones) { @SuppressWarnings("UnstableApiUsage") private static void groupItems( final CollapsibleEntryRegistry registry, - final BlockColorMap> blocks, + final BlockColorMap blocks, final ResourceLocation itemIdentifier, final TagKey tag ) { diff --git a/refinedstorage2-platform-fabric/src/main/resources/fabric.mod.json b/refinedstorage2-platform-fabric/src/main/resources/fabric.mod.json index 8b04bc9c4..e9adbd5d4 100644 --- a/refinedstorage2-platform-fabric/src/main/resources/fabric.mod.json +++ b/refinedstorage2-platform-fabric/src/main/resources/fabric.mod.json @@ -45,7 +45,7 @@ "depends": { "fabricloader": ">=0.14.6", "fabric-api": "*", - "minecraft": "1.20.1", + "minecraft": "1.20.4", "java": ">=17", "cloth-config2": "*", "team_reborn_energy": "*" diff --git a/refinedstorage2-platform-forge/.gitignore b/refinedstorage2-platform-forge/.gitignore index 737e26b00..643cb1816 100644 --- a/refinedstorage2-platform-forge/.gitignore +++ b/refinedstorage2-platform-forge/.gitignore @@ -1 +1 @@ -run/ \ No newline at end of file +runs/ \ No newline at end of file diff --git a/refinedstorage2-platform-forge/build.gradle b/refinedstorage2-platform-forge/build.gradle index 2223434c7..3e5fc0444 100644 --- a/refinedstorage2-platform-forge/build.gradle +++ b/refinedstorage2-platform-forge/build.gradle @@ -17,19 +17,19 @@ forgeProject("refinedstorage2", project(":refinedstorage2-platform-common"), api archivesBaseName = 'refinedstorage2-platform-forge' dependencies { - compileOnly fg.deobf(common.jei.api.get()) - testCompileOnly fg.deobf(common.jei.api.get()) - compileOnly fg.deobf(forge.jei.api.get()) - runtimeOnly fg.deobf(forge.jei.impl.get()) + compileOnly common.jei.api + testCompileOnly common.jei.api + compileOnly forge.jei.api + runtimeOnly forge.jei.impl - compileOnly fg.deobf(forge.rei.impl.get()) - compileOnly fg.deobf(forge.rei.architectury.get()) - compileOnly fg.deobf(forge.rei.cloth.math.get()) -// runtimeOnly fg.deobf(forge.rei.impl.get()) -// runtimeOnly fg.deobf(forge.rei.architectury.get()) + compileOnly forge.rei.impl + compileOnly forge.rei.architectury + compileOnly forge.rei.cloth.math +// runtimeOnly forge.rei.impl +// runtimeOnly forge.rei.architectury - runtimeOnly fg.deobf("top.theillusivec4.curios:curios-forge:5.2.0+1.20.1") - compileOnly fg.deobf("top.theillusivec4.curios:curios-forge:5.2.0+1.20.1:api") + runtimeOnly "top.theillusivec4.curios:curios-neoforge:7.1.0+1.20.4" + compileOnly "top.theillusivec4.curios:curios-neoforge:7.1.0+1.20.4:api" } enablePublishing() diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ClientModInitializer.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ClientModInitializer.java index b263d2a08..9c36c3628 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ClientModInitializer.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ClientModInitializer.java @@ -30,7 +30,6 @@ import com.mojang.blaze3d.platform.InputConstants; import net.minecraft.client.KeyMapping; -import net.minecraft.client.gui.screens.MenuScreens; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.MenuAccess; import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; @@ -38,16 +37,17 @@ import net.minecraft.client.renderer.item.ItemProperties; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.MenuType; -import net.minecraftforge.client.event.InputEvent; -import net.minecraftforge.client.event.ModelEvent; -import net.minecraftforge.client.event.RegisterClientTooltipComponentFactoriesEvent; -import net.minecraftforge.client.event.RegisterKeyMappingsEvent; -import net.minecraftforge.client.settings.KeyConflictContext; -import net.minecraftforge.client.settings.KeyModifier; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.ModList; -import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.ModList; +import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; +import net.neoforged.neoforge.client.event.InputEvent; +import net.neoforged.neoforge.client.event.ModelEvent; +import net.neoforged.neoforge.client.event.RegisterClientTooltipComponentFactoriesEvent; +import net.neoforged.neoforge.client.event.RegisterKeyMappingsEvent; +import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent; +import net.neoforged.neoforge.client.settings.KeyConflictContext; +import net.neoforged.neoforge.client.settings.KeyModifier; +import net.neoforged.neoforge.common.NeoForge; import org.lwjgl.glfw.GLFW; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -66,17 +66,8 @@ private ClientModInitializer() { @SubscribeEvent public static void onClientSetup(final FMLClientSetupEvent e) { - MinecraftForge.EVENT_BUS.addListener(ClientModInitializer::onKeyInput); + NeoForge.EVENT_BUS.addListener(ClientModInitializer::onKeyInput); e.enqueueWork(ClientModInitializer::registerModelPredicates); - e.enqueueWork(() -> registerScreens(new ScreenRegistration() { - @Override - public > void register( - final MenuType type, - final ScreenConstructor factory - ) { - MenuScreens.register(type, factory::create); - } - })); e.enqueueWork(ClientModInitializer::registerItemProperties); registerBlockEntityRenderer(); registerGridSynchronizers(); @@ -101,8 +92,21 @@ private static void registerModelPredicates() { @SubscribeEvent public static void onRegisterModelGeometry(final ModelEvent.RegisterGeometryLoaders e) { registerDiskModels(); - e.register(DISK_DRIVE.getPath(), new DiskDriveGeometryLoader()); - e.register(PORTABLE_GRID.getPath(), new PortableGridGeometryLoader()); + e.register(DISK_DRIVE, new DiskDriveGeometryLoader()); + e.register(PORTABLE_GRID, new PortableGridGeometryLoader()); + } + + @SubscribeEvent + public static void onRegisterMenuScreens(final RegisterMenuScreensEvent e) { + registerScreens(new ScreenRegistration() { + @Override + public > void register( + final MenuType type, + final ScreenConstructor factory + ) { + e.register(type, factory::create); + } + }); } @SubscribeEvent diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ConfigImpl.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ConfigImpl.java index 3d4344c94..10348249b 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ConfigImpl.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ConfigImpl.java @@ -10,14 +10,14 @@ import java.util.Optional; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.common.ForgeConfigSpec; +import net.neoforged.neoforge.common.ModConfigSpec; public class ConfigImpl implements Config { private static final String ENERGY_USAGE = "energyUsage"; private static final String ENERGY_CAPACITY = "energyCapacity"; - private final ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder(); - private final ForgeConfigSpec spec; + private final ModConfigSpec.Builder builder = new ModConfigSpec.Builder(); + private final ModConfigSpec spec; private final SimpleEnergyUsageEntry cable; private final ControllerEntry controller; @@ -82,7 +82,7 @@ public ConfigImpl() { spec = builder.build(); } - public ForgeConfigSpec getSpec() { + public ModConfigSpec getSpec() { return spec; } @@ -192,7 +192,7 @@ public PortableGridEntry getPortableGrid() { } private class SimpleEnergyUsageEntryImpl implements SimpleEnergyUsageEntry { - private final ForgeConfigSpec.LongValue energyUsage; + private final ModConfigSpec.LongValue energyUsage; SimpleEnergyUsageEntryImpl(final String path, final String readableName, final long defaultValue) { builder.push(path); @@ -209,7 +209,7 @@ public long getEnergyUsage() { } private class ControllerEntryImpl implements ControllerEntry { - private final ForgeConfigSpec.LongValue energyCapacity; + private final ModConfigSpec.LongValue energyCapacity; private ControllerEntryImpl() { builder.push("controller"); @@ -225,8 +225,8 @@ public long getEnergyCapacity() { } private class DiskDriveEntryImpl implements DiskDriveEntry { - private final ForgeConfigSpec.LongValue energyUsage; - private final ForgeConfigSpec.LongValue energyUsagePerDisk; + private final ModConfigSpec.LongValue energyUsage; + private final ModConfigSpec.LongValue energyUsagePerDisk; private DiskDriveEntryImpl() { builder.push("diskDrive"); @@ -249,19 +249,19 @@ public long getEnergyUsagePerDisk() { } private class GridEntryImpl implements GridEntry { - private final ForgeConfigSpec.BooleanValue largeFont; - private final ForgeConfigSpec.IntValue maxRowsStretch; - private final ForgeConfigSpec.BooleanValue preventSortingWhileShiftIsDown; - private final ForgeConfigSpec.BooleanValue detailedTooltip; - private final ForgeConfigSpec.BooleanValue rememberSearchQuery; - private final ForgeConfigSpec.LongValue energyUsage; - private final ForgeConfigSpec.BooleanValue smoothScrolling; - private final ForgeConfigSpec.BooleanValue autoSelected; - private final ForgeConfigSpec.ConfigValue synchronizer; - private final ForgeConfigSpec.ConfigValue storageChannelType; - private final ForgeConfigSpec.EnumValue sortingDirection; - private final ForgeConfigSpec.EnumValue sortingType; - private final ForgeConfigSpec.EnumValue size; + private final ModConfigSpec.BooleanValue largeFont; + private final ModConfigSpec.IntValue maxRowsStretch; + private final ModConfigSpec.BooleanValue preventSortingWhileShiftIsDown; + private final ModConfigSpec.BooleanValue detailedTooltip; + private final ModConfigSpec.BooleanValue rememberSearchQuery; + private final ModConfigSpec.LongValue energyUsage; + private final ModConfigSpec.BooleanValue smoothScrolling; + private final ModConfigSpec.BooleanValue autoSelected; + private final ModConfigSpec.ConfigValue synchronizer; + private final ModConfigSpec.ConfigValue storageChannelType; + private final ModConfigSpec.EnumValue sortingDirection; + private final ModConfigSpec.EnumValue sortingType; + private final ModConfigSpec.EnumValue size; GridEntryImpl() { builder.push("grid"); @@ -420,8 +420,8 @@ public void clearStorageChannelType() { } private class CraftingGridEntryImpl implements CraftingGridEntry { - private final ForgeConfigSpec.LongValue energyUsage; - private final ForgeConfigSpec.EnumValue craftingMatrixCloseBehavior; + private final ModConfigSpec.LongValue energyUsage; + private final ModConfigSpec.EnumValue craftingMatrixCloseBehavior; CraftingGridEntryImpl() { builder.push("craftingGrid"); @@ -446,11 +446,11 @@ public CraftingGridMatrixCloseBehavior getCraftingMatrixCloseBehavior() { } private class StorageBlockEntryImpl implements StorageBlockEntry { - private final ForgeConfigSpec.LongValue oneKEnergyUsage; - private final ForgeConfigSpec.LongValue fourKEnergyUsage; - private final ForgeConfigSpec.LongValue sixteenKEnergyUsage; - private final ForgeConfigSpec.LongValue sixtyFourKEnergyUsage; - private final ForgeConfigSpec.LongValue creativeUsage; + private final ModConfigSpec.LongValue oneKEnergyUsage; + private final ModConfigSpec.LongValue fourKEnergyUsage; + private final ModConfigSpec.LongValue sixteenKEnergyUsage; + private final ModConfigSpec.LongValue sixtyFourKEnergyUsage; + private final ModConfigSpec.LongValue creativeUsage; StorageBlockEntryImpl() { builder.push("storageBlock"); @@ -499,11 +499,11 @@ public long getCreativeEnergyUsage() { } private class FluidStorageBlockEntryImpl implements FluidStorageBlockEntry { - private final ForgeConfigSpec.LongValue sixtyFourBEnergyUsage; - private final ForgeConfigSpec.LongValue twoHundredFiftySixBEnergyUsage; - private final ForgeConfigSpec.LongValue thousandTwentyFourBEnergyUsage; - private final ForgeConfigSpec.LongValue fourThousandNinetySixBEnergyUsage; - private final ForgeConfigSpec.LongValue creativeUsage; + private final ModConfigSpec.LongValue sixtyFourBEnergyUsage; + private final ModConfigSpec.LongValue twoHundredFiftySixBEnergyUsage; + private final ModConfigSpec.LongValue thousandTwentyFourBEnergyUsage; + private final ModConfigSpec.LongValue fourThousandNinetySixBEnergyUsage; + private final ModConfigSpec.LongValue creativeUsage; FluidStorageBlockEntryImpl() { builder.push("fluidStorageBlock"); @@ -577,16 +577,16 @@ public long getCreativeEnergyUsage() { } private class UpgradeEntryImpl implements UpgradeEntry { - private final ForgeConfigSpec.LongValue speedUpgradeEnergyUsage; - private final ForgeConfigSpec.LongValue stackUpgradeEnergyUsage; - private final ForgeConfigSpec.LongValue fortune1UpgradeEnergyUsage; - private final ForgeConfigSpec.LongValue fortune2UpgradeEnergyUsage; - private final ForgeConfigSpec.LongValue fortune3UpgradeEnergyUsage; - private final ForgeConfigSpec.LongValue silkTouchUpgradeEnergyUsage; - private final ForgeConfigSpec.LongValue regulatorUpgradeEnergyUsage; - private final ForgeConfigSpec.LongValue rangeUpgradeEnergyUsage; - private final ForgeConfigSpec.LongValue creativeRangeUpgradeEnergyUsage; - private final ForgeConfigSpec.IntValue rangeUpgradeRange; + private final ModConfigSpec.LongValue speedUpgradeEnergyUsage; + private final ModConfigSpec.LongValue stackUpgradeEnergyUsage; + private final ModConfigSpec.LongValue fortune1UpgradeEnergyUsage; + private final ModConfigSpec.LongValue fortune2UpgradeEnergyUsage; + private final ModConfigSpec.LongValue fortune3UpgradeEnergyUsage; + private final ModConfigSpec.LongValue silkTouchUpgradeEnergyUsage; + private final ModConfigSpec.LongValue regulatorUpgradeEnergyUsage; + private final ModConfigSpec.LongValue rangeUpgradeEnergyUsage; + private final ModConfigSpec.LongValue creativeRangeUpgradeEnergyUsage; + private final ModConfigSpec.IntValue rangeUpgradeRange; UpgradeEntryImpl() { builder.push("upgrade"); @@ -680,10 +680,10 @@ public int getRangeUpgradeRange() { } private class WirelessGridEntryImpl implements WirelessGridEntry { - private final ForgeConfigSpec.LongValue energyCapacity; - private final ForgeConfigSpec.LongValue openEnergyUsage; - private final ForgeConfigSpec.LongValue extractEnergyUsage; - private final ForgeConfigSpec.LongValue insertEnergyUsage; + private final ModConfigSpec.LongValue energyCapacity; + private final ModConfigSpec.LongValue openEnergyUsage; + private final ModConfigSpec.LongValue extractEnergyUsage; + private final ModConfigSpec.LongValue insertEnergyUsage; WirelessGridEntryImpl() { builder.push("wirelessGrid"); @@ -716,8 +716,8 @@ public long getInsertEnergyUsage() { } private class WirelessTransmitterEntryImpl implements WirelessTransmitterEntry { - private final ForgeConfigSpec.LongValue energyUsage; - private final ForgeConfigSpec.IntValue baseRange; + private final ModConfigSpec.LongValue energyUsage; + private final ModConfigSpec.IntValue baseRange; WirelessTransmitterEntryImpl() { builder.push("wirelessTransmitter"); @@ -740,10 +740,10 @@ public int getBaseRange() { } private class PortableGridEntryImpl implements PortableGridEntry { - private final ForgeConfigSpec.LongValue energyCapacity; - private final ForgeConfigSpec.LongValue openEnergyUsage; - private final ForgeConfigSpec.LongValue extractEnergyUsage; - private final ForgeConfigSpec.LongValue insertEnergyUsage; + private final ModConfigSpec.LongValue energyCapacity; + private final ModConfigSpec.LongValue openEnergyUsage; + private final ModConfigSpec.LongValue extractEnergyUsage; + private final ModConfigSpec.LongValue insertEnergyUsage; PortableGridEntryImpl() { builder.push("portableGrid"); diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ModInitializer.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ModInitializer.java index e89360b73..3fdf498d6 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ModInitializer.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ModInitializer.java @@ -1,423 +1,491 @@ -package com.refinedmods.refinedstorage2.platform.forge; - -import com.refinedmods.refinedstorage2.api.network.energy.EnergyStorage; -import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.support.energy.EnergyBlockEntity; -import com.refinedmods.refinedstorage2.platform.api.support.energy.EnergyItem; -import com.refinedmods.refinedstorage2.platform.common.AbstractModInitializer; -import com.refinedmods.refinedstorage2.platform.common.PlatformProxy; -import com.refinedmods.refinedstorage2.platform.common.content.BlockEntityTypeFactory; -import com.refinedmods.refinedstorage2.platform.common.content.Blocks; -import com.refinedmods.refinedstorage2.platform.common.content.CreativeModeTabItems; -import com.refinedmods.refinedstorage2.platform.common.content.DirectRegistryCallback; -import com.refinedmods.refinedstorage2.platform.common.content.MenuTypeFactory; -import com.refinedmods.refinedstorage2.platform.common.content.RegistryCallback; -import com.refinedmods.refinedstorage2.platform.common.grid.WirelessGridItem; -import com.refinedmods.refinedstorage2.platform.common.iface.InterfaceBlockEntity; -import com.refinedmods.refinedstorage2.platform.common.iface.InterfacePlatformExternalStorageProviderFactory; -import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.AbstractDiskDriveBlockEntity; -import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridType; -import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseBlock; -import com.refinedmods.refinedstorage2.platform.common.upgrade.RegulatorUpgradeItem; -import com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil; -import com.refinedmods.refinedstorage2.platform.common.util.ServerEventQueue; -import com.refinedmods.refinedstorage2.platform.forge.exporter.FluidHandlerExporterTransferStrategyFactory; -import com.refinedmods.refinedstorage2.platform.forge.exporter.ItemHandlerExporterTransferStrategyFactory; -import com.refinedmods.refinedstorage2.platform.forge.grid.strategy.FluidGridExtractionStrategy; -import com.refinedmods.refinedstorage2.platform.forge.grid.strategy.FluidGridInsertionStrategy; -import com.refinedmods.refinedstorage2.platform.forge.grid.strategy.ItemGridExtractionStrategy; -import com.refinedmods.refinedstorage2.platform.forge.grid.strategy.ItemGridScrollingStrategy; -import com.refinedmods.refinedstorage2.platform.forge.importer.FluidHandlerImporterTransferStrategyFactory; -import com.refinedmods.refinedstorage2.platform.forge.importer.ItemHandlerImporterTransferStrategyFactory; -import com.refinedmods.refinedstorage2.platform.forge.packet.NetworkManager; -import com.refinedmods.refinedstorage2.platform.forge.storage.diskdrive.ForgeDiskDriveBlockEntity; -import com.refinedmods.refinedstorage2.platform.forge.storage.externalstorage.FluidHandlerPlatformExternalStorageProviderFactory; -import com.refinedmods.refinedstorage2.platform.forge.storage.externalstorage.ItemHandlerPlatformExternalStorageProviderFactory; -import com.refinedmods.refinedstorage2.platform.forge.storage.portablegrid.ForgePortableGridBlockEntity; -import com.refinedmods.refinedstorage2.platform.forge.support.energy.EnergyStorageAdapter; -import com.refinedmods.refinedstorage2.platform.forge.support.network.bounditem.CuriosSlotReferenceFactory; -import com.refinedmods.refinedstorage2.platform.forge.support.network.bounditem.CuriosSlotReferenceProvider; -import com.refinedmods.refinedstorage2.platform.forge.support.resource.ResourceContainerFluidHandlerAdapter; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Optional; -import java.util.function.Function; -import java.util.function.Supplier; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import net.minecraft.core.Direction; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.core.registries.Registries; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.sounds.SoundEvent; -import net.minecraft.world.Container; -import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.inventory.MenuType; -import net.minecraft.world.item.CreativeModeTab; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.crafting.RecipeSerializer; -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; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.common.capabilities.ICapabilityProvider; -import net.minecraftforge.common.extensions.IForgeMenuType; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.IEnergyStorage; -import net.minecraftforge.event.AttachCapabilitiesEvent; -import net.minecraftforge.event.TickEvent; -import net.minecraftforge.event.entity.player.PlayerInteractEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fluids.capability.IFluidHandler; -import net.minecraftforge.fml.DistExecutor; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; -import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.items.wrapper.InvWrapper; -import net.minecraftforge.registries.DeferredRegister; -import net.minecraftforge.registries.ForgeRegistries; -import net.minecraftforge.registries.RegisterEvent; - -import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; -import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; - -@Mod(IdentifierUtil.MOD_ID) -public class ModInitializer extends AbstractModInitializer { - private final DeferredRegister blockRegistry = - DeferredRegister.create(ForgeRegistries.BLOCKS, IdentifierUtil.MOD_ID); - private final DeferredRegister itemRegistry = - DeferredRegister.create(ForgeRegistries.ITEMS, IdentifierUtil.MOD_ID); - private final DeferredRegister> blockEntityTypeRegistry = - DeferredRegister.create(ForgeRegistries.BLOCK_ENTITY_TYPES, IdentifierUtil.MOD_ID); - private final DeferredRegister> menuTypeRegistry = - DeferredRegister.create(ForgeRegistries.MENU_TYPES, IdentifierUtil.MOD_ID); - private final DeferredRegister soundEventRegistry = - DeferredRegister.create(ForgeRegistries.SOUND_EVENTS, IdentifierUtil.MOD_ID); - private final DeferredRegister> recipeSerializerRegistry = - DeferredRegister.create(ForgeRegistries.RECIPE_SERIALIZERS, IdentifierUtil.MOD_ID); - - public ModInitializer() { - PlatformProxy.loadPlatform(new PlatformImpl(new NetworkManager())); - initializePlatformApi(); - registerAdditionalGridInsertionStrategyFactories(); - registerGridExtractionStrategyFactories(); - registerGridScrollingStrategyFactories(); - registerImporterTransferStrategyFactories(); - registerExporterTransferStrategyFactories(); - registerExternalStorageProviderFactories(); - registerContent(); - registerSounds(); - registerRecipeSerializers(); - registerTickHandler(); - registerSlotReferenceProviders(); - - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> { - FMLJavaModLoadingContext.get().getModEventBus().addListener(ClientModInitializer::onClientSetup); - FMLJavaModLoadingContext.get().getModEventBus().addListener(ClientModInitializer::onRegisterModelGeometry); - FMLJavaModLoadingContext.get().getModEventBus().addListener(ClientModInitializer::onRegisterKeyMappings); - FMLJavaModLoadingContext.get().getModEventBus().addListener( - ClientModInitializer::onRegisterTooltipFactories - ); - }); - - FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onCommonSetup); - FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onRegister); - MinecraftForge.EVENT_BUS.addListener(this::registerWrenchingEvent); - MinecraftForge.EVENT_BUS.addGenericListener(BlockEntity.class, this::registerBlockEntityCapabilities); - MinecraftForge.EVENT_BUS.addGenericListener(ItemStack.class, this::registerItemStackCapabilities); - } - - private void registerAdditionalGridInsertionStrategyFactories() { - PlatformApi.INSTANCE.addGridInsertionStrategyFactory(FluidGridInsertionStrategy::new); - } - - private void registerGridExtractionStrategyFactories() { - PlatformApi.INSTANCE.addGridExtractionStrategyFactory(ItemGridExtractionStrategy::new); - PlatformApi.INSTANCE.addGridExtractionStrategyFactory(FluidGridExtractionStrategy::new); - } - - private void registerGridScrollingStrategyFactories() { - PlatformApi.INSTANCE.addGridScrollingStrategyFactory(ItemGridScrollingStrategy::new); - } - - private void registerImporterTransferStrategyFactories() { - PlatformApi.INSTANCE.getImporterTransferStrategyRegistry().register( - createIdentifier("item"), - new ItemHandlerImporterTransferStrategyFactory() - ); - PlatformApi.INSTANCE.getImporterTransferStrategyRegistry().register( - createIdentifier("fluid"), - new FluidHandlerImporterTransferStrategyFactory() - ); - } - - private void registerExporterTransferStrategyFactories() { - PlatformApi.INSTANCE.getExporterTransferStrategyRegistry().register( - createIdentifier("item"), - new ItemHandlerExporterTransferStrategyFactory() - ); - PlatformApi.INSTANCE.getExporterTransferStrategyRegistry().register( - createIdentifier("fluid"), - new FluidHandlerExporterTransferStrategyFactory() - ); - } - - private void registerExternalStorageProviderFactories() { - PlatformApi.INSTANCE.addExternalStorageProviderFactory(new InterfacePlatformExternalStorageProviderFactory()); - PlatformApi.INSTANCE.addExternalStorageProviderFactory(new ItemHandlerPlatformExternalStorageProviderFactory()); - PlatformApi.INSTANCE.addExternalStorageProviderFactory( - new FluidHandlerPlatformExternalStorageProviderFactory()); - } - - private void registerContent() { - registerBlocks(); - registerItems(); - registerBlockEntities(); - registerMenus(); - } - - private void registerBlocks() { - registerBlocks( - new ForgeRegistryCallback<>(blockRegistry), - ForgeDiskDriveBlockEntity::new, - (pos, state) -> new ForgePortableGridBlockEntity(PortableGridType.NORMAL, pos, state), - (pos, state) -> new ForgePortableGridBlockEntity(PortableGridType.CREATIVE, pos, state) - ); - blockRegistry.register(FMLJavaModLoadingContext.get().getModEventBus()); - } - - private void registerItems() { - registerItems( - new ForgeRegistryCallback<>(itemRegistry), - () -> new RegulatorUpgradeItem(PlatformApi.INSTANCE.getUpgradeRegistry()) { - @Override - public boolean shouldCauseReequipAnimation(final ItemStack oldStack, - final ItemStack newStack, - final boolean slotChanged) { - return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); - } - }, - () -> new WirelessGridItem(false) { - @Override - public boolean shouldCauseReequipAnimation(final ItemStack oldStack, - final ItemStack newStack, - final boolean slotChanged) { - return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); - } - }, - () -> new WirelessGridItem(true) { - @Override - public boolean shouldCauseReequipAnimation(final ItemStack oldStack, - final ItemStack newStack, - final boolean slotChanged) { - return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); - } - } - ); - itemRegistry.register(FMLJavaModLoadingContext.get().getModEventBus()); - } - - private void registerBlockEntities() { - registerBlockEntities( - new ForgeRegistryCallback<>(blockEntityTypeRegistry), - new BlockEntityTypeFactory() { - @Override - public BlockEntityType create(final BlockEntitySupplier factory, - final Block... allowedBlocks) { - return new BlockEntityType<>(factory::create, new HashSet<>(Arrays.asList(allowedBlocks)), null); - } - }, - ForgeDiskDriveBlockEntity::new, - (pos, state) -> new ForgePortableGridBlockEntity(PortableGridType.NORMAL, pos, state), - (pos, state) -> new ForgePortableGridBlockEntity(PortableGridType.CREATIVE, pos, state) - ); - blockEntityTypeRegistry.register(FMLJavaModLoadingContext.get().getModEventBus()); - } - - private void registerMenus() { - registerMenus(new ForgeRegistryCallback<>(menuTypeRegistry), new MenuTypeFactory() { - @Override - public MenuType create(final MenuSupplier supplier) { - return IForgeMenuType.create(supplier::create); - } - }); - menuTypeRegistry.register(FMLJavaModLoadingContext.get().getModEventBus()); - } - - private void registerSounds() { - registerSounds(new ForgeRegistryCallback<>(soundEventRegistry)); - soundEventRegistry.register(FMLJavaModLoadingContext.get().getModEventBus()); - } - - private void registerRecipeSerializers() { - registerRecipeSerializers(new ForgeRegistryCallback<>(recipeSerializerRegistry)); - recipeSerializerRegistry.register(FMLJavaModLoadingContext.get().getModEventBus()); - } - - private void registerTickHandler() { - MinecraftForge.EVENT_BUS.addListener(this::onServerTick); - } - - protected void registerSlotReferenceProviders() { - CuriosSlotReferenceProvider.create().ifPresent(slotReferenceProvider -> { - PlatformApi.INSTANCE.getSlotReferenceFactoryRegistry().register( - createIdentifier("curios"), - CuriosSlotReferenceFactory.INSTANCE - ); - PlatformApi.INSTANCE.addSlotReferenceProvider(slotReferenceProvider); - }); - } - - @SubscribeEvent - public void onCommonSetup(final FMLCommonSetupEvent e) { - registerUpgradeMappings(); - } - - @SubscribeEvent - public void onRegister(final RegisterEvent e) { - e.register( - Registries.LOOT_FUNCTION_TYPE, - helper -> registerLootFunctions(new DirectRegistryCallback<>(BuiltInRegistries.LOOT_FUNCTION_TYPE)) - ); - e.register(Registries.CREATIVE_MODE_TAB, helper -> helper.register( - createIdentifier("general"), - CreativeModeTab.builder() - .title(createTranslation("itemGroup", "general")) - .icon(() -> new ItemStack(Blocks.INSTANCE.getController().getDefault())) - .displayItems((params, output) -> CreativeModeTabItems.append(output::accept)) - .build() - )); - } - - @SubscribeEvent - public void registerWrenchingEvent(final PlayerInteractEvent.RightClickBlock e) { - final Level level = e.getLevel(); - final BlockState state = level.getBlockState(e.getHitVec().getBlockPos()); - if (!(state.getBlock() instanceof AbstractBaseBlock block)) { - return; - } - block.tryUseWrench(state, level, e.getHitVec(), e.getEntity(), e.getHand()).or(() -> block.tryUpdateColor( - state, - level, - e.getHitVec().getBlockPos(), - e.getEntity(), - e.getHand() - )).ifPresent(result -> { - e.setCanceled(true); - e.setCancellationResult(result); - }); - } - - @SubscribeEvent - public void registerBlockEntityCapabilities(final AttachCapabilitiesEvent e) { - if (e.getObject() instanceof EnergyBlockEntity energyBlockEntity) { - registerEnergyBlockEntity(e, energyBlockEntity); - } - if (e.getObject() instanceof AbstractDiskDriveBlockEntity diskDriveBlockEntity) { - registerItemHandler(e, diskDriveBlockEntity, AbstractDiskDriveBlockEntity::getDiskInventory); - } - if (e.getObject() instanceof InterfaceBlockEntity interfaceBlockEntity) { - registerItemHandler(e, interfaceBlockEntity, InterfaceBlockEntity::getExportedResourcesAsContainer); - registerFluidHandler( - e, - interfaceBlockEntity, - blockEntity -> new ResourceContainerFluidHandlerAdapter(blockEntity.getExportedResources()) - ); - } - } - - private void registerItemHandler(final AttachCapabilitiesEvent e, - final T blockEntity, - final Function containerSupplier) { - final LazyOptional capability = LazyOptional.of(() -> new InvWrapper( - containerSupplier.apply(blockEntity) - )); - e.addCapability(createIdentifier("items"), new ICapabilityProvider() { - @Override - @Nonnull - public LazyOptional getCapability(final Capability cap, @Nullable final Direction side) { - if (cap == ForgeCapabilities.ITEM_HANDLER) { - return capability.cast(); - } - return LazyOptional.empty(); - } - }); - } - - private void registerFluidHandler(final AttachCapabilitiesEvent e, - final T blockEntity, - final Function handlerSupplier) { - final LazyOptional capability = LazyOptional.of(() -> handlerSupplier.apply(blockEntity)); - e.addCapability(createIdentifier("fluids"), new ICapabilityProvider() { - @Override - @Nonnull - public LazyOptional getCapability(final Capability cap, @Nullable final Direction side) { - if (cap == ForgeCapabilities.FLUID_HANDLER) { - return capability.cast(); - } - return LazyOptional.empty(); - } - }); - } - - private void registerEnergyBlockEntity(final AttachCapabilitiesEvent e, - final EnergyBlockEntity energyBlockEntity) { - final LazyOptional capability = LazyOptional.of( - () -> new EnergyStorageAdapter(energyBlockEntity.getEnergyStorage()) - ); - e.addCapability(createIdentifier("energy"), new ICapabilityProvider() { - @Override - @Nonnull - public LazyOptional getCapability(final Capability cap, - @Nullable final Direction side) { - if (cap == ForgeCapabilities.ENERGY) { - return capability.cast(); - } - return LazyOptional.empty(); - } - }); - } - - @SubscribeEvent - public void registerItemStackCapabilities(final AttachCapabilitiesEvent e) { - if (e.getObject().getItem() instanceof EnergyItem energyItem) { - final Optional energyStorage = energyItem.createEnergyStorage(e.getObject()); - final LazyOptional forgeEnergyStorage = energyStorage.map( - storage -> LazyOptional.of(() -> (IEnergyStorage) new EnergyStorageAdapter(storage)) - ).orElse(LazyOptional.empty()); - e.addCapability(createIdentifier("energy"), new ICapabilityProvider() { - @Override - public LazyOptional getCapability(final Capability cap, - @Nullable final Direction side) { - if (cap == ForgeCapabilities.ENERGY) { - return forgeEnergyStorage.cast(); - } - return LazyOptional.empty(); - } - }); - } - } - - @SubscribeEvent - public void onServerTick(final TickEvent.ServerTickEvent e) { - if (e.phase == TickEvent.Phase.START) { - ServerEventQueue.runQueuedActions(); - } - } - - private record ForgeRegistryCallback(DeferredRegister registry) implements RegistryCallback { - @Override - public Supplier register(final ResourceLocation id, final Supplier value) { - return registry.register(id.getPath(), value); - } - } -} +package com.refinedmods.refinedstorage2.platform.forge; + +import com.refinedmods.refinedstorage2.platform.api.PlatformApi; +import com.refinedmods.refinedstorage2.platform.common.AbstractModInitializer; +import com.refinedmods.refinedstorage2.platform.common.PlatformProxy; +import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; +import com.refinedmods.refinedstorage2.platform.common.content.BlockEntityTypeFactory; +import com.refinedmods.refinedstorage2.platform.common.content.Blocks; +import com.refinedmods.refinedstorage2.platform.common.content.CreativeModeTabItems; +import com.refinedmods.refinedstorage2.platform.common.content.DirectRegistryCallback; +import com.refinedmods.refinedstorage2.platform.common.content.Items; +import com.refinedmods.refinedstorage2.platform.common.content.MenuTypeFactory; +import com.refinedmods.refinedstorage2.platform.common.content.RegistryCallback; +import com.refinedmods.refinedstorage2.platform.common.grid.WirelessGridItem; +import com.refinedmods.refinedstorage2.platform.common.iface.InterfacePlatformExternalStorageProviderFactory; +import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridType; +import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseBlock; +import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; +import com.refinedmods.refinedstorage2.platform.common.upgrade.RegulatorUpgradeItem; +import com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil; +import com.refinedmods.refinedstorage2.platform.common.util.ServerEventQueue; +import com.refinedmods.refinedstorage2.platform.forge.exporter.FluidHandlerExporterTransferStrategyFactory; +import com.refinedmods.refinedstorage2.platform.forge.exporter.ItemHandlerExporterTransferStrategyFactory; +import com.refinedmods.refinedstorage2.platform.forge.grid.strategy.FluidGridExtractionStrategy; +import com.refinedmods.refinedstorage2.platform.forge.grid.strategy.FluidGridInsertionStrategy; +import com.refinedmods.refinedstorage2.platform.forge.grid.strategy.ItemGridExtractionStrategy; +import com.refinedmods.refinedstorage2.platform.forge.grid.strategy.ItemGridScrollingStrategy; +import com.refinedmods.refinedstorage2.platform.forge.importer.FluidHandlerImporterTransferStrategyFactory; +import com.refinedmods.refinedstorage2.platform.forge.importer.ItemHandlerImporterTransferStrategyFactory; +import com.refinedmods.refinedstorage2.platform.forge.storage.diskdrive.ForgeDiskDriveBlockEntity; +import com.refinedmods.refinedstorage2.platform.forge.storage.externalstorage.FluidHandlerPlatformExternalStorageProviderFactory; +import com.refinedmods.refinedstorage2.platform.forge.storage.externalstorage.ItemHandlerPlatformExternalStorageProviderFactory; +import com.refinedmods.refinedstorage2.platform.forge.storage.portablegrid.ForgePortableGridBlockEntity; +import com.refinedmods.refinedstorage2.platform.forge.support.energy.EnergyStorageAdapter; +import com.refinedmods.refinedstorage2.platform.forge.support.network.bounditem.CuriosSlotReferenceFactory; +import com.refinedmods.refinedstorage2.platform.forge.support.network.bounditem.CuriosSlotReferenceProvider; +import com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s.CraftingGridClearPacket; +import com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s.CraftingGridRecipeTransferPacket; +import com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s.GridExtractPacket; +import com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s.GridInsertPacket; +import com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s.GridScrollPacket; +import com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s.PropertyChangePacket; +import com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s.ResourceFilterSlotChangePacket; +import com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s.ResourceSlotAmountChangePacket; +import com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s.ResourceSlotChangePacket; +import com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s.SingleAmountChangePacket; +import com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s.StorageInfoRequestPacket; +import com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s.UseNetworkBoundItemPacket; +import com.refinedmods.refinedstorage2.platform.forge.support.packet.s2c.EnergyInfoPacket; +import com.refinedmods.refinedstorage2.platform.forge.support.packet.s2c.GridActivePacket; +import com.refinedmods.refinedstorage2.platform.forge.support.packet.s2c.GridClearPacket; +import com.refinedmods.refinedstorage2.platform.forge.support.packet.s2c.GridUpdatePacket; +import com.refinedmods.refinedstorage2.platform.forge.support.packet.s2c.NetworkTransmitterStatusPacket; +import com.refinedmods.refinedstorage2.platform.forge.support.packet.s2c.ResourceSlotUpdatePacket; +import com.refinedmods.refinedstorage2.platform.forge.support.packet.s2c.StorageInfoResponsePacket; +import com.refinedmods.refinedstorage2.platform.forge.support.packet.s2c.WirelessTransmitterRangePacket; +import com.refinedmods.refinedstorage2.platform.forge.support.resource.ResourceContainerFluidHandlerAdapter; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.function.Supplier; + +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.RecipeSerializer; +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; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.Mod; +import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; +import net.neoforged.fml.loading.FMLEnvironment; +import net.neoforged.neoforge.capabilities.Capabilities; +import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; +import net.neoforged.neoforge.common.NeoForge; +import net.neoforged.neoforge.common.extensions.IMenuTypeExtension; +import net.neoforged.neoforge.event.TickEvent; +import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent; +import net.neoforged.neoforge.items.wrapper.InvWrapper; +import net.neoforged.neoforge.network.event.RegisterPayloadHandlerEvent; +import net.neoforged.neoforge.network.registration.IPayloadRegistrar; +import net.neoforged.neoforge.registries.DeferredRegister; +import net.neoforged.neoforge.registries.RegisterEvent; + +import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.MOD_ID; +import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; +import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; + +@Mod(IdentifierUtil.MOD_ID) +public class ModInitializer extends AbstractModInitializer { + private final DeferredRegister blockRegistry = + DeferredRegister.create(BuiltInRegistries.BLOCK, IdentifierUtil.MOD_ID); + private final DeferredRegister itemRegistry = + DeferredRegister.create(BuiltInRegistries.ITEM, IdentifierUtil.MOD_ID); + private final DeferredRegister> blockEntityTypeRegistry = + DeferredRegister.create(BuiltInRegistries.BLOCK_ENTITY_TYPE, IdentifierUtil.MOD_ID); + private final DeferredRegister> menuTypeRegistry = + DeferredRegister.create(BuiltInRegistries.MENU, IdentifierUtil.MOD_ID); + private final DeferredRegister soundEventRegistry = + DeferredRegister.create(BuiltInRegistries.SOUND_EVENT, IdentifierUtil.MOD_ID); + private final DeferredRegister> recipeSerializerRegistry = + DeferredRegister.create(BuiltInRegistries.RECIPE_SERIALIZER, IdentifierUtil.MOD_ID); + + public ModInitializer(final IEventBus eventBus) { + PlatformProxy.loadPlatform(new PlatformImpl()); + initializePlatformApi(); + registerAdditionalGridInsertionStrategyFactories(); + registerGridExtractionStrategyFactories(); + registerGridScrollingStrategyFactories(); + registerImporterTransferStrategyFactories(); + registerExporterTransferStrategyFactories(); + registerExternalStorageProviderFactories(); + registerContent(eventBus); + registerSounds(eventBus); + registerRecipeSerializers(eventBus); + registerTickHandler(); + registerSlotReferenceProviders(); + + if (FMLEnvironment.dist == Dist.CLIENT) { + eventBus.addListener(ClientModInitializer::onClientSetup); + eventBus.addListener(ClientModInitializer::onRegisterModelGeometry); + eventBus.addListener(ClientModInitializer::onRegisterMenuScreens); + eventBus.addListener(ClientModInitializer::onRegisterKeyMappings); + eventBus.addListener(ClientModInitializer::onRegisterTooltipFactories); + } + + eventBus.addListener(this::onCommonSetup); + eventBus.addListener(this::onRegister); + eventBus.addListener(this::registerNetworkPackets); + eventBus.addListener(this::registerCapabilities); + + NeoForge.EVENT_BUS.addListener(this::registerWrenchingEvent); + } + + private void registerAdditionalGridInsertionStrategyFactories() { + PlatformApi.INSTANCE.addGridInsertionStrategyFactory(FluidGridInsertionStrategy::new); + } + + private void registerGridExtractionStrategyFactories() { + PlatformApi.INSTANCE.addGridExtractionStrategyFactory(ItemGridExtractionStrategy::new); + PlatformApi.INSTANCE.addGridExtractionStrategyFactory(FluidGridExtractionStrategy::new); + } + + private void registerGridScrollingStrategyFactories() { + PlatformApi.INSTANCE.addGridScrollingStrategyFactory(ItemGridScrollingStrategy::new); + } + + private void registerImporterTransferStrategyFactories() { + PlatformApi.INSTANCE.getImporterTransferStrategyRegistry().register( + createIdentifier("item"), + new ItemHandlerImporterTransferStrategyFactory() + ); + PlatformApi.INSTANCE.getImporterTransferStrategyRegistry().register( + createIdentifier("fluid"), + new FluidHandlerImporterTransferStrategyFactory() + ); + } + + private void registerExporterTransferStrategyFactories() { + PlatformApi.INSTANCE.getExporterTransferStrategyRegistry().register( + createIdentifier("item"), + new ItemHandlerExporterTransferStrategyFactory() + ); + PlatformApi.INSTANCE.getExporterTransferStrategyRegistry().register( + createIdentifier("fluid"), + new FluidHandlerExporterTransferStrategyFactory() + ); + } + + private void registerExternalStorageProviderFactories() { + PlatformApi.INSTANCE.addExternalStorageProviderFactory(new InterfacePlatformExternalStorageProviderFactory()); + PlatformApi.INSTANCE.addExternalStorageProviderFactory(new ItemHandlerPlatformExternalStorageProviderFactory()); + PlatformApi.INSTANCE.addExternalStorageProviderFactory( + new FluidHandlerPlatformExternalStorageProviderFactory()); + } + + private void registerContent(final IEventBus eventBus) { + registerBlocks(eventBus); + registerItems(eventBus); + registerBlockEntities(eventBus); + registerMenus(eventBus); + } + + private void registerBlocks(final IEventBus eventBus) { + registerBlocks( + new ForgeRegistryCallback<>(blockRegistry), + ForgeDiskDriveBlockEntity::new, + (pos, state) -> new ForgePortableGridBlockEntity(PortableGridType.NORMAL, pos, state), + (pos, state) -> new ForgePortableGridBlockEntity(PortableGridType.CREATIVE, pos, state) + ); + blockRegistry.register(eventBus); + } + + private void registerItems(final IEventBus eventBus) { + registerItems( + new ForgeRegistryCallback<>(itemRegistry), + () -> new RegulatorUpgradeItem(PlatformApi.INSTANCE.getUpgradeRegistry()) { + @Override + public boolean shouldCauseReequipAnimation(final ItemStack oldStack, + final ItemStack newStack, + final boolean slotChanged) { + return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); + } + }, + () -> new WirelessGridItem(false) { + @Override + public boolean shouldCauseReequipAnimation(final ItemStack oldStack, + final ItemStack newStack, + final boolean slotChanged) { + return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); + } + }, + () -> new WirelessGridItem(true) { + @Override + public boolean shouldCauseReequipAnimation(final ItemStack oldStack, + final ItemStack newStack, + final boolean slotChanged) { + return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); + } + } + ); + itemRegistry.register(eventBus); + } + + private void registerBlockEntities(final IEventBus eventBus) { + registerBlockEntities( + new ForgeRegistryCallback<>(blockEntityTypeRegistry), + new BlockEntityTypeFactory() { + @Override + public BlockEntityType create(final BlockEntitySupplier factory, + final Block... allowedBlocks) { + return new BlockEntityType<>(factory::create, new HashSet<>(Arrays.asList(allowedBlocks)), null); + } + }, + ForgeDiskDriveBlockEntity::new, + (pos, state) -> new ForgePortableGridBlockEntity(PortableGridType.NORMAL, pos, state), + (pos, state) -> new ForgePortableGridBlockEntity(PortableGridType.CREATIVE, pos, state) + ); + blockEntityTypeRegistry.register(eventBus); + } + + private void registerMenus(final IEventBus eventBus) { + registerMenus(new ForgeRegistryCallback<>(menuTypeRegistry), new MenuTypeFactory() { + @Override + public MenuType create(final MenuSupplier supplier) { + return IMenuTypeExtension.create(supplier::create); + } + }); + menuTypeRegistry.register(eventBus); + } + + private void registerCapabilities(final RegisterCapabilitiesEvent event) { + event.registerBlockEntity( + Capabilities.ItemHandler.BLOCK, + BlockEntities.INSTANCE.getDiskDrive(), + (be, side) -> new InvWrapper(be.getDiskInventory()) + ); + event.registerBlockEntity( + Capabilities.ItemHandler.BLOCK, + BlockEntities.INSTANCE.getInterface(), + (be, side) -> new InvWrapper(be.getExportedResourcesAsContainer()) + ); + event.registerBlockEntity( + Capabilities.FluidHandler.BLOCK, + BlockEntities.INSTANCE.getInterface(), + (be, side) -> new ResourceContainerFluidHandlerAdapter(be.getExportedResources()) + ); + event.registerBlockEntity( + Capabilities.EnergyStorage.BLOCK, + BlockEntities.INSTANCE.getController(), + (be, side) -> new EnergyStorageAdapter(be.getEnergyStorage()) + ); + event.registerBlockEntity( + Capabilities.EnergyStorage.BLOCK, + BlockEntities.INSTANCE.getPortableGrid(), + (be, side) -> new EnergyStorageAdapter(be.getEnergyStorage()) + ); + event.registerItem( + Capabilities.EnergyStorage.ITEM, + (stack, ctx) -> new EnergyStorageAdapter(Items.INSTANCE.getWirelessGrid().createEnergyStorage(stack)), + Items.INSTANCE.getWirelessGrid() + ); + Items.INSTANCE.getControllers().forEach(controllerItem -> event.registerItem( + Capabilities.EnergyStorage.ITEM, + (stack, ctx) -> new EnergyStorageAdapter(controllerItem.get().createEnergyStorage(stack)), + controllerItem.get() + )); + } + + private void registerSounds(final IEventBus eventBus) { + registerSounds(new ForgeRegistryCallback<>(soundEventRegistry)); + soundEventRegistry.register(eventBus); + } + + private void registerRecipeSerializers(final IEventBus eventBus) { + registerRecipeSerializers(new ForgeRegistryCallback<>(recipeSerializerRegistry)); + recipeSerializerRegistry.register(eventBus); + } + + private void registerTickHandler() { + NeoForge.EVENT_BUS.addListener(this::onServerTick); + } + + protected void registerSlotReferenceProviders() { + CuriosSlotReferenceProvider.create().ifPresent(slotReferenceProvider -> { + PlatformApi.INSTANCE.getSlotReferenceFactoryRegistry().register( + createIdentifier("curios"), + CuriosSlotReferenceFactory.INSTANCE + ); + PlatformApi.INSTANCE.addSlotReferenceProvider(slotReferenceProvider); + }); + } + + @SubscribeEvent + public void onCommonSetup(final FMLCommonSetupEvent e) { + registerUpgradeMappings(); + } + + @SubscribeEvent + public void onRegister(final RegisterEvent e) { + e.register( + Registries.LOOT_FUNCTION_TYPE, + helper -> registerLootFunctions(new DirectRegistryCallback<>(BuiltInRegistries.LOOT_FUNCTION_TYPE)) + ); + e.register(Registries.CREATIVE_MODE_TAB, helper -> helper.register( + createIdentifier("general"), + CreativeModeTab.builder() + .title(createTranslation("itemGroup", "general")) + .icon(() -> new ItemStack(Blocks.INSTANCE.getController().getDefault())) + .displayItems((params, output) -> CreativeModeTabItems.append(output::accept)) + .build() + )); + } + + @SubscribeEvent + public void registerWrenchingEvent(final PlayerInteractEvent.RightClickBlock e) { + final Level level = e.getLevel(); + final BlockState state = level.getBlockState(e.getHitVec().getBlockPos()); + if (!(state.getBlock() instanceof AbstractBaseBlock block)) { + return; + } + block.tryUseWrench(state, level, e.getHitVec(), e.getEntity(), e.getHand()).or(() -> block.tryUpdateColor( + state, + level, + e.getHitVec().getBlockPos(), + e.getEntity(), + e.getHand() + )).ifPresent(result -> { + e.setCanceled(true); + e.setCancellationResult(result); + }); + } + + @SubscribeEvent + public void registerNetworkPackets(final RegisterPayloadHandlerEvent event) { + final IPayloadRegistrar registrar = event.registrar(MOD_ID); + registerServerToClientPackets(registrar); + registerClientToServerPackets(registrar); + } + + private static void registerServerToClientPackets(final IPayloadRegistrar registrar) { + registrar.play( + PacketIds.ENERGY_INFO, + EnergyInfoPacket::decode, + handler -> handler.client(EnergyInfoPacket::handle) + ); + registrar.play( + PacketIds.GRID_ACTIVE, + GridActivePacket::decode, + handler -> handler.client(GridActivePacket::handle) + ); + registrar.play( + PacketIds.GRID_CLEAR, + buf -> new GridClearPacket(), + handler -> handler.client((packet, ctx) -> GridClearPacket.handle(ctx)) + ); + registrar.play( + PacketIds.GRID_UPDATE, + GridUpdatePacket::decode, + handler -> handler.client(GridUpdatePacket::handle) + ); + registrar.play( + PacketIds.NETWORK_TRANSMITTER_STATUS, + NetworkTransmitterStatusPacket::decode, + handler -> handler.client(NetworkTransmitterStatusPacket::handle) + ); + registrar.play( + PacketIds.RESOURCE_SLOT_UPDATE, + ResourceSlotUpdatePacket::decode, + handler -> handler.client(ResourceSlotUpdatePacket::handle) + ); + registrar.play( + PacketIds.STORAGE_INFO_RESPONSE, + StorageInfoResponsePacket::decode, + handler -> handler.client(StorageInfoResponsePacket::handle) + ); + registrar.play( + PacketIds.WIRELESS_TRANSMITTER_RANGE, + WirelessTransmitterRangePacket::decode, + handler -> handler.client(WirelessTransmitterRangePacket::handle) + ); + } + + private static void registerClientToServerPackets(final IPayloadRegistrar registrar) { + registrar.play( + PacketIds.CRAFTING_GRID_CLEAR, + CraftingGridClearPacket::decode, + handler -> handler.server(CraftingGridClearPacket::handle) + ); + registrar.play( + PacketIds.CRAFTING_GRID_RECIPE_TRANSFER, + CraftingGridRecipeTransferPacket::decode, + handler -> handler.server(CraftingGridRecipeTransferPacket::handle) + ); + registrar.play( + PacketIds.GRID_EXTRACT, + GridExtractPacket::decode, + handler -> handler.server(GridExtractPacket::handle) + ); + registrar.play( + PacketIds.GRID_INSERT, + GridInsertPacket::decode, + handler -> handler.server(GridInsertPacket::handle) + ); + registrar.play( + PacketIds.GRID_SCROLL, + GridScrollPacket::decode, + handler -> handler.server(GridScrollPacket::handle) + ); + registrar.play( + PacketIds.PROPERTY_CHANGE, + PropertyChangePacket::decode, + handler -> handler.server(PropertyChangePacket::handle) + ); + registrar.play( + PacketIds.RESOURCE_FILTER_SLOT_CHANGE, + ResourceFilterSlotChangePacket::decode, + handler -> handler.server(ResourceFilterSlotChangePacket::handle) + ); + registrar.play( + PacketIds.RESOURCE_SLOT_AMOUNT_CHANGE, + ResourceSlotAmountChangePacket::decode, + handler -> handler.server(ResourceSlotAmountChangePacket::handle) + ); + registrar.play( + PacketIds.RESOURCE_SLOT_CHANGE, + ResourceSlotChangePacket::decode, + handler -> handler.server(ResourceSlotChangePacket::handle) + ); + registrar.play( + PacketIds.SINGLE_AMOUNT_CHANGE, + SingleAmountChangePacket::decode, + handler -> handler.server(SingleAmountChangePacket::handle) + ); + registrar.play( + PacketIds.STORAGE_INFO_REQUEST, + StorageInfoRequestPacket::decode, + handler -> handler.server(StorageInfoRequestPacket::handle) + ); + registrar.play( + PacketIds.USE_NETWORK_BOUND_ITEM, + UseNetworkBoundItemPacket::decode, + handler -> handler.server(UseNetworkBoundItemPacket::handle) + ); + } + + @SubscribeEvent + public void onServerTick(final TickEvent.ServerTickEvent e) { + if (e.phase == TickEvent.Phase.START) { + ServerEventQueue.runQueuedActions(); + } + } + + private record ForgeRegistryCallback(DeferredRegister registry) implements RegistryCallback { + @Override + public Supplier register(final ResourceLocation id, final Supplier value) { + return registry.register(id.getPath(), value); + } + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/PlatformImpl.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/PlatformImpl.java index f9b5af568..7384eed48 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/PlatformImpl.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/PlatformImpl.java @@ -13,12 +13,11 @@ import com.refinedmods.refinedstorage2.platform.forge.grid.strategy.ItemGridInsertionStrategy; import com.refinedmods.refinedstorage2.platform.forge.grid.view.ForgeFluidGridResourceFactory; import com.refinedmods.refinedstorage2.platform.forge.grid.view.ForgeItemGridResourceFactory; -import com.refinedmods.refinedstorage2.platform.forge.packet.NetworkManager; -import com.refinedmods.refinedstorage2.platform.forge.packet.c2s.ClientToServerCommunicationsImpl; -import com.refinedmods.refinedstorage2.platform.forge.packet.s2c.ServerToClientCommunicationsImpl; import com.refinedmods.refinedstorage2.platform.forge.support.containermenu.ContainerTransferDestination; import com.refinedmods.refinedstorage2.platform.forge.support.containermenu.MenuOpenerImpl; import com.refinedmods.refinedstorage2.platform.forge.support.energy.EnergyStorageAdapter; +import com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s.ClientToServerCommunicationsImpl; +import com.refinedmods.refinedstorage2.platform.forge.support.packet.s2c.ServerToClientCommunicationsImpl; import com.refinedmods.refinedstorage2.platform.forge.support.render.FluidStackFluidRenderer; import java.util.ArrayList; @@ -37,6 +36,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.NonNullList; +import net.minecraft.core.registries.Registries; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; @@ -54,47 +54,46 @@ import net.minecraft.world.item.Items; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.item.crafting.CraftingRecipe; -import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.Vec3; -import net.minecraftforge.client.ForgeHooksClient; -import net.minecraftforge.common.ForgeHooks; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.common.util.FakePlayerFactory; -import net.minecraftforge.event.ForgeEventFactory; -import net.minecraftforge.event.level.BlockEvent; -import net.minecraftforge.fluids.FluidActionResult; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidType; -import net.minecraftforge.fluids.FluidUtil; -import net.minecraftforge.fluids.capability.IFluidHandler; -import net.minecraftforge.fluids.capability.templates.FluidTank; -import net.minecraftforge.fml.ModLoadingContext; -import net.minecraftforge.fml.config.ModConfig; -import net.minecraftforge.items.ItemHandlerHelper; -import net.minecraftforge.items.wrapper.InvWrapper; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.fml.ModLoadingContext; +import net.neoforged.fml.config.ModConfig; +import net.neoforged.neoforge.capabilities.Capabilities; +import net.neoforged.neoforge.client.ClientHooks; +import net.neoforged.neoforge.common.CommonHooks; +import net.neoforged.neoforge.common.NeoForge; +import net.neoforged.neoforge.common.util.FakePlayerFactory; +import net.neoforged.neoforge.event.EventHooks; +import net.neoforged.neoforge.event.level.BlockEvent; +import net.neoforged.neoforge.fluids.FluidActionResult; +import net.neoforged.neoforge.fluids.FluidStack; +import net.neoforged.neoforge.fluids.FluidType; +import net.neoforged.neoforge.fluids.FluidUtil; +import net.neoforged.neoforge.fluids.capability.IFluidHandler; +import net.neoforged.neoforge.fluids.capability.templates.FluidTank; +import net.neoforged.neoforge.items.ItemHandlerHelper; +import net.neoforged.neoforge.items.wrapper.InvWrapper; import static com.refinedmods.refinedstorage2.platform.forge.support.resource.VariantUtil.ofFluidStack; import static com.refinedmods.refinedstorage2.platform.forge.support.resource.VariantUtil.toFluidStack; public final class PlatformImpl extends AbstractPlatform { private static final TagKey WRENCH_TAG = TagKey.create( - ForgeRegistries.ITEMS.getRegistryKey(), + Registries.ITEM, new ResourceLocation("forge", "tools/wrench") ); private final ConfigImpl config = new ConfigImpl(); - public PlatformImpl(final NetworkManager networkManager) { + public PlatformImpl() { super( - new ServerToClientCommunicationsImpl(networkManager), - new ClientToServerCommunicationsImpl(networkManager), + new ServerToClientCommunicationsImpl(), + new ClientToServerCommunicationsImpl(), new MenuOpenerImpl(), new FluidStackFluidRenderer(), ItemGridInsertionStrategy::new @@ -169,7 +168,9 @@ public Optional convertJeiIngredientToFluid(final Object ingredie @Override public Optional convertToBucket(final FluidResource fluidResource) { - return new ItemStack(Items.BUCKET).getCapability(ForgeCapabilities.FLUID_HANDLER_ITEM, null).map(dest -> { + return Optional.ofNullable( + new ItemStack(Items.BUCKET).getCapability(Capabilities.FluidHandler.ITEM) + ).map(dest -> { dest.fill( toFluidStack(fluidResource, FluidType.BUCKET_VOLUME), IFluidHandler.FluidAction.EXECUTE @@ -206,15 +207,15 @@ public ItemStack getCloneItemStack(final BlockState state, public NonNullList getRemainingCraftingItems(final Player player, final CraftingRecipe craftingRecipe, final CraftingContainer container) { - ForgeHooks.setCraftingPlayer(player); + CommonHooks.setCraftingPlayer(player); final NonNullList remainingItems = craftingRecipe.getRemainingItems(container); - ForgeHooks.setCraftingPlayer(null); + CommonHooks.setCraftingPlayer(null); return remainingItems; } @Override public void onItemCrafted(final Player player, final ItemStack craftedStack, final CraftingContainer container) { - ForgeEventFactory.firePlayerCraftingEvent(player, craftedStack, container); + EventHooks.firePlayerCraftingEvent(player, craftedStack, container); } @Override @@ -228,7 +229,7 @@ public Player getFakePlayer(final ServerLevel level, @Nullable final UUID player @Override public boolean canBreakBlock(final Level level, final BlockPos pos, final BlockState state, final Player player) { final BlockEvent.BreakEvent e = new BlockEvent.BreakEvent(level, pos, state, player); - return !MinecraftForge.EVENT_BUS.post(e); + return !NeoForge.EVENT_BUS.post(e).isCanceled(); } @Override @@ -246,7 +247,7 @@ public boolean placeBlock( stack, new BlockHitResult(Vec3.ZERO, direction, pos, false) ); - final InteractionResult result = ForgeHooks.onPlaceItemIntoWorld(ctx); + final InteractionResult result = CommonHooks.onPlaceItemIntoWorld(ctx); return result.consumesAction(); } @@ -278,7 +279,7 @@ public boolean placeFluid( public ItemStack getBlockAsItemStack(final Block block, final BlockState state, final Direction direction, - final BlockGetter level, + final LevelReader level, final BlockPos position, final Player player) { return block.getCloneItemStack( @@ -303,7 +304,7 @@ public List processTooltipComponents( final Optional imageComponent, final List components ) { - return new ArrayList<>(ForgeHooksClient.gatherTooltipComponents( + return new ArrayList<>(ClientHooks.gatherTooltipComponents( stack, components, imageComponent, @@ -330,7 +331,7 @@ public void renderTooltip(final GuiGraphics graphics, @Override public Optional getEnergyStorage(final ItemStack stack) { - return stack.getCapability(ForgeCapabilities.ENERGY) + return Optional.ofNullable(stack.getCapability(Capabilities.EnergyStorage.ITEM)) .filter(EnergyStorageAdapter.class::isInstance) .map(EnergyStorageAdapter.class::cast) .map(EnergyStorageAdapter::getEnergyStorage); diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/BlockModelProvider.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/BlockModelProvider.java index c30c37371..ada4b6bd0 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/BlockModelProvider.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/BlockModelProvider.java @@ -6,12 +6,12 @@ import net.minecraft.data.PackOutput; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.common.data.ExistingFileHelper; +import net.neoforged.neoforge.common.data.ExistingFileHelper; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.MOD_ID; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; -public class BlockModelProvider extends net.minecraftforge.client.model.generators.BlockModelProvider { +public class BlockModelProvider extends net.neoforged.neoforge.client.model.generators.BlockModelProvider { private static final ResourceLocation EMISSIVE_ALL_CUTOUT = createIdentifier("block/emissive_all_cutout"); private static final ResourceLocation EMISSIVE_NORTH_CUTOUT = createIdentifier("block/emissive_north_cutout"); private static final ResourceLocation NORTH_CUTOUT = createIdentifier("block/north_cutout"); @@ -59,7 +59,7 @@ private void registerControllers() { }); } - private void registerGrids(final BlockColorMap> blockMap, final String name) { + private void registerGrids(final BlockColorMap, ?> blockMap, final String name) { blockMap.forEach((color, id, block) -> { final ResourceLocation cutout = createIdentifier("block/" + name + "/cutouts/" + color.getName()); registerEmissiveGrids(name, color.getName(), cutout); diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/BlockStateProvider.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/BlockStateProvider.java index 4016e62a1..de698c113 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/BlockStateProvider.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/BlockStateProvider.java @@ -3,7 +3,7 @@ import com.refinedmods.refinedstorage2.platform.common.constructordestructor.AbstractConstructorDestructorBlock; import com.refinedmods.refinedstorage2.platform.common.content.BlockColorMap; import com.refinedmods.refinedstorage2.platform.common.content.Blocks; -import com.refinedmods.refinedstorage2.platform.common.controller.ControllerBlock; +import com.refinedmods.refinedstorage2.platform.common.controller.AbstractControllerBlock; import com.refinedmods.refinedstorage2.platform.common.controller.ControllerEnergyType; import com.refinedmods.refinedstorage2.platform.common.detector.DetectorBlock; import com.refinedmods.refinedstorage2.platform.common.grid.AbstractGridBlock; @@ -26,15 +26,15 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.BooleanProperty; -import net.minecraftforge.client.model.generators.ConfiguredModel; -import net.minecraftforge.client.model.generators.ModelFile; -import net.minecraftforge.client.model.generators.MultiPartBlockStateBuilder; -import net.minecraftforge.common.data.ExistingFileHelper; +import net.neoforged.neoforge.client.model.generators.ConfiguredModel; +import net.neoforged.neoforge.client.model.generators.ModelFile; +import net.neoforged.neoforge.client.model.generators.MultiPartBlockStateBuilder; +import net.neoforged.neoforge.common.data.ExistingFileHelper; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.MOD_ID; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; -public class BlockStateProvider extends net.minecraftforge.client.model.generators.BlockStateProvider { +public class BlockStateProvider extends net.neoforged.neoforge.client.model.generators.BlockStateProvider { private static final Map PROPERTY_BY_DIRECTION = new EnumMap<>(Map.of( Direction.NORTH, CableBlockSupport.NORTH, Direction.EAST, CableBlockSupport.EAST, @@ -150,7 +150,7 @@ private void registerGrids() { } private void configureGridVariants(final DyeColor color, - final Supplier> block, + final Supplier> block, final String name) { final ModelFile inactive = modelFile(createIdentifier("block/" + name + "/inactive")); final ModelFile active = modelFile(createIdentifier("block/" + name + "/" + color.getName())); @@ -180,19 +180,19 @@ private void configureControllerVariants(final DyeColor color, final Supplier blockMap, final String type) { + private void registerConstructorDestructors(final BlockColorMap blockMap, final String type) { blockMap.forEach((color, id, block) -> { final MultiPartBlockStateBuilder builder = addCableWithExtensions(block.get(), color); final ModelFile activeModel = modelFile(createIdentifier("block/" + type + "/active")); diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/DataGenerators.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/DataGenerators.java index 005a6dee7..995129786 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/DataGenerators.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/DataGenerators.java @@ -10,10 +10,10 @@ import net.minecraft.core.HolderLookup; import net.minecraft.data.DataGenerator; import net.minecraft.data.DataGenerator.PackGenerator; -import net.minecraftforge.common.data.ExistingFileHelper; -import net.minecraftforge.data.event.GatherDataEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod.EventBusSubscriber; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.Mod.EventBusSubscriber; +import net.neoforged.neoforge.common.data.ExistingFileHelper; +import net.neoforged.neoforge.data.event.GatherDataEvent; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.MOD_ID; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/ItemModelProvider.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/ItemModelProvider.java index c7b4af6f0..77c648389 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/ItemModelProvider.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/ItemModelProvider.java @@ -2,14 +2,9 @@ import com.refinedmods.refinedstorage2.platform.common.constructordestructor.ConstructorBlock; import com.refinedmods.refinedstorage2.platform.common.constructordestructor.DestructorBlock; -import com.refinedmods.refinedstorage2.platform.common.content.BlockColorMap; import com.refinedmods.refinedstorage2.platform.common.content.Blocks; import com.refinedmods.refinedstorage2.platform.common.content.ColorMap; -import com.refinedmods.refinedstorage2.platform.common.controller.ControllerBlock; -import com.refinedmods.refinedstorage2.platform.common.detector.DetectorBlock; import com.refinedmods.refinedstorage2.platform.common.exporter.ExporterBlock; -import com.refinedmods.refinedstorage2.platform.common.grid.CraftingGridBlock; -import com.refinedmods.refinedstorage2.platform.common.grid.GridBlock; import com.refinedmods.refinedstorage2.platform.common.importer.ImporterBlock; import com.refinedmods.refinedstorage2.platform.common.networking.CableBlock; import com.refinedmods.refinedstorage2.platform.common.networking.NetworkReceiverBlock; @@ -19,13 +14,13 @@ import net.minecraft.data.PackOutput; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.client.model.generators.ModelFile; -import net.minecraftforge.common.data.ExistingFileHelper; +import net.neoforged.neoforge.client.model.generators.ModelFile; +import net.neoforged.neoforge.common.data.ExistingFileHelper; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.MOD_ID; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; -public class ItemModelProvider extends net.minecraftforge.client.model.generators.ItemModelProvider { +public class ItemModelProvider extends net.neoforged.neoforge.client.model.generators.ItemModelProvider { private static final String CUTOUT_TEXTURE_KEY = "cutout"; private static final String CABLE_TEXTURE_KEY = "cable"; @@ -101,7 +96,7 @@ private void registerControllers() { final ResourceLocation nearlyOff = createIdentifier("block/controller/nearly_off"); final ResourceLocation nearlyOn = createIdentifier("block/controller/nearly_on"); final ResourceLocation stored = createIdentifier("stored_in_controller"); - final ColorMap blocks = Blocks.INSTANCE.getController(); + final var blocks = Blocks.INSTANCE.getController(); blocks.forEach((color, id, block) -> withExistingParent(id.getPath(), base) .override() @@ -124,7 +119,7 @@ private void registerControllers() { } private void registerCreativeControllers() { - final BlockColorMap blocks = Blocks.INSTANCE.getCreativeController(); + final var blocks = Blocks.INSTANCE.getCreativeController(); blocks.forEach((color, id, block) -> withExistingParent( id.getPath(), createIdentifier("block/controller/" + color.getName()) @@ -132,7 +127,7 @@ private void registerCreativeControllers() { } private void registerGrids() { - final BlockColorMap blocks = Blocks.INSTANCE.getGrid(); + final var blocks = Blocks.INSTANCE.getGrid(); blocks.forEach((color, id, block) -> withExistingParent( id.getPath(), createIdentifier("block/grid/" + color.getName()) @@ -140,7 +135,7 @@ private void registerGrids() { } private void registerCraftingGrids() { - final BlockColorMap blocks = Blocks.INSTANCE.getCraftingGrid(); + final var blocks = Blocks.INSTANCE.getCraftingGrid(); blocks.forEach((color, id, block) -> withExistingParent( id.getPath(), createIdentifier("block/crafting_grid/" + color.getName()) @@ -148,7 +143,7 @@ private void registerCraftingGrids() { } private void registerDetectors() { - final BlockColorMap blocks = Blocks.INSTANCE.getDetector(); + final var blocks = Blocks.INSTANCE.getDetector(); blocks.forEach((color, id, block) -> withExistingParent( id.getPath(), createIdentifier("block/detector/" + color.getName()) diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/recipe/RecoloringRecipeProvider.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/recipe/RecoloringRecipeProvider.java index 1e302bc06..960c797fc 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/recipe/RecoloringRecipeProvider.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/recipe/RecoloringRecipeProvider.java @@ -3,11 +3,9 @@ import com.refinedmods.refinedstorage2.platform.common.content.Blocks; import com.refinedmods.refinedstorage2.platform.common.content.Tags; -import java.util.function.Consumer; - import net.minecraft.data.PackOutput; -import net.minecraft.data.recipes.FinishedRecipe; import net.minecraft.data.recipes.RecipeCategory; +import net.minecraft.data.recipes.RecipeOutput; import net.minecraft.data.recipes.RecipeProvider; import net.minecraft.data.recipes.ShapelessRecipeBuilder; import net.minecraft.tags.TagKey; @@ -23,46 +21,46 @@ public RecoloringRecipeProvider(final PackOutput output) { } @Override - protected void buildRecipes(final Consumer provider) { + protected void buildRecipes(final RecipeOutput output) { Blocks.INSTANCE.getCable().forEach((color, id, block) -> recolorItems(Tags.CABLES, block.get().asItem(), color) - .save(provider, createIdentifier("coloring/" + color.getName() + "_cable"))); + .save(output, createIdentifier("coloring/" + color.getName() + "_cable"))); Blocks.INSTANCE.getImporter().forEach((color, id, block) -> recolorItems(Tags.IMPORTERS, block.get().asItem(), color) - .save(provider, createIdentifier("coloring/" + color.getName() + "_importer"))); + .save(output, createIdentifier("coloring/" + color.getName() + "_importer"))); Blocks.INSTANCE.getExporter().forEach((color, id, block) -> recolorItems(Tags.EXPORTERS, block.get().asItem(), color) - .save(provider, createIdentifier("coloring/" + color.getName() + "_exporter"))); + .save(output, createIdentifier("coloring/" + color.getName() + "_exporter"))); Blocks.INSTANCE.getExternalStorage().forEach((color, id, block) -> recolorItems(Tags.EXTERNAL_STORAGES, block.get().asItem(), color) - .save(provider, createIdentifier("coloring/" + color.getName() + "_external_storage"))); + .save(output, createIdentifier("coloring/" + color.getName() + "_external_storage"))); Blocks.INSTANCE.getController().forEach((color, id, block) -> recolorItems(Tags.CONTROLLERS, block.get().asItem(), color) - .save(provider, createIdentifier("coloring/" + color.getName() + "_controller"))); + .save(output, createIdentifier("coloring/" + color.getName() + "_controller"))); Blocks.INSTANCE.getGrid().forEach((color, id, block) -> recolorItems(Tags.GRIDS, block.get().asItem(), color) - .save(provider, createIdentifier("coloring/" + color.getName() + "_grid"))); + .save(output, createIdentifier("coloring/" + color.getName() + "_grid"))); Blocks.INSTANCE.getCraftingGrid().forEach((color, id, block) -> recolorItems(Tags.CRAFTING_GRIDS, block.get().asItem(), color) - .save(provider, createIdentifier("coloring/" + color.getName() + "_crafting_grid"))); + .save(output, createIdentifier("coloring/" + color.getName() + "_crafting_grid"))); Blocks.INSTANCE.getDetector().forEach((color, id, block) -> recolorItems(Tags.DETECTORS, block.get().asItem(), color) - .save(provider, createIdentifier("coloring/" + color.getName() + "_detector"))); + .save(output, createIdentifier("coloring/" + color.getName() + "_detector"))); Blocks.INSTANCE.getConstructor().forEach((color, id, block) -> recolorItems(Tags.CONSTRUCTORS, block.get().asItem(), color) - .save(provider, createIdentifier("coloring/" + color.getName() + "_constructor"))); + .save(output, createIdentifier("coloring/" + color.getName() + "_constructor"))); Blocks.INSTANCE.getDestructor().forEach((color, id, block) -> recolorItems(Tags.DESTRUCTORS, block.get().asItem(), color) - .save(provider, createIdentifier("coloring/" + color.getName() + "_destructor"))); + .save(output, createIdentifier("coloring/" + color.getName() + "_destructor"))); Blocks.INSTANCE.getWirelessTransmitter().forEach((color, id, block) -> recolorItems(Tags.WIRELESS_TRANSMITTERS, block.get().asItem(), color) - .save(provider, createIdentifier("coloring/" + color.getName() + "_wireless_transmitter"))); + .save(output, createIdentifier("coloring/" + color.getName() + "_wireless_transmitter"))); Blocks.INSTANCE.getNetworkReceiver().forEach((color, id, block) -> recolorItems(Tags.NETWORK_RECEIVERS, block.get().asItem(), color) - .save(provider, createIdentifier("coloring/" + color.getName() + "_network_receiver"))); + .save(output, createIdentifier("coloring/" + color.getName() + "_network_receiver"))); Blocks.INSTANCE.getNetworkTransmitter().forEach((color, id, block) -> recolorItems(Tags.NETWORK_TRANSMITTERS, block.get().asItem(), color) - .save(provider, createIdentifier("coloring/" + color.getName() + "_network_transmitter"))); + .save(output, createIdentifier("coloring/" + color.getName() + "_network_transmitter"))); } private ShapelessRecipeBuilder recolorItems(final TagKey dyeable, final Item result, final DyeColor color) { diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/tag/BlockTagsProvider.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/tag/BlockTagsProvider.java index 87db693d9..da99aad83 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/tag/BlockTagsProvider.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/tag/BlockTagsProvider.java @@ -7,7 +7,7 @@ import net.minecraft.core.registries.Registries; import net.minecraft.data.PackOutput; import net.minecraft.world.level.block.Block; -import net.minecraftforge.common.data.ExistingFileHelper; +import net.neoforged.neoforge.common.data.ExistingFileHelper; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.MOD_ID; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/tag/ItemTagGenerator.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/tag/ItemTagGenerator.java index f93ae1e0b..79c1a2f30 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/tag/ItemTagGenerator.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/tag/ItemTagGenerator.java @@ -15,9 +15,10 @@ import net.minecraft.data.tags.ItemTagsProvider; import net.minecraft.data.tags.TagsProvider; import net.minecraft.tags.TagKey; +import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; -import net.minecraftforge.common.data.ExistingFileHelper; +import net.neoforged.neoforge.common.data.ExistingFileHelper; import static com.refinedmods.refinedstorage2.platform.common.content.Tags.CABLES; import static com.refinedmods.refinedstorage2.platform.common.content.Tags.CONSTRUCTORS; @@ -47,7 +48,7 @@ public ItemTagGenerator(final PackOutput packOutput, @Override protected void addTags(final HolderLookup.Provider provider) { - addAllToTag(CABLES, Items.INSTANCE.getCables()); + addAllToTag2(CABLES, Items.INSTANCE.getCables()); addAllToTag(CONTROLLERS, Items.INSTANCE.getControllers()); addAllToTag(CREATIVE_CONTROLLERS, Blocks.INSTANCE.getCreativeController().values().stream() .map(Block::asItem) @@ -112,8 +113,10 @@ protected void addTags(final HolderLookup.Provider provider) { } private void addAllToTag(final TagKey t, final Collection> items) { - tag(t) - .add(items.stream().map(Supplier::get).toArray(Item[]::new)) - .replace(false); + tag(t).add(items.stream().map(Supplier::get).toArray(Item[]::new)).replace(false); + } + + private void addAllToTag2(final TagKey t, final Collection> items) { + tag(t).add(items.stream().map(Supplier::get).toArray(Item[]::new)).replace(false); } } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/exporter/FluidHandlerExporterTransferStrategyFactory.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/exporter/FluidHandlerExporterTransferStrategyFactory.java index f56dd7a1d..95e8e6649 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/exporter/FluidHandlerExporterTransferStrategyFactory.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/exporter/FluidHandlerExporterTransferStrategyFactory.java @@ -10,9 +10,9 @@ import com.refinedmods.refinedstorage2.platform.common.content.Items; import com.refinedmods.refinedstorage2.platform.common.exporter.AbstractFuzzyExporterTransferStrategy; import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.forge.storage.CapabilityCache; +import com.refinedmods.refinedstorage2.platform.forge.storage.CapabilityCacheImpl; import com.refinedmods.refinedstorage2.platform.forge.storage.FluidHandlerInsertableStorage; -import com.refinedmods.refinedstorage2.platform.forge.storage.InteractionCoordinates; -import com.refinedmods.refinedstorage2.platform.forge.storage.InteractionCoordinatesImpl; import javax.annotation.Nullable; @@ -28,7 +28,7 @@ public ExporterTransferStrategy create(final ServerLevel level, final UpgradeState upgradeState, final AmountOverride amountOverride, final boolean fuzzyMode) { - final InteractionCoordinates coordinates = new InteractionCoordinatesImpl(level, pos, direction); + final CapabilityCache coordinates = new CapabilityCacheImpl(level, pos, direction); final FluidHandlerInsertableStorage destination = new FluidHandlerInsertableStorage( coordinates, amountOverride diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/exporter/ItemHandlerExporterTransferStrategyFactory.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/exporter/ItemHandlerExporterTransferStrategyFactory.java index 69d9421dc..cbf67a051 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/exporter/ItemHandlerExporterTransferStrategyFactory.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/exporter/ItemHandlerExporterTransferStrategyFactory.java @@ -9,7 +9,7 @@ import com.refinedmods.refinedstorage2.platform.common.content.Items; import com.refinedmods.refinedstorage2.platform.common.exporter.AbstractFuzzyExporterTransferStrategy; import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; -import com.refinedmods.refinedstorage2.platform.forge.storage.InteractionCoordinatesImpl; +import com.refinedmods.refinedstorage2.platform.forge.storage.CapabilityCacheImpl; import com.refinedmods.refinedstorage2.platform.forge.storage.ItemHandlerInsertableStorage; import javax.annotation.Nullable; @@ -26,7 +26,7 @@ public ExporterTransferStrategy create(final ServerLevel level, final UpgradeState upgradeState, final AmountOverride amountOverride, final boolean fuzzyMode) { - final InteractionCoordinatesImpl coordinates = new InteractionCoordinatesImpl(level, pos, direction); + final CapabilityCacheImpl coordinates = new CapabilityCacheImpl(level, pos, direction); final ItemHandlerInsertableStorage destination = new ItemHandlerInsertableStorage(coordinates, amountOverride); final int transferQuota = upgradeState.has(Items.INSTANCE.getStackUpgrade()) ? 64 : 1; if (fuzzyMode) { diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/CursorItemHandler.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/CursorItemHandler.java index f20a35695..e9a6f9690 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/CursorItemHandler.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/CursorItemHandler.java @@ -4,8 +4,8 @@ import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.items.ItemHandlerHelper; +import net.neoforged.neoforge.items.IItemHandler; +import net.neoforged.neoforge.items.ItemHandlerHelper; class CursorItemHandler implements IItemHandler { private final AbstractContainerMenu containerMenu; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/FluidGridExtractionStrategy.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/FluidGridExtractionStrategy.java index 07a6ea211..a35a2310a 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/FluidGridExtractionStrategy.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/FluidGridExtractionStrategy.java @@ -20,11 +20,11 @@ import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.fluids.capability.IFluidHandlerItem; -import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.items.ItemHandlerHelper; -import net.minecraftforge.items.wrapper.PlayerMainInvWrapper; +import net.neoforged.neoforge.capabilities.Capabilities; +import net.neoforged.neoforge.fluids.capability.IFluidHandlerItem; +import net.neoforged.neoforge.items.IItemHandler; +import net.neoforged.neoforge.items.ItemHandlerHelper; +import net.neoforged.neoforge.items.wrapper.PlayerMainInvWrapper; import static com.refinedmods.refinedstorage2.platform.forge.support.resource.VariantUtil.toFluidAction; import static com.refinedmods.refinedstorage2.platform.forge.support.resource.VariantUtil.toFluidStack; @@ -64,10 +64,9 @@ public boolean onExtract(final PlatformStorageChannelType storageChannelT return false; } - @SuppressWarnings("ConstantConditions") @Nullable private IFluidHandlerItem getFluidStorage(final ItemStack stack) { - return stack.getCapability(ForgeCapabilities.FLUID_HANDLER_ITEM, null).orElse(null); + return stack.getCapability(Capabilities.FluidHandler.ITEM); } private void extract(final FluidResource fluidResource, diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/FluidGridInsertionStrategy.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/FluidGridInsertionStrategy.java index 2c06a5603..8e9e32db0 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/FluidGridInsertionStrategy.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/FluidGridInsertionStrategy.java @@ -14,9 +14,9 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.capability.IFluidHandlerItem; +import net.neoforged.neoforge.capabilities.Capabilities; +import net.neoforged.neoforge.fluids.FluidStack; +import net.neoforged.neoforge.fluids.capability.IFluidHandlerItem; import static com.refinedmods.refinedstorage2.platform.forge.support.resource.VariantUtil.ofFluidStack; import static com.refinedmods.refinedstorage2.platform.forge.support.resource.VariantUtil.toFluidAction; @@ -58,10 +58,9 @@ private IFluidHandlerItem getFluidCursorStorage() { return getFluidStorage(menu.getCarried()); } - @SuppressWarnings("ConstantConditions") @Nullable private IFluidHandlerItem getFluidStorage(final ItemStack stack) { - return stack.getCapability(ForgeCapabilities.FLUID_HANDLER_ITEM, null).orElse(null); + return stack.getCapability(Capabilities.FluidHandler.ITEM); } @Override diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/ItemGridExtractionStrategy.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/ItemGridExtractionStrategy.java index 0019988ab..ddc7ee399 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/ItemGridExtractionStrategy.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/ItemGridExtractionStrategy.java @@ -9,13 +9,13 @@ import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; -import com.refinedmods.refinedstorage2.platform.forge.storage.InteractionCoordinates; +import com.refinedmods.refinedstorage2.platform.forge.storage.CapabilityCache; import com.refinedmods.refinedstorage2.platform.forge.storage.ItemHandlerInsertableStorage; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.items.wrapper.PlayerMainInvWrapper; +import net.neoforged.neoforge.items.IItemHandler; +import net.neoforged.neoforge.items.wrapper.PlayerMainInvWrapper; public class ItemGridExtractionStrategy implements GridExtractionStrategy { private final GridOperations gridOperations; @@ -40,7 +40,7 @@ public boolean onExtract(final PlatformStorageChannelType storageChannelT gridOperations.extract( itemResource, extractMode, - new ItemHandlerInsertableStorage(InteractionCoordinates.ofItemHandler(handler), AmountOverride.NONE) + new ItemHandlerInsertableStorage(CapabilityCache.ofItemHandler(handler), AmountOverride.NONE) ); return true; } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/ItemGridInsertionStrategy.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/ItemGridInsertionStrategy.java index f2faa680b..4869a801b 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/ItemGridInsertionStrategy.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/ItemGridInsertionStrategy.java @@ -8,15 +8,15 @@ import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; -import com.refinedmods.refinedstorage2.platform.forge.storage.InteractionCoordinates; +import com.refinedmods.refinedstorage2.platform.forge.storage.CapabilityCache; import com.refinedmods.refinedstorage2.platform.forge.storage.ItemHandlerExtractableStorage; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.items.wrapper.InvWrapper; -import net.minecraftforge.items.wrapper.RangedWrapper; +import net.neoforged.neoforge.items.wrapper.InvWrapper; +import net.neoforged.neoforge.items.wrapper.RangedWrapper; import static com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource.ofItemStack; @@ -44,7 +44,7 @@ public boolean onInsert(final GridInsertMode insertMode, final boolean tryAltern itemResource, insertMode, new ItemHandlerExtractableStorage( - InteractionCoordinates.ofItemHandler(playerCursorItemHandler), + CapabilityCache.ofItemHandler(playerCursorItemHandler), AmountOverride.NONE ) ); @@ -68,7 +68,7 @@ public boolean onTransfer(final int slotIndex) { itemResource, GridInsertMode.ENTIRE_RESOURCE, new ItemHandlerExtractableStorage( - InteractionCoordinates.ofItemHandler(storage), + CapabilityCache.ofItemHandler(storage), AmountOverride.NONE ) ); diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/ItemGridScrollingStrategy.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/ItemGridScrollingStrategy.java index f8897e040..9f35497d5 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/ItemGridScrollingStrategy.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/ItemGridScrollingStrategy.java @@ -11,17 +11,17 @@ import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; -import com.refinedmods.refinedstorage2.platform.forge.storage.InteractionCoordinates; +import com.refinedmods.refinedstorage2.platform.forge.storage.CapabilityCache; import com.refinedmods.refinedstorage2.platform.forge.storage.ItemHandlerExtractableStorage; import com.refinedmods.refinedstorage2.platform.forge.storage.ItemHandlerInsertableStorage; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.items.wrapper.InvWrapper; -import net.minecraftforge.items.wrapper.PlayerMainInvWrapper; -import net.minecraftforge.items.wrapper.RangedWrapper; +import net.neoforged.neoforge.items.IItemHandler; +import net.neoforged.neoforge.items.wrapper.InvWrapper; +import net.neoforged.neoforge.items.wrapper.PlayerMainInvWrapper; +import net.neoforged.neoforge.items.wrapper.RangedWrapper; public class ItemGridScrollingStrategy implements GridScrollingStrategy { private final GridOperations gridOperations; @@ -62,7 +62,7 @@ private void handleInventoryToGridScroll(final ItemResource itemResource, final itemResource, GridInsertMode.SINGLE_RESOURCE, new ItemHandlerExtractableStorage( - InteractionCoordinates.ofItemHandler(sourceStorage), + CapabilityCache.ofItemHandler(sourceStorage), AmountOverride.NONE ) ); @@ -73,7 +73,7 @@ private void handleGridToInventoryScroll(final ItemResource itemResource, final itemResource, GridExtractMode.SINGLE_RESOURCE, new ItemHandlerInsertableStorage( - InteractionCoordinates.ofItemHandler(destinationStorage), + CapabilityCache.ofItemHandler(destinationStorage), AmountOverride.NONE ) ); diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/view/ForgeFluidGridResourceFactory.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/view/ForgeFluidGridResourceFactory.java index ef83d4c66..82e5e732f 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/view/ForgeFluidGridResourceFactory.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/view/ForgeFluidGridResourceFactory.java @@ -3,8 +3,8 @@ import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; import com.refinedmods.refinedstorage2.platform.common.grid.view.AbstractFluidGridResourceFactory; -import net.minecraftforge.fluids.FluidType; -import net.minecraftforge.fml.ModList; +import net.neoforged.fml.ModList; +import net.neoforged.neoforge.fluids.FluidType; import static com.refinedmods.refinedstorage2.platform.forge.support.resource.VariantUtil.toFluidStack; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/view/ForgeItemGridResourceFactory.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/view/ForgeItemGridResourceFactory.java index 2b26546e8..4f2a318ba 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/view/ForgeItemGridResourceFactory.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/view/ForgeItemGridResourceFactory.java @@ -6,7 +6,7 @@ import java.util.Optional; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.fml.ModList; +import net.neoforged.fml.ModList; public class ForgeItemGridResourceFactory extends AbstractItemGridResourceFactory { @Override diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/FluidHandlerImporterSource.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/FluidHandlerImporterSource.java index 38db50f8f..a6d0f31e1 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/FluidHandlerImporterSource.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/FluidHandlerImporterSource.java @@ -7,27 +7,27 @@ import com.refinedmods.refinedstorage2.api.storage.InsertableStorage; import com.refinedmods.refinedstorage2.platform.api.exporter.AmountOverride; import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.forge.storage.CapabilityCache; import com.refinedmods.refinedstorage2.platform.forge.storage.FluidHandlerExtractableStorage; import com.refinedmods.refinedstorage2.platform.forge.storage.FluidHandlerInsertableStorage; -import com.refinedmods.refinedstorage2.platform.forge.storage.InteractionCoordinates; import java.util.Iterator; class FluidHandlerImporterSource implements ImporterSource { - private final InteractionCoordinates interactionCoordinates; + private final CapabilityCache capabilityCache; private final InsertableStorage insertTarget; private final ExtractableStorage extractTarget; - FluidHandlerImporterSource(final InteractionCoordinates interactionCoordinates, + FluidHandlerImporterSource(final CapabilityCache capabilityCache, final AmountOverride amountOverride) { - this.interactionCoordinates = interactionCoordinates; - this.insertTarget = new FluidHandlerInsertableStorage(interactionCoordinates, AmountOverride.NONE); - this.extractTarget = new FluidHandlerExtractableStorage(interactionCoordinates, amountOverride); + this.capabilityCache = capabilityCache; + this.insertTarget = new FluidHandlerInsertableStorage(capabilityCache, AmountOverride.NONE); + this.extractTarget = new FluidHandlerExtractableStorage(capabilityCache, amountOverride); } @Override public Iterator getResources() { - return interactionCoordinates.getFluidIterator(); + return capabilityCache.getFluidIterator(); } @Override diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/FluidHandlerImporterTransferStrategyFactory.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/FluidHandlerImporterTransferStrategyFactory.java index 2dfd7152f..9c40b2a51 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/FluidHandlerImporterTransferStrategyFactory.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/FluidHandlerImporterTransferStrategyFactory.java @@ -9,12 +9,12 @@ import com.refinedmods.refinedstorage2.platform.api.upgrade.UpgradeState; import com.refinedmods.refinedstorage2.platform.common.content.Items; import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; -import com.refinedmods.refinedstorage2.platform.forge.storage.InteractionCoordinatesImpl; +import com.refinedmods.refinedstorage2.platform.forge.storage.CapabilityCacheImpl; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.server.level.ServerLevel; -import net.minecraftforge.fluids.FluidType; +import net.neoforged.neoforge.fluids.FluidType; public class FluidHandlerImporterTransferStrategyFactory implements ImporterTransferStrategyFactory { @Override @@ -23,7 +23,7 @@ public ImporterTransferStrategy create(final ServerLevel level, final Direction direction, final UpgradeState upgradeState, final AmountOverride amountOverride) { - final ImporterSource source = new FluidHandlerImporterSource(new InteractionCoordinatesImpl( + final ImporterSource source = new FluidHandlerImporterSource(new CapabilityCacheImpl( level, pos, direction diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/ItemHandlerImporterSource.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/ItemHandlerImporterSource.java index 3f7f61b0f..fc311e115 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/ItemHandlerImporterSource.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/ItemHandlerImporterSource.java @@ -7,27 +7,27 @@ import com.refinedmods.refinedstorage2.api.storage.InsertableStorage; import com.refinedmods.refinedstorage2.platform.api.exporter.AmountOverride; import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.forge.storage.InteractionCoordinates; +import com.refinedmods.refinedstorage2.platform.forge.storage.CapabilityCache; import com.refinedmods.refinedstorage2.platform.forge.storage.ItemHandlerExtractableStorage; import com.refinedmods.refinedstorage2.platform.forge.storage.ItemHandlerInsertableStorage; import java.util.Iterator; class ItemHandlerImporterSource implements ImporterSource { - private final InteractionCoordinates interactionCoordinates; + private final CapabilityCache capabilityCache; private final InsertableStorage insertTarget; private final ExtractableStorage extractTarget; - ItemHandlerImporterSource(final InteractionCoordinates interactionCoordinates, + ItemHandlerImporterSource(final CapabilityCache capabilityCache, final AmountOverride amountOverride) { - this.interactionCoordinates = interactionCoordinates; - this.insertTarget = new ItemHandlerInsertableStorage(interactionCoordinates, AmountOverride.NONE); - this.extractTarget = new ItemHandlerExtractableStorage(interactionCoordinates, amountOverride); + this.capabilityCache = capabilityCache; + this.insertTarget = new ItemHandlerInsertableStorage(capabilityCache, AmountOverride.NONE); + this.extractTarget = new ItemHandlerExtractableStorage(capabilityCache, amountOverride); } @Override public Iterator getResources() { - return interactionCoordinates.getItemIterator(); + return capabilityCache.getItemIterator(); } @Override diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/ItemHandlerImporterTransferStrategyFactory.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/ItemHandlerImporterTransferStrategyFactory.java index deefb2463..a1f0a946a 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/ItemHandlerImporterTransferStrategyFactory.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/ItemHandlerImporterTransferStrategyFactory.java @@ -9,7 +9,7 @@ import com.refinedmods.refinedstorage2.platform.api.upgrade.UpgradeState; import com.refinedmods.refinedstorage2.platform.common.content.Items; import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; -import com.refinedmods.refinedstorage2.platform.forge.storage.InteractionCoordinatesImpl; +import com.refinedmods.refinedstorage2.platform.forge.storage.CapabilityCacheImpl; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -22,7 +22,7 @@ public ImporterTransferStrategy create(final ServerLevel level, final Direction direction, final UpgradeState upgradeState, final AmountOverride amountOverride) { - final ImporterSource source = new ItemHandlerImporterSource(new InteractionCoordinatesImpl( + final ImporterSource source = new ItemHandlerImporterSource(new CapabilityCacheImpl( level, pos, direction diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/NetworkManager.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/NetworkManager.java deleted file mode 100644 index c6aa77220..000000000 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/NetworkManager.java +++ /dev/null @@ -1,195 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.forge.packet; - -import com.refinedmods.refinedstorage2.platform.forge.packet.c2s.CraftingGridClearPacket; -import com.refinedmods.refinedstorage2.platform.forge.packet.c2s.CraftingGridRecipeTransferPacket; -import com.refinedmods.refinedstorage2.platform.forge.packet.c2s.GridExtractPacket; -import com.refinedmods.refinedstorage2.platform.forge.packet.c2s.GridInsertPacket; -import com.refinedmods.refinedstorage2.platform.forge.packet.c2s.GridScrollPacket; -import com.refinedmods.refinedstorage2.platform.forge.packet.c2s.PropertyChangePacket; -import com.refinedmods.refinedstorage2.platform.forge.packet.c2s.ResourceFilterSlotChangePacket; -import com.refinedmods.refinedstorage2.platform.forge.packet.c2s.ResourceSlotAmountChangePacket; -import com.refinedmods.refinedstorage2.platform.forge.packet.c2s.ResourceSlotChangePacket; -import com.refinedmods.refinedstorage2.platform.forge.packet.c2s.SingleAmountChangePacket; -import com.refinedmods.refinedstorage2.platform.forge.packet.c2s.StorageInfoRequestPacket; -import com.refinedmods.refinedstorage2.platform.forge.packet.c2s.UseNetworkBoundItemPacket; -import com.refinedmods.refinedstorage2.platform.forge.packet.s2c.EnergyInfoPacket; -import com.refinedmods.refinedstorage2.platform.forge.packet.s2c.GridActivePacket; -import com.refinedmods.refinedstorage2.platform.forge.packet.s2c.GridClearPacket; -import com.refinedmods.refinedstorage2.platform.forge.packet.s2c.GridUpdatePacket; -import com.refinedmods.refinedstorage2.platform.forge.packet.s2c.NetworkTransmitterStatusPacket; -import com.refinedmods.refinedstorage2.platform.forge.packet.s2c.ResourceSlotUpdatePacket; -import com.refinedmods.refinedstorage2.platform.forge.packet.s2c.StorageInfoResponsePacket; -import com.refinedmods.refinedstorage2.platform.forge.packet.s2c.WirelessTransmitterRangePacket; - -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerPlayer; -import net.minecraftforge.network.NetworkRegistry; -import net.minecraftforge.network.PacketDistributor; -import net.minecraftforge.network.simple.SimpleChannel; - -import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; - -public class NetworkManager { - private static final String PROTOCOL_VERSION = "1"; - - private final ResourceLocation channel = createIdentifier("main_channel"); - private final SimpleChannel handler = NetworkRegistry.ChannelBuilder - .named(channel) - .clientAcceptedVersions(PROTOCOL_VERSION::equals) - .serverAcceptedVersions(PROTOCOL_VERSION::equals) - .networkProtocolVersion(() -> PROTOCOL_VERSION) - .simpleChannel(); - - public NetworkManager() { - int id = 0; - handler.registerMessage( - id++, - EnergyInfoPacket.class, - EnergyInfoPacket::encode, - EnergyInfoPacket::decode, - EnergyInfoPacket::handle - ); - handler.registerMessage( - id++, - WirelessTransmitterRangePacket.class, - WirelessTransmitterRangePacket::encode, - WirelessTransmitterRangePacket::decode, - WirelessTransmitterRangePacket::handle - ); - handler.registerMessage( - id++, - PropertyChangePacket.class, - PropertyChangePacket::encode, - PropertyChangePacket::decode, - PropertyChangePacket::handle - ); - handler.registerMessage( - id++, - StorageInfoRequestPacket.class, - StorageInfoRequestPacket::encode, - StorageInfoRequestPacket::decode, - StorageInfoRequestPacket::handle - ); - handler.registerMessage( - id++, - StorageInfoResponsePacket.class, - StorageInfoResponsePacket::encode, - StorageInfoResponsePacket::decode, - StorageInfoResponsePacket::handle - ); - handler.registerMessage( - id++, - ResourceSlotUpdatePacket.class, - ResourceSlotUpdatePacket::encode, - ResourceSlotUpdatePacket::decode, - ResourceSlotUpdatePacket::handle - ); - handler.registerMessage( - id++, - GridActivePacket.class, - GridActivePacket::encode, - GridActivePacket::decode, - GridActivePacket::handle - ); - handler.registerMessage( - id++, - GridClearPacket.class, - (packet, buf) -> { - }, - buf -> new GridClearPacket(), - (buf, ctx) -> GridClearPacket.handle(ctx) - ); - handler.registerMessage( - id++, - GridUpdatePacket.class, - GridUpdatePacket::encode, - GridUpdatePacket::decode, - GridUpdatePacket::handle - ); - handler.registerMessage( - id++, - GridInsertPacket.class, - GridInsertPacket::encode, - GridInsertPacket::decode, - GridInsertPacket::handle - ); - handler.registerMessage( - id++, - GridExtractPacket.class, - GridExtractPacket::encode, - GridExtractPacket::decode, - GridExtractPacket::handle - ); - handler.registerMessage( - id++, - GridScrollPacket.class, - GridScrollPacket::encode, - GridScrollPacket::decode, - GridScrollPacket::handle - ); - handler.registerMessage( - id++, - ResourceSlotAmountChangePacket.class, - ResourceSlotAmountChangePacket::encode, - ResourceSlotAmountChangePacket::decode, - ResourceSlotAmountChangePacket::handle - ); - handler.registerMessage( - id++, - ResourceSlotChangePacket.class, - ResourceSlotChangePacket::encode, - ResourceSlotChangePacket::decode, - ResourceSlotChangePacket::handle - ); - handler.registerMessage( - id++, - ResourceFilterSlotChangePacket.class, - ResourceFilterSlotChangePacket::encode, - ResourceFilterSlotChangePacket::decode, - ResourceFilterSlotChangePacket::handle - ); - handler.registerMessage( - id++, - CraftingGridClearPacket.class, - CraftingGridClearPacket::encode, - CraftingGridClearPacket::decode, - CraftingGridClearPacket::handle - ); - handler.registerMessage( - id++, - CraftingGridRecipeTransferPacket.class, - CraftingGridRecipeTransferPacket::encode, - CraftingGridRecipeTransferPacket::decode, - CraftingGridRecipeTransferPacket::handle - ); - handler.registerMessage( - id++, - SingleAmountChangePacket.class, - SingleAmountChangePacket::encode, - SingleAmountChangePacket::decode, - SingleAmountChangePacket::handle - ); - handler.registerMessage( - id++, - UseNetworkBoundItemPacket.class, - UseNetworkBoundItemPacket::encode, - UseNetworkBoundItemPacket::decode, - UseNetworkBoundItemPacket::handle - ); - handler.registerMessage( - id++, - NetworkTransmitterStatusPacket.class, - NetworkTransmitterStatusPacket::encode, - NetworkTransmitterStatusPacket::decode, - NetworkTransmitterStatusPacket::handle - ); - } - - public void send(final ServerPlayer player, final Object message) { - handler.send(PacketDistributor.PLAYER.with(() -> player), message); - } - - public void send(final Object message) { - handler.sendToServer(message); - } -} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/CraftingGridClearPacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/CraftingGridClearPacket.java deleted file mode 100644 index ce1c0161b..000000000 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/CraftingGridClearPacket.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.forge.packet.c2s; - -import com.refinedmods.refinedstorage2.platform.common.grid.CraftingGridContainerMenu; - -import java.util.function.Supplier; - -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.server.level.ServerPlayer; -import net.minecraftforge.network.NetworkEvent; - -public class CraftingGridClearPacket { - private final boolean toPlayerInventory; - - public CraftingGridClearPacket(final boolean toPlayerInventory) { - this.toPlayerInventory = toPlayerInventory; - } - - public static CraftingGridClearPacket decode(final FriendlyByteBuf buf) { - return new CraftingGridClearPacket(buf.readBoolean()); - } - - public static void encode(final CraftingGridClearPacket packet, final FriendlyByteBuf buf) { - buf.writeBoolean(packet.toPlayerInventory); - } - - public static void handle(final CraftingGridClearPacket packet, final Supplier ctx) { - final ServerPlayer player = ctx.get().getSender(); - if (player != null && player.containerMenu instanceof CraftingGridContainerMenu craftingGridMenu) { - ctx.get().enqueueWork(() -> craftingGridMenu.clear(packet.toPlayerInventory)); - } - ctx.get().setPacketHandled(true); - } -} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/GridInsertPacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/GridInsertPacket.java deleted file mode 100644 index 244cd205a..000000000 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/GridInsertPacket.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.forge.packet.c2s; - -import com.refinedmods.refinedstorage2.api.grid.operations.GridInsertMode; -import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridInsertionStrategy; - -import java.util.function.Supplier; - -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.player.Player; -import net.minecraftforge.network.NetworkEvent; - -public class GridInsertPacket { - private final boolean single; - private final boolean tryAlternatives; - - public GridInsertPacket(final boolean single, final boolean tryAlternatives) { - this.single = single; - this.tryAlternatives = tryAlternatives; - } - - public static GridInsertPacket decode(final FriendlyByteBuf buf) { - return new GridInsertPacket(buf.readBoolean(), buf.readBoolean()); - } - - public static void encode(final GridInsertPacket packet, final FriendlyByteBuf buf) { - buf.writeBoolean(packet.single); - buf.writeBoolean(packet.tryAlternatives); - } - - public static void handle(final GridInsertPacket packet, final Supplier ctx) { - final ServerPlayer player = ctx.get().getSender(); - if (player != null) { - ctx.get().enqueueWork(() -> handle(packet, player)); - } - ctx.get().setPacketHandled(true); - } - - private static void handle(final GridInsertPacket packet, final Player player) { - if (player.containerMenu instanceof GridInsertionStrategy strategy) { - final GridInsertMode mode = packet.single ? GridInsertMode.SINGLE_RESOURCE : GridInsertMode.ENTIRE_RESOURCE; - strategy.onInsert(mode, packet.tryAlternatives); - } - } -} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/PropertyChangePacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/PropertyChangePacket.java deleted file mode 100644 index 199f204d8..000000000 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/PropertyChangePacket.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.forge.packet.c2s; - -import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseContainerMenu; - -import java.util.function.Supplier; - -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.player.Player; -import net.minecraftforge.network.NetworkEvent; - -public class PropertyChangePacket { - private final ResourceLocation id; - private final int value; - - public PropertyChangePacket(final ResourceLocation id, final int value) { - this.id = id; - this.value = value; - } - - public static PropertyChangePacket decode(final FriendlyByteBuf buf) { - return new PropertyChangePacket(buf.readResourceLocation(), buf.readInt()); - } - - public static void encode(final PropertyChangePacket packet, final FriendlyByteBuf buf) { - buf.writeResourceLocation(packet.id); - buf.writeInt(packet.value); - } - - public static void handle(final PropertyChangePacket packet, final Supplier ctx) { - final ServerPlayer player = ctx.get().getSender(); - if (player != null) { - ctx.get().enqueueWork(() -> handle(packet, player)); - } - ctx.get().setPacketHandled(true); - } - - private static void handle(final PropertyChangePacket packet, final Player player) { - if (player.containerMenu instanceof AbstractBaseContainerMenu menu) { - menu.receivePropertyChangeFromClient(packet.id, packet.value); - } - } -} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ResourceFilterSlotChangePacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ResourceFilterSlotChangePacket.java deleted file mode 100644 index a46a439a9..000000000 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ResourceFilterSlotChangePacket.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.forge.packet.c2s; - -import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; -import com.refinedmods.refinedstorage2.platform.common.support.containermenu.AbstractResourceContainerMenu; - -import java.util.Objects; -import java.util.function.Supplier; -import javax.annotation.Nullable; - -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraftforge.network.NetworkEvent; - -public class ResourceFilterSlotChangePacket { - private final int slotIndex; - @Nullable - private final T resource; - @Nullable - private final PlatformStorageChannelType storageChannelType; - @Nullable - private final ResourceLocation storageChannelTypeId; - - public ResourceFilterSlotChangePacket(final int slotIndex, - @Nullable final T resource, - @Nullable final PlatformStorageChannelType storageChannelType, - @Nullable final ResourceLocation storageChannelTypeId) { - this.slotIndex = slotIndex; - this.resource = resource; - this.storageChannelType = storageChannelType; - this.storageChannelTypeId = storageChannelTypeId; - } - - public static ResourceFilterSlotChangePacket decode(final FriendlyByteBuf buf) { - final int slotIndex = buf.readInt(); - final ResourceLocation storageChannelTypeId = buf.readResourceLocation(); - return PlatformApi.INSTANCE.getStorageChannelTypeRegistry().get(storageChannelTypeId) - .map(storageChannelType -> decode(buf, slotIndex, storageChannelType, storageChannelTypeId)) - .orElseGet(() -> new ResourceFilterSlotChangePacket<>(slotIndex, null, null, storageChannelTypeId)); - } - - private static ResourceFilterSlotChangePacket decode(final FriendlyByteBuf buf, - final int slotIndex, - final PlatformStorageChannelType type, - final ResourceLocation typeId) { - final T resource = type.fromBuffer(buf); - return new ResourceFilterSlotChangePacket<>(slotIndex, resource, type, typeId); - } - - public static void encode(final ResourceFilterSlotChangePacket packet, final FriendlyByteBuf buf) { - buf.writeInt(packet.slotIndex); - buf.writeResourceLocation(Objects.requireNonNull(packet.storageChannelTypeId)); - Objects.requireNonNull(packet.storageChannelType).toBuffer(Objects.requireNonNull(packet.resource), buf); - } - - public static void handle(final ResourceFilterSlotChangePacket packet, - final Supplier ctx) { - final ServerPlayer player = ctx.get().getSender(); - if (player != null) { - ctx.get().enqueueWork(() -> handle(player, packet)); - } - ctx.get().setPacketHandled(true); - } - - private static void handle(final Player player, final ResourceFilterSlotChangePacket packet) { - final AbstractContainerMenu menu = player.containerMenu; - if (menu instanceof AbstractResourceContainerMenu containerMenu) { - containerMenu.handleResourceFilterSlotUpdate( - packet.slotIndex, - Objects.requireNonNull(packet.storageChannelType), - Objects.requireNonNull(packet.resource) - ); - } - } -} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ResourceSlotAmountChangePacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ResourceSlotAmountChangePacket.java deleted file mode 100644 index 9244a94f6..000000000 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ResourceSlotAmountChangePacket.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.forge.packet.c2s; - -import com.refinedmods.refinedstorage2.platform.common.support.containermenu.AbstractResourceContainerMenu; - -import java.util.function.Supplier; - -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.player.Player; -import net.minecraftforge.network.NetworkEvent; - -public class ResourceSlotAmountChangePacket { - private final int slotIndex; - private final long amount; - - public ResourceSlotAmountChangePacket(final int slotIndex, final long amount) { - this.slotIndex = slotIndex; - this.amount = amount; - } - - public static ResourceSlotAmountChangePacket decode(final FriendlyByteBuf buf) { - return new ResourceSlotAmountChangePacket(buf.readInt(), buf.readLong()); - } - - public static void encode(final ResourceSlotAmountChangePacket packet, final FriendlyByteBuf buf) { - buf.writeInt(packet.slotIndex); - buf.writeLong(packet.amount); - } - - public static void handle(final ResourceSlotAmountChangePacket packet, final Supplier ctx) { - final ServerPlayer player = ctx.get().getSender(); - if (player != null) { - ctx.get().enqueueWork(() -> handle(packet, player)); - } - ctx.get().setPacketHandled(true); - } - - private static void handle(final ResourceSlotAmountChangePacket packet, final Player player) { - if (player.containerMenu instanceof AbstractResourceContainerMenu containerMenu) { - containerMenu.handleResourceSlotAmountChange(packet.slotIndex, packet.amount); - } - } -} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ResourceSlotChangePacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ResourceSlotChangePacket.java deleted file mode 100644 index f4766cc0f..000000000 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ResourceSlotChangePacket.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.forge.packet.c2s; - -import com.refinedmods.refinedstorage2.platform.common.support.containermenu.AbstractResourceContainerMenu; - -import java.util.function.Supplier; - -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.player.Player; -import net.minecraftforge.network.NetworkEvent; - -public class ResourceSlotChangePacket { - private final int slotIndex; - private final boolean tryAlternatives; - - public ResourceSlotChangePacket(final int slotIndex, final boolean tryAlternatives) { - this.slotIndex = slotIndex; - this.tryAlternatives = tryAlternatives; - } - - public static ResourceSlotChangePacket decode(final FriendlyByteBuf buf) { - return new ResourceSlotChangePacket(buf.readInt(), buf.readBoolean()); - } - - public static void encode(final ResourceSlotChangePacket packet, final FriendlyByteBuf buf) { - buf.writeInt(packet.slotIndex); - buf.writeBoolean(packet.tryAlternatives); - } - - public static void handle(final ResourceSlotChangePacket packet, - final Supplier ctx) { - final ServerPlayer player = ctx.get().getSender(); - if (player != null) { - ctx.get().enqueueWork(() -> handle(packet, player)); - } - ctx.get().setPacketHandled(true); - } - - private static void handle(final ResourceSlotChangePacket packet, final Player player) { - if (player.containerMenu instanceof AbstractResourceContainerMenu containerMenu) { - containerMenu.handleResourceSlotChange(packet.slotIndex, packet.tryAlternatives); - } - } -} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/SingleAmountChangePacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/SingleAmountChangePacket.java deleted file mode 100644 index a7615cd73..000000000 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/SingleAmountChangePacket.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.forge.packet.c2s; - -import com.refinedmods.refinedstorage2.platform.common.support.containermenu.AbstractSingleAmountContainerMenu; - -import java.util.function.Supplier; - -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.player.Player; -import net.minecraftforge.network.NetworkEvent; - -public class SingleAmountChangePacket { - private final double amount; - - public SingleAmountChangePacket(final double amount) { - this.amount = amount; - } - - public static SingleAmountChangePacket decode(final FriendlyByteBuf buf) { - return new SingleAmountChangePacket(buf.readDouble()); - } - - public static void encode(final SingleAmountChangePacket packet, final FriendlyByteBuf buf) { - buf.writeDouble(packet.amount); - } - - public static void handle(final SingleAmountChangePacket packet, final Supplier ctx) { - final ServerPlayer player = ctx.get().getSender(); - if (player != null) { - ctx.get().enqueueWork(() -> handle(packet, player)); - } - ctx.get().setPacketHandled(true); - } - - private static void handle(final SingleAmountChangePacket packet, final Player player) { - if (player.containerMenu instanceof AbstractSingleAmountContainerMenu singleAmountContainerMenu) { - singleAmountContainerMenu.changeAmountOnServer(packet.amount); - } - } -} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/StorageInfoRequestPacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/StorageInfoRequestPacket.java deleted file mode 100644 index c6d5755ed..000000000 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/StorageInfoRequestPacket.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.forge.packet.c2s; - -import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.storage.StorageInfo; -import com.refinedmods.refinedstorage2.platform.common.Platform; - -import java.util.UUID; -import java.util.function.Supplier; - -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.server.level.ServerPlayer; -import net.minecraftforge.network.NetworkEvent; - -public class StorageInfoRequestPacket { - private final UUID id; - - public StorageInfoRequestPacket(final UUID id) { - this.id = id; - } - - public static StorageInfoRequestPacket decode(final FriendlyByteBuf buf) { - return new StorageInfoRequestPacket(buf.readUUID()); - } - - public static void encode(final StorageInfoRequestPacket packet, final FriendlyByteBuf buf) { - buf.writeUUID(packet.id); - } - - public static void handle(final StorageInfoRequestPacket packet, final Supplier ctx) { - final ServerPlayer player = ctx.get().getSender(); - if (player != null) { - ctx.get().enqueueWork(() -> handle(packet, player)); - } - ctx.get().setPacketHandled(true); - } - - private static void handle(final StorageInfoRequestPacket packet, final ServerPlayer player) { - final StorageInfo info = PlatformApi.INSTANCE - .getStorageRepository(player.getCommandSenderWorld()) - .getInfo(packet.id); - - Platform.INSTANCE.getServerToClientCommunications().sendStorageInfoResponse(player, packet.id, info); - } -} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/ClientProxy.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/ClientProxy.java deleted file mode 100644 index af5d7ba85..000000000 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/ClientProxy.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.forge.packet.s2c; - -import java.util.Optional; - -import net.minecraft.client.Minecraft; -import net.minecraft.world.entity.player.Player; - -final class ClientProxy { - private ClientProxy() { - } - - // This method exists to avoid classloading errors on LocalPlayer. - static Optional getPlayer() { - return Optional.ofNullable(Minecraft.getInstance().player); - } -} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/EnergyInfoPacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/EnergyInfoPacket.java deleted file mode 100644 index f51476e95..000000000 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/EnergyInfoPacket.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.forge.packet.s2c; - -import com.refinedmods.refinedstorage2.platform.common.support.energy.EnergyContainerMenu; - -import java.util.function.Supplier; - -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraftforge.network.NetworkEvent; - -public class EnergyInfoPacket { - private final long stored; - private final long capacity; - - public EnergyInfoPacket(final long stored, final long capacity) { - this.stored = stored; - this.capacity = capacity; - } - - public static EnergyInfoPacket decode(final FriendlyByteBuf buf) { - return new EnergyInfoPacket(buf.readLong(), buf.readLong()); - } - - public static void encode(final EnergyInfoPacket packet, final FriendlyByteBuf buf) { - buf.writeLong(packet.stored); - buf.writeLong(packet.capacity); - } - - public static void handle(final EnergyInfoPacket packet, final Supplier ctx) { - ctx.get().enqueueWork(() -> ClientProxy.getPlayer().ifPresent(player -> handle(player, packet))); - ctx.get().setPacketHandled(true); - } - - private static void handle(final Player player, final EnergyInfoPacket packet) { - final AbstractContainerMenu menu = player.containerMenu; - if (menu instanceof EnergyContainerMenu energy) { - energy.getEnergyInfo().setEnergy(packet.stored, packet.capacity); - } - } -} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/GridActivePacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/GridActivePacket.java deleted file mode 100644 index 09296201c..000000000 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/GridActivePacket.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.forge.packet.s2c; - -import com.refinedmods.refinedstorage2.api.grid.watcher.GridWatcher; - -import java.util.function.Supplier; - -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraftforge.network.NetworkEvent; - -public class GridActivePacket { - private final boolean active; - - public GridActivePacket(final boolean active) { - this.active = active; - } - - public static GridActivePacket decode(final FriendlyByteBuf buf) { - return new GridActivePacket(buf.readBoolean()); - } - - public static void encode(final GridActivePacket packet, final FriendlyByteBuf buf) { - buf.writeBoolean(packet.active); - } - - public static void handle(final GridActivePacket packet, final Supplier ctx) { - ctx.get().enqueueWork(() -> ClientProxy.getPlayer().ifPresent(player -> handle(player, packet))); - ctx.get().setPacketHandled(true); - } - - private static void handle(final Player player, final GridActivePacket packet) { - final AbstractContainerMenu menu = player.containerMenu; - if (menu instanceof GridWatcher gridWatcher) { - gridWatcher.onActiveChanged(packet.active); - } - } -} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/GridClearPacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/GridClearPacket.java deleted file mode 100644 index fd6664637..000000000 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/GridClearPacket.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.forge.packet.s2c; - -import com.refinedmods.refinedstorage2.platform.common.grid.AbstractGridContainerMenu; - -import java.util.function.Supplier; - -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraftforge.network.NetworkEvent; - -public class GridClearPacket { - public static void handle(final Supplier ctx) { - ctx.get().enqueueWork(() -> ClientProxy.getPlayer().ifPresent(GridClearPacket::handle)); - ctx.get().setPacketHandled(true); - } - - private static void handle(final Player player) { - final AbstractContainerMenu menu = player.containerMenu; - if (menu instanceof AbstractGridContainerMenu grid) { - grid.onClear(); - } - } -} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/GridUpdatePacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/GridUpdatePacket.java deleted file mode 100644 index fcb25ae42..000000000 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/GridUpdatePacket.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.forge.packet.s2c; - -import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; -import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; -import com.refinedmods.refinedstorage2.platform.common.grid.AbstractGridContainerMenu; -import com.refinedmods.refinedstorage2.platform.common.util.PacketUtil; - -import java.util.function.Supplier; -import javax.annotation.Nullable; - -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.player.Player; -import net.minecraftforge.network.NetworkEvent; - -public class GridUpdatePacket { - private final PlatformStorageChannelType storageChannelType; - private final ResourceLocation storageChannelTypeId; - private final T resource; - private final long amount; - @Nullable - private final TrackedResource trackedResource; - - public GridUpdatePacket( - final PlatformStorageChannelType storageChannelType, - final ResourceLocation storageChannelTypeId, - final T resource, - final long amount, - @Nullable final TrackedResource trackedResource - ) { - this.storageChannelType = storageChannelType; - this.storageChannelTypeId = storageChannelTypeId; - this.resource = resource; - this.amount = amount; - this.trackedResource = trackedResource; - } - - @SuppressWarnings("unchecked") - public static GridUpdatePacket decode(final FriendlyByteBuf buf) { - final ResourceLocation storageChannelTypeId = buf.readResourceLocation(); - final PlatformStorageChannelType storageChannelType = PlatformApi.INSTANCE - .getStorageChannelTypeRegistry() - .get(storageChannelTypeId) - .orElseThrow(); - final Object resource = storageChannelType.fromBuffer(buf); - final long amount = buf.readLong(); - final TrackedResource trackedResource = PacketUtil.readTrackedResource(buf); - return new GridUpdatePacket<>( - (PlatformStorageChannelType) storageChannelType, - storageChannelTypeId, - resource, - amount, - trackedResource - ); - } - - public static void encode(final GridUpdatePacket packet, final FriendlyByteBuf buf) { - buf.writeResourceLocation(packet.storageChannelTypeId); - packet.storageChannelType.toBuffer(packet.resource, buf); - buf.writeLong(packet.amount); - PacketUtil.writeTrackedResource(buf, packet.trackedResource); - } - - public static void handle(final GridUpdatePacket packet, final Supplier ctx) { - ctx.get().enqueueWork(() -> ClientProxy.getPlayer().ifPresent(player -> handle(player, packet))); - ctx.get().setPacketHandled(true); - } - - private static void handle(final Player player, final GridUpdatePacket packet) { - if (player.containerMenu instanceof AbstractGridContainerMenu containerMenu) { - containerMenu.onResourceUpdate(packet.resource, packet.amount, packet.trackedResource); - } - } -} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/NetworkTransmitterStatusPacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/NetworkTransmitterStatusPacket.java deleted file mode 100644 index 400c4a751..000000000 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/NetworkTransmitterStatusPacket.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.forge.packet.s2c; - -import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterContainerMenu; -import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterStatus; - -import java.util.function.Supplier; - -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraftforge.network.NetworkEvent; - -public class NetworkTransmitterStatusPacket { - private final boolean error; - private final Component message; - - public NetworkTransmitterStatusPacket(final boolean error, final Component message) { - this.error = error; - this.message = message; - } - - public static NetworkTransmitterStatusPacket decode(final FriendlyByteBuf buf) { - return new NetworkTransmitterStatusPacket(buf.readBoolean(), buf.readComponent()); - } - - public static void encode(final NetworkTransmitterStatusPacket packet, final FriendlyByteBuf buf) { - buf.writeBoolean(packet.error); - buf.writeComponent(packet.message); - } - - public static void handle(final NetworkTransmitterStatusPacket packet, final Supplier ctx) { - ctx.get().enqueueWork(() -> ClientProxy.getPlayer().ifPresent(player -> handle(player, packet))); - ctx.get().setPacketHandled(true); - } - - private static void handle(final Player player, final NetworkTransmitterStatusPacket packet) { - final AbstractContainerMenu menu = player.containerMenu; - if (menu instanceof NetworkTransmitterContainerMenu containerMenu) { - containerMenu.setStatus(new NetworkTransmitterStatus(packet.error, packet.message)); - } - } -} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/StorageInfoResponsePacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/StorageInfoResponsePacket.java deleted file mode 100644 index 3886ec311..000000000 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/StorageInfoResponsePacket.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.forge.packet.s2c; - -import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.common.storage.ClientStorageRepository; - -import java.util.UUID; -import java.util.function.Supplier; - -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.world.entity.player.Player; -import net.minecraftforge.network.NetworkEvent; - -public class StorageInfoResponsePacket { - private final UUID id; - private final long stored; - private final long capacity; - - public StorageInfoResponsePacket(final UUID id, final long stored, final long capacity) { - this.id = id; - this.stored = stored; - this.capacity = capacity; - } - - public static StorageInfoResponsePacket decode(final FriendlyByteBuf buf) { - return new StorageInfoResponsePacket(buf.readUUID(), buf.readLong(), buf.readLong()); - } - - public static void encode(final StorageInfoResponsePacket packet, final FriendlyByteBuf buf) { - buf.writeUUID(packet.id); - buf.writeLong(packet.stored); - buf.writeLong(packet.capacity); - } - - public static void handle(final StorageInfoResponsePacket packet, final Supplier ctx) { - ctx.get().enqueueWork(() -> ClientProxy.getPlayer().ifPresent(player -> handle(player, packet))); - ctx.get().setPacketHandled(true); - } - - private static void handle(final Player player, final StorageInfoResponsePacket packet) { - final ClientStorageRepository storageRepository = - (ClientStorageRepository) PlatformApi.INSTANCE.getStorageRepository(player.level()); - storageRepository.setInfo(packet.id, packet.stored, packet.capacity); - } -} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/WirelessTransmitterRangePacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/WirelessTransmitterRangePacket.java deleted file mode 100644 index 44ebeb71f..000000000 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/WirelessTransmitterRangePacket.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.forge.packet.s2c; - -import com.refinedmods.refinedstorage2.platform.common.wirelesstransmitter.WirelessTransmitterContainerMenu; - -import java.util.function.Supplier; - -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraftforge.network.NetworkEvent; - -public class WirelessTransmitterRangePacket { - private final int range; - - public WirelessTransmitterRangePacket(final int range) { - this.range = range; - } - - public static WirelessTransmitterRangePacket decode(final FriendlyByteBuf buf) { - return new WirelessTransmitterRangePacket(buf.readInt()); - } - - public static void encode(final WirelessTransmitterRangePacket packet, final FriendlyByteBuf buf) { - buf.writeInt(packet.range); - } - - public static void handle(final WirelessTransmitterRangePacket packet, final Supplier ctx) { - ctx.get().enqueueWork(() -> ClientProxy.getPlayer().ifPresent(player -> handle(player, packet))); - ctx.get().setPacketHandled(true); - } - - private static void handle(final Player player, final WirelessTransmitterRangePacket packet) { - final AbstractContainerMenu menu = player.containerMenu; - if (menu instanceof WirelessTransmitterContainerMenu containerMenu) { - containerMenu.setRange(packet.range); - } - } -} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/RefinedStorageREIClientPlugin.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/RefinedStorageREIClientPlugin.java index 55e345c93..a9f815312 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/RefinedStorageREIClientPlugin.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/RefinedStorageREIClientPlugin.java @@ -7,9 +7,8 @@ import com.refinedmods.refinedstorage2.platform.common.content.ContentIds; import com.refinedmods.refinedstorage2.platform.common.content.Items; import com.refinedmods.refinedstorage2.platform.common.content.Tags; +import com.refinedmods.refinedstorage2.platform.common.controller.ControllerBlockItem; import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseScreen; -import com.refinedmods.refinedstorage2.platform.common.support.ColorableBlock; -import com.refinedmods.refinedstorage2.platform.common.support.energy.EnergyItemHelperImpl; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -26,7 +25,6 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; import net.minecraft.world.item.Item; -import net.minecraft.world.level.block.Block; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; @@ -72,8 +70,11 @@ public void registerCollapsibleEntries(final CollapsibleEntryRegistry registry) registry.group( createIdentifier("fully_charged_controller"), createTranslation("block", "controller.rei_fully_charged"), - EnergyItemHelperImpl.createAllAtEnergyCapacity(Items.INSTANCE.getControllers()) - .map(EntryStacks::of).collect(Collectors.toList()) + Items.INSTANCE.getControllers().stream() + .map(Supplier::get) + .map(ControllerBlockItem::createAtEnergyCapacity) + .map(EntryStacks::of) + .collect(Collectors.toList()) ); groupItems( registry, @@ -104,7 +105,7 @@ public void registerExclusionZones(final ExclusionZones zones) { @SuppressWarnings("UnstableApiUsage") private static void groupItems( final CollapsibleEntryRegistry registry, - final BlockColorMap> blocks, + final BlockColorMap blocks, final ResourceLocation itemIdentifier, final TagKey tag ) { diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/InteractionCoordinates.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/CapabilityCache.java similarity index 86% rename from refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/InteractionCoordinates.java rename to refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/CapabilityCache.java index 21b9690e9..4cbdd7e04 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/InteractionCoordinates.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/CapabilityCache.java @@ -6,21 +6,21 @@ import java.util.Collections; import java.util.Iterator; +import java.util.Optional; import javax.annotation.Nullable; import com.google.common.collect.AbstractIterator; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.capability.IFluidHandler; -import net.minecraftforge.items.IItemHandler; +import net.neoforged.neoforge.fluids.FluidStack; +import net.neoforged.neoforge.fluids.capability.IFluidHandler; +import net.neoforged.neoforge.items.IItemHandler; import static com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource.ofItemStack; import static com.refinedmods.refinedstorage2.platform.forge.support.resource.VariantUtil.ofFluidStack; -public interface InteractionCoordinates { - default LazyOptional getItemHandler() { - return LazyOptional.empty(); +public interface CapabilityCache { + default Optional getItemHandler() { + return Optional.empty(); } default Iterator getItemIterator() { @@ -69,8 +69,8 @@ protected ResourceAmount computeNext() { ).orElse(Collections.emptyListIterator()); } - default LazyOptional getFluidHandler() { - return LazyOptional.empty(); + default Optional getFluidHandler() { + return Optional.empty(); } default Iterator getFluidIterator() { @@ -119,11 +119,11 @@ protected ResourceAmount computeNext() { ).orElse(Collections.emptyListIterator()); } - static InteractionCoordinates ofItemHandler(final IItemHandler itemHandler) { - return new InteractionCoordinates() { + static CapabilityCache ofItemHandler(final IItemHandler itemHandler) { + return new CapabilityCache() { @Override - public LazyOptional getItemHandler() { - return LazyOptional.of(() -> itemHandler); + public Optional getItemHandler() { + return Optional.of(itemHandler); } }; } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/CapabilityCacheImpl.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/CapabilityCacheImpl.java new file mode 100644 index 000000000..744e854fe --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/CapabilityCacheImpl.java @@ -0,0 +1,31 @@ +package com.refinedmods.refinedstorage2.platform.forge.storage; + +import java.util.Optional; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.server.level.ServerLevel; +import net.neoforged.neoforge.capabilities.BlockCapabilityCache; +import net.neoforged.neoforge.capabilities.Capabilities; +import net.neoforged.neoforge.fluids.capability.IFluidHandler; +import net.neoforged.neoforge.items.IItemHandler; + +public final class CapabilityCacheImpl implements CapabilityCache { + private final BlockCapabilityCache itemCapabilityCache; + private final BlockCapabilityCache fluidCapabilityCache; + + public CapabilityCacheImpl(final ServerLevel level, final BlockPos pos, final Direction direction) { + this.itemCapabilityCache = BlockCapabilityCache.create(Capabilities.ItemHandler.BLOCK, level, pos, direction); + this.fluidCapabilityCache = BlockCapabilityCache.create(Capabilities.FluidHandler.BLOCK, level, pos, direction); + } + + @Override + public Optional getItemHandler() { + return Optional.ofNullable(itemCapabilityCache.getCapability()); + } + + @Override + public Optional getFluidHandler() { + return Optional.ofNullable(fluidCapabilityCache.getCapability()); + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/FluidHandlerExtractableStorage.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/FluidHandlerExtractableStorage.java index ea15717c6..76cb7c3ee 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/FluidHandlerExtractableStorage.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/FluidHandlerExtractableStorage.java @@ -6,24 +6,24 @@ import com.refinedmods.refinedstorage2.platform.api.exporter.AmountOverride; import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; -import net.minecraftforge.fluids.FluidStack; +import net.neoforged.neoforge.fluids.FluidStack; import static com.refinedmods.refinedstorage2.platform.forge.support.resource.VariantUtil.toFluidAction; import static com.refinedmods.refinedstorage2.platform.forge.support.resource.VariantUtil.toFluidStack; public class FluidHandlerExtractableStorage implements ExtractableStorage { - private final InteractionCoordinates interactionCoordinates; + private final CapabilityCache capabilityCache; private final AmountOverride amountOverride; - public FluidHandlerExtractableStorage(final InteractionCoordinates interactionCoordinates, + public FluidHandlerExtractableStorage(final CapabilityCache capabilityCache, final AmountOverride amountOverride) { - this.interactionCoordinates = interactionCoordinates; + this.capabilityCache = capabilityCache; this.amountOverride = amountOverride; } @Override public long extract(final FluidResource resource, final long amount, final Action action, final Actor actor) { - return interactionCoordinates.getFluidHandler().map(fluidHandler -> { + return capabilityCache.getFluidHandler().map(fluidHandler -> { final long correctedAmount = amountOverride.overrideAmount( resource, amount, diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/FluidHandlerInsertableStorage.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/FluidHandlerInsertableStorage.java index 152f07317..016d59d48 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/FluidHandlerInsertableStorage.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/FluidHandlerInsertableStorage.java @@ -6,25 +6,25 @@ import com.refinedmods.refinedstorage2.platform.api.exporter.AmountOverride; import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.capability.IFluidHandler; +import net.neoforged.neoforge.fluids.FluidStack; +import net.neoforged.neoforge.fluids.capability.IFluidHandler; import static com.refinedmods.refinedstorage2.platform.forge.support.resource.VariantUtil.toFluidAction; import static com.refinedmods.refinedstorage2.platform.forge.support.resource.VariantUtil.toFluidStack; public class FluidHandlerInsertableStorage implements InsertableStorage { - private final InteractionCoordinates interactionCoordinates; + private final CapabilityCache capabilityCache; private final AmountOverride amountOverride; - public FluidHandlerInsertableStorage(final InteractionCoordinates interactionCoordinates, + public FluidHandlerInsertableStorage(final CapabilityCache capabilityCache, final AmountOverride amountOverride) { - this.interactionCoordinates = interactionCoordinates; + this.capabilityCache = capabilityCache; this.amountOverride = amountOverride; } @Override public long insert(final FluidResource resource, final long amount, final Action action, final Actor actor) { - return interactionCoordinates + return capabilityCache .getFluidHandler() .map(fluidHandler -> { final long correctedAmount = amountOverride.overrideAmount( diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/ForgeHandlerUtil.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/ForgeHandlerUtil.java index 515b84658..93e7bc03c 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/ForgeHandlerUtil.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/ForgeHandlerUtil.java @@ -3,9 +3,9 @@ import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.capability.IFluidHandler; -import net.minecraftforge.items.IItemHandler; +import net.neoforged.neoforge.fluids.FluidStack; +import net.neoforged.neoforge.fluids.capability.IFluidHandler; +import net.neoforged.neoforge.items.IItemHandler; import static com.refinedmods.refinedstorage2.platform.forge.support.resource.VariantUtil.isSame; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/InteractionCoordinatesImpl.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/InteractionCoordinatesImpl.java deleted file mode 100644 index fc22d8bc0..000000000 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/InteractionCoordinatesImpl.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.forge.storage; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.fluids.capability.IFluidHandler; -import net.minecraftforge.items.IItemHandler; - -public final class InteractionCoordinatesImpl implements InteractionCoordinates { - private final Level level; - private final BlockPos pos; - private final Direction direction; - - public InteractionCoordinatesImpl(final Level level, final BlockPos pos, final Direction direction) { - this.level = level; - this.pos = pos; - this.direction = direction; - } - - @Override - public LazyOptional getItemHandler() { - final BlockEntity blockEntity = level.getBlockEntity(pos); - if (blockEntity == null) { - return LazyOptional.empty(); - } - return blockEntity.getCapability(ForgeCapabilities.ITEM_HANDLER, direction); - } - - @Override - public LazyOptional getFluidHandler() { - final BlockEntity blockEntity = level.getBlockEntity(pos); - if (blockEntity == null) { - return LazyOptional.empty(); - } - return blockEntity.getCapability(ForgeCapabilities.FLUID_HANDLER, direction); - } -} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/ItemHandlerExtractableStorage.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/ItemHandlerExtractableStorage.java index 8a362a8d7..a27d8b68d 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/ItemHandlerExtractableStorage.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/ItemHandlerExtractableStorage.java @@ -7,21 +7,21 @@ import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.items.IItemHandler; +import net.neoforged.neoforge.items.IItemHandler; public class ItemHandlerExtractableStorage implements ExtractableStorage { - private final InteractionCoordinates interactionCoordinates; + private final CapabilityCache capabilityCache; private final AmountOverride amountOverride; - public ItemHandlerExtractableStorage(final InteractionCoordinates interactionCoordinates, + public ItemHandlerExtractableStorage(final CapabilityCache capabilityCache, final AmountOverride amountOverride) { - this.interactionCoordinates = interactionCoordinates; + this.capabilityCache = capabilityCache; this.amountOverride = amountOverride; } @Override public long extract(final ItemResource resource, final long amount, final Action action, final Actor actor) { - return interactionCoordinates.getItemHandler().map(itemHandler -> { + return capabilityCache.getItemHandler().map(itemHandler -> { final ItemStack toExtractStack = resource.toItemStack(amount); final long correctedAmount = amountOverride.overrideAmount( resource, diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/ItemHandlerInsertableStorage.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/ItemHandlerInsertableStorage.java index 5c0bbac8f..3ddfeb57f 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/ItemHandlerInsertableStorage.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/ItemHandlerInsertableStorage.java @@ -7,22 +7,22 @@ import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.items.ItemHandlerHelper; +import net.neoforged.neoforge.items.IItemHandler; +import net.neoforged.neoforge.items.ItemHandlerHelper; public class ItemHandlerInsertableStorage implements InsertableStorage { - private final InteractionCoordinates interactionCoordinates; + private final CapabilityCache capabilityCache; private final AmountOverride amountOverride; - public ItemHandlerInsertableStorage(final InteractionCoordinates interactionCoordinates, + public ItemHandlerInsertableStorage(final CapabilityCache capabilityCache, final AmountOverride amountOverride) { - this.interactionCoordinates = interactionCoordinates; + this.capabilityCache = capabilityCache; this.amountOverride = amountOverride; } @Override public long insert(final ItemResource resource, final long amount, final Action action, final Actor actor) { - return interactionCoordinates + return capabilityCache .getItemHandler() .map(itemHandler -> { final long correctedAmount = amountOverride.overrideAmount( diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/DiskDriveBakedModel.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/DiskDriveBakedModel.java index 0ab217024..4e3445e3f 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/DiskDriveBakedModel.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/DiskDriveBakedModel.java @@ -35,8 +35,8 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.client.model.BakedModelWrapper; -import net.minecraftforge.client.model.data.ModelData; +import net.neoforged.neoforge.client.model.BakedModelWrapper; +import net.neoforged.neoforge.client.model.data.ModelData; import org.joml.Vector3f; class DiskDriveBakedModel extends BakedModelWrapper { diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/DiskDriveGeometryLoader.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/DiskDriveGeometryLoader.java index dd6b3cfd4..a5aa8243f 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/DiskDriveGeometryLoader.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/DiskDriveGeometryLoader.java @@ -2,7 +2,7 @@ import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonObject; -import net.minecraftforge.client.model.geometry.IGeometryLoader; +import net.neoforged.neoforge.client.model.geometry.IGeometryLoader; public class DiskDriveGeometryLoader implements IGeometryLoader { @Override diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/DiskDriveUnbakedGeometry.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/DiskDriveUnbakedGeometry.java index 481de4f96..1a394efc8 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/DiskDriveUnbakedGeometry.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/DiskDriveUnbakedGeometry.java @@ -14,8 +14,8 @@ import net.minecraft.client.resources.model.ModelState; import net.minecraft.client.resources.model.UnbakedModel; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.client.model.geometry.IGeometryBakingContext; -import net.minecraftforge.client.model.geometry.IUnbakedGeometry; +import net.neoforged.neoforge.client.model.geometry.IGeometryBakingContext; +import net.neoforged.neoforge.client.model.geometry.IUnbakedGeometry; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; import static java.util.Objects.requireNonNull; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/ForgeDiskDriveBlockEntity.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/ForgeDiskDriveBlockEntity.java index 427d5ec76..8612c9ad8 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/ForgeDiskDriveBlockEntity.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/ForgeDiskDriveBlockEntity.java @@ -7,8 +7,8 @@ import net.minecraft.core.BlockPos; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.client.model.data.ModelData; -import net.minecraftforge.client.model.data.ModelProperty; +import net.neoforged.neoforge.client.model.data.ModelData; +import net.neoforged.neoforge.client.model.data.ModelProperty; public class ForgeDiskDriveBlockEntity extends AbstractDiskDriveBlockEntity { public static final ModelProperty DISKS_PROPERTY = new ModelProperty<>(); diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/FluidHandlerExternalStorageProvider.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/FluidHandlerExternalStorageProvider.java index 3ee239795..5ab10b892 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/FluidHandlerExternalStorageProvider.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/FluidHandlerExternalStorageProvider.java @@ -8,21 +8,21 @@ import com.refinedmods.refinedstorage2.api.storage.external.ExternalStorageProvider; import com.refinedmods.refinedstorage2.platform.api.exporter.AmountOverride; import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.forge.storage.CapabilityCache; import com.refinedmods.refinedstorage2.platform.forge.storage.FluidHandlerExtractableStorage; import com.refinedmods.refinedstorage2.platform.forge.storage.FluidHandlerInsertableStorage; -import com.refinedmods.refinedstorage2.platform.forge.storage.InteractionCoordinates; import java.util.Iterator; class FluidHandlerExternalStorageProvider implements ExternalStorageProvider { - private final InteractionCoordinates interactionCoordinates; + private final CapabilityCache capabilityCache; private final InsertableStorage insertTarget; private final ExtractableStorage extractTarget; - FluidHandlerExternalStorageProvider(final InteractionCoordinates interactionCoordinates) { - this.interactionCoordinates = interactionCoordinates; - this.insertTarget = new FluidHandlerInsertableStorage(interactionCoordinates, AmountOverride.NONE); - this.extractTarget = new FluidHandlerExtractableStorage(interactionCoordinates, AmountOverride.NONE); + FluidHandlerExternalStorageProvider(final CapabilityCache capabilityCache) { + this.capabilityCache = capabilityCache; + this.insertTarget = new FluidHandlerInsertableStorage(capabilityCache, AmountOverride.NONE); + this.extractTarget = new FluidHandlerExtractableStorage(capabilityCache, AmountOverride.NONE); } @Override @@ -37,6 +37,6 @@ public long insert(final FluidResource resource, final long amount, final Action @Override public Iterator> iterator() { - return interactionCoordinates.getFluidAmountIterator(); + return capabilityCache.getFluidAmountIterator(); } } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/FluidHandlerPlatformExternalStorageProviderFactory.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/FluidHandlerPlatformExternalStorageProviderFactory.java index 08d4928d3..e8f31713c 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/FluidHandlerPlatformExternalStorageProviderFactory.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/FluidHandlerPlatformExternalStorageProviderFactory.java @@ -1,29 +1,29 @@ -package com.refinedmods.refinedstorage2.platform.forge.storage.externalstorage; - -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; -import com.refinedmods.refinedstorage2.api.storage.external.ExternalStorageProvider; -import com.refinedmods.refinedstorage2.platform.api.storage.externalstorage.PlatformExternalStorageProviderFactory; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; -import com.refinedmods.refinedstorage2.platform.forge.storage.InteractionCoordinatesImpl; - -import java.util.Optional; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.server.level.ServerLevel; - -public class FluidHandlerPlatformExternalStorageProviderFactory implements PlatformExternalStorageProviderFactory { - @Override - @SuppressWarnings("unchecked") - public Optional> create(final ServerLevel level, - final BlockPos pos, - final Direction direction, - final StorageChannelType storageChannelType) { - if (storageChannelType != StorageChannelTypes.FLUID) { - return Optional.empty(); - } - return Optional.of((ExternalStorageProvider) new FluidHandlerExternalStorageProvider( - new InteractionCoordinatesImpl(level, pos, direction) - )); - } -} +package com.refinedmods.refinedstorage2.platform.forge.storage.externalstorage; + +import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; +import com.refinedmods.refinedstorage2.api.storage.external.ExternalStorageProvider; +import com.refinedmods.refinedstorage2.platform.api.storage.externalstorage.PlatformExternalStorageProviderFactory; +import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.forge.storage.CapabilityCacheImpl; + +import java.util.Optional; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.server.level.ServerLevel; + +public class FluidHandlerPlatformExternalStorageProviderFactory implements PlatformExternalStorageProviderFactory { + @Override + @SuppressWarnings("unchecked") + public Optional> create(final ServerLevel level, + final BlockPos pos, + final Direction direction, + final StorageChannelType storageChannelType) { + if (storageChannelType != StorageChannelTypes.FLUID) { + return Optional.empty(); + } + return Optional.of((ExternalStorageProvider) new FluidHandlerExternalStorageProvider( + new CapabilityCacheImpl(level, pos, direction) + )); + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/ItemHandlerExternalStorageProvider.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/ItemHandlerExternalStorageProvider.java index c176ea173..8085c54a9 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/ItemHandlerExternalStorageProvider.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/ItemHandlerExternalStorageProvider.java @@ -8,21 +8,21 @@ import com.refinedmods.refinedstorage2.api.storage.external.ExternalStorageProvider; import com.refinedmods.refinedstorage2.platform.api.exporter.AmountOverride; import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.forge.storage.InteractionCoordinates; +import com.refinedmods.refinedstorage2.platform.forge.storage.CapabilityCache; import com.refinedmods.refinedstorage2.platform.forge.storage.ItemHandlerExtractableStorage; import com.refinedmods.refinedstorage2.platform.forge.storage.ItemHandlerInsertableStorage; import java.util.Iterator; class ItemHandlerExternalStorageProvider implements ExternalStorageProvider { - private final InteractionCoordinates interactionCoordinates; + private final CapabilityCache capabilityCache; private final InsertableStorage insertTarget; private final ExtractableStorage extractTarget; - ItemHandlerExternalStorageProvider(final InteractionCoordinates interactionCoordinates) { - this.interactionCoordinates = interactionCoordinates; - this.insertTarget = new ItemHandlerInsertableStorage(interactionCoordinates, AmountOverride.NONE); - this.extractTarget = new ItemHandlerExtractableStorage(interactionCoordinates, AmountOverride.NONE); + ItemHandlerExternalStorageProvider(final CapabilityCache capabilityCache) { + this.capabilityCache = capabilityCache; + this.insertTarget = new ItemHandlerInsertableStorage(capabilityCache, AmountOverride.NONE); + this.extractTarget = new ItemHandlerExtractableStorage(capabilityCache, AmountOverride.NONE); } @Override @@ -37,6 +37,6 @@ public long insert(final ItemResource resource, final long amount, final Action @Override public Iterator> iterator() { - return interactionCoordinates.getItemAmountIterator(); + return capabilityCache.getItemAmountIterator(); } } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/ItemHandlerPlatformExternalStorageProviderFactory.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/ItemHandlerPlatformExternalStorageProviderFactory.java index 96ff121dc..0a19e2c7f 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/ItemHandlerPlatformExternalStorageProviderFactory.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/ItemHandlerPlatformExternalStorageProviderFactory.java @@ -1,29 +1,29 @@ -package com.refinedmods.refinedstorage2.platform.forge.storage.externalstorage; - -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; -import com.refinedmods.refinedstorage2.api.storage.external.ExternalStorageProvider; -import com.refinedmods.refinedstorage2.platform.api.storage.externalstorage.PlatformExternalStorageProviderFactory; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; -import com.refinedmods.refinedstorage2.platform.forge.storage.InteractionCoordinatesImpl; - -import java.util.Optional; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.server.level.ServerLevel; - -public class ItemHandlerPlatformExternalStorageProviderFactory implements PlatformExternalStorageProviderFactory { - @Override - @SuppressWarnings("unchecked") - public Optional> create(final ServerLevel level, - final BlockPos pos, - final Direction direction, - final StorageChannelType storageChannelType) { - if (storageChannelType != StorageChannelTypes.ITEM) { - return Optional.empty(); - } - return Optional.of((ExternalStorageProvider) new ItemHandlerExternalStorageProvider( - new InteractionCoordinatesImpl(level, pos, direction) - )); - } -} +package com.refinedmods.refinedstorage2.platform.forge.storage.externalstorage; + +import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; +import com.refinedmods.refinedstorage2.api.storage.external.ExternalStorageProvider; +import com.refinedmods.refinedstorage2.platform.api.storage.externalstorage.PlatformExternalStorageProviderFactory; +import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.forge.storage.CapabilityCacheImpl; + +import java.util.Optional; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.server.level.ServerLevel; + +public class ItemHandlerPlatformExternalStorageProviderFactory implements PlatformExternalStorageProviderFactory { + @Override + @SuppressWarnings("unchecked") + public Optional> create(final ServerLevel level, + final BlockPos pos, + final Direction direction, + final StorageChannelType storageChannelType) { + if (storageChannelType != StorageChannelTypes.ITEM) { + return Optional.empty(); + } + return Optional.of((ExternalStorageProvider) new ItemHandlerExternalStorageProvider( + new CapabilityCacheImpl(level, pos, direction) + )); + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/ForgePortableGridBlockEntity.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/ForgePortableGridBlockEntity.java index fba568027..44e47e042 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/ForgePortableGridBlockEntity.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/ForgePortableGridBlockEntity.java @@ -8,8 +8,8 @@ import net.minecraft.core.BlockPos; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.client.model.data.ModelData; -import net.minecraftforge.client.model.data.ModelProperty; +import net.neoforged.neoforge.client.model.data.ModelData; +import net.neoforged.neoforge.client.model.data.ModelProperty; public class ForgePortableGridBlockEntity extends AbstractPortableGridBlockEntity { public static final ModelProperty DISK_PROPERTY = new ModelProperty<>(); diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/PortableGridBakedModel.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/PortableGridBakedModel.java index acdb86400..121a16686 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/PortableGridBakedModel.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/PortableGridBakedModel.java @@ -29,8 +29,8 @@ import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.client.model.BakedModelWrapper; -import net.minecraftforge.client.model.data.ModelData; +import net.neoforged.neoforge.client.model.BakedModelWrapper; +import net.neoforged.neoforge.client.model.data.ModelData; import org.joml.Vector3f; class PortableGridBakedModel extends BakedModelWrapper { diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/PortableGridGeometryLoader.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/PortableGridGeometryLoader.java index 1e32ebdfc..54e7d2251 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/PortableGridGeometryLoader.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/PortableGridGeometryLoader.java @@ -2,7 +2,7 @@ import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonObject; -import net.minecraftforge.client.model.geometry.IGeometryLoader; +import net.neoforged.neoforge.client.model.geometry.IGeometryLoader; public class PortableGridGeometryLoader implements IGeometryLoader { @Override diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/PortableGridUnbakedGeometry.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/PortableGridUnbakedGeometry.java index c031be700..a5e6a89bf 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/PortableGridUnbakedGeometry.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/PortableGridUnbakedGeometry.java @@ -14,8 +14,8 @@ import net.minecraft.client.resources.model.ModelState; import net.minecraft.client.resources.model.UnbakedModel; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.client.model.geometry.IGeometryBakingContext; -import net.minecraftforge.client.model.geometry.IUnbakedGeometry; +import net.neoforged.neoforge.client.model.geometry.IGeometryBakingContext; +import net.neoforged.neoforge.client.model.geometry.IUnbakedGeometry; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; import static java.util.Objects.requireNonNull; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/containermenu/ContainerTransferDestination.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/containermenu/ContainerTransferDestination.java index 949780b95..2b0bfd443 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/containermenu/ContainerTransferDestination.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/containermenu/ContainerTransferDestination.java @@ -4,8 +4,8 @@ import net.minecraft.world.Container; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.items.ItemHandlerHelper; -import net.minecraftforge.items.wrapper.InvWrapper; +import net.neoforged.neoforge.items.ItemHandlerHelper; +import net.neoforged.neoforge.items.wrapper.InvWrapper; public record ContainerTransferDestination(Container destination) implements TransferDestination { @Override diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/containermenu/MenuOpenerImpl.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/containermenu/MenuOpenerImpl.java index 5e979946e..0dfef840c 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/containermenu/MenuOpenerImpl.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/containermenu/MenuOpenerImpl.java @@ -5,17 +5,12 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.MenuProvider; -import net.minecraftforge.network.NetworkHooks; public class MenuOpenerImpl implements MenuOpener { @Override public void openMenu(final ServerPlayer player, final MenuProvider menuProvider) { if (menuProvider instanceof ExtendedMenuProvider extendedMenuProvider) { - NetworkHooks.openScreen( - player, - menuProvider, - buf -> extendedMenuProvider.writeScreenOpeningData(player, buf) - ); + player.openMenu(menuProvider, buf -> extendedMenuProvider.writeScreenOpeningData(player, buf)); } else { player.openMenu(menuProvider); } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/energy/EnergyStorageAdapter.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/energy/EnergyStorageAdapter.java index 18ec4d73f..50597f01a 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/energy/EnergyStorageAdapter.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/energy/EnergyStorageAdapter.java @@ -3,7 +3,7 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.network.energy.EnergyStorage; -import net.minecraftforge.energy.IEnergyStorage; +import net.neoforged.neoforge.energy.IEnergyStorage; public class EnergyStorageAdapter implements IEnergyStorage { private final EnergyStorage energyStorage; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/network/bounditem/CuriosSlotReference.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/network/bounditem/CuriosSlotReference.java index d382c2bcc..505f32dac 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/network/bounditem/CuriosSlotReference.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/network/bounditem/CuriosSlotReference.java @@ -34,7 +34,6 @@ public void writeToBuffer(final FriendlyByteBuf buf) { @Override public Optional resolve(final Player player) { return CuriosApi.getCuriosInventory(player) - .resolve() .flatMap(curiosInventory -> curiosInventory.findCurio(identifier, index)) .map(SlotResult::stack); } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/network/bounditem/CuriosSlotReferenceProvider.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/network/bounditem/CuriosSlotReferenceProvider.java index a0486d21a..ff3970877 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/network/bounditem/CuriosSlotReferenceProvider.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/network/bounditem/CuriosSlotReferenceProvider.java @@ -10,7 +10,7 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; -import net.minecraftforge.fml.ModList; +import net.neoforged.fml.ModList; import top.theillusivec4.curios.api.CuriosApi; public class CuriosSlotReferenceProvider implements SlotReferenceProvider { @@ -20,7 +20,6 @@ private CuriosSlotReferenceProvider() { @Override public List find(final Player player, final Set validItems) { return CuriosApi.getCuriosInventory(player) - .resolve() .map(curiosInventory -> curiosInventory.findCurios("refinedstorage2")) .orElse(Collections.emptyList()) .stream() diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ClientToServerCommunicationsImpl.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/ClientToServerCommunicationsImpl.java similarity index 70% rename from refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ClientToServerCommunicationsImpl.java rename to refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/ClientToServerCommunicationsImpl.java index e4139b303..e321fab45 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ClientToServerCommunicationsImpl.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/ClientToServerCommunicationsImpl.java @@ -1,4 +1,4 @@ -package com.refinedmods.refinedstorage2.platform.forge.packet.c2s; +package com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s; import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; import com.refinedmods.refinedstorage2.api.grid.operations.GridInsertMode; @@ -9,16 +9,16 @@ import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.support.ClientToServerCommunications; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.PropertyType; -import com.refinedmods.refinedstorage2.platform.forge.packet.NetworkManager; import java.util.List; import java.util.UUID; -public class ClientToServerCommunicationsImpl implements ClientToServerCommunications { - private final NetworkManager networkManager; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.neoforged.neoforge.network.PacketDistributor; - public ClientToServerCommunicationsImpl(final NetworkManager networkManager) { - this.networkManager = networkManager; +public class ClientToServerCommunicationsImpl implements ClientToServerCommunications { + private void sendPacket(final CustomPacketPayload packet) { + PacketDistributor.SERVER.noArg().send(packet); } @Override @@ -26,9 +26,8 @@ public void sendGridExtract(final PlatformStorageChannelType storageChann final T resource, final GridExtractMode mode, final boolean cursor) { - PlatformApi.INSTANCE.getStorageChannelTypeRegistry() - .getId(storageChannelType) - .ifPresent(id -> networkManager.send(new GridExtractPacket<>( + PlatformApi.INSTANCE.getStorageChannelTypeRegistry().getId(storageChannelType) + .ifPresent(id -> sendPacket(new GridExtractPacket<>( storageChannelType, id, resource, @@ -44,7 +43,7 @@ public void sendGridScroll(final PlatformStorageChannelType storageChanne final int slotIndex) { PlatformApi.INSTANCE.getStorageChannelTypeRegistry() .getId(storageChannelType) - .ifPresent(id -> networkManager.send(new GridScrollPacket<>( + .ifPresent(id -> sendPacket(new GridScrollPacket<>( storageChannelType, id, resource, @@ -55,32 +54,32 @@ public void sendGridScroll(final PlatformStorageChannelType storageChanne @Override public void sendGridInsert(final GridInsertMode mode, final boolean tryAlternatives) { - networkManager.send(new GridInsertPacket(mode == GridInsertMode.SINGLE_RESOURCE, tryAlternatives)); + sendPacket(new GridInsertPacket(mode == GridInsertMode.SINGLE_RESOURCE, tryAlternatives)); } @Override public void sendCraftingGridClear(final boolean toPlayerInventory) { - networkManager.send(new CraftingGridClearPacket(toPlayerInventory)); + sendPacket(new CraftingGridClearPacket(toPlayerInventory)); } @Override public void sendCraftingGridRecipeTransfer(final List> recipe) { - networkManager.send(new CraftingGridRecipeTransferPacket(recipe)); + sendPacket(new CraftingGridRecipeTransferPacket(recipe)); } @Override public void sendPropertyChange(final PropertyType type, final T value) { - networkManager.send(new PropertyChangePacket(type.id(), type.serializer().apply(value))); + sendPacket(new PropertyChangePacket(type.id(), type.serializer().apply(value))); } @Override public void sendStorageInfoRequest(final UUID storageId) { - networkManager.send(new StorageInfoRequestPacket(storageId)); + sendPacket(new StorageInfoRequestPacket(storageId)); } @Override public void sendResourceSlotChange(final int slotIndex, final boolean tryAlternatives) { - networkManager.send(new ResourceSlotChangePacket(slotIndex, tryAlternatives)); + sendPacket(new ResourceSlotChangePacket(slotIndex, tryAlternatives)); } @Override @@ -88,7 +87,7 @@ public void sendResourceFilterSlotChange(final PlatformStorageChannelType final T resource, final int slotIndex) { PlatformApi.INSTANCE.getStorageChannelTypeRegistry().getId(storageChannelType).ifPresent( - id -> networkManager.send(new ResourceFilterSlotChangePacket<>( + id -> sendPacket(new ResourceFilterSlotChangePacket<>( slotIndex, resource, storageChannelType, @@ -99,16 +98,16 @@ public void sendResourceFilterSlotChange(final PlatformStorageChannelType @Override public void sendResourceSlotAmountChange(final int slotIndex, final long amount) { - networkManager.send(new ResourceSlotAmountChangePacket(slotIndex, amount)); + sendPacket(new ResourceSlotAmountChangePacket(slotIndex, amount)); } @Override public void sendSingleAmountChange(final double amount) { - networkManager.send(new SingleAmountChangePacket(amount)); + sendPacket(new SingleAmountChangePacket(amount)); } @Override public void sendUseNetworkBoundItem(final SlotReference slotReference) { - networkManager.send(new UseNetworkBoundItemPacket(slotReference)); + sendPacket(new UseNetworkBoundItemPacket(slotReference)); } } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/CraftingGridClearPacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/CraftingGridClearPacket.java new file mode 100644 index 000000000..1f856b6fc --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/CraftingGridClearPacket.java @@ -0,0 +1,33 @@ +package com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s; + +import com.refinedmods.refinedstorage2.platform.common.grid.CraftingGridContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; +import net.neoforged.neoforge.network.handling.PlayPayloadContext; + +public record CraftingGridClearPacket(boolean toPlayerInventory) implements CustomPacketPayload { + public static CraftingGridClearPacket decode(final FriendlyByteBuf buf) { + return new CraftingGridClearPacket(buf.readBoolean()); + } + + public static void handle(final CraftingGridClearPacket packet, final PlayPayloadContext context) { + context.player().ifPresent(player -> context.workHandler().submitAsync(() -> { + if (player.containerMenu instanceof CraftingGridContainerMenu craftingGridContainerMenu) { + craftingGridContainerMenu.clear(packet.toPlayerInventory()); + } + })); + } + + @Override + public void write(final FriendlyByteBuf friendlyByteBuf) { + friendlyByteBuf.writeBoolean(toPlayerInventory); + } + + @Override + public ResourceLocation id() { + return PacketIds.CRAFTING_GRID_CLEAR; + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/CraftingGridRecipeTransferPacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/CraftingGridRecipeTransferPacket.java similarity index 51% rename from refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/CraftingGridRecipeTransferPacket.java rename to refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/CraftingGridRecipeTransferPacket.java index 2916db592..45289443c 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/CraftingGridRecipeTransferPacket.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/CraftingGridRecipeTransferPacket.java @@ -1,25 +1,19 @@ -package com.refinedmods.refinedstorage2.platform.forge.packet.c2s; +package com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s; import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.grid.CraftingGridContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; import com.refinedmods.refinedstorage2.platform.common.util.PacketUtil; import java.util.ArrayList; import java.util.List; -import java.util.function.Supplier; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.player.Player; -import net.minecraftforge.network.NetworkEvent; - -public class CraftingGridRecipeTransferPacket { - private final List> recipe; - - public CraftingGridRecipeTransferPacket(final List> recipe) { - this.recipe = recipe; - } +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; +import net.neoforged.neoforge.network.handling.PlayPayloadContext; +public record CraftingGridRecipeTransferPacket(List> recipe) implements CustomPacketPayload { public static CraftingGridRecipeTransferPacket decode(final FriendlyByteBuf buf) { final int slots = buf.readInt(); final List> recipe = new ArrayList<>(slots); @@ -34,9 +28,10 @@ public static CraftingGridRecipeTransferPacket decode(final FriendlyByteBuf buf) return new CraftingGridRecipeTransferPacket(recipe); } - public static void encode(final CraftingGridRecipeTransferPacket packet, final FriendlyByteBuf buf) { - buf.writeInt(packet.recipe.size()); - for (final List slotPossibilities : packet.recipe) { + @Override + public void write(final FriendlyByteBuf buf) { + buf.writeInt(recipe.size()); + for (final List slotPossibilities : recipe) { buf.writeInt(slotPossibilities.size()); for (final ItemResource slotPossibility : slotPossibilities) { PacketUtil.writeItemResource(buf, slotPossibility); @@ -44,17 +39,16 @@ public static void encode(final CraftingGridRecipeTransferPacket packet, final F } } - public static void handle(final CraftingGridRecipeTransferPacket packet, final Supplier ctx) { - final ServerPlayer player = ctx.get().getSender(); - if (player != null) { - ctx.get().enqueueWork(() -> handle(packet, player)); - } - ctx.get().setPacketHandled(true); + public static void handle(final CraftingGridRecipeTransferPacket packet, final PlayPayloadContext context) { + context.player().ifPresent(player -> context.workHandler().submitAsync(() -> { + if (player.containerMenu instanceof CraftingGridContainerMenu craftingGridContainerMenu) { + craftingGridContainerMenu.transferRecipe(packet.recipe()); + } + })); } - private static void handle(final CraftingGridRecipeTransferPacket packet, final Player player) { - if (player.containerMenu instanceof CraftingGridContainerMenu craftingGridContainerMenu) { - craftingGridContainerMenu.transferRecipe(packet.recipe); - } + @Override + public ResourceLocation id() { + return PacketIds.CRAFTING_GRID_RECIPE_TRANSFER; } } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/GridExtractPacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/GridExtractPacket.java similarity index 50% rename from refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/GridExtractPacket.java rename to refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/GridExtractPacket.java index 27ab57c38..605e15e03 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/GridExtractPacket.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/GridExtractPacket.java @@ -1,38 +1,23 @@ -package com.refinedmods.refinedstorage2.platform.forge.packet.c2s; +package com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s; import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridExtractionStrategy; import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; - -import java.util.function.Supplier; +import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerPlayer; -import net.minecraftforge.network.NetworkEvent; - -public class GridExtractPacket { - private final PlatformStorageChannelType storageChannelType; - private final ResourceLocation storageChannelTypeId; - private final T resource; - private final GridExtractMode mode; - private final boolean cursor; - - public GridExtractPacket( - final PlatformStorageChannelType storageChannelType, - final ResourceLocation storageChannelTypeId, - final T resource, - final GridExtractMode mode, - final boolean cursor - ) { - this.storageChannelType = storageChannelType; - this.storageChannelTypeId = storageChannelTypeId; - this.resource = resource; - this.mode = mode; - this.cursor = cursor; - } +import net.neoforged.neoforge.network.handling.PlayPayloadContext; +public record GridExtractPacket( + PlatformStorageChannelType storageChannelType, + ResourceLocation storageChannelTypeId, + T resource, + GridExtractMode mode, + boolean cursor +) implements CustomPacketPayload { @SuppressWarnings("unchecked") public static GridExtractPacket decode(final FriendlyByteBuf buf) { final ResourceLocation storageChannelTypeId = buf.readResourceLocation(); @@ -52,24 +37,17 @@ public static GridExtractPacket decode(final FriendlyByteBuf buf) { ); } - public static void encode(final GridExtractPacket packet, final FriendlyByteBuf buf) { - buf.writeResourceLocation(packet.storageChannelTypeId); - writeMode(buf, packet.mode); - buf.writeBoolean(packet.cursor); - packet.storageChannelType.toBuffer(packet.resource, buf); - } - - public static void handle(final GridExtractPacket packet, final Supplier ctx) { - final ServerPlayer player = ctx.get().getSender(); - if (player != null && player.containerMenu instanceof GridExtractionStrategy strategy) { - ctx.get().enqueueWork(() -> strategy.onExtract( - packet.storageChannelType, - packet.resource, - packet.mode, - packet.cursor - )); - } - ctx.get().setPacketHandled(true); + public static void handle(final GridExtractPacket packet, final PlayPayloadContext ctx) { + ctx.player().ifPresent(player -> ctx.workHandler().submitAsync(() -> { + if (player.containerMenu instanceof GridExtractionStrategy strategy) { + strategy.onExtract( + packet.storageChannelType, + packet.resource, + packet.mode, + packet.cursor + ); + } + })); } private static GridExtractMode getMode(final byte mode) { @@ -86,4 +64,17 @@ public static void writeMode(final FriendlyByteBuf buf, final GridExtractMode mo buf.writeByte(1); } } + + @Override + public void write(final FriendlyByteBuf buf) { + buf.writeResourceLocation(storageChannelTypeId); + writeMode(buf, mode); + buf.writeBoolean(cursor); + storageChannelType.toBuffer(resource, buf); + } + + @Override + public ResourceLocation id() { + return PacketIds.GRID_EXTRACT; + } } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/GridInsertPacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/GridInsertPacket.java new file mode 100644 index 000000000..11dd710b7 --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/GridInsertPacket.java @@ -0,0 +1,38 @@ +package com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s; + +import com.refinedmods.refinedstorage2.api.grid.operations.GridInsertMode; +import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridInsertionStrategy; +import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; +import net.neoforged.neoforge.network.handling.PlayPayloadContext; + +public record GridInsertPacket(boolean single, boolean tryAlternatives) implements CustomPacketPayload { + public static GridInsertPacket decode(final FriendlyByteBuf buf) { + return new GridInsertPacket(buf.readBoolean(), buf.readBoolean()); + } + + public static void handle(final GridInsertPacket packet, final PlayPayloadContext ctx) { + ctx.player().ifPresent(player -> ctx.workHandler().submitAsync(() -> { + if (player.containerMenu instanceof GridInsertionStrategy strategy) { + final GridInsertMode mode = packet.single + ? GridInsertMode.SINGLE_RESOURCE + : GridInsertMode.ENTIRE_RESOURCE; + strategy.onInsert(mode, packet.tryAlternatives); + } + })); + } + + @Override + public void write(final FriendlyByteBuf buf) { + buf.writeBoolean(single); + buf.writeBoolean(tryAlternatives); + } + + @Override + public ResourceLocation id() { + return PacketIds.GRID_INSERT; + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/GridScrollPacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/GridScrollPacket.java similarity index 53% rename from refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/GridScrollPacket.java rename to refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/GridScrollPacket.java index 44a8a7130..36c24612f 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/GridScrollPacket.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/GridScrollPacket.java @@ -1,38 +1,23 @@ -package com.refinedmods.refinedstorage2.platform.forge.packet.c2s; +package com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollMode; import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridScrollingStrategy; import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; - -import java.util.function.Supplier; +import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerPlayer; -import net.minecraftforge.network.NetworkEvent; - -public class GridScrollPacket { - private final PlatformStorageChannelType storageChannelType; - private final ResourceLocation storageChannelTypeId; - private final T resource; - private final GridScrollMode mode; - private final int slotIndex; - - public GridScrollPacket( - final PlatformStorageChannelType storageChannelType, - final ResourceLocation storageChannelTypeId, - final T resource, - final GridScrollMode mode, - final int slotIndex - ) { - this.storageChannelType = storageChannelType; - this.storageChannelTypeId = storageChannelTypeId; - this.resource = resource; - this.mode = mode; - this.slotIndex = slotIndex; - } +import net.neoforged.neoforge.network.handling.PlayPayloadContext; +public record GridScrollPacket( + PlatformStorageChannelType storageChannelType, + ResourceLocation storageChannelTypeId, + T resource, + GridScrollMode mode, + int slotIndex +) implements CustomPacketPayload { @SuppressWarnings("unchecked") public static GridScrollPacket decode(final FriendlyByteBuf buf) { final ResourceLocation storageChannelTypeId = buf.readResourceLocation(); @@ -52,24 +37,17 @@ public static GridScrollPacket decode(final FriendlyByteBuf buf) { ); } - public static void encode(final GridScrollPacket packet, final FriendlyByteBuf buf) { - buf.writeResourceLocation(packet.storageChannelTypeId); - writeMode(buf, packet.mode); - buf.writeInt(packet.slotIndex); - packet.storageChannelType.toBuffer(packet.resource, buf); - } - - public static void handle(final GridScrollPacket packet, final Supplier ctx) { - final ServerPlayer player = ctx.get().getSender(); - if (player != null && player.containerMenu instanceof GridScrollingStrategy strategy) { - strategy.onScroll( - packet.storageChannelType, - packet.resource, - packet.mode, - packet.slotIndex - ); - } - ctx.get().setPacketHandled(true); + public static void handle(final GridScrollPacket packet, final PlayPayloadContext ctx) { + ctx.player().ifPresent(player -> ctx.workHandler().submitAsync(() -> { + if (player.containerMenu instanceof GridScrollingStrategy strategy) { + strategy.onScroll( + packet.storageChannelType, + packet.resource, + packet.mode, + packet.slotIndex + ); + } + })); } private static GridScrollMode getMode(final byte mode) { @@ -88,4 +66,17 @@ private static void writeMode(final FriendlyByteBuf buf, final GridScrollMode mo case INVENTORY_TO_GRID -> buf.writeByte(2); } } + + @Override + public void write(final FriendlyByteBuf buf) { + buf.writeResourceLocation(storageChannelTypeId); + writeMode(buf, mode); + buf.writeInt(slotIndex); + storageChannelType.toBuffer(resource, buf); + } + + @Override + public ResourceLocation id() { + return PacketIds.GRID_SCROLL; + } } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/PropertyChangePacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/PropertyChangePacket.java new file mode 100644 index 000000000..439a08233 --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/PropertyChangePacket.java @@ -0,0 +1,28 @@ +package com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s; + +import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseContainerMenu; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; +import net.neoforged.neoforge.network.handling.PlayPayloadContext; + +public record PropertyChangePacket(ResourceLocation id, int value) implements CustomPacketPayload { + public static PropertyChangePacket decode(final FriendlyByteBuf buf) { + return new PropertyChangePacket(buf.readResourceLocation(), buf.readInt()); + } + + public static void handle(final PropertyChangePacket packet, final PlayPayloadContext ctx) { + ctx.player().ifPresent(player -> ctx.workHandler().submitAsync(() -> { + if (player.containerMenu instanceof AbstractBaseContainerMenu menu) { + menu.receivePropertyChangeFromClient(packet.id, packet.value); + } + })); + } + + @Override + public void write(final FriendlyByteBuf buf) { + buf.writeResourceLocation(id); + buf.writeInt(value); + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/ResourceFilterSlotChangePacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/ResourceFilterSlotChangePacket.java new file mode 100644 index 000000000..9619b428d --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/ResourceFilterSlotChangePacket.java @@ -0,0 +1,65 @@ +package com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s; + +import com.refinedmods.refinedstorage2.platform.api.PlatformApi; +import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.common.support.containermenu.AbstractResourceContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; + +import java.util.Objects; +import javax.annotation.Nullable; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; +import net.neoforged.neoforge.network.handling.PlayPayloadContext; + +public record ResourceFilterSlotChangePacket( + int slotIndex, + @Nullable + T resource, + @Nullable + PlatformStorageChannelType storageChannelType, + @Nullable + ResourceLocation storageChannelTypeId +) implements CustomPacketPayload { + public static ResourceFilterSlotChangePacket decode(final FriendlyByteBuf buf) { + final int slotIndex = buf.readInt(); + final ResourceLocation storageChannelTypeId = buf.readResourceLocation(); + return PlatformApi.INSTANCE.getStorageChannelTypeRegistry().get(storageChannelTypeId) + .map(storageChannelType -> decode(buf, slotIndex, storageChannelType, storageChannelTypeId)) + .orElseGet(() -> new ResourceFilterSlotChangePacket<>(slotIndex, null, null, storageChannelTypeId)); + } + + private static ResourceFilterSlotChangePacket decode(final FriendlyByteBuf buf, + final int slotIndex, + final PlatformStorageChannelType type, + final ResourceLocation typeId) { + final T resource = type.fromBuffer(buf); + return new ResourceFilterSlotChangePacket<>(slotIndex, resource, type, typeId); + } + + public static void handle(final ResourceFilterSlotChangePacket packet, + final PlayPayloadContext ctx) { + ctx.player().ifPresent(player -> ctx.workHandler().submitAsync(() -> { + if (player.containerMenu instanceof AbstractResourceContainerMenu containerMenu) { + containerMenu.handleResourceFilterSlotUpdate( + packet.slotIndex, + Objects.requireNonNull(packet.storageChannelType), + Objects.requireNonNull(packet.resource) + ); + } + })); + } + + @Override + public void write(final FriendlyByteBuf buf) { + buf.writeInt(slotIndex); + buf.writeResourceLocation(Objects.requireNonNull(storageChannelTypeId)); + Objects.requireNonNull(storageChannelType).toBuffer(Objects.requireNonNull(resource), buf); + } + + @Override + public ResourceLocation id() { + return PacketIds.RESOURCE_FILTER_SLOT_CHANGE; + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/ResourceSlotAmountChangePacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/ResourceSlotAmountChangePacket.java new file mode 100644 index 000000000..2f73419a7 --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/ResourceSlotAmountChangePacket.java @@ -0,0 +1,34 @@ +package com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s; + +import com.refinedmods.refinedstorage2.platform.common.support.containermenu.AbstractResourceContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; +import net.neoforged.neoforge.network.handling.PlayPayloadContext; + +public record ResourceSlotAmountChangePacket(int slotIndex, long amount) implements CustomPacketPayload { + public static ResourceSlotAmountChangePacket decode(final FriendlyByteBuf buf) { + return new ResourceSlotAmountChangePacket(buf.readInt(), buf.readLong()); + } + + public static void handle(final ResourceSlotAmountChangePacket packet, final PlayPayloadContext ctx) { + ctx.player().ifPresent(player -> ctx.workHandler().submitAsync(() -> { + if (player.containerMenu instanceof AbstractResourceContainerMenu containerMenu) { + containerMenu.handleResourceSlotAmountChange(packet.slotIndex, packet.amount); + } + })); + } + + @Override + public void write(final FriendlyByteBuf buf) { + buf.writeInt(slotIndex); + buf.writeLong(amount); + } + + @Override + public ResourceLocation id() { + return PacketIds.RESOURCE_SLOT_AMOUNT_CHANGE; + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/ResourceSlotChangePacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/ResourceSlotChangePacket.java new file mode 100644 index 000000000..9c03ffeea --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/ResourceSlotChangePacket.java @@ -0,0 +1,35 @@ +package com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s; + +import com.refinedmods.refinedstorage2.platform.common.support.containermenu.AbstractResourceContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; +import net.neoforged.neoforge.network.handling.PlayPayloadContext; + +public record ResourceSlotChangePacket(int slotIndex, boolean tryAlternatives) implements CustomPacketPayload { + public static ResourceSlotChangePacket decode(final FriendlyByteBuf buf) { + return new ResourceSlotChangePacket(buf.readInt(), buf.readBoolean()); + } + + public static void handle(final ResourceSlotChangePacket packet, + final PlayPayloadContext ctx) { + ctx.player().ifPresent(player -> ctx.workHandler().submitAsync(() -> { + if (player.containerMenu instanceof AbstractResourceContainerMenu containerMenu) { + containerMenu.handleResourceSlotChange(packet.slotIndex, packet.tryAlternatives); + } + })); + } + + @Override + public void write(final FriendlyByteBuf buf) { + buf.writeInt(slotIndex); + buf.writeBoolean(tryAlternatives); + } + + @Override + public ResourceLocation id() { + return PacketIds.RESOURCE_SLOT_CHANGE; + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/SingleAmountChangePacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/SingleAmountChangePacket.java new file mode 100644 index 000000000..52e6e3213 --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/SingleAmountChangePacket.java @@ -0,0 +1,33 @@ +package com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s; + +import com.refinedmods.refinedstorage2.platform.common.support.containermenu.AbstractSingleAmountContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; +import net.neoforged.neoforge.network.handling.PlayPayloadContext; + +public record SingleAmountChangePacket(double amount) implements CustomPacketPayload { + public static SingleAmountChangePacket decode(final FriendlyByteBuf buf) { + return new SingleAmountChangePacket(buf.readDouble()); + } + + public static void handle(final SingleAmountChangePacket packet, final PlayPayloadContext context) { + context.player().ifPresent(player -> context.workHandler().submitAsync(() -> { + if (player.containerMenu instanceof AbstractSingleAmountContainerMenu singleAmountContainerMenu) { + singleAmountContainerMenu.changeAmountOnServer(packet.amount()); + } + })); + } + + @Override + public void write(final FriendlyByteBuf buf) { + buf.writeDouble(amount); + } + + @Override + public ResourceLocation id() { + return PacketIds.SINGLE_AMOUNT_CHANGE; + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/StorageInfoRequestPacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/StorageInfoRequestPacket.java new file mode 100644 index 000000000..a19cd1f10 --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/StorageInfoRequestPacket.java @@ -0,0 +1,43 @@ +package com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s; + +import com.refinedmods.refinedstorage2.platform.api.PlatformApi; +import com.refinedmods.refinedstorage2.platform.api.storage.StorageInfo; +import com.refinedmods.refinedstorage2.platform.common.Platform; +import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; + +import java.util.UUID; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; +import net.neoforged.neoforge.network.handling.PlayPayloadContext; + +public record StorageInfoRequestPacket(UUID storageId) implements CustomPacketPayload { + public static StorageInfoRequestPacket decode(final FriendlyByteBuf buf) { + return new StorageInfoRequestPacket(buf.readUUID()); + } + + public static void handle(final StorageInfoRequestPacket packet, final PlayPayloadContext context) { + context.player().ifPresent(player -> context.workHandler().submitAsync(() -> { + final StorageInfo info = PlatformApi.INSTANCE + .getStorageRepository(player.getCommandSenderWorld()) + .getInfo(packet.storageId()); + Platform.INSTANCE.getServerToClientCommunications().sendStorageInfoResponse( + (ServerPlayer) player, + packet.storageId(), + info + ); + })); + } + + @Override + public void write(final FriendlyByteBuf buf) { + buf.writeUUID(storageId); + } + + @Override + public ResourceLocation id() { + return PacketIds.STORAGE_INFO_REQUEST; + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/UseNetworkBoundItemPacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/UseNetworkBoundItemPacket.java similarity index 53% rename from refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/UseNetworkBoundItemPacket.java rename to refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/UseNetworkBoundItemPacket.java index f13e0139f..52d344471 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/UseNetworkBoundItemPacket.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/UseNetworkBoundItemPacket.java @@ -1,44 +1,32 @@ -package com.refinedmods.refinedstorage2.platform.forge.packet.c2s; +package com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.support.energy.AbstractNetworkBoundEnergyItem; import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.NetworkBoundItemSession; import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.SlotReference; +import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; -import java.util.function.Supplier; import javax.annotation.Nullable; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; -import net.minecraftforge.network.NetworkEvent; +import net.minecraft.world.entity.player.Player; +import net.neoforged.neoforge.network.handling.PlayPayloadContext; import static java.util.Objects.requireNonNull; -public class UseNetworkBoundItemPacket { - @Nullable - private final SlotReference slotReference; - - public UseNetworkBoundItemPacket(@Nullable final SlotReference slotReference) { - this.slotReference = slotReference; - } - +public record UseNetworkBoundItemPacket(@Nullable SlotReference slotReference) implements CustomPacketPayload { public static UseNetworkBoundItemPacket decode(final FriendlyByteBuf buf) { return new UseNetworkBoundItemPacket(PlatformApi.INSTANCE.getSlotReference(buf).orElse(null)); } - public static void encode(final UseNetworkBoundItemPacket packet, final FriendlyByteBuf buf) { - PlatformApi.INSTANCE.writeSlotReference(requireNonNull(packet.slotReference), buf); - } - - public static void handle(final UseNetworkBoundItemPacket packet, final Supplier ctx) { - final ServerPlayer player = ctx.get().getSender(); - if (player != null) { - ctx.get().enqueueWork(() -> handle(packet, player)); - } - ctx.get().setPacketHandled(true); + public static void handle(final UseNetworkBoundItemPacket packet, final PlayPayloadContext ctx) { + ctx.player().ifPresent(player -> ctx.workHandler().submitAsync(() -> doHandle(packet, player))); } - private static void handle(final UseNetworkBoundItemPacket packet, final ServerPlayer player) { + private static void doHandle(final UseNetworkBoundItemPacket packet, final Player player) { if (packet.slotReference == null) { return; } @@ -48,10 +36,20 @@ private static void handle(final UseNetworkBoundItemPacket packet, final ServerP } final NetworkBoundItemSession sess = PlatformApi.INSTANCE.getNetworkBoundItemHelper().openSession( stack, - player, + (ServerPlayer) player, packet.slotReference ); - networkBoundItem.use(player, packet.slotReference, sess); + networkBoundItem.use((ServerPlayer) player, packet.slotReference, sess); }); } + + @Override + public void write(final FriendlyByteBuf buf) { + PlatformApi.INSTANCE.writeSlotReference(requireNonNull(slotReference), buf); + } + + @Override + public ResourceLocation id() { + return PacketIds.USE_NETWORK_BOUND_ITEM; + } } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/package-info.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/package-info.java similarity index 73% rename from refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/package-info.java rename to refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/package-info.java index 2c84d440c..2e5a53e4b 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/package-info.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/package-info.java @@ -1,6 +1,6 @@ @ParametersAreNonnullByDefault @FieldsAndMethodsAreNonnullByDefault -package com.refinedmods.refinedstorage2.platform.forge.packet.c2s; +package com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s; import com.refinedmods.refinedstorage2.api.core.FieldsAndMethodsAreNonnullByDefault; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/EnergyInfoPacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/EnergyInfoPacket.java new file mode 100644 index 000000000..9fa311980 --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/EnergyInfoPacket.java @@ -0,0 +1,36 @@ +package com.refinedmods.refinedstorage2.platform.forge.support.packet.s2c; + +import com.refinedmods.refinedstorage2.platform.common.support.energy.EnergyContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.neoforged.neoforge.network.handling.PlayPayloadContext; + +public record EnergyInfoPacket(long stored, long capacity) implements CustomPacketPayload { + public static EnergyInfoPacket decode(final FriendlyByteBuf buf) { + return new EnergyInfoPacket(buf.readLong(), buf.readLong()); + } + + public static void handle(final EnergyInfoPacket packet, final PlayPayloadContext ctx) { + ctx.player().ifPresent(player -> ctx.workHandler().submitAsync(() -> { + final AbstractContainerMenu menu = player.containerMenu; + if (menu instanceof EnergyContainerMenu energy) { + energy.getEnergyInfo().setEnergy(packet.stored, packet.capacity); + } + })); + } + + @Override + public void write(final FriendlyByteBuf buf) { + buf.writeLong(stored); + buf.writeLong(capacity); + } + + @Override + public ResourceLocation id() { + return PacketIds.ENERGY_INFO; + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/GridActivePacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/GridActivePacket.java new file mode 100644 index 000000000..9be4a20b0 --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/GridActivePacket.java @@ -0,0 +1,35 @@ +package com.refinedmods.refinedstorage2.platform.forge.support.packet.s2c; + +import com.refinedmods.refinedstorage2.api.grid.watcher.GridWatcher; +import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.neoforged.neoforge.network.handling.PlayPayloadContext; + +public record GridActivePacket(boolean active) implements CustomPacketPayload { + public static GridActivePacket decode(final FriendlyByteBuf buf) { + return new GridActivePacket(buf.readBoolean()); + } + + public static void handle(final GridActivePacket packet, final PlayPayloadContext ctx) { + ctx.player().ifPresent(player -> ctx.workHandler().submitAsync(() -> { + final AbstractContainerMenu menu = player.containerMenu; + if (menu instanceof GridWatcher gridWatcher) { + gridWatcher.onActiveChanged(packet.active); + } + })); + } + + @Override + public void write(final FriendlyByteBuf friendlyByteBuf) { + friendlyByteBuf.writeBoolean(active); + } + + @Override + public ResourceLocation id() { + return PacketIds.GRID_ACTIVE; + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/GridClearPacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/GridClearPacket.java new file mode 100644 index 000000000..5728cbaff --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/GridClearPacket.java @@ -0,0 +1,31 @@ +package com.refinedmods.refinedstorage2.platform.forge.support.packet.s2c; + +import com.refinedmods.refinedstorage2.platform.common.grid.AbstractGridContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.neoforged.neoforge.network.handling.PlayPayloadContext; + +public class GridClearPacket implements CustomPacketPayload { + public static void handle(final PlayPayloadContext ctx) { + ctx.player().ifPresent(player -> ctx.workHandler().submitAsync(() -> { + final AbstractContainerMenu menu = player.containerMenu; + if (menu instanceof AbstractGridContainerMenu grid) { + grid.onClear(); + } + })); + } + + @Override + public void write(final FriendlyByteBuf friendlyByteBuf) { + // no op + } + + @Override + public ResourceLocation id() { + return PacketIds.GRID_CLEAR; + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/GridUpdatePacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/GridUpdatePacket.java new file mode 100644 index 000000000..eacf93ea4 --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/GridUpdatePacket.java @@ -0,0 +1,61 @@ +package com.refinedmods.refinedstorage2.platform.forge.support.packet.s2c; + +import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; +import com.refinedmods.refinedstorage2.platform.api.PlatformApi; +import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.common.grid.AbstractGridContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; +import com.refinedmods.refinedstorage2.platform.common.util.PacketUtil; + +import javax.annotation.Nullable; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; +import net.neoforged.neoforge.network.handling.PlayPayloadContext; + +public record GridUpdatePacket(PlatformStorageChannelType storageChannelType, + ResourceLocation storageChannelTypeId, + T resource, + long amount, + @Nullable TrackedResource trackedResource) implements CustomPacketPayload { + @SuppressWarnings("unchecked") + public static GridUpdatePacket decode(final FriendlyByteBuf buf) { + final ResourceLocation storageChannelTypeId = buf.readResourceLocation(); + final PlatformStorageChannelType storageChannelType = PlatformApi.INSTANCE + .getStorageChannelTypeRegistry() + .get(storageChannelTypeId) + .orElseThrow(); + final Object resource = storageChannelType.fromBuffer(buf); + final long amount = buf.readLong(); + final TrackedResource trackedResource = PacketUtil.readTrackedResource(buf); + return new GridUpdatePacket<>( + (PlatformStorageChannelType) storageChannelType, + storageChannelTypeId, + resource, + amount, + trackedResource + ); + } + + public static void handle(final GridUpdatePacket packet, final PlayPayloadContext ctx) { + ctx.player().ifPresent(player -> ctx.workHandler().submitAsync(() -> { + if (player.containerMenu instanceof AbstractGridContainerMenu containerMenu) { + containerMenu.onResourceUpdate(packet.resource, packet.amount, packet.trackedResource); + } + })); + } + + @Override + public void write(final FriendlyByteBuf buf) { + buf.writeResourceLocation(storageChannelTypeId); + storageChannelType.toBuffer(resource, buf); + buf.writeLong(amount); + PacketUtil.writeTrackedResource(buf, trackedResource); + } + + @Override + public ResourceLocation id() { + return PacketIds.GRID_UPDATE; + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/NetworkTransmitterStatusPacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/NetworkTransmitterStatusPacket.java new file mode 100644 index 000000000..ace9ee7f7 --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/NetworkTransmitterStatusPacket.java @@ -0,0 +1,38 @@ +package com.refinedmods.refinedstorage2.platform.forge.support.packet.s2c; + +import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterStatus; +import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; + +import net.minecraft.network.FriendlyByteBuf; +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; +import net.neoforged.neoforge.network.handling.PlayPayloadContext; + +public record NetworkTransmitterStatusPacket(boolean error, Component message) implements CustomPacketPayload { + public static NetworkTransmitterStatusPacket decode(final FriendlyByteBuf buf) { + return new NetworkTransmitterStatusPacket(buf.readBoolean(), buf.readComponent()); + } + + public static void handle(final NetworkTransmitterStatusPacket packet, final PlayPayloadContext ctx) { + ctx.player().ifPresent(player -> ctx.workHandler().submitAsync(() -> { + final AbstractContainerMenu menu = player.containerMenu; + if (menu instanceof NetworkTransmitterContainerMenu containerMenu) { + containerMenu.setStatus(new NetworkTransmitterStatus(packet.error, packet.message)); + } + })); + } + + @Override + public void write(final FriendlyByteBuf buf) { + buf.writeBoolean(error); + buf.writeComponent(message); + } + + @Override + public ResourceLocation id() { + return PacketIds.NETWORK_TRANSMITTER_STATUS; + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/ResourceSlotUpdatePacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/ResourceSlotUpdatePacket.java similarity index 50% rename from refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/ResourceSlotUpdatePacket.java rename to refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/ResourceSlotUpdatePacket.java index 850bb7704..2b0f5d91d 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/ResourceSlotUpdatePacket.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/ResourceSlotUpdatePacket.java @@ -1,34 +1,22 @@ -package com.refinedmods.refinedstorage2.platform.forge.packet.s2c; +package com.refinedmods.refinedstorage2.platform.forge.support.packet.s2c; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceAmountTemplate; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.AbstractResourceContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; -import java.util.function.Supplier; import javax.annotation.Nullable; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraftforge.network.NetworkEvent; - -public class ResourceSlotUpdatePacket { - private final int slotIndex; - @Nullable - private final ResourceAmountTemplate resourceAmount; - @Nullable - private final ResourceLocation storageChannelTypeId; - - public ResourceSlotUpdatePacket(final int slotIndex, - @Nullable final ResourceAmountTemplate resourceAmount, - @Nullable final ResourceLocation storageChannelTypeId) { - this.slotIndex = slotIndex; - this.resourceAmount = resourceAmount; - this.storageChannelTypeId = storageChannelTypeId; - } +import net.neoforged.neoforge.network.handling.PlayPayloadContext; +public record ResourceSlotUpdatePacket(int slotIndex, + @Nullable ResourceAmountTemplate resourceAmount, + @Nullable ResourceLocation storageChannelTypeId) + implements CustomPacketPayload { public static ResourceSlotUpdatePacket decode(final FriendlyByteBuf buf) { final int slotIndex = buf.readInt(); final boolean present = buf.readBoolean(); @@ -50,27 +38,29 @@ private static ResourceSlotUpdatePacket decode(final FriendlyByteBuf buf, return new ResourceSlotUpdatePacket<>(slotIndex, resourceAmount, null); } - public static void encode(final ResourceSlotUpdatePacket packet, final FriendlyByteBuf buf) { - buf.writeInt(packet.slotIndex); - final boolean present = packet.resourceAmount != null && packet.storageChannelTypeId != null; + public static void handle(final ResourceSlotUpdatePacket packet, + final PlayPayloadContext ctx) { + ctx.player().ifPresent(player -> ctx.workHandler().submitAsync(() -> { + if (player.containerMenu instanceof AbstractResourceContainerMenu containerMenu) { + containerMenu.handleResourceSlotUpdate(packet.slotIndex, packet.resourceAmount); + } + })); + } + + @Override + public void write(final FriendlyByteBuf buf) { + buf.writeInt(slotIndex); + final boolean present = resourceAmount != null && storageChannelTypeId != null; buf.writeBoolean(present); if (present) { - buf.writeResourceLocation(packet.storageChannelTypeId); - packet.resourceAmount.getStorageChannelType().toBuffer(packet.resourceAmount.getResource(), buf); - buf.writeLong(packet.resourceAmount.getAmount()); + buf.writeResourceLocation(storageChannelTypeId); + resourceAmount.getStorageChannelType().toBuffer(resourceAmount.getResource(), buf); + buf.writeLong(resourceAmount.getAmount()); } } - public static void handle(final ResourceSlotUpdatePacket packet, - final Supplier ctx) { - ClientProxy.getPlayer().ifPresent(player -> handle(player, packet)); - ctx.get().setPacketHandled(true); - } - - private static void handle(final Player player, final ResourceSlotUpdatePacket packet) { - final AbstractContainerMenu menu = player.containerMenu; - if (menu instanceof AbstractResourceContainerMenu containerMenu) { - containerMenu.handleResourceSlotUpdate(packet.slotIndex, packet.resourceAmount); - } + @Override + public ResourceLocation id() { + return PacketIds.RESOURCE_SLOT_UPDATE; } } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/ServerToClientCommunicationsImpl.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/ServerToClientCommunicationsImpl.java similarity index 72% rename from refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/ServerToClientCommunicationsImpl.java rename to refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/ServerToClientCommunicationsImpl.java index 66a23a460..00595fd82 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/ServerToClientCommunicationsImpl.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/ServerToClientCommunicationsImpl.java @@ -1,4 +1,4 @@ -package com.refinedmods.refinedstorage2.platform.forge.packet.s2c; +package com.refinedmods.refinedstorage2.platform.forge.support.packet.s2c; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; @@ -7,33 +7,32 @@ import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceAmountTemplate; import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterStatus; import com.refinedmods.refinedstorage2.platform.common.support.ServerToClientCommunications; -import com.refinedmods.refinedstorage2.platform.forge.packet.NetworkManager; import java.util.UUID; import javax.annotation.Nullable; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.server.level.ServerPlayer; +import net.neoforged.neoforge.network.PacketDistributor; public class ServerToClientCommunicationsImpl implements ServerToClientCommunications { - private final NetworkManager networkManager; - - public ServerToClientCommunicationsImpl(final NetworkManager networkManager) { - this.networkManager = networkManager; + private void sendToPlayer(final ServerPlayer player, final CustomPacketPayload packet) { + PacketDistributor.PLAYER.with(player).send(packet); } @Override public void sendEnergyInfo(final ServerPlayer player, final long stored, final long capacity) { - networkManager.send(player, new EnergyInfoPacket(stored, capacity)); + sendToPlayer(player, new EnergyInfoPacket(stored, capacity)); } @Override public void sendWirelessTransmitterRange(final ServerPlayer player, final int range) { - networkManager.send(player, new WirelessTransmitterRangePacket(range)); + sendToPlayer(player, new WirelessTransmitterRangePacket(range)); } @Override public void sendGridActiveness(final ServerPlayer player, final boolean active) { - networkManager.send(player, new GridActivePacket(active)); + sendToPlayer(player, new GridActivePacket(active)); } @Override @@ -45,7 +44,7 @@ public void sendGridUpdate(final ServerPlayer player, PlatformApi.INSTANCE .getStorageChannelTypeRegistry() .getId(storageChannelType) - .ifPresent(id -> networkManager.send(player, new GridUpdatePacket<>( + .ifPresent(id -> sendToPlayer(player, new GridUpdatePacket<>( storageChannelType, id, resource, @@ -56,7 +55,7 @@ public void sendGridUpdate(final ServerPlayer player, @Override public void sendGridClear(final ServerPlayer player) { - networkManager.send(player, new GridClearPacket()); + sendToPlayer(player, new GridClearPacket()); } @Override @@ -66,13 +65,13 @@ public void sendResourceSlotUpdate(final ServerPlayer player, if (resourceAmount != null) { PlatformApi.INSTANCE.getStorageChannelTypeRegistry() .getId(resourceAmount.getStorageChannelType()) - .ifPresent(id -> networkManager.send(player, new ResourceSlotUpdatePacket<>( + .ifPresent(id -> sendToPlayer(player, new ResourceSlotUpdatePacket<>( slotIndex, resourceAmount, id ))); } else { - networkManager.send(player, new ResourceSlotUpdatePacket<>( + sendToPlayer(player, new ResourceSlotUpdatePacket<>( slotIndex, null, null @@ -84,11 +83,11 @@ public void sendResourceSlotUpdate(final ServerPlayer player, public void sendStorageInfoResponse(final ServerPlayer player, final UUID id, final StorageInfo storageInfo) { - networkManager.send(player, new StorageInfoResponsePacket(id, storageInfo.stored(), storageInfo.capacity())); + sendToPlayer(player, new StorageInfoResponsePacket(id, storageInfo.stored(), storageInfo.capacity())); } @Override public void sendNetworkTransmitterStatus(final ServerPlayer player, final NetworkTransmitterStatus status) { - networkManager.send(player, new NetworkTransmitterStatusPacket(status.error(), status.message())); + sendToPlayer(player, new NetworkTransmitterStatusPacket(status.error(), status.message())); } } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/StorageInfoResponsePacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/StorageInfoResponsePacket.java new file mode 100644 index 000000000..b3c195102 --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/StorageInfoResponsePacket.java @@ -0,0 +1,38 @@ +package com.refinedmods.refinedstorage2.platform.forge.support.packet.s2c; + +import com.refinedmods.refinedstorage2.platform.api.PlatformApi; +import com.refinedmods.refinedstorage2.platform.common.storage.ClientStorageRepository; +import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; + +import java.util.UUID; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; +import net.neoforged.neoforge.network.handling.PlayPayloadContext; + +public record StorageInfoResponsePacket(UUID storageId, long stored, long capacity) implements CustomPacketPayload { + public static StorageInfoResponsePacket decode(final FriendlyByteBuf buf) { + return new StorageInfoResponsePacket(buf.readUUID(), buf.readLong(), buf.readLong()); + } + + public static void handle(final StorageInfoResponsePacket packet, final PlayPayloadContext ctx) { + ctx.player().ifPresent(player -> ctx.workHandler().submitAsync(() -> { + final ClientStorageRepository storageRepository = (ClientStorageRepository) + PlatformApi.INSTANCE.getStorageRepository(player.level()); + storageRepository.setInfo(packet.storageId, packet.stored, packet.capacity); + })); + } + + @Override + public void write(final FriendlyByteBuf buf) { + buf.writeUUID(storageId); + buf.writeLong(stored); + buf.writeLong(capacity); + } + + @Override + public ResourceLocation id() { + return PacketIds.STORAGE_INFO_RESPONSE; + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/WirelessTransmitterRangePacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/WirelessTransmitterRangePacket.java new file mode 100644 index 000000000..82c9264b5 --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/WirelessTransmitterRangePacket.java @@ -0,0 +1,33 @@ +package com.refinedmods.refinedstorage2.platform.forge.support.packet.s2c; + +import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; +import com.refinedmods.refinedstorage2.platform.common.wirelesstransmitter.WirelessTransmitterContainerMenu; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; +import net.neoforged.neoforge.network.handling.PlayPayloadContext; + +public record WirelessTransmitterRangePacket(int range) implements CustomPacketPayload { + public static WirelessTransmitterRangePacket decode(final FriendlyByteBuf buf) { + return new WirelessTransmitterRangePacket(buf.readInt()); + } + + public static void handle(final WirelessTransmitterRangePacket packet, final PlayPayloadContext ctx) { + ctx.player().ifPresent(player -> ctx.workHandler().submitAsync(() -> { + if (player.containerMenu instanceof WirelessTransmitterContainerMenu containerMenu) { + containerMenu.setRange(packet.range); + } + })); + } + + @Override + public void write(final FriendlyByteBuf friendlyByteBuf) { + friendlyByteBuf.writeInt(range); + } + + @Override + public ResourceLocation id() { + return PacketIds.WIRELESS_TRANSMITTER_RANGE; + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/package-info.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/package-info.java similarity index 73% rename from refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/package-info.java rename to refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/package-info.java index 69965b022..26a5ccdc9 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/package-info.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/package-info.java @@ -1,6 +1,6 @@ @ParametersAreNonnullByDefault @FieldsAndMethodsAreNonnullByDefault -package com.refinedmods.refinedstorage2.platform.forge.packet; +package com.refinedmods.refinedstorage2.platform.forge.support.packet.s2c; import com.refinedmods.refinedstorage2.api.core.FieldsAndMethodsAreNonnullByDefault; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/FluidStackFluidRenderer.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/FluidStackFluidRenderer.java index 0a798ccc7..4cd49fde3 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/FluidStackFluidRenderer.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/FluidStackFluidRenderer.java @@ -16,9 +16,9 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.inventory.InventoryMenu; import net.minecraft.world.level.material.Fluid; -import net.minecraftforge.client.extensions.common.IClientFluidTypeExtensions; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidType; +import net.neoforged.neoforge.client.extensions.common.IClientFluidTypeExtensions; +import net.neoforged.neoforge.fluids.FluidStack; +import net.neoforged.neoforge.fluids.FluidType; public class FluidStackFluidRenderer extends AbstractFluidRenderer { private final Map stackCache = new HashMap<>(); diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/ItemBakedModel.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/ItemBakedModel.java index 8ea0e223f..580ce1cc6 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/ItemBakedModel.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/ItemBakedModel.java @@ -14,7 +14,7 @@ import net.minecraft.world.item.ItemDisplayContext; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.client.model.BakedModelWrapper; +import net.neoforged.neoforge.client.model.BakedModelWrapper; public class ItemBakedModel extends BakedModelWrapper { private final List unculledFaces; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/RotationTranslationModelBaker.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/RotationTranslationModelBaker.java index 21b3e5da3..763d1e87a 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/RotationTranslationModelBaker.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/RotationTranslationModelBaker.java @@ -10,7 +10,7 @@ import net.minecraft.client.resources.model.ModelBaker; import net.minecraft.client.resources.model.ModelState; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.client.model.SimpleModelState; +import net.neoforged.neoforge.client.model.SimpleModelState; public class RotationTranslationModelBaker { private final ModelState state; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/resource/ResourceContainerFluidHandlerAdapter.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/resource/ResourceContainerFluidHandlerAdapter.java index 8c79a48ad..1fedece10 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/resource/ResourceContainerFluidHandlerAdapter.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/resource/ResourceContainerFluidHandlerAdapter.java @@ -7,8 +7,8 @@ import javax.annotation.Nullable; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.capability.IFluidHandler; +import net.neoforged.neoforge.fluids.FluidStack; +import net.neoforged.neoforge.fluids.capability.IFluidHandler; import static com.refinedmods.refinedstorage2.platform.forge.support.resource.VariantUtil.ofFluidStack; import static com.refinedmods.refinedstorage2.platform.forge.support.resource.VariantUtil.toAction; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/resource/VariantUtil.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/resource/VariantUtil.java index 2e8fc5d99..0a3cd6f8a 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/resource/VariantUtil.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/resource/VariantUtil.java @@ -5,8 +5,8 @@ import java.util.Objects; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.capability.IFluidHandler; +import net.neoforged.neoforge.fluids.FluidStack; +import net.neoforged.neoforge.fluids.capability.IFluidHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/refinedstorage2-platform-forge/src/main/resources/META-INF/accesstransformer.cfg b/refinedstorage2-platform-forge/src/main/resources/META-INF/accesstransformer.cfg index 7509fcbc1..7b36b1489 100644 --- a/refinedstorage2-platform-forge/src/main/resources/META-INF/accesstransformer.cfg +++ b/refinedstorage2-platform-forge/src/main/resources/META-INF/accesstransformer.cfg @@ -1,2 +1,2 @@ -public net.minecraft.client.gui.components.EditBox f_94097_ # canLoseFocus -public net.minecraft.client.gui.GuiGraphics m_280497_(Lnet/minecraft/client/gui/Font;Ljava/util/List;IILnet/minecraft/client/gui/screens/inventory/tooltip/ClientTooltipPositioner;)V # renderTooltipInternal +public net.minecraft.client.gui.components.EditBox canLoseFocus +public net.minecraft.client.gui.GuiGraphics renderTooltipInternal(Lnet/minecraft/client/gui/Font;Ljava/util/List;IILnet/minecraft/client/gui/screens/inventory/tooltip/ClientTooltipPositioner;)V diff --git a/refinedstorage2-platform-forge/src/main/resources/META-INF/mods.toml b/refinedstorage2-platform-forge/src/main/resources/META-INF/mods.toml index a82146007..ef5cf1c45 100644 --- a/refinedstorage2-platform-forge/src/main/resources/META-INF/mods.toml +++ b/refinedstorage2-platform-forge/src/main/resources/META-INF/mods.toml @@ -1,5 +1,5 @@ modLoader = "javafml" -loaderVersion = "[47,)" +loaderVersion = "[2,)" issueTrackerURL = "https://github.com/refinedmods/refinedstorage2" license = "MIT" [[mods]] diff --git a/refinedstorage2-platform-forge/src/main/resources/pack.mcmeta b/refinedstorage2-platform-forge/src/main/resources/pack.mcmeta index 5aecfd166..08cce3f92 100644 --- a/refinedstorage2-platform-forge/src/main/resources/pack.mcmeta +++ b/refinedstorage2-platform-forge/src/main/resources/pack.mcmeta @@ -3,6 +3,6 @@ "description": { "text": "Refined Storage 2 resources" }, - "pack_format": 15 + "pack_format": 18 } } diff --git a/settings.gradle b/settings.gradle index 142a92e09..349a8af92 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,4 +1,4 @@ -gradle.ext.refinedArchitectVersion = "0.9.1" +gradle.ext.refinedArchitectVersion = "0.11.2" dependencyResolutionManagement { repositories {