Skip to content

Commit

Permalink
Move remaining registry types to deferred registration, fix item colo…
Browse files Browse the repository at this point in the history
…ur method for cells
  • Loading branch information
62832 committed Jul 13, 2024
1 parent 5fab88b commit 65bc21c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 50 deletions.
39 changes: 10 additions & 29 deletions src/main/java/gripe/_90/megacells/MEGACells.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.client.renderer.item.ItemProperties;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.FastColor;
import net.minecraft.world.entity.npc.VillagerTrades;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
Expand All @@ -36,10 +36,8 @@
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.OnDatapackSyncEvent;
import net.neoforged.neoforge.event.server.ServerStartedEvent;
import net.neoforged.neoforge.registries.RegisterEvent;

import appeng.api.AECapabilities;
import appeng.api.client.StorageCellModels;
import appeng.api.features.HotkeyAction;
import appeng.api.implementations.items.IAEItemPowerStorage;
import appeng.api.networking.GridServices;
Expand Down Expand Up @@ -89,15 +87,15 @@ public MEGACells(ModContainer container, IEventBus modEventBus) {
MEGABlocks.DR.register(modEventBus);
MEGAItems.DR.register(modEventBus);
MEGABlockEntities.DR.register(modEventBus);
MEGAMenus.DR.register(modEventBus);
MEGAComponents.DR.register(modEventBus);
MEGACreativeTab.DR.register(modEventBus);

modEventBus.addListener(MEGACells::registerAll);
modEventBus.addListener(MEGACells::initUpgrades);
modEventBus.addListener(MEGACells::initStorageCells);
modEventBus.addListener(MEGACells::initVillagerTrades);
modEventBus.addListener(MEGACells::initCapabilities);

MEGAComponents.DEFERRED.register(modEventBus);

initCompression();
initLavaTransform();

Expand All @@ -112,12 +110,6 @@ public static ResourceLocation makeId(String path) {
return ResourceLocation.fromNamespaceAndPath(MODID, path);
}

private static void registerAll(RegisterEvent event) {
event.register(Registries.MENU, helper -> MEGAMenus.getMenuTypes().forEach(helper::register));

event.register(Registries.CREATIVE_MODE_TAB, MEGACreativeTab.ID, () -> MEGACreativeTab.TAB);
}

private static void initUpgrades(FMLCommonSetupEvent event) {
event.enqueueWork(() -> {
var storageCellGroup = GuiText.StorageCells.getTranslationKey();
Expand Down Expand Up @@ -278,7 +270,6 @@ private static void init(IEventBus modEventBus) {
modEventBus.addListener(Client::initCraftingUnitModels);
modEventBus.addListener(Client::initEnergyCellProps);
modEventBus.addListener(Client::initItemColours);
modEventBus.addListener(Client::initStorageCellModels);
}

private static void initScreens(RegisterMenuScreensEvent event) {
Expand Down Expand Up @@ -332,22 +323,12 @@ private static void initItemColours(RegisterColorHandlersEvent.Item event) {
portableCells.addAll(MEGAItems.getItemPortables());
portableCells.addAll(MEGAItems.getFluidPortables());

event.register(BasicStorageCell::getColor, standardCells.toArray(new ItemLike[0]));
event.register(PortableCellItem::getColor, portableCells.toArray(new ItemLike[0]));
}

private static void initStorageCellModels(FMLClientSetupEvent event) {
event.enqueueWork(() -> {
var itemCell = makeId("block/drive/cells/mega_item_cell");
MEGAItems.getItemCells().forEach(cell -> StorageCellModels.registerModel(cell, itemCell));
MEGAItems.getItemPortables().forEach(cell -> StorageCellModels.registerModel(cell, itemCell));

var fluidCell = makeId("block/drive/cells/mega_item_cell");
MEGAItems.getFluidCells().forEach(cell -> StorageCellModels.registerModel(cell, fluidCell));
MEGAItems.getFluidPortables().forEach(cell -> StorageCellModels.registerModel(cell, fluidCell));

StorageCellModels.registerModel(MEGAItems.BULK_ITEM_CELL, makeId("block/drive/cells/bulk_item_cell"));
});
event.register(
(stack, tintIndex) -> FastColor.ARGB32.opaque(BasicStorageCell.getColor(stack, tintIndex)),
standardCells.toArray(new ItemLike[0]));
event.register(
(stack, tintIndex) -> FastColor.ARGB32.opaque(PortableCellItem.getColor(stack, tintIndex)),
portableCells.toArray(new ItemLike[0]));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import io.netty.buffer.ByteBuf;

public final class MEGAComponents {
public static final DeferredRegister<DataComponentType<?>> DEFERRED =
public static final DeferredRegister<DataComponentType<?>> DR =
DeferredRegister.create(Registries.DATA_COMPONENT_TYPE, MEGACells.MODID);

public static final DataComponentType<AEKey> BULK_CELL_ITEM = register(
Expand Down Expand Up @@ -63,7 +63,7 @@ private static <T> DataComponentType<T> register(String name, Consumer<DataCompo
var builder = DataComponentType.<T>builder();
customizer.accept(builder);
var componentType = builder.build();
DEFERRED.register(name, () -> componentType);
DR.register(name, () -> componentType);
return componentType;
}
}
20 changes: 12 additions & 8 deletions src/main/java/gripe/_90/megacells/definition/MEGACreativeTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import java.util.ArrayList;

import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.item.CreativeModeTab;
import net.neoforged.neoforge.registries.DeferredRegister;

import appeng.block.AEBaseBlock;
import appeng.block.AEBaseBlockItem;
Expand All @@ -14,13 +15,16 @@
import gripe._90.megacells.MEGACells;

public final class MEGACreativeTab {
public static final ResourceLocation ID = MEGACells.makeId("tab");

public static final CreativeModeTab TAB = CreativeModeTab.builder()
.title(MEGATranslations.ModName.text())
.icon(MEGAItems.ITEM_CELL_256M::stack)
.displayItems(MEGACreativeTab::populateTab)
.build();
public static final DeferredRegister<CreativeModeTab> DR =
DeferredRegister.create(Registries.CREATIVE_MODE_TAB, MEGACells.MODID);

static {
DR.register("tab", () -> CreativeModeTab.builder()
.title(MEGATranslations.ModName.text())
.icon(MEGAItems.ITEM_CELL_256M::stack)
.displayItems(MEGACreativeTab::populateTab)
.build());
}

private static void populateTab(CreativeModeTab.ItemDisplayParameters params, CreativeModeTab.Output output) {
var itemDefs = new ArrayList<ItemDefinition<?>>();
Expand Down
15 changes: 4 additions & 11 deletions src/main/java/gripe/_90/megacells/definition/MEGAMenus.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package gripe._90.megacells.definition;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.inventory.MenuType;
import net.neoforged.neoforge.registries.DeferredRegister;

import appeng.helpers.InterfaceLogicHost;
import appeng.helpers.patternprovider.PatternProviderLogicHost;
Expand All @@ -17,11 +14,7 @@
import gripe._90.megacells.menu.MEGAPatternProviderMenu;

public final class MEGAMenus {
private static final Map<ResourceLocation, MenuType<?>> MENU_TYPES = new HashMap<>();

public static Map<ResourceLocation, MenuType<?>> getMenuTypes() {
return Collections.unmodifiableMap(MENU_TYPES);
}
public static final DeferredRegister<MenuType<?>> DR = DeferredRegister.create(Registries.MENU, MEGACells.MODID);

public static final MenuType<MEGAInterfaceMenu> MEGA_INTERFACE =
create("mega_interface", MEGAInterfaceMenu::new, InterfaceLogicHost.class);
Expand All @@ -31,7 +24,7 @@ public static Map<ResourceLocation, MenuType<?>> getMenuTypes() {
private static <C extends AEBaseMenu, I> MenuType<C> create(
String id, MenuTypeBuilder.MenuFactory<C, I> factory, Class<I> host) {
var menu = MenuTypeBuilder.create(factory, host).build(MEGACells.makeId(id));
MENU_TYPES.put(MEGACells.makeId(id), menu);
DR.register(id, () -> menu);
return menu;
}
}

0 comments on commit 65bc21c

Please sign in to comment.