Skip to content

Commit

Permalink
Merge pull request #39 from sweetrpg/feature/35-mark-tags
Browse files Browse the repository at this point in the history
#35 Show if items are from tags
  • Loading branch information
paulyhedral authored Dec 5, 2024
2 parents 980a3e7 + 6744438 commit b0cdad5
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 58 deletions.
1 change: 1 addition & 0 deletions CHANGELOG/1.18/current.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
- `[FIX]` Increased recipe calculation depth to 3
- `[FIX]` Added checks for recipe and ingredient namespaces in determining intermediate/raw status
- `[FIX]` Changed text for crafting queue sections
- `[NEW]` Intermediate and raw materials that are tags are marked with an asterisk
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@ private static void handlePopulateShoppingList() {

materials.forEach(m -> {
var haveQty = InventoryUtil.getQuantityOf(player, m.getItemId());
var needed = m.getQuantity() - haveQty;
var needed = m.getAmount() - haveQty;

if(needed > 0)
sMgr.addItem(player, m.getItemId(), needed);
});
fuel.forEach(f -> {
var haveQty = InventoryUtil.getQuantityOf(player, f.getItemId());
var needed = f.getQuantity() - haveQty;
var needed = f.getAmount() - haveQty;

if(needed > 0)
sMgr.addItem(player, f.getItemId(), needed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public class CraftQueueOverlay {
var mgr = CraftingQueueManager.INSTANCE;
var products = mgr.getEndProducts().stream().sorted((i1, i2) -> {
var item1 = ForgeRegistries.ITEMS.getValue(i1.getProductId());
if(item1 == null) return 0;
var item2 = ForgeRegistries.ITEMS.getValue(i2.getProductId());
if(item2 == null) return 0;
return item1.getDescription().getString().compareTo(item2.getDescription().getString());
}).toList();

Expand Down Expand Up @@ -103,6 +105,9 @@ public class CraftQueueOverlay {
var p = products.get(i);

var item = ForgeRegistries.ITEMS.getValue(p.getProductId());
if(item == null) {
continue;
}
var stack = item.getDefaultInstance();
var selectedRecipe = p.getRecipes().get(p.getIndex());
var amountProduced = selectedRecipe.getResultItem().getCount() * p.getIterations();
Expand All @@ -118,7 +123,7 @@ public class CraftQueueOverlay {
}

Player player = Minecraft.getInstance().player;
var inventory = player.getInventory();
// var inventory = player.getInventory();

// SECTION: intermediates

Expand All @@ -136,18 +141,20 @@ public class CraftQueueOverlay {
// items
var sortedIntermediates = mgr.getIntermediates().stream().sorted((i1, i2) -> {
var item1 = ForgeRegistries.ITEMS.getValue(i1.getItemId());
if(item1 == null) return 0;
var item2 = ForgeRegistries.ITEMS.getValue(i2.getItemId());
if(item2 == null) return 0;
return item1.getDescription().getString().compareTo(item2.getDescription().getString());
}).toList();
for(int i = 0; i < sortedIntermediates.size(); i++) {
var inter = sortedIntermediates.get(i);

var item = ForgeRegistries.ITEMS.getValue(inter.getItemId());
var stack = item.getDefaultInstance();
stack.setCount(inter.getQuantity());
stack.setCount(inter.getAmount());

int playerHasQuantity = InventoryUtil.getQuantityOf(player, inter.getItemId());
if(playerHasQuantity >= inter.getQuantity()) {
if(playerHasQuantity >= inter.getAmount()) {
// don't need to display this intermediate, since the user doesn't need to make it
continue;
}
Expand All @@ -159,14 +166,16 @@ public class CraftQueueOverlay {
final int lambdaYpos = yPos;
if(playerHasQuantity > 0) {
var countText = I18n.get(Constants.TRANSLATION_KEY_GUI_HAVE, playerHasQuantity);
var text = String.format("%s [%s]",
var text = String.format("%s%s [%s]",
item.getDescription().getString(MAX_STRING_LENGTH - countText.length() - 3),
inter.isTag() ? "*" : "",
countText);
CraftTracker.LOGGER.trace("text: {}", text);
GuiComponent.drawString(poseStack, gui.getFont(), text, x + ITEM_NAME_X_OFFSET, lambdaYpos + 4, TEXT_COLOR);
}
else {
var text = item.getDescription().getString(MAX_STRING_LENGTH);
var text = item.getDescription().getString(MAX_STRING_LENGTH) +
(inter.isTag() ? "*" : "");
GuiComponent.drawString(poseStack, gui.getFont(), text, x + ITEM_NAME_X_OFFSET, yPos + 4, TEXT_COLOR);
}

Expand Down Expand Up @@ -199,10 +208,10 @@ public class CraftQueueOverlay {

var item = ForgeRegistries.ITEMS.getValue(m.getItemId());
var stack = item.getDefaultInstance();
stack.setCount(m.getQuantity());
stack.setCount(m.getAmount());

int playerHasQuantity = InventoryUtil.getQuantityOf(player, m.getItemId());
if(playerHasQuantity >= m.getQuantity()) {
if(playerHasQuantity >= m.getAmount()) {
// don't need to display this intermediate, since the user doesn't need to make it
continue;
}
Expand All @@ -214,14 +223,16 @@ public class CraftQueueOverlay {
final int lambdaYpos = yPos;
if(playerHasQuantity > 0) {
var countText = I18n.get(Constants.TRANSLATION_KEY_GUI_HAVE, playerHasQuantity);
var text = String.format("%s [%s]",
var text = String.format("%s%s [%s]",
item.getDescription().getString(MAX_STRING_LENGTH - countText.length() - 3),
m.isTag() ? "*" : "",
countText);
CraftTracker.LOGGER.trace("text: {}", text);
GuiComponent.drawString(poseStack, gui.getFont(), text, x + ITEM_NAME_X_OFFSET, lambdaYpos + 4, TEXT_COLOR);
}
else {
var text = item.getDescription().getString(MAX_STRING_LENGTH);
var text = item.getDescription().getString(MAX_STRING_LENGTH) +
(m.isTag() ? "*" : "");
GuiComponent.drawString(poseStack, gui.getFont(), text, x + ITEM_NAME_X_OFFSET, yPos + 4, TEXT_COLOR);
}

Expand Down Expand Up @@ -254,10 +265,10 @@ public class CraftQueueOverlay {

var item = ForgeRegistries.ITEMS.getValue(f.getItemId());
var stack = item.getDefaultInstance();
stack.setCount(f.getQuantity());
stack.setCount(f.getAmount());

int playerHasQuantity = InventoryUtil.getQuantityOf(player, f.getItemId());
if(playerHasQuantity >= f.getQuantity()) {
if(playerHasQuantity >= f.getAmount()) {
// don't need to display this intermediate, since the user doesn't need to make it
continue;
}
Expand All @@ -269,14 +280,16 @@ public class CraftQueueOverlay {
final int lambdaYpos = yPos;
if(playerHasQuantity > 0) {
var countText = I18n.get(Constants.TRANSLATION_KEY_GUI_HAVE, playerHasQuantity);
var text = String.format("%s [%s]",
var text = String.format("%s%s [%s]",
item.getDescription().getString(MAX_STRING_LENGTH - countText.length() - 3),
f.isTag() ? "*" : "",
countText);
CraftTracker.LOGGER.trace("text: {}", text);
GuiComponent.drawString(poseStack, gui.getFont(), text, x + ITEM_NAME_X_OFFSET, lambdaYpos + 4, TEXT_COLOR);
}
else {
var text = item.getDescription().getString(MAX_STRING_LENGTH);
var text = item.getDescription().getString(MAX_STRING_LENGTH) +
(f.isTag() ? "*" : "");
GuiComponent.drawString(poseStack, gui.getFont(), text, x + ITEM_NAME_X_OFFSET, yPos + 4, TEXT_COLOR);
}

Expand Down
Loading

0 comments on commit b0cdad5

Please sign in to comment.