Skip to content

Commit

Permalink
Release 0.3.2
Browse files Browse the repository at this point in the history
- [feat] Added support for the alchemy profession
- [fix] Empty air items should not show up in recipe list
- [fix] Empty air items can no longer be learned
- [fix] Attempted to fix non-vendors from appearing in vendor list
- [bug] Fixed issue storing profession levels due to tooltip styling update
- [bug] Fixed issue with tracking tooltip being cut off
- [chore] Added update checker
- [chore] Added titles for Runehilda and Axel Otto
- [chore] Improved efficiency of crafting station slot rendering
  • Loading branch information
blackjack26 committed Aug 21, 2024
1 parent ae75548 commit 103d46b
Show file tree
Hide file tree
Showing 15 changed files with 118 additions and 22 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cloth_config_version=12.0.119
mod_menu_version=8.0.1

# Project Metadata
mod_version=0.3.1
mod_version=0.3.2
mod_name=Blockgame Journal
default_release_type=release
github_owner=blackjack26
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.entity.Entity;
import net.minecraft.entity.passive.ChickenEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
Expand Down Expand Up @@ -261,6 +260,9 @@ private ActionResult handleEntityAttacked(PlayerEntity playerEntity, Entity enti
// All vendors have custom names. This should prevent players from being marked as vendors
if (entity.hasCustomName()) {
lastAttackedEntity = entity;

// Reset crafting station handler when attacking a new entity
craftingStationHandler.reset();
}

return ActionResult.PASS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -47,6 +45,7 @@ public class CraftingStationHandler {

private final RecipeTrackerGameFeature gameFeature;
private final List<CraftingStationItem> inventory = new ArrayList<>();
private final Map<Integer, Byte> statusCache = new HashMap<>();

private int syncId = -1;
private String npcName = "";
Expand All @@ -55,6 +54,8 @@ public class CraftingStationHandler {
@Nullable
private CraftingStationItem lastClickedItem;

private boolean createOrUpdateVendor = false;

public CraftingStationHandler(RecipeTrackerGameFeature gameFeature) {
this.gameFeature = gameFeature;
}
Expand All @@ -66,7 +67,17 @@ public void init() {
DrawSlotListener.EVENT.register(this::drawSlot);
}

public void reset() {
this.syncId = -1;
this.inventory.clear();
this.npcName = "";
this.lastClickedItem = null;
this.statusCache.clear();
this.createOrUpdateVendor = false;
}

private ActionResult handleOpenScreen(OpenScreenS2CPacket packet) {
this.createOrUpdateVendor = false;
String screenName = packet.getName().getString();

// Look for screen name "Some Name (#page#/#max#)" - exclude "Party" from the name
Expand All @@ -88,10 +99,7 @@ private ActionResult handleOpenScreen(OpenScreenS2CPacket packet) {

if (lastAttackedEntity != null) {
this.npcName = entityName;

if (Journal.INSTANCE != null) {
NPCUtil.createOrUpdate(this.npcName, lastAttackedEntity);
}
this.createOrUpdateVendor = true;
} else {
this.npcName = matcher.group(1);
}
Expand All @@ -101,6 +109,7 @@ private ActionResult handleOpenScreen(OpenScreenS2CPacket packet) {

// TODO: Add paging
this.inventory.clear();
this.statusCache.clear();

return ActionResult.PASS;
}
Expand All @@ -125,6 +134,12 @@ private ActionResult handleScreenInventory(InventoryS2CPacket packet) {
this.inventory.add(invItem);
});

Entity lastAttackedEntity = this.gameFeature.getLastAttackedEntity();
if (this.createOrUpdateVendor && !this.inventory.isEmpty() && Journal.INSTANCE != null && lastAttackedEntity != null) {
NPCUtil.createOrUpdate(this.npcName, lastAttackedEntity);
this.createOrUpdateVendor = false;
}

return ActionResult.PASS;
}

Expand Down Expand Up @@ -174,6 +189,16 @@ private void drawSlot(DrawContext context, Slot slot) {
return;
}

Byte status = this.statusCache.get(slot.id);
if (status != null) {
if (status == 1) {
this.highlightSlot(context, slot, 0x30FF0000); // Missing
} else if (status == 2) {
this.highlightSlot(context, slot, 0x40CCCC00); // Outdated
}
return;
}

// See if slot item matches inventory item
ItemStack slotItem = slot.getStack();
CraftingStationItem inventoryItem = this.inventory.get(slot.id);
Expand All @@ -196,6 +221,9 @@ private void drawSlot(DrawContext context, Slot slot) {
inventoryItem.setOutdated(ItemUtil.isOutdated(entry, inventoryItem));
if (highlightOutdated && inventoryItem.getOutdated()) {
this.highlightSlot(context, slot, 0x40CCCC00);
this.statusCache.put(slot.id, (byte) 2);
} else {
this.statusCache.put(slot.id, (byte) 0);
}
return;
}
Expand All @@ -204,6 +232,7 @@ private void drawSlot(DrawContext context, Slot slot) {
// If the item is not in the journal, highlight it
if (highlightMissing) {
this.highlightSlot(context, slot, 0x30FF0000);
this.statusCache.put(slot.id, (byte) 1);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import dev.bnjc.blockgamejournal.listener.screen.ScreenReceivedInventoryListener;
import dev.bnjc.blockgamejournal.util.NbtUtil;
import dev.bnjc.blockgamejournal.util.Profession;
import dev.bnjc.blockgamejournal.util.StringUtil;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.item.ItemStack;
Expand All @@ -24,7 +25,7 @@

public class ProfileHandler {
private static final Logger LOGGER = BlockgameJournal.getLogger("Profile Handler");
private static final Pattern LEVEL_PATTERN = Pattern.compile("Level: (\\d+)");
private static final Pattern LEVEL_PATTERN = Pattern.compile("^Level: (\\d+)");

private final RecipeTrackerGameFeature gameFeature;
private int syncId = -1;
Expand Down Expand Up @@ -63,6 +64,7 @@ private ActionResult handleScreenInventory(InventoryS2CPacket packet) {
parseProfessionLevel(inv, Profession.HERBALISM);
parseProfessionLevel(inv, Profession.RUNECARVING);
parseProfessionLevel(inv, Profession.COOKING);
parseProfessionLevel(inv, Profession.ALCHEMY);

return ActionResult.PASS;
}
Expand All @@ -89,13 +91,10 @@ private void parseProfessionLevel(List<ItemStack> inv, Profession profession) {
continue;
}

String line = textLine.getString();
if (line.contains(profession == Profession.EINHERJAR ? "Level:" : "Current Level:")) {
Matcher levelMatcher = LEVEL_PATTERN.matcher(line);
if (levelMatcher.find()) {
this.setProfessionLevel(profession, Integer.parseInt(levelMatcher.group(1)));
return;
}
Matcher levelMatcher = LEVEL_PATTERN.matcher(StringUtil.removeFormatting(textLine.getString()));
if (levelMatcher.find()) {
this.setProfessionLevel(profession, Integer.parseInt(levelMatcher.group(1)));
return;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ private void storeRecipe(List<ItemStack> inventory) {
}

ItemStack recipeItem = inventory.get(ITEM_INDEX);
if (recipeItem.isEmpty()) {
LOGGER.warn("[Blockgame Journal] Recipe item is empty, cannot store recipe. Try again later.");
return;
}

// Store the recipe in the player's journal
BlockgameJournal.LOGGER.debug("[Blockgame Journal] Storing recipe for {}", ItemUtil.getName(recipeItem));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ private void filter(@Nullable String filter) {
filtered = this.items;
} else {
filtered = this.items.stream()
.filter(item -> SearchUtil.defaultPredicate(item.getStack(), filter))
.filter(item -> SearchUtil.defaultPredicate(item.getStack(), filter) && !item.getStack().isEmpty())
.toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class TrackingWidget extends ScrollableViewWidget {

private int lastY;
private int xOffset = 10;
private int mouseX = 0;
private int mouseY = 0;

public TrackingWidget(Screen parent, int x, int y, int width, int height) {
super(x, y, width, height, Text.empty());
Expand Down Expand Up @@ -75,6 +77,9 @@ protected void renderContents(DrawContext context, int mouseX, int mouseY, float
return;
}

this.mouseX = mouseX;
this.mouseY = mouseY;

this.lastY = this.getY() + 12;
this.xOffset = 10;
this.ingredientPositions.clear();
Expand Down Expand Up @@ -110,8 +115,15 @@ protected void renderContents(DrawContext context, int mouseX, int mouseY, float
this.renderRecipesKnown(context, trackingList.getKnownRecipes());
this.renderRequiredProfessions(context, trackingList.getProfessions());
this.renderIngredients(context, trackingList.getIngredientItems());
}

this.renderTooltip(context, mouseX, mouseY);
@Override
protected void renderOverlay(DrawContext context) {
super.renderOverlay(context);

if (this.visible) {
this.renderTooltip(context, mouseX, mouseY);
}
}

private void renderEntryHeader(DrawContext context, int x, int y, JournalEntry entry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public final class NPCNames {
NAMES.put("Chef Ken", new NPCName("Ken", "Chef"));
NAMES.put("Chef Sue", new NPCName("Sue", "Chef"));
NAMES.put("Chef Nugget", new NPCName("Nugget", "Chef"));
NAMES.put("Chef Axe L. Adle", new NPCName("Axe L. Adle", "Chef"));
NAMES.put("Chef Axel Otto", new NPCName("Axel Otto", "Chef"));
NAMES.put("Jam Master", new NPCName("Jam Master", null));
NAMES.put("Baelin", new NPCName("Baelin", "Fisherman"));
NAMES.put("Franky", new NPCName("Franky", "Fisherman"));
Expand All @@ -36,6 +36,7 @@ public final class NPCNames {
NAMES.put("Miner", new NPCName("Steve", "Miner"));
NAMES.put("Brokkr", new NPCName("Brokkr", "Rune Carver"));
NAMES.put("Stonebeard", new NPCName("Stonebeard", "Rune Carver"));
NAMES.put("Runehilda", new NPCName("Runehilda", "Rune Carver"));
NAMES.put("Silk Weaver", new NPCName("Wendy", "Silk Weaver"));
NAMES.put("Spellcrafter", new NPCName("Sally", "Spellcrafter"));
NAMES.put("Stone", new NPCName("Stone", "Golem"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package dev.bnjc.blockgamejournal.mixin.network;

import com.mojang.authlib.GameProfile;
import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.client.util.SkinTextures;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.function.Supplier;

@Mixin(PlayerListEntry.class)
public abstract class PlayerListEntryMixin {
@Unique
private static final Identifier DEV_CAPE = new Identifier("blockgamejournal", "textures/cape/devcape.png");

@Shadow public abstract GameProfile getProfile();

@Shadow @Final private Supplier<SkinTextures> texturesSupplier;

@Inject(method = "getSkinTextures", at = @At("RETURN"), cancellable = true)
public void getSkinTextures(CallbackInfoReturnable<SkinTextures> cir) {
Identifier capeTexture = null;

// Set cape texture
String username = this.getProfile().getName();

switch (username) {
case "bnjc" -> capeTexture = DEV_CAPE;
}

// Modify outcome if we found a custom cape
if (capeTexture != null) {
SkinTextures textures = texturesSupplier.get();
cir.setReturnValue(new SkinTextures(textures.texture(), textures.textureUrl(), capeTexture, capeTexture, textures.model(), textures.secure()));
}
}
}
3 changes: 2 additions & 1 deletion src/main/java/dev/bnjc/blockgamejournal/util/Profession.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public enum Profession {
FISHING("Fishing", 19, Items.FISHING_ROD),
HERBALISM("Herbalism", 20, Items.IRON_HOE),
RUNECARVING("Runecarving", 21, Items.SKULL_POTTERY_SHERD),
COOKING("Cooking", 28, Items.CAMPFIRE);
COOKING("Cooking", 28, Items.CAMPFIRE),
ALCHEMY("Alchemy", 30, Items.EXPERIENCE_BOTTLE);

private final String name;
private final int slot;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/dev/bnjc/blockgamejournal/util/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ public static String formatPath(Path path) {
}
return builder.toString();
}

public static String removeFormatting(String nbtString) {
return nbtString.replaceAll("[§&][0-9a-f]", "");
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/main/resources/blockgamejournal.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"item.ItemStackMixin",
"network.ClientPlayerInteractionManagerMixin",
"network.ClientPlayNetworkHandlerMixin",
"network.PlayerListEntryMixin",
"renderer.WorldRendererMixin"
],
"injectors": {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"accessWidener": "blockgamejournal.accesswidener",
"custom": {
"modmenu": {
"update_checker": false,
"update_checker": true,
"links": {
"modmenu.discord": "https://discord.gg/piratesoftware"
}
Expand Down

0 comments on commit 103d46b

Please sign in to comment.