From 265d8993f94047772ecac41f11fa1b6670f246b6 Mon Sep 17 00:00:00 2001 From: 90 <90@national.shitposting.agency> Date: Wed, 25 Jan 2023 09:28:31 +0000 Subject: [PATCH] clean up init again --- .../java/gripe/_90/megacells/MEGACells.java | 35 +++-- .../gripe/_90/megacells/MEGACellsClient.java | 63 +++++---- .../gripe/_90/megacells/forge/MEGACells.java | 68 +++++----- .../_90/megacells/forge/MEGACellsClient.java | 122 +++++++++--------- 4 files changed, 166 insertions(+), 122 deletions(-) diff --git a/fabric/src/main/java/gripe/_90/megacells/MEGACells.java b/fabric/src/main/java/gripe/_90/megacells/MEGACells.java index 775001f1..1e25bd13 100644 --- a/fabric/src/main/java/gripe/_90/megacells/MEGACells.java +++ b/fabric/src/main/java/gripe/_90/megacells/MEGACells.java @@ -20,6 +20,16 @@ public class MEGACells implements IAEAddonEntrypoint { @Override public void onAe2Initialized() { + initAll(); + registerAll(); + + InitStorageCells.init(); + InitUpgrades.init(); + + initCompression(); + } + + private void initAll() { MEGABlocks.init(); MEGAItems.init(); MEGAParts.init(); @@ -28,19 +38,26 @@ public void onAe2Initialized() { if (Utils.PLATFORM.isModLoaded("appbot")) { AppBotItems.init(); } + } - MEGABlocks.getBlocks().forEach(b -> { - Registry.register(Registry.BLOCK, b.id(), b.block()); - Registry.register(Registry.ITEM, b.id(), b.asItem()); - }); - MEGAItems.getItems().forEach(i -> Registry.register(Registry.ITEM, i.id(), i.asItem())); - MEGABlockEntities.getBlockEntityTypes().forEach((k, v) -> Registry.register(Registry.BLOCK_ENTITY_TYPE, k, v)); + private void registerAll() { + for (var block : MEGABlocks.getBlocks()) { + Registry.register(Registry.BLOCK, block.id(), block.block()); + Registry.register(Registry.ITEM, block.id(), block.asItem()); + } - Registry.register(Registry.MENU, AppEng.makeId("mega_pattern_provider"), MEGAPatternProviderMenu.TYPE); + for (var item : MEGAItems.getItems()) { + Registry.register(Registry.ITEM, item.id(), item.asItem()); + } - InitStorageCells.init(); - InitUpgrades.init(); + for (var blockEntity : MEGABlockEntities.getBlockEntityTypes().entrySet()) { + Registry.register(Registry.BLOCK_ENTITY_TYPE, blockEntity.getKey(), blockEntity.getValue()); + } + + Registry.register(Registry.MENU, AppEng.makeId("mega_pattern_provider"), MEGAPatternProviderMenu.TYPE); + } + private void initCompression() { ServerLifecycleEvents.SERVER_STARTED.register(server -> CompressionService.INSTANCE.load()); ServerLifecycleEvents.END_DATA_PACK_RELOAD.register((server, resourceManager, success) -> { if (success) { diff --git a/fabric/src/main/java/gripe/_90/megacells/MEGACellsClient.java b/fabric/src/main/java/gripe/_90/megacells/MEGACellsClient.java index d83a1131..4d2d7067 100644 --- a/fabric/src/main/java/gripe/_90/megacells/MEGACellsClient.java +++ b/fabric/src/main/java/gripe/_90/megacells/MEGACellsClient.java @@ -45,11 +45,20 @@ public class MEGACellsClient implements IAEAddonEntrypoint { @Override public void onAe2Initialized() { + initScreens(); + initBlockModels(); + initItemModels(); + initItemColors(); + } + + private void initScreens() { ClientLifecycleEvents.CLIENT_STARTED.register(client -> { InitScreens.register(MEGAPatternProviderMenu.TYPE, PatternProviderScreen::new, "/screens/megacells/mega_pattern_provider.json"); }); + } + private void initBlockModels() { for (var type : MEGACraftingUnitType.values()) { ModelLoadingRegistry.INSTANCE.registerResourceProvider(resourceManager -> new SimpleModelLoader<>( Utils.makeId("block/crafting/" + type.getAffix() + "_formed"), @@ -60,31 +69,6 @@ public void onAe2Initialized() { BlockEntityRenderers.register(MEGABlockEntities.MEGA_CRAFTING_MONITOR, CraftingMonitorRenderer::new); - var cells = new ArrayList<>(MEGAItems.getItemCells()); - cells.addAll(MEGAItems.getFluidCells()); - cells.add(MEGAItems.BULK_ITEM_CELL); - - var portables = new ArrayList<>(MEGAItems.getItemPortables()); - portables.addAll(MEGAItems.getFluidPortables()); - - if (Utils.PLATFORM.isModLoaded("appbot")) { - cells.addAll(AppBotItems.getCells()); - portables.addAll(AppBotItems.getPortables()); - } - - ColorProviderRegistry.ITEM.register(BasicStorageCell::getColor, cells.toArray(new ItemLike[0])); - ColorProviderRegistry.ITEM.register(PortableCellItem::getColor, portables.toArray(new ItemLike[0])); - - ItemProperties.register(MEGABlocks.MEGA_ENERGY_CELL.asItem(), AppEng.makeId("fill_level"), - (is, level, entity, seed) -> { - var energyCell = (EnergyCellBlockItem) MEGABlocks.MEGA_ENERGY_CELL.asItem(); - - double curPower = energyCell.getAECurrentPower(is); - double maxPower = energyCell.getAEMaxPower(is); - - return (float) (curPower / maxPower); - }); - ModelsReloadCallback.EVENT.register(modelRegistry -> { var customizers = new HashMap>(); customizers.put(MEGABlocks.CRAFTING_MONITOR.id(), model -> model instanceof MonitorBakedModel @@ -115,4 +99,33 @@ public void onAe2Initialized() { } }); } + + private void initItemModels() { + ItemProperties.register(MEGABlocks.MEGA_ENERGY_CELL.asItem(), AppEng.makeId("fill_level"), + (is, level, entity, seed) -> { + var energyCell = (EnergyCellBlockItem) MEGABlocks.MEGA_ENERGY_CELL.asItem(); + + double curPower = energyCell.getAECurrentPower(is); + double maxPower = energyCell.getAEMaxPower(is); + + return (float) (curPower / maxPower); + }); + } + + private void initItemColors() { + var cells = new ArrayList<>(MEGAItems.getItemCells()); + cells.addAll(MEGAItems.getFluidCells()); + cells.add(MEGAItems.BULK_ITEM_CELL); + + var portables = new ArrayList<>(MEGAItems.getItemPortables()); + portables.addAll(MEGAItems.getFluidPortables()); + + if (Utils.PLATFORM.isModLoaded("appbot")) { + cells.addAll(AppBotItems.getCells()); + portables.addAll(AppBotItems.getPortables()); + } + + ColorProviderRegistry.ITEM.register(BasicStorageCell::getColor, cells.toArray(new ItemLike[0])); + ColorProviderRegistry.ITEM.register(PortableCellItem::getColor, portables.toArray(new ItemLike[0])); + } } diff --git a/forge/src/main/java/gripe/_90/megacells/forge/MEGACells.java b/forge/src/main/java/gripe/_90/megacells/forge/MEGACells.java index 97f60282..b2c59ac7 100644 --- a/forge/src/main/java/gripe/_90/megacells/forge/MEGACells.java +++ b/forge/src/main/java/gripe/_90/megacells/forge/MEGACells.java @@ -30,8 +30,18 @@ @Mod(Utils.MODID) public class MEGACells { public MEGACells() { + initAll(); + var bus = FMLJavaModLoadingContext.get().getModEventBus(); + bus.addListener(this::registerAll); + bus.addListener(this::initCells); + + initCompression(); + + DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> MEGACellsClient::new); + } + private void initAll() { MEGABlocks.init(); MEGAItems.init(); MEGAParts.init(); @@ -44,44 +54,44 @@ public MEGACells() { if (Utils.PLATFORM.isModLoaded("appbot")) { AppBotItems.init(); } + } - bus.addListener((RegisterEvent event) -> { - if (event.getRegistryKey().equals(Registry.BLOCK_REGISTRY)) { - MEGABlocks.getBlocks().forEach(b -> { - ForgeRegistries.BLOCKS.register(b.id(), b.block()); - ForgeRegistries.ITEMS.register(b.id(), b.asItem()); - }); - } + private void registerAll(RegisterEvent event) { + if (event.getRegistryKey().equals(Registry.BLOCK_REGISTRY)) { + MEGABlocks.getBlocks().forEach(b -> { + ForgeRegistries.BLOCKS.register(b.id(), b.block()); + ForgeRegistries.ITEMS.register(b.id(), b.asItem()); + }); + } - if (event.getRegistryKey().equals(Registry.ITEM_REGISTRY)) { - MEGAItems.getItems().forEach(i -> ForgeRegistries.ITEMS.register(i.id(), i.asItem())); - } + if (event.getRegistryKey().equals(Registry.ITEM_REGISTRY)) { + MEGAItems.getItems().forEach(i -> ForgeRegistries.ITEMS.register(i.id(), i.asItem())); + } - if (event.getRegistryKey().equals(Registry.BLOCK_ENTITY_TYPE_REGISTRY)) { - MEGABlockEntities.getBlockEntityTypes().forEach(ForgeRegistries.BLOCK_ENTITY_TYPES::register); - } + if (event.getRegistryKey().equals(Registry.BLOCK_ENTITY_TYPE_REGISTRY)) { + MEGABlockEntities.getBlockEntityTypes().forEach(ForgeRegistries.BLOCK_ENTITY_TYPES::register); + } - if (event.getRegistryKey().equals(Registry.MENU_REGISTRY)) { - ForgeRegistries.MENU_TYPES.register(AppEng.makeId("mega_pattern_provider"), - MEGAPatternProviderMenu.TYPE); - } - }); + if (event.getRegistryKey().equals(Registry.MENU_REGISTRY)) { + ForgeRegistries.MENU_TYPES.register(AppEng.makeId("mega_pattern_provider"), + MEGAPatternProviderMenu.TYPE); + } + } - bus.addListener((FMLCommonSetupEvent event) -> { - event.enqueueWork(InitStorageCells::init); - event.enqueueWork(InitUpgrades::init); + private void initCells(FMLCommonSetupEvent event) { + event.enqueueWork(InitStorageCells::init); + event.enqueueWork(InitUpgrades::init); - event.enqueueWork(() -> { - if (Utils.PLATFORM.isModLoaded("appmek")) { - AppMekIntegration.initUpgrades(); - AppMekIntegration.initStorageCells(); - } - }); + event.enqueueWork(() -> { + if (Utils.PLATFORM.isModLoaded("appmek")) { + AppMekIntegration.initUpgrades(); + AppMekIntegration.initStorageCells(); + } }); + } + private void initCompression() { MinecraftForge.EVENT_BUS.addListener((ServerStartedEvent event) -> CompressionService.INSTANCE.load()); MinecraftForge.EVENT_BUS.addListener((AddReloadListenerEvent event) -> CompressionService.INSTANCE.load()); - - DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> MEGACellsClient::new); } } diff --git a/forge/src/main/java/gripe/_90/megacells/forge/MEGACellsClient.java b/forge/src/main/java/gripe/_90/megacells/forge/MEGACellsClient.java index 81531cc5..7c561084 100644 --- a/forge/src/main/java/gripe/_90/megacells/forge/MEGACellsClient.java +++ b/forge/src/main/java/gripe/_90/megacells/forge/MEGACellsClient.java @@ -42,85 +42,89 @@ public class MEGACellsClient { public MEGACellsClient() { var bus = FMLJavaModLoadingContext.get().getModEventBus(); + bus.addListener(this::initScreens); + bus.addListener(this::initModels); + bus.addListener(this::initModelRotation); + bus.addListener(this::initItemColors); + } - bus.addListener((FMLClientSetupEvent event) -> { - InitScreens.register(MEGAPatternProviderMenu.TYPE, PatternProviderScreen::new, - "/screens/megacells/mega_pattern_provider.json"); - }); + private void initScreens(FMLClientSetupEvent ignoredEvent) { + InitScreens.register(MEGAPatternProviderMenu.TYPE, PatternProviderScreen::new, + "/screens/megacells/mega_pattern_provider.json"); + } - bus.addListener((ModelEvent.RegisterGeometryLoaders event) -> { - for (var type : MEGACraftingUnitType.values()) { - event.register("block/crafting/" + type.getAffix() + "_formed", - new SimpleModelLoader<>(() -> new CraftingCubeModel(new MEGACraftingUnitModelProvider(type)))); + private void initModels(ModelEvent.RegisterGeometryLoaders event) { + for (var type : MEGACraftingUnitType.values()) { + event.register("block/crafting/" + type.getAffix() + "_formed", + new SimpleModelLoader<>(() -> new CraftingCubeModel(new MEGACraftingUnitModelProvider(type)))); - ItemBlockRenderTypes.setRenderLayer(type.getDefinition().block(), RenderType.cutout()); - } + ItemBlockRenderTypes.setRenderLayer(type.getDefinition().block(), RenderType.cutout()); + } - BlockEntityRenderers.register(MEGABlockEntities.MEGA_CRAFTING_MONITOR, CraftingMonitorRenderer::new); + BlockEntityRenderers.register(MEGABlockEntities.MEGA_CRAFTING_MONITOR, CraftingMonitorRenderer::new); - ItemProperties.register(MEGABlocks.MEGA_ENERGY_CELL.asItem(), AppEng.makeId("fill_level"), - (is, level, entity, seed) -> { - var energyCell = (EnergyCellBlockItem) MEGABlocks.MEGA_ENERGY_CELL.asItem(); + ItemProperties.register(MEGABlocks.MEGA_ENERGY_CELL.asItem(), AppEng.makeId("fill_level"), + (is, level, entity, seed) -> { + var energyCell = (EnergyCellBlockItem) MEGABlocks.MEGA_ENERGY_CELL.asItem(); - double curPower = energyCell.getAECurrentPower(is); - double maxPower = energyCell.getAEMaxPower(is); + double curPower = energyCell.getAECurrentPower(is); + double maxPower = energyCell.getAEMaxPower(is); - return (float) (curPower / maxPower); - }); - }); - - bus.addListener((RegisterColorHandlersEvent.Item event) -> { - var cells = new ArrayList<>(MEGAItems.getItemCells()); - cells.addAll(MEGAItems.getFluidCells()); - cells.add(MEGAItems.BULK_ITEM_CELL); + return (float) (curPower / maxPower); + }); + } - var portables = new ArrayList<>(MEGAItems.getItemPortables()); - portables.addAll(MEGAItems.getFluidPortables()); + private void initModelRotation(ModelEvent.BakingCompleted event) { + var modelRegistry = event.getModels(); + var customizers = new HashMap>(); + customizers.put(MEGABlocks.CRAFTING_MONITOR.id(), model -> model instanceof MonitorBakedModel + ? model + : new AutoRotatingBakedModel(model)); - if (Utils.PLATFORM.isModLoaded("appmek")) { - cells.addAll(AppMekItems.getCells()); - portables.addAll(AppMekItems.getPortables()); - cells.add(AppMekItems.RADIOACTIVE_CHEMICAL_CELL); + for (var block : MEGABlocks.getBlocks()) { + if (!(block.block() instanceof CraftingUnitBlock)) { + customizers.put(block.id(), AutoRotatingBakedModel::new); } + } - if (Utils.PLATFORM.isModLoaded("appbot")) { - cells.addAll(AppBotItems.getCells()); - portables.addAll(AppBotItems.getPortables()); + for (var location : modelRegistry.keySet()) { + if (!location.getNamespace().equals(Utils.MODID)) { + continue; } - event.register(BasicStorageCell::getColor, cells.toArray(new ItemLike[0])); - event.register(PortableCellItem::getColor, portables.toArray(new ItemLike[0])); - }); + var originalModel = modelRegistry.get(location); + var customizer = customizers.get(location); - bus.addListener((ModelEvent.BakingCompleted event) -> { - var modelRegistry = event.getModels(); - var customizers = new HashMap>(); - customizers.put(MEGABlocks.CRAFTING_MONITOR.id(), model -> model instanceof MonitorBakedModel - ? model - : new AutoRotatingBakedModel(model)); + if (customizer != null) { + var newModel = customizer.apply(originalModel); - for (var block : MEGABlocks.getBlocks()) { - if (!(block.block() instanceof CraftingUnitBlock)) { - customizers.put(block.id(), AutoRotatingBakedModel::new); + if (newModel != originalModel) { + modelRegistry.put(location, newModel); } } + } + } - for (var location : modelRegistry.keySet()) { - if (!location.getNamespace().equals(Utils.MODID)) { - continue; - } + private void initItemColors(RegisterColorHandlersEvent.Item event) { + var cells = new ArrayList<>(MEGAItems.getItemCells()); + cells.addAll(MEGAItems.getFluidCells()); + cells.add(MEGAItems.BULK_ITEM_CELL); - var originalModel = modelRegistry.get(location); - var customizer = customizers.get(location); + var portables = new ArrayList<>(MEGAItems.getItemPortables()); + portables.addAll(MEGAItems.getFluidPortables()); - if (customizer != null) { - var newModel = customizer.apply(originalModel); + if (Utils.PLATFORM.isModLoaded("appmek")) { + cells.addAll(AppMekItems.getCells()); + portables.addAll(AppMekItems.getPortables()); + cells.add(AppMekItems.RADIOACTIVE_CHEMICAL_CELL); + } - if (newModel != originalModel) { - modelRegistry.put(location, newModel); - } - } - } - }); + if (Utils.PLATFORM.isModLoaded("appbot")) { + cells.addAll(AppBotItems.getCells()); + portables.addAll(AppBotItems.getPortables()); + } + + event.register(BasicStorageCell::getColor, cells.toArray(new ItemLike[0])); + event.register(PortableCellItem::getColor, portables.toArray(new ItemLike[0])); } }