Skip to content

Commit

Permalink
Fix guidebook not showing info for other block tiers
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Jun 23, 2024
1 parent 0df3f13 commit f4d7cf9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 35 deletions.
12 changes: 5 additions & 7 deletions src/main/java/owmii/powah/lib/block/AbstractEnergyBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,11 @@ public void additionalEnergyInfo(ItemStack stack, Energy.Item energy, List<Compo
@Override
public InfoBox getInfoBox(ItemStack stack, InfoBox box) {
Energy.ifPresent(stack, storage -> {
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;
}
Expand Down
15 changes: 6 additions & 9 deletions src/main/java/owmii/powah/lib/block/AbstractGeneratorBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
14 changes: 0 additions & 14 deletions src/main/java/owmii/powah/lib/client/wiki/Wiki.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,7 +24,6 @@ public class Wiki {
public static final Marker MARKER = new MarkerManager.Log4jMarker("Wiki");
private final List<Entry> categories = new ArrayList<>();
private final Map<ItemLike, List<RecipeHolder<CraftingRecipe>>> crafting = new HashMap<>();
private final Map<ItemLike, List<RecipeHolder<SmeltingRecipe>>> smelting = new HashMap<>();
private final String modId;

public Wiki() {
Expand Down Expand Up @@ -60,10 +58,6 @@ public Map<ItemLike, List<RecipeHolder<CraftingRecipe>>> getCrafting() {
return this.crafting;
}

public Map<ItemLike, List<RecipeHolder<SmeltingRecipe>>> getSmelting() {
return this.smelting;
}

public String getModId() {
return this.modId;
}
Expand All @@ -78,7 +72,6 @@ public String getModVersion() {

private void updateRecipes() {
this.crafting.clear();
this.smelting.clear();

var clientLevel = Minecraft.getInstance().level;
if (clientLevel == null) {
Expand All @@ -98,13 +91,6 @@ private void updateRecipes() {
}
});
this.crafting.put(item, crafting);
List<RecipeHolder<SmeltingRecipe>> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f4d7cf9

Please sign in to comment.