Skip to content

Commit

Permalink
add developer creative tab
Browse files Browse the repository at this point in the history
  • Loading branch information
UpcraftLP committed Oct 1, 2024
1 parent 5945768 commit 2bd3eba
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Common/src/main/java/dev/upcraft/sparkweave/SparkweaveMod.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package dev.upcraft.sparkweave;

import com.google.common.base.Preconditions;
import dev.upcraft.sparkweave.api.SparkweaveApi;
import dev.upcraft.sparkweave.api.entrypoint.MainEntryPoint;
import dev.upcraft.sparkweave.api.event.CommandEvents;
import dev.upcraft.sparkweave.api.platform.ModContainer;
import dev.upcraft.sparkweave.api.platform.services.RegistryService;
import dev.upcraft.sparkweave.api.registry.RegistryHandler;
import dev.upcraft.sparkweave.command.SparkweaveCommandRoot;
import dev.upcraft.sparkweave.util.SparkweaveDevCreativeTab;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import org.apache.commons.lang3.Validate;

Expand All @@ -18,6 +22,13 @@ public class SparkweaveMod implements MainEntryPoint {
@Override
public void onInitialize(ModContainer mod) {
CommandEvents.REGISTER.register(SparkweaveCommandRoot::register);
var service = RegistryService.get();

if(SparkweaveApi.DEVELOPMENT_ENVIRONMENT) {
var creativeTabsRegister = RegistryHandler.create(Registries.CREATIVE_MODE_TAB, SparkweaveMod.MODID);
creativeTabsRegister.register(SparkweaveDevCreativeTab.DEBUG_MODE_TAB, SparkweaveDevCreativeTab::buildTab);
creativeTabsRegister.accept(service);
}
}

public static ResourceLocation id(String path) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package dev.upcraft.sparkweave.util;

import dev.upcraft.sparkweave.SparkweaveMod;
import dev.upcraft.sparkweave.api.item.CreativeTabHelper;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.LightBlock;

public class SparkweaveDevCreativeTab {

public static final ResourceKey<CreativeModeTab> DEBUG_MODE_TAB = ResourceKey.create(Registries.CREATIVE_MODE_TAB, SparkweaveMod.id("debug_tab"));

public static CreativeModeTab buildTab() {
return CreativeTabHelper.newBuilder(DEBUG_MODE_TAB).icon(Items.COMMAND_BLOCK::getDefaultInstance).displayItems((itemDisplayParameters, output) -> {
output.accept(Items.COMMAND_BLOCK);
output.accept(Items.CHAIN_COMMAND_BLOCK);
output.accept(Items.STRUCTURE_BLOCK);
output.accept(Items.STRUCTURE_VOID);
for(int light : new int[]{ 15, 7, 3, 1 }) {
output.accept(LightBlock.setLightOnStack(new ItemStack(Items.LIGHT), light));
}


}).build();
}
}

0 comments on commit 2bd3eba

Please sign in to comment.