From f4d7cf9840f5366783285133b8e5d6e365d6dd1c Mon Sep 17 00:00:00 2001 From: Sebastian Hartte Date: Sun, 23 Jun 2024 13:10:46 +0200 Subject: [PATCH] Fix guidebook not showing info for other block tiers --- .../powah/lib/block/AbstractEnergyBlock.java | 12 +++++------- .../lib/block/AbstractGeneratorBlock.java | 15 ++++++--------- .../owmii/powah/lib/client/wiki/Wiki.java | 14 -------------- .../client/wiki/page/panel/EnergyPanel.java | 3 +-- .../lib/client/wiki/page/panel/ItemPanel.java | 19 ++++++++++++++++--- 5 files changed, 28 insertions(+), 35 deletions(-) diff --git a/src/main/java/owmii/powah/lib/block/AbstractEnergyBlock.java b/src/main/java/owmii/powah/lib/block/AbstractEnergyBlock.java index 5d16dfec..9630c0c3 100644 --- a/src/main/java/owmii/powah/lib/block/AbstractEnergyBlock.java +++ b/src/main/java/owmii/powah/lib/block/AbstractEnergyBlock.java @@ -128,13 +128,11 @@ public void additionalEnergyInfo(ItemStack stack, Energy.Item energy, List { - if (storage != null) { - if (storage.getMaxEnergyStored() > 0) - box.set(Component.translatable("info.lollipop.capacity"), - Component.translatable("info.lollipop.fe", Util.addCommas(storage.getCapacity()))); - box.set(Component.translatable("info.lollipop.max.io"), - Component.translatable("info.lollipop.fe.pet.tick", Util.addCommas(storage.getMaxExtract()))); - } + if (storage.getMaxEnergyStored() > 0) + box.set(Component.translatable("info.lollipop.capacity"), + Component.translatable("info.lollipop.fe", Util.addCommas(storage.getCapacity()))); + box.set(Component.translatable("info.lollipop.max.io"), + Component.translatable("info.lollipop.fe.pet.tick", Util.addCommas(storage.getMaxExtract()))); }); return box; } diff --git a/src/main/java/owmii/powah/lib/block/AbstractGeneratorBlock.java b/src/main/java/owmii/powah/lib/block/AbstractGeneratorBlock.java index 952563c2..136837e2 100644 --- a/src/main/java/owmii/powah/lib/block/AbstractGeneratorBlock.java +++ b/src/main/java/owmii/powah/lib/block/AbstractGeneratorBlock.java @@ -36,15 +36,12 @@ public Transfer getTransferType() { @Override public InfoBox getInfoBox(ItemStack stack, InfoBox box) { Energy.ifPresent(stack, storage -> { - if (storage instanceof Energy.Item) { - Energy.Item energy = (Energy.Item) storage; - box.set(Component.translatable("info.lollipop.capacity"), - Component.translatable("info.lollipop.fe", Util.addCommas(energy.getCapacity()))); - box.set(Component.translatable("info.lollipop.generates"), - Component.translatable("info.lollipop.fe.pet.tick", Util.addCommas(getConfig().getGeneration(this.variant)))); - box.set(Component.translatable("info.lollipop.max.extract"), - Component.translatable("info.lollipop.fe.pet.tick", Util.addCommas(energy.getMaxExtract()))); - } + box.set(Component.translatable("info.lollipop.capacity"), + Component.translatable("info.lollipop.fe", Util.addCommas(storage.getCapacity()))); + box.set(Component.translatable("info.lollipop.generates"), + Component.translatable("info.lollipop.fe.pet.tick", Util.addCommas(getConfig().getGeneration(this.variant)))); + box.set(Component.translatable("info.lollipop.max.extract"), + Component.translatable("info.lollipop.fe.pet.tick", Util.addCommas(storage.getMaxExtract()))); }); return box; } diff --git a/src/main/java/owmii/powah/lib/client/wiki/Wiki.java b/src/main/java/owmii/powah/lib/client/wiki/Wiki.java index a3720ee6..779172d9 100644 --- a/src/main/java/owmii/powah/lib/client/wiki/Wiki.java +++ b/src/main/java/owmii/powah/lib/client/wiki/Wiki.java @@ -10,7 +10,6 @@ import net.minecraft.world.item.crafting.CraftingRecipe; import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.item.crafting.RecipeType; -import net.minecraft.world.item.crafting.SmeltingRecipe; import net.minecraft.world.level.ItemLike; import net.neoforged.neoforge.client.event.RecipesUpdatedEvent; import net.neoforged.neoforge.common.NeoForge; @@ -25,7 +24,6 @@ public class Wiki { public static final Marker MARKER = new MarkerManager.Log4jMarker("Wiki"); private final List categories = new ArrayList<>(); private final Map>> crafting = new HashMap<>(); - private final Map>> smelting = new HashMap<>(); private final String modId; public Wiki() { @@ -60,10 +58,6 @@ public Map>> getCrafting() { return this.crafting; } - public Map>> getSmelting() { - return this.smelting; - } - public String getModId() { return this.modId; } @@ -78,7 +72,6 @@ public String getModVersion() { private void updateRecipes() { this.crafting.clear(); - this.smelting.clear(); var clientLevel = Minecraft.getInstance().level; if (clientLevel == null) { @@ -98,13 +91,6 @@ private void updateRecipes() { } }); this.crafting.put(item, crafting); - List> smelting = new ArrayList<>(); - recipeManager.getAllRecipesFor(RecipeType.SMELTING).forEach(holder -> { - if (holder.value().getResultItem(registryAccess).is(item)) { - smelting.add(holder); - } - }); - this.smelting.put(item, smelting); }); watch.stop(); Powah.LOGGER.info(MARKER, "Wiki recipes collecting completed in : {} ms", watch.getTime()); diff --git a/src/main/java/owmii/powah/lib/client/wiki/page/panel/EnergyPanel.java b/src/main/java/owmii/powah/lib/client/wiki/page/panel/EnergyPanel.java index 38e6610f..5765632f 100644 --- a/src/main/java/owmii/powah/lib/client/wiki/page/panel/EnergyPanel.java +++ b/src/main/java/owmii/powah/lib/client/wiki/page/panel/EnergyPanel.java @@ -30,9 +30,8 @@ public EnergyPanel(ItemLike[] items, Section parent) { @Override public void render(GuiGraphics gui, int x, int y, int mx, int my, float pt, Font font, WikiScreen screen) { super.render(gui, x, y, mx, my, pt, font, screen); - if (getItem() instanceof InfoBox.IInfoBoxHolder) { + if (getItem() instanceof InfoBox.IInfoBoxHolder holder) { int i = 0; - InfoBox.IInfoBoxHolder holder = (InfoBox.IInfoBoxHolder) getItem(); InfoBox box = holder.getInfoBox(new ItemStack(getItem()), new InfoBox(0xff0000, 0x3d3d3d)); for (var entry : box.getLines().entrySet()) { Texture.WIKI_INF_LN_BG.draw(gui, x + 9, y + 80 + (i * 12)); diff --git a/src/main/java/owmii/powah/lib/client/wiki/page/panel/ItemPanel.java b/src/main/java/owmii/powah/lib/client/wiki/page/panel/ItemPanel.java index 4c6d1fe9..8a45f875 100644 --- a/src/main/java/owmii/powah/lib/client/wiki/page/panel/ItemPanel.java +++ b/src/main/java/owmii/powah/lib/client/wiki/page/panel/ItemPanel.java @@ -7,9 +7,11 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.ItemLike; +import org.jetbrains.annotations.NotNull; import owmii.powah.Powah; import owmii.powah.lib.client.screen.Texture; import owmii.powah.lib.client.screen.widget.IconButton; @@ -49,14 +51,25 @@ protected static ItemLike[] getSiblings(ItemLike item) { return new ItemLike[0]; } else { var id = BuiltInRegistries.ITEM.getKey(item.asItem()); - if (item instanceof IVariantEntry variantEntry) { - id = ResourceLocation.fromNamespaceAndPath(id.getNamespace(), id.getPath().replace("_" + variantEntry.getVariant().getName(), "")); + if (item instanceof BlockItem blockItem && blockItem.getBlock() instanceof IVariantEntry variantEntry) { + id = getVariantBaseId(id, variantEntry.getVariant().getName()); + } else if (item instanceof IVariantEntry variantEntry) { + id = getVariantBaseId(id, variantEntry.getVariant().getName()); } - return VarReg.getSiblingIds(Objects.requireNonNull(id).getPath()).stream().map(rl -> BuiltInRegistries.ITEM.get(Powah.id(rl))) + + return VarReg.getSiblingIds(Objects.requireNonNull(id).getPath()) + .stream() + .map(rl -> BuiltInRegistries.ITEM.get(Powah.id(rl))) + .filter(i -> i != Items.AIR) .toArray(ItemLike[]::new); } } + private static @NotNull ResourceLocation getVariantBaseId(ResourceLocation id, String variantEntry) { + id = ResourceLocation.fromNamespaceAndPath(id.getNamespace(), id.getPath().replace("_" + variantEntry, "")); + return id; + } + @Override public void init(int x, int y, WikiScreen screen) { super.init(x, y, screen);