From a444352f8d1baf992ea00fef274d7e26d4e1da84 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 +++++++ .../refinedstorage/common/content/ContentIds.java | 2 ++ .../refinedstorage/fabric/ModInitializerImpl.java | 2 +- .../refinedstorage/neoforge/ModInitializer.java | 2 +- .../refinedstorage/common/exporter/ExporterTest.java | 2 +- .../refinedstorage/common/importer/ImporterTest.java | 2 +- 8 files changed, 22 insertions(+), 4 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/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-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