Skip to content

Commit

Permalink
refactoring creative tab registration
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobgranberry committed Sep 18, 2024
1 parent 5aa2b56 commit 2c37797
Show file tree
Hide file tree
Showing 54 changed files with 138 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,17 @@
import net.minecraft.world.phys.shapes.Shapes;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.registries.DeferredBlock;
import net.neoforged.neoforge.registries.DeferredRegister;

//
// Template for block configuration data (populated using GSON)
//
public class WesterosBlockDef extends WesterosBlockStateRecord {
public static final DeferredRegister.Blocks BLOCKS = DeferredRegister.createBlocks(WesterosBlocks.MOD_ID);
public static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(WesterosBlocks.MOD_ID);

private static final float DEF_FLOAT = -999.0F;
public static final int DEF_INT = -999;

Expand Down Expand Up @@ -98,24 +102,24 @@ public class WesterosBlockDef extends WesterosBlockStateRecord {
public String legacyBlockID = null;
public List<String> legacyBlockIDList = null;

public static final DeferredRegister.Blocks BLOCKS = DeferredRegister.createBlocks(WesterosBlocks.MOD_ID);
public static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(WesterosBlocks.MOD_ID);

public static <T extends Block> DeferredBlock<T> registerBlock(String blockName, Supplier<T> block) {
DeferredBlock<T> deferredBlock = BLOCKS.register(blockName, block);
registerBlockItem(blockName, deferredBlock);
return deferredBlock;
}

public static void register(IEventBus eventBus) {
BLOCKS.register(eventBus);
ITEMS.register(eventBus);
}

private static <T extends Block> void registerBlockItem(String blockName, DeferredBlock<T> block) {
ITEMS.register(blockName, () -> new BlockItem(block.get(), new Item.Properties()));
}

public void registerWallOrFloorBlock(Block floorblock, Block wallblock) {
DeferredBlock<Block> floorItem = registerBlock(this.blockName, () -> floorblock);
DeferredBlock<Block> wallItem = registerBlock("wall_" + this.blockName,() -> wallblock);
registerBlockItem(this.blockName, floorItem);
registerBlockItem(this.blockName, wallItem);
// AuxileryUtils.registerCreativeTab(itemBlock, getCreativeTab());
}

Expand Down Expand Up @@ -859,14 +863,14 @@ public SoundType getSoundType() {
return ss;
}

public CreativeModeTab getCreativeTab() {
CreativeModeTab ct = tabTable.get(creativeTab);
if (ct == null) {
WesterosBlocks.log.warn(String.format("Invalid tab name '%s' in block '%s'", creativeTab, blockName));
ct = WesterosBlocksCreativeTab.tabWesterosMisc;
}
return ct;
}
// public CreativeModeTab getCreativeTab() {
// CreativeModeTab ct = tabTable.get(creativeTab);
// if (ct == null) {
// WesterosBlocks.log.warn(String.format("Invalid tab name '%s' in block '%s'", creativeTab, blockName));
// ct = WesterosBlocksCreativeTab.tabWesterosMisc;
// }
// return ct;
// }

public static CreativeModeTab getCreativeTab(String tabName) {
return tabTable.get(tabName);
Expand Down Expand Up @@ -1018,16 +1022,16 @@ public static void initialize() {
stepSoundTable.put("plant", SoundType.CROP);
stepSoundTable.put("slime", SoundType.FUNGUS);
// Tab table
tabTable.put("buildingBlocks", BuiltInRegistries.CREATIVE_MODE_TAB.getOrThrow(CreativeModeTabs.BUILDING_BLOCKS));
// tabTable.put("buildingBlocks", BuiltInRegistries.CREATIVE_MODE_TAB.getOrThrow(CreativeModeTabs.BUILDING_BLOCKS));
//tabTable.put("decorations", CreativeModeTabs.DECORATIONS);
tabTable.put("redstone", BuiltInRegistries.CREATIVE_MODE_TAB.getOrThrow(CreativeModeTabs.REDSTONE_BLOCKS));
// tabTable.put("redstone", BuiltInRegistries.CREATIVE_MODE_TAB.getOrThrow(CreativeModeTabs.REDSTONE_BLOCKS));
//tabTable.put("transportation", CreativeModeTabs.TRANSPORTATION);
//tabTable.put("misc", CreativeModeTabs.MISC);
tabTable.put("food", BuiltInRegistries.CREATIVE_MODE_TAB.getOrThrow(CreativeModeTabs.FOOD_AND_DRINKS));
tabTable.put("tools", BuiltInRegistries.CREATIVE_MODE_TAB.getOrThrow(CreativeModeTabs.TOOLS_AND_UTILITIES));
tabTable.put("combat", BuiltInRegistries.CREATIVE_MODE_TAB.getOrThrow(CreativeModeTabs.COMBAT));
// tabTable.put("food", BuiltInRegistries.CREATIVE_MODE_TAB.getOrThrow(CreativeModeTabs.FOOD_AND_DRINKS));
// tabTable.put("tools", BuiltInRegistries.CREATIVE_MODE_TAB.getOrThrow(CreativeModeTabs.TOOLS_AND_UTILITIES));
// tabTable.put("combat", BuiltInRegistries.CREATIVE_MODE_TAB.getOrThrow(CreativeModeTabs.COMBAT));
//tabTable.put("brewing", CreativeModeTabs.BREWING);
tabTable.put("materials", BuiltInRegistries.CREATIVE_MODE_TAB.getOrThrow(CreativeModeTabs.INGREDIENTS));
// tabTable.put("materials", BuiltInRegistries.CREATIVE_MODE_TAB.getOrThrow(CreativeModeTabs.INGREDIENTS));

// Standard block types
typeTable.put("solid", new WCSolidBlock.Factory());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.DoorBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.core.BlockPos;
import net.minecraft.CrashReport;
import net.minecraft.ReportedException;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.level.Level;
Expand Down Expand Up @@ -90,6 +90,7 @@ public class WesterosBlocks {
public static Path modConfigPath;
public static WesterosBlockColorMap[] colorMaps;
public static WesterosItemMenuOverrides[] menuOverrides;

// Network setup TODO: FIXME NEOFORGE NETWORKING
// public static SimpleChannel simpleChannel; // used to transmit your network messages
// public static final String CHANNEL = "wbchannel";
Expand All @@ -112,11 +113,12 @@ public WesterosBlocks(IEventBus modEventBus, ModContainer modContainer) {
// Register the setup method for tile entities
// TODO FIXME
// WesterosBlockDef.TILE_ENTITY_TYPES.register(modEventBus);
WesterosBlockDef.BLOCKS.register(modEventBus);
WesterosBlockDef.ITEMS.register(modEventBus);

// Register ourselves for server and other game events we are interested in
NeoForge.EVENT_BUS.register(this);

WesterosBlockDef.register(modEventBus);
WesterosBlocksCreativeTab.register(modEventBus);
// Create the config folder
Path configPath = FMLPaths.CONFIGDIR.get();
modConfigPath = Paths.get(configPath.toAbsolutePath().toString(), MOD_ID);
Expand All @@ -136,6 +138,8 @@ public WesterosBlocks(IEventBus modEventBus, ModContainer modContainer) {
if (FMLEnvironment.dist.isClient()) {
modContainer.registerExtensionPoint(IConfigScreenFactory.class, ConfigurationScreen::new);
}


}

private void onCommonSetupEvent(final FMLCommonSetupEvent event) {
Expand Down Expand Up @@ -333,7 +337,7 @@ public static void initialize() {
// Initialize
log.info("initialize start");
WesterosBlockDef.initialize();
WesterosBlocksCreativeTab.init();
// WesterosBlocksCreativeTab.init();
// If snow-in-taiga //TODO:FIXME
// if (Config.snowInTaiga) {
// Biome b = ForgeRegistries.BIOMES.getValue(ResourceLocation.fromNamespaceAndPath("minecraft", "taiga"));
Expand Down
Loading

0 comments on commit 2c37797

Please sign in to comment.