Skip to content

Commit

Permalink
Release 0.3.6
Browse files Browse the repository at this point in the history
- [fix] David S. Pumpkins now can store recipes
- [fix] Lock toggle works in vendor view when sorting A to Z
- [fix] Items will be marked as outdated if a required recipe is added/removed or if a level req changes
- [chore] Added total recipes known count
  • Loading branch information
blackjack26 committed Oct 2, 2024
1 parent 2f2042f commit beddab3
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 21 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.5
mod_version=0.3.6
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 @@ -84,7 +84,7 @@ public boolean createEntry(
return false;
}

JournalEntry entry = new JournalEntryBuilder(this.ingredients, vendor, stationItem.getSlot()).build(item);
JournalEntry entry = new JournalEntryBuilder(this.ingredients, vendorName, stationItem.getSlot()).build(item);
if (!this.validateEntry(stationItem, entry)) {
BlockgameJournal.LOGGER.warn("[Blockgame Journal] Recipe validation failed");
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
import net.minecraft.item.ItemStack;
import net.minecraft.item.KnowledgeBookItem;
import net.minecraft.item.PlayerHeadItem;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList;
import net.minecraft.network.packet.s2c.play.InventoryS2CPacket;
import net.minecraft.network.packet.s2c.play.OpenScreenS2CPacket;
import net.minecraft.scoreboard.ScoreboardDisplaySlot;
import net.minecraft.screen.slot.Slot;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
Expand Down Expand Up @@ -101,8 +104,14 @@ private ActionResult handleOpenScreen(OpenScreenS2CPacket packet) {
}

// Look for screen name "Some Name (#page#/#max#)" - exclude "Party" from the name
Matcher matcher = Pattern.compile("^((?!Party)[\\w\\s]+)\\s\\(\\d+/\\d+\\)").matcher(screenName);
Matcher matcher = Pattern.compile("^((?!Party)[^(]+)\\s\\(\\d+/\\d+\\)").matcher(screenName);
if (matcher.find() || screenName.equals(entityName)) {
// Citizens2 uses "CIT-<entity name>" as the entity name if no custom name is set
if (entityName.startsWith("CIT-")) {
entityName = matcher.group(1);
interactionEntity.setCustomName(Text.literal(entityName));
}

this.syncId = packet.getSyncId();
this.vendorName = entityName;
this.stationItems.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,11 @@ private void showVendorItems() {
.map(entry -> {
if (JournalScreen.vendorItemSort == ItemListWidget.VendorSort.A_TO_Z) {
JournalItemStack stack = JournalItemStack.fromKnownItem(entry.getKey());

if (entry.getValue().stream().allMatch(JournalEntry::isLocked) && UnlockedButtonWidget.isToggled()) {
return List.<JournalItemStack>of();
}

if (stack != null) {
this.adjustLoreNbt(stack);
return List.of(stack);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,13 @@ protected void renderContents(DrawContext context, int mouseX, int mouseY, float
return;
}

int totalKnown = knownRecipes.values().stream().mapToInt(known -> known ? 1 : 0).sum();
int totalRecipes = knownRecipes.size();

// Render "Known Recipes" text
MutableText titleText = Text.literal("Learned Recipes").formatted(Formatting.WHITE, Formatting.BOLD);
MutableText countText = Text.literal(" (" + totalKnown + "/" + totalRecipes + ")").formatted(Formatting.GRAY);
countText.setStyle(countText.getStyle().withBold(false));
MutableText titleText = Text.literal("Learned Recipes").formatted(Formatting.WHITE, Formatting.BOLD).append(countText);
context.drawText(textRenderer, titleText, this.getX(), this.lastY, 0x404040, false);

this.lastY += 12;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,17 @@

public class JournalEntryBuilder {
private final List<ItemStack> ingredientStacks;
private final Entity npc;
private final String vendorName;
private final int slot;

public JournalEntryBuilder(List<ItemStack> ingredientStacks, Entity npc, int slot) {
public JournalEntryBuilder(List<ItemStack> ingredientStacks, String vendorName, int slot) {
this.ingredientStacks = ingredientStacks;
this.npc = npc;
this.slot = slot;
this.vendorName = vendorName;
}

public JournalEntry build(ItemStack stack) {
String npcName = npc.getEntityName();
if (!(npc instanceof PlayerEntity) && npc.hasCustomName()) {
npcName = npc.getCustomName().getString();
}
return new JournalEntry(stack, getIngredients(), npcName, slot, System.currentTimeMillis());
return new JournalEntry(stack, getIngredients(), vendorName, slot, System.currentTimeMillis());
}

private Map<String, Integer> getIngredients() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,10 @@ public NPCEntry(String name, GameProfile gameProfile, @Nullable BlockPos positio
this.entityType = EntityType.getId(EntityType.PLAYER).toString();
}

public static NPCEntry of(Entity entity) {
public static NPCEntry of(Entity entity, String name) {
String world = entity.getEntityWorld().getRegistryKey().getValue().toString();
if (entity instanceof PlayerEntity) {
return new NPCEntry(entity.getEntityName(), ((PlayerEntity)entity).getGameProfile(), entity.getBlockPos(), world);
}

// Create a new GameProfile with the entity's UUID and name
String name = entity.getEntityName();
if (entity.hasCustomName()) {
name = entity.getCustomName().getString();
return new NPCEntry(name, ((PlayerEntity)entity).getGameProfile(), entity.getBlockPos(), world);
}

GameProfile profile = new GameProfile(entity.getUuid(), name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public final class NPCNames {

NAMES.put("Myrkheim Dealer", new NPCName("Myrkheim Dealer", "Unreliable Guide"));
NAMES.put("Sunken Dealer", new NPCName("Sunken Dealer", null));

NAMES.put("Ol' Eggman", new NPCName("Ol' Eggman", "Glute Maxer")); // Mothman March
NAMES.put("David S. Pumpkins", new NPCName("David S. Pumpkins", "His Own Thang")); // Halloween Bash
NAMES.put("Feathers", new NPCName("Feathers", "Turkey")); // Turkey Terror
NAMES.put("Saint Nick", new NPCName("Saint Nick", "Santa")); // Winter Wonderland
}

private NPCNames() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static void createOrUpdate(String name, @NotNull Entity entity) {
return;
}

NPCEntry npcEntry = NPCEntry.of(entity);
NPCEntry npcEntry = NPCEntry.of(entity, name);

// Check if there is an existing NPC entry with the same name
NPCEntry existing = Journal.INSTANCE.getKnownNPCs().get(name);
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/dev/bnjc/blockgamejournal/util/ItemUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,16 @@ public static boolean isOutdated(JournalEntry entry, CraftingStationItem expecte
}
}

// Check to see if there is a new level requirement
if (entry.getRequiredLevel() != expected.getRequiredLevel()) {
return true;
}

// Check to see if recipe has been removed or added
if ((entry.recipeKnown() == null && expected.getRecipeKnown() != null) || (entry.recipeKnown() != null && expected.getRecipeKnown() == null)) {
return true;
}

return false;
}

Expand Down

0 comments on commit beddab3

Please sign in to comment.