Skip to content

Commit

Permalink
Update to NeoForge 20.6.12-beta & fix guidebook item NBT (#7850)
Browse files Browse the repository at this point in the history
  • Loading branch information
Technici4n authored May 1, 2024
1 parent dd8fce9 commit 25aa735
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 76 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ artifact_basename=appliedenergistics2-neoforge
minecraft_release=1.20
minecraft_version=1.20.6
minecraft_version_range=1.20.6
neoforge_version=20.6.1-beta
neoforge_version_range=[20.6.1-beta,)
neoforge_version=20.6.12-beta
neoforge_version_range=[20.6.12-beta,)

#########################################################
# Parchment #
Expand Down
3 changes: 2 additions & 1 deletion guidebook/items-blocks-machines/facades.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ navigation:
parent: items-blocks-machines/items-blocks-machines-index.md
title: Facades
icon: facade
icon_nbt: '{item: "minecraft:stone"}'
icon_components:
"ae2:facade_item": "minecraft:stone"
position: 110
categories:
- network infrastructure
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/appeng/client/guidebook/Guide.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import net.neoforged.neoforge.client.event.RegisterClientReloadListenersEvent;
import net.neoforged.neoforge.client.event.ScreenEvent;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.resource.ResourcePackLoader;

import appeng.client.guidebook.compiler.PageCompiler;
import appeng.client.guidebook.compiler.ParsedGuidePage;
Expand Down Expand Up @@ -157,9 +158,8 @@ public static void runDatapackReload() {

PackRepository packRepository = new PackRepository(
new ServerPacksSource(new DirectoryValidator(path -> false)));
net.neoforged.neoforge.resource.ResourcePackLoader.loadResourcePacks(packRepository,
map -> net.neoforged.neoforge.resource.ResourcePackLoader.buildPackFinder(map,
PackType.SERVER_DATA));
// This fires AddPackFindersEvent but it's probably ok.
ResourcePackLoader.populatePackRepository(packRepository, PackType.SERVER_DATA);
packRepository.reload();
packRepository.setSelected(packRepository.getAvailableIds());

Expand Down
20 changes: 6 additions & 14 deletions src/main/java/appeng/client/guidebook/compiler/Frontmatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@

import java.util.Map;

import com.mojang.brigadier.exceptions.CommandSyntaxException;

import org.jetbrains.annotations.Nullable;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;

import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.TagParser;
import net.minecraft.resources.ResourceLocation;

public record Frontmatter(
Expand All @@ -37,7 +33,7 @@ public static Frontmatter parse(ResourceLocation pageId, String yamlText) {
position = getInt(navigationMap, "position");
}
var iconIdStr = getString(navigationMap, "icon");
CompoundTag iconNbt = getCompound(navigationMap, "icon_nbt");
Map<?, ?> iconComponents = getCompound(navigationMap, "icon_components");

ResourceLocation parentId = null;
if (parentIdStr != null) {
Expand All @@ -49,7 +45,7 @@ public static Frontmatter parse(ResourceLocation pageId, String yamlText) {
iconId = IdUtils.resolveId(iconIdStr, pageId.getNamespace());
}

navigation = new FrontmatterNavigation(title, parentId, position, iconId, iconNbt);
navigation = new FrontmatterNavigation(title, parentId, position, iconId, iconComponents);
}

return new Frontmatter(
Expand Down Expand Up @@ -78,18 +74,14 @@ private static int getInt(Map<?, ?> map, String key) {
}

@Nullable
private static CompoundTag getCompound(Map<?, ?> map, String key) {
private static Map<?, ?> getCompound(Map<?, ?> map, String key) {
var value = map.get(key);
if (value == null) {
return null;
}
if (!(value instanceof String string)) {
throw new IllegalArgumentException("Key " + key + " has to be a string (SNBT format)!");
}
try {
return TagParser.parseTag(string);
} catch (CommandSyntaxException e) {
throw new IllegalArgumentException("Key " + key + " is not a valid SNBT string: " + string, e);
if (!(value instanceof Map<?, ?> mapValue)) {
throw new IllegalArgumentException("Key " + key + " has to be a map!");
}
return mapValue;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package appeng.client.guidebook.compiler;

import java.util.Map;

import org.jetbrains.annotations.Nullable;

import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;

/**
Expand All @@ -13,5 +14,5 @@ public record FrontmatterNavigation(
@Nullable ResourceLocation parent,
int position,
@Nullable ResourceLocation iconItemId,
@Nullable CompoundTag iconNbt) {
@Nullable Map<?, ?> iconComponents) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
import java.util.Map;
import java.util.Objects;

import com.mojang.serialization.JavaOps;

import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.minecraft.core.component.DataComponentPatch;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.NbtOps;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;

Expand Down Expand Up @@ -117,10 +118,10 @@ private static NavigationNode createNode(HashMap<ResourceLocation, NavigationNod
if (navigationEntry.iconItemId() != null) {
var iconItem = BuiltInRegistries.ITEM.getHolder(navigationEntry.iconItemId()).orElseThrow();

if (navigationEntry.iconNbt() != null) {
var patch = DataComponentPatch.CODEC.parse(NbtOps.INSTANCE, navigationEntry.iconNbt())
if (navigationEntry.iconComponents() != null) {
var patch = DataComponentPatch.CODEC.parse(JavaOps.INSTANCE, navigationEntry.iconComponents())
.resultOrPartial(err -> LOGGER.error("Failed to deserialize component patch {} for icon {}: {}",
navigationEntry.iconNbt(), navigationEntry.iconItemId(), err));
navigationEntry.iconComponents(), navigationEntry.iconItemId(), err));
icon = new ItemStack(iconItem, 1, patch.orElse(DataComponentPatch.EMPTY));
} else {
icon = new ItemStack(iconItem);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/appeng/core/AppEngClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public AppEngClient(IEventBus modEventBus) {
modEventBus.addListener(this::registerEntityLayerDefinitions);
modEventBus.addListener(this::registerHotkeys);
modEventBus.addListener(this::registerDimensionSpecialEffects);
modEventBus.addListener(InitScreens::init);

BlockAttackHook.install();
RenderBlockOutlineHook.install();
Expand Down Expand Up @@ -288,7 +289,6 @@ private void registerEntityLayerDefinitions(EntityRenderersEvent.RegisterLayerDe
*/
private void postClientSetup(Minecraft minecraft) {
StyleManager.initialize(minecraft.getResourceManager());
InitScreens.init();
InitStackRenderHandlers.init();
InitRenderTypes.init();

Expand Down
88 changes: 45 additions & 43 deletions src/main/java/appeng/init/client/InitScreens.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.MenuType;
import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent;

import appeng.client.gui.AEBaseScreen;
import appeng.client.gui.implementations.CellWorkbenchScreen;
Expand Down Expand Up @@ -116,74 +117,74 @@ public final class InitScreens {
private InitScreens() {
}

public static void init() {
public static void init(RegisterMenuScreensEvent event) {
// spotless:off
register(QNBMenu.TYPE, QNBScreen::new, "/screens/qnb.json");
register(SkyChestMenu.TYPE, SkyChestScreen::new, "/screens/sky_chest.json");
register(ChestMenu.TYPE, ChestScreen::new, "/screens/chest.json");
register(WirelessAccessPointMenu.TYPE, WirelessAccessPointScreen::new, "/screens/wireless_access_point.json");
register(NetworkStatusMenu.NETWORK_TOOL_TYPE, NetworkStatusScreen::new, "/screens/network_status.json");
register(NetworkStatusMenu.CONTROLLER_TYPE, NetworkStatusScreen::new, "/screens/network_status.json");
register(CraftingCPUMenu.TYPE, CraftingCPUScreen<CraftingCPUMenu>::new, "/screens/crafting_cpu.json");
register(NetworkToolMenu.TYPE, NetworkToolScreen::new, "/screens/network_tool.json");
register(QuartzKnifeMenu.TYPE, QuartzKnifeScreen::new, "/screens/quartz_knife.json");
register(DriveMenu.TYPE, DriveScreen::new, "/screens/drive.json");
register(VibrationChamberMenu.TYPE, VibrationChamberScreen::new, "/screens/vibration_chamber.json");
register(CondenserMenu.TYPE, CondenserScreen::new, "/screens/condenser.json");
register(InterfaceMenu.TYPE, InterfaceScreen<InterfaceMenu>::new, "/screens/interface.json");
register(IOBusMenu.EXPORT_TYPE, IOBusScreen::new, "/screens/export_bus.json");
register(IOBusMenu.IMPORT_TYPE, IOBusScreen::new, "/screens/import_bus.json");
register(IOPortMenu.TYPE, IOPortScreen::new, "/screens/io_port.json");
register(StorageBusMenu.TYPE, StorageBusScreen::new, "/screens/storage_bus.json");
register(SetStockAmountMenu.TYPE, SetStockAmountScreen::new, "/screens/set_stock_amount.json");
register(FormationPlaneMenu.TYPE, FormationPlaneScreen::new, "/screens/formation_plane.json");
register(PriorityMenu.TYPE, PriorityScreen::new, "/screens/priority.json");
register(StorageLevelEmitterMenu.TYPE, StorageLevelEmitterScreen::new, "/screens/level_emitter.json");
register(EnergyLevelEmitterMenu.TYPE, EnergyLevelEmitterScreen::new, "/screens/energy_level_emitter.json");
register(SpatialIOPortMenu.TYPE, SpatialIOPortScreen::new, "/screens/spatial_io_port.json");
register(InscriberMenu.TYPE, InscriberScreen::new, "/screens/inscriber.json");
register(CellWorkbenchMenu.TYPE, CellWorkbenchScreen::new, "/screens/cell_workbench.json");
register(PatternProviderMenu.TYPE, PatternProviderScreen<PatternProviderMenu>::new, "/screens/pattern_provider.json");
register(MolecularAssemblerMenu.TYPE, MolecularAssemblerScreen::new, "/screens/molecular_assembler.json");
register(CraftAmountMenu.TYPE, CraftAmountScreen::new, "/screens/craft_amount.json");
register(CraftConfirmMenu.TYPE, CraftConfirmScreen::new, "/screens/craft_confirm.json");
register(CraftingStatusMenu.TYPE, CraftingStatusScreen::new, "/screens/crafting_status.json");
register(SpatialAnchorMenu.TYPE, SpatialAnchorScreen::new, "/screens/spatial_anchor.json");
register(event, QNBMenu.TYPE, QNBScreen::new, "/screens/qnb.json");
register(event, SkyChestMenu.TYPE, SkyChestScreen::new, "/screens/sky_chest.json");
register(event, ChestMenu.TYPE, ChestScreen::new, "/screens/chest.json");
register(event, WirelessAccessPointMenu.TYPE, WirelessAccessPointScreen::new, "/screens/wireless_access_point.json");
register(event, NetworkStatusMenu.NETWORK_TOOL_TYPE, NetworkStatusScreen::new, "/screens/network_status.json");
register(event, NetworkStatusMenu.CONTROLLER_TYPE, NetworkStatusScreen::new, "/screens/network_status.json");
register(event, CraftingCPUMenu.TYPE, CraftingCPUScreen<CraftingCPUMenu>::new, "/screens/crafting_cpu.json");
register(event, NetworkToolMenu.TYPE, NetworkToolScreen::new, "/screens/network_tool.json");
register(event, QuartzKnifeMenu.TYPE, QuartzKnifeScreen::new, "/screens/quartz_knife.json");
register(event, DriveMenu.TYPE, DriveScreen::new, "/screens/drive.json");
register(event, VibrationChamberMenu.TYPE, VibrationChamberScreen::new, "/screens/vibration_chamber.json");
register(event, CondenserMenu.TYPE, CondenserScreen::new, "/screens/condenser.json");
register(event, InterfaceMenu.TYPE, InterfaceScreen<InterfaceMenu>::new, "/screens/interface.json");
register(event, IOBusMenu.EXPORT_TYPE, IOBusScreen::new, "/screens/export_bus.json");
register(event, IOBusMenu.IMPORT_TYPE, IOBusScreen::new, "/screens/import_bus.json");
register(event, IOPortMenu.TYPE, IOPortScreen::new, "/screens/io_port.json");
register(event, StorageBusMenu.TYPE, StorageBusScreen::new, "/screens/storage_bus.json");
register(event, SetStockAmountMenu.TYPE, SetStockAmountScreen::new, "/screens/set_stock_amount.json");
register(event, FormationPlaneMenu.TYPE, FormationPlaneScreen::new, "/screens/formation_plane.json");
register(event, PriorityMenu.TYPE, PriorityScreen::new, "/screens/priority.json");
register(event, StorageLevelEmitterMenu.TYPE, StorageLevelEmitterScreen::new, "/screens/level_emitter.json");
register(event, EnergyLevelEmitterMenu.TYPE, EnergyLevelEmitterScreen::new, "/screens/energy_level_emitter.json");
register(event, SpatialIOPortMenu.TYPE, SpatialIOPortScreen::new, "/screens/spatial_io_port.json");
register(event, InscriberMenu.TYPE, InscriberScreen::new, "/screens/inscriber.json");
register(event, CellWorkbenchMenu.TYPE, CellWorkbenchScreen::new, "/screens/cell_workbench.json");
register(event, PatternProviderMenu.TYPE, PatternProviderScreen<PatternProviderMenu>::new, "/screens/pattern_provider.json");
register(event, MolecularAssemblerMenu.TYPE, MolecularAssemblerScreen::new, "/screens/molecular_assembler.json");
register(event, CraftAmountMenu.TYPE, CraftAmountScreen::new, "/screens/craft_amount.json");
register(event, CraftConfirmMenu.TYPE, CraftConfirmScreen::new, "/screens/craft_confirm.json");
register(event, CraftingStatusMenu.TYPE, CraftingStatusScreen::new, "/screens/crafting_status.json");
register(event, SpatialAnchorMenu.TYPE, SpatialAnchorScreen::new, "/screens/spatial_anchor.json");

// Terminals
InitScreens.<MEStorageMenu, MEStorageScreen<MEStorageMenu>>register(
InitScreens.<MEStorageMenu, MEStorageScreen<MEStorageMenu>>register(event,
MEStorageMenu.TYPE,
MEStorageScreen::new,
"/screens/terminals/terminal.json");
InitScreens.<MEStorageMenu, MEStorageScreen<MEStorageMenu>>register(
InitScreens.<MEStorageMenu, MEStorageScreen<MEStorageMenu>>register(event,
BasicCellChestMenu.TYPE,
MEStorageScreen::new,
"/screens/terminals/terminal.json");
InitScreens.<MEStorageMenu, MEStorageScreen<MEStorageMenu>>register(
InitScreens.<MEStorageMenu, MEStorageScreen<MEStorageMenu>>register(event,
MEStorageMenu.PORTABLE_ITEM_CELL_TYPE,
MEStorageScreen::new,
"/screens/terminals/portable_item_cell.json");
InitScreens.<MEStorageMenu, MEStorageScreen<MEStorageMenu>>register(
InitScreens.<MEStorageMenu, MEStorageScreen<MEStorageMenu>>register(event,
MEStorageMenu.PORTABLE_FLUID_CELL_TYPE,
MEStorageScreen::new,
"/screens/terminals/portable_fluid_cell.json");
InitScreens.<MEStorageMenu, MEStorageScreen<MEStorageMenu>>register(
InitScreens.<MEStorageMenu, MEStorageScreen<MEStorageMenu>>register(event,
MEStorageMenu.WIRELESS_TYPE,
MEStorageScreen::new,
"/screens/terminals/wireless_terminal.json");
InitScreens.<CraftingTermMenu, CraftingTermScreen<CraftingTermMenu>>register(
InitScreens.<CraftingTermMenu, CraftingTermScreen<CraftingTermMenu>>register(event,
CraftingTermMenu.TYPE,
CraftingTermScreen::new,
"/screens/terminals/crafting_terminal.json");
InitScreens.<WirelessCraftingTermMenu, CraftingTermScreen<WirelessCraftingTermMenu>>register(
InitScreens.<WirelessCraftingTermMenu, CraftingTermScreen<WirelessCraftingTermMenu>>register(event,
WirelessCraftingTermMenu.TYPE,
CraftingTermScreen::new,
"/screens/terminals/crafting_terminal.json");
InitScreens.<PatternEncodingTermMenu, PatternEncodingTermScreen<PatternEncodingTermMenu>>register(
InitScreens.<PatternEncodingTermMenu, PatternEncodingTermScreen<PatternEncodingTermMenu>>register(event,
PatternEncodingTermMenu.TYPE,
PatternEncodingTermScreen::new,
"/screens/terminals/pattern_encoding_terminal.json");
InitScreens.<PatternAccessTermMenu, PatternAccessTermScreen<PatternAccessTermMenu>>register(
InitScreens.<PatternAccessTermMenu, PatternAccessTermScreen<PatternAccessTermMenu>>register(event,
PatternAccessTermMenu.TYPE, PatternAccessTermScreen::new,
"/screens/terminals/pattern_access_terminal.json");
// spotless:on
Expand All @@ -192,11 +193,12 @@ public static void init() {
/**
* Registers a screen for a given menu and ensures the given style is applied after opening the screen.
*/
public static <M extends AEBaseMenu, U extends AEBaseScreen<M>> void register(MenuType<M> type,
public static <M extends AEBaseMenu, U extends AEBaseScreen<M>> void register(RegisterMenuScreensEvent event,
MenuType<M> type,
StyledScreenFactory<M, U> factory,
String stylePath) {
MENU_STYLES.put(type, stylePath);
MenuScreens.<M, U>register(type, (menu, playerInv, title) -> {
event.<M, U>register(type, (menu, playerInv, title) -> {
var style = StyleManager.loadStyleDoc(stylePath);

return factory.create(menu, playerInv, title, style);
Expand Down
8 changes: 2 additions & 6 deletions src/test/java/appeng/init/client/InitScreensTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoSettings;

import net.minecraft.client.gui.screens.MenuScreens;
import net.minecraft.locale.Language;
import net.minecraft.network.chat.contents.TranslatableContents;
import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent;

import appeng.client.gui.MockResourceManager;
import appeng.client.gui.style.ScreenStyle;
Expand All @@ -53,9 +51,7 @@ class InitScreensTest {

@BeforeAll
static void setUp() {
try (MockedStatic<MenuScreens> registration = Mockito.mockStatic(MenuScreens.class)) {
InitScreens.init();
}
InitScreens.init(new RegisterMenuScreensEvent(new HashMap<>()));
}

/**
Expand Down

0 comments on commit 25aa735

Please sign in to comment.