Skip to content

Commit

Permalink
feat: expose creative mode tab id
Browse files Browse the repository at this point in the history
As requested by Technici4n

For addon mods who want to add few items
to our main tab.
  • Loading branch information
raoulvdberge committed Oct 12, 2024
1 parent a2da917 commit cbbf7ee
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -207,4 +208,6 @@ EnergyStorage asBlockItemEnergyStorage(
Optional<Pattern> getPattern(ItemStack stack, Level level);

void openAutocraftingPreview(List<ResourceAmount> requests, @Nullable Object parentScreen);

ResourceLocation getCreativeModeTabId();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -408,6 +409,11 @@ public void openAutocraftingPreview(final List<ResourceAmount> 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -605,4 +607,9 @@ public void openAutocraftingPreview(final List<ResourceAmount> requests, @Nullab
}
ClientPlatformUtil.openCraftingPreview(requests, parentScreen);
}

@Override
public ResourceLocation getCreativeModeTabId() {
return ContentIds.CREATIVE_MODE_TAB;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cbbf7ee

Please sign in to comment.