From cbbf7ee341ea69546d596243d0de32771214c13f Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Sat, 12 Oct 2024 17:22:37 +0200 Subject: [PATCH] feat: expose creative mode tab id As requested by Technici4n For addon mods who want to add few items to our main tab. --- .../refinedstorage/common/api/RefinedStorageApi.java | 3 +++ .../refinedstorage/common/api/RefinedStorageApiProxy.java | 6 ++++++ .../refinedstorage/common/RefinedStorageApiImpl.java | 7 +++++++ .../common/autocrafting/AutocrafterBlockEntity.java | 1 - .../AbstractConstructorBlockEntity.java | 1 - .../refinedstorage/common/content/ContentIds.java | 2 ++ .../common/exporter/AbstractExporterBlockEntity.java | 1 - .../common/importer/AbstractImporterBlockEntity.java | 1 - .../common/networking/WirelessTransmitterBlockEntity.java | 1 - .../diskinterface/AbstractDiskInterfaceBlockEntity.java | 1 - .../refinedstorage/fabric/ModInitializerImpl.java | 2 +- .../refinedstorage/neoforge/ModInitializer.java | 2 +- .../refinedstorage/common/exporter/ExporterTest.java | 2 +- .../refinedstorage/common/importer/ImporterTest.java | 2 +- 14 files changed, 22 insertions(+), 10 deletions(-) diff --git a/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageApi.java b/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageApi.java index 95b3116cc..585eaa5f4 100644 --- a/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageApi.java +++ b/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageApi.java @@ -54,6 +54,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.player.Player; @@ -207,4 +208,6 @@ EnergyStorage asBlockItemEnergyStorage( Optional getPattern(ItemStack stack, Level level); void openAutocraftingPreview(List requests, @Nullable Object parentScreen); + + ResourceLocation getCreativeModeTabId(); } diff --git a/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageApiProxy.java b/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageApiProxy.java index cd6065445..f33b6d74b 100644 --- a/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageApiProxy.java +++ b/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageApiProxy.java @@ -54,6 +54,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.player.Player; @@ -408,6 +409,11 @@ public void openAutocraftingPreview(final List requests, @Nullab ensureLoaded().openAutocraftingPreview(requests, parentScreen); } + @Override + public ResourceLocation getCreativeModeTabId() { + return ensureLoaded().getCreativeModeTabId(); + } + private RefinedStorageApi ensureLoaded() { if (delegate == null) { throw new IllegalStateException("API not loaded yet"); diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/RefinedStorageApiImpl.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/RefinedStorageApiImpl.java index 71589c077..0f328fcc4 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/RefinedStorageApiImpl.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/RefinedStorageApiImpl.java @@ -50,6 +50,7 @@ import com.refinedmods.refinedstorage.common.api.support.slotreference.SlotReferenceProvider; import com.refinedmods.refinedstorage.common.api.upgrade.UpgradeRegistry; import com.refinedmods.refinedstorage.common.api.wirelesstransmitter.WirelessTransmitterRangeModifier; +import com.refinedmods.refinedstorage.common.content.ContentIds; import com.refinedmods.refinedstorage.common.grid.NoopGridSynchronizer; import com.refinedmods.refinedstorage.common.grid.screen.hint.GridInsertionHintsImpl; import com.refinedmods.refinedstorage.common.grid.screen.hint.ItemGridInsertionHint; @@ -104,6 +105,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; @@ -605,4 +607,9 @@ public void openAutocraftingPreview(final List requests, @Nullab } ClientPlatformUtil.openCraftingPreview(requests, parentScreen); } + + @Override + public ResourceLocation getCreativeModeTabId() { + return ContentIds.CREATIVE_MODE_TAB; + } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/AutocrafterBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/AutocrafterBlockEntity.java index 3b6401a9c..a0c59c865 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/AutocrafterBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/AutocrafterBlockEntity.java @@ -32,7 +32,6 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/constructordestructor/AbstractConstructorBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/constructordestructor/AbstractConstructorBlockEntity.java index 7e8add10f..d30fa7823 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/constructordestructor/AbstractConstructorBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/constructordestructor/AbstractConstructorBlockEntity.java @@ -36,7 +36,6 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.state.BlockState; diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/content/ContentIds.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/content/ContentIds.java index 3d932e4e2..31f38d827 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/content/ContentIds.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/content/ContentIds.java @@ -9,6 +9,8 @@ import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createIdentifier; public final class ContentIds { + public static final ResourceLocation CREATIVE_MODE_TAB = createIdentifier("general"); + public static final ResourceLocation DISK_DRIVE = createIdentifier("disk_drive"); public static final ResourceLocation MACHINE_CASING = createIdentifier("machine_casing"); public static final ResourceLocation CABLE = createIdentifier("cable"); diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/exporter/AbstractExporterBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/exporter/AbstractExporterBlockEntity.java index 227a77533..961903cbd 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/exporter/AbstractExporterBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/exporter/AbstractExporterBlockEntity.java @@ -41,7 +41,6 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.state.BlockState; import org.slf4j.Logger; diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/importer/AbstractImporterBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/importer/AbstractImporterBlockEntity.java index e10917621..6e722c5cb 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/importer/AbstractImporterBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/importer/AbstractImporterBlockEntity.java @@ -40,7 +40,6 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.state.BlockState; import org.slf4j.Logger; diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/WirelessTransmitterBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/WirelessTransmitterBlockEntity.java index 49ace3368..acd182a92 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/WirelessTransmitterBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/WirelessTransmitterBlockEntity.java @@ -27,7 +27,6 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.state.BlockState; diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/diskinterface/AbstractDiskInterfaceBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/diskinterface/AbstractDiskInterfaceBlockEntity.java index 81c72b10b..27e78416b 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/diskinterface/AbstractDiskInterfaceBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/diskinterface/AbstractDiskInterfaceBlockEntity.java @@ -28,7 +28,6 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.state.BlockState; diff --git a/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/ModInitializerImpl.java b/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/ModInitializerImpl.java index 37d2390c8..2eb94d057 100644 --- a/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/ModInitializerImpl.java +++ b/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/ModInitializerImpl.java @@ -400,7 +400,7 @@ public boolean allowComponentsUpdateAnimation(final Player player, private void registerCreativeModeTab() { Registry.register( BuiltInRegistries.CREATIVE_MODE_TAB, - createIdentifier("general"), + RefinedStorageApi.INSTANCE.getCreativeModeTabId(), CreativeModeTab.builder(CreativeModeTab.Row.TOP, 0) .title(ContentNames.MOD) .icon(() -> new ItemStack(Blocks.INSTANCE.getCreativeController().getDefault())) diff --git a/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/ModInitializer.java b/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/ModInitializer.java index 2964aed52..fb0e8e4eb 100644 --- a/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/ModInitializer.java +++ b/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/ModInitializer.java @@ -528,7 +528,7 @@ public void onRegister(final RegisterEvent e) { helper -> registerLootFunctions(new DirectRegistryCallback<>(BuiltInRegistries.LOOT_FUNCTION_TYPE)) ); e.register(Registries.CREATIVE_MODE_TAB, helper -> helper.register( - createIdentifier("general"), + RefinedStorageApi.INSTANCE.getCreativeModeTabId(), CreativeModeTab.builder() .title(ContentNames.MOD) .icon(() -> new ItemStack(Blocks.INSTANCE.getCreativeController().getDefault())) diff --git a/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/exporter/ExporterTest.java b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/exporter/ExporterTest.java index 09e93ba91..fa0298721 100644 --- a/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/exporter/ExporterTest.java +++ b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/exporter/ExporterTest.java @@ -129,7 +129,7 @@ public static void shouldExportItemWithRegulatorUpgrade(final GameTestHelper hel if (upgrade.getItem() instanceof RegulatorUpgradeItem upgradeItem) { upgradeItem.setAmount(upgrade, asResource(DIRT.getDefaultInstance()), 10); } - exporter.addUpgradeItem(upgrade); + exporter.addUpgrade(upgrade); // Assert sequence diff --git a/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/importer/ImporterTest.java b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/importer/ImporterTest.java index ed203c400..57209f6d7 100644 --- a/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/importer/ImporterTest.java +++ b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/importer/ImporterTest.java @@ -140,7 +140,7 @@ public static void shouldImportItemWithRegulatorUpgrade(final GameTestHelper hel if (upgrade.getItem() instanceof RegulatorUpgradeItem upgradeItem) { upgradeItem.setAmount(upgrade, asResource(DIRT.getDefaultInstance()), 10); } - importer.addUpgradeItem(upgrade); + importer.addUpgrade(upgrade); // Assert sequence