Skip to content

Commit

Permalink
Merge pull request #6 from sweetrpg/1.18
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
paulyhedral authored Nov 23, 2024
2 parents 38c5d16 + 425ab14 commit 733f93f
Show file tree
Hide file tree
Showing 14 changed files with 210 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .release-info/1.18/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.19
0.0.24
3 changes: 2 additions & 1 deletion CHANGELOG/1.18/current.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- `[NEW]` First releasable build
- `[NEW]` Remove items from the queue when they've been crafted or picked up
- `[NEW]` Show count of inventory items in the materials list
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[![Craft Tracker Logo](images/CraftTracker.jpeg)]
![Craft Tracker Logo](images/CraftTracker.jpeg)

# Craft Tracker

<a href="https://www.curseforge.com/minecraft/mc-mods/craft-tracker">
<img src="http://cf.way2muchnoise.eu/full_626455_downloads.svg" alt="Curseforge Downloads">
</a>
<a href="https://www.curseforge.com/minecraft/mc-mods/craft-tracker">
<a href="https://modrinth.com/mod/craft-tracker">
<img src="https://img.shields.io/modrinth/dt/" alt="Modrinth Downloads">
</a>

Expand All @@ -15,12 +15,13 @@

**Craft Tracker** is a **Minecraft** mod made for **Minecraft Forge**.

* TODO
* Add items to a queue to keep track of what you need
* Setup a shopping list so you know what to gather
* Share the shopping list with other players so they can help

## Integrations

* [JEI](https://www.curseforge.com/minecraft/mc-mods/jei) &mdash; supports search for new recipes
* [Patchouli](https://www.curseforge.com/minecraft/mc-mods/patchouli) &mdash; adds the Craft Tracking book
* [JEI](https://www.curseforge.com/minecraft/mc-mods/jei) &mdash; version 9.7.2.281 or higher

## Contributing

Expand Down
2 changes: 2 additions & 0 deletions src/generated/resources/assets/crafttracker/lang/de_de.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"crafttracker.screen.craft_list.empty_message": "Die Warteschlange ist leer.",
"crafttracker.screen.craft_list.have": "habe %d",
"crafttracker.screen.craft_list.section.fuel": "Kraftstoff",
"crafttracker.screen.craft_list.section.intermediates": "Zwischenprodukte",
"crafttracker.screen.craft_list.section.materials": "Materialien",
"crafttracker.screen.craft_list.section.products": "Produkte",
Expand Down
2 changes: 2 additions & 0 deletions src/generated/resources/assets/crafttracker/lang/en_gb.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"crafttracker.screen.craft_list.empty_message": "The queue is empty.",
"crafttracker.screen.craft_list.have": "have %d",
"crafttracker.screen.craft_list.section.fuel": "Fuel",
"crafttracker.screen.craft_list.section.intermediates": "Intermediates",
"crafttracker.screen.craft_list.section.materials": "Materials",
"crafttracker.screen.craft_list.section.products": "Products",
Expand Down
2 changes: 2 additions & 0 deletions src/generated/resources/assets/crafttracker/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"crafttracker.screen.craft_list.empty_message": "The queue is empty.",
"crafttracker.screen.craft_list.have": "have %d",
"crafttracker.screen.craft_list.section.fuel": "Fuel",
"crafttracker.screen.craft_list.section.intermediates": "Intermediates",
"crafttracker.screen.craft_list.section.materials": "Materials",
"crafttracker.screen.craft_list.section.products": "Products",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import com.sweetrpg.crafttracker.common.lib.Constants;
import com.sweetrpg.crafttracker.common.manager.CraftingQueueManager;
import mezz.jei.api.constants.VanillaTypes;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraftforge.client.gui.IIngameOverlay;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.server.command.TextComponentHelper;

public class CraftQueueOverlay {

Expand Down Expand Up @@ -89,7 +91,7 @@ public class CraftQueueOverlay {

// SECTION: intermediates
if(!mgr.getIntermediates().isEmpty()) {
yPos += (TEXT_HEIGHT * 2);
yPos += (TEXT_HEIGHT * 1.5);
CraftTracker.LOGGER.trace("yPos (before intermediates title): {}", yPos);

// title
Expand Down Expand Up @@ -119,7 +121,7 @@ public class CraftQueueOverlay {

// SECTION: raw materials
if(!mgr.getRawMaterials().isEmpty()) {
yPos += (TEXT_HEIGHT * 2);
yPos += (TEXT_HEIGHT * 1.5);
CraftTracker.LOGGER.trace("yPos (before materials title): {}", yPos);

// title
Expand All @@ -129,6 +131,8 @@ public class CraftQueueOverlay {
yPos += TEXT_HEIGHT + 2;
CraftTracker.LOGGER.trace("yPos (after materials title): {}", yPos);

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

// items
for(int i = 0; i < mgr.getRawMaterials().size(); i++) {
var m = mgr.getRawMaterials().get(i);
Expand All @@ -140,7 +144,25 @@ public class CraftQueueOverlay {
var drawable = CTPlugin.jeiRuntime.getJeiHelpers().getGuiHelper()
.createDrawableIngredient(VanillaTypes.ITEM_STACK, stack);
drawable.draw(poseStack, x + SECTION_X_OFFSET, yPos);
GuiComponent.drawString(poseStack, gui.getFont(), item.getDescription().getString(MAX_STRING_LENGTH), x + ITEM_NAME_X_OFFSET, yPos + 4, TEXT_COLOR);

final int lambdaYpos = yPos;
if(inventory.contains(stack)) {
inventory.items.stream()
.filter((inv) -> inv.getItem().getRegistryName().equals(m.getItemId()))
.map((inv) -> inv.getCount())
.findFirst()
.ifPresent((count) -> {
var text = String.format("%s [%d]",
item.getDescription().getString(MAX_STRING_LENGTH),
count);
CraftTracker.LOGGER.debug("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);
GuiComponent.drawString(poseStack, gui.getFont(), text, x + ITEM_NAME_X_OFFSET, yPos + 4, TEXT_COLOR);
}

yPos += LINE_HEIGHT + 2;
CraftTracker.LOGGER.trace("yPos (materials item {}): {}", i, yPos);
Expand All @@ -150,7 +172,7 @@ public class CraftQueueOverlay {
// SECTION: fuel

if(!mgr.getFuel().isEmpty()) {
yPos += (TEXT_HEIGHT * 2);
yPos += (TEXT_HEIGHT * 1.5);
CraftTracker.LOGGER.trace("yPos (before fuel title): {}", yPos);

// title
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@
import com.sweetrpg.crafttracker.CraftTracker;
import com.sweetrpg.crafttracker.common.lib.Constants;
import com.sweetrpg.crafttracker.common.manager.CraftingQueueManager;
import com.sweetrpg.crafttracker.common.network.PacketHandler;
import com.sweetrpg.crafttracker.common.network.packet.QueueCommandPacket;
import com.sweetrpg.crafttracker.common.network.packet.data.QueueCommandData;
import net.minecraft.client.Minecraft;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedInEvent;
import net.minecraftforge.event.entity.player.PlayerEvent.*;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.common.Mod;

import static com.sweetrpg.crafttracker.common.network.packet.data.QueueCommandData.QueueCommand.RECALCULATE;

@Mod.EventBusSubscriber(modid = Constants.MOD_ID)
public class EventHandler {

Expand Down Expand Up @@ -47,13 +56,63 @@ public void onEntitySpawn(final EntityJoinWorldEvent event) {
public void playerLoggedIn(final PlayerLoggedInEvent event) {
CraftTracker.LOGGER.debug("EventHandler#playerLoggedIn: {}", event);

// CraftingQueueManager.INSTANCE.load(event.getPlayer());
}

// @SubscribeEvent
// public void onLootDrop(final LootingLevelEvent event) {
// CraftTracker.LOGGER.debug("EventHandler#onLootDrop: {}", event);
//
// }
@SubscribeEvent
public void onItemCrafted(final ItemCraftedEvent event) {
CraftTracker.LOGGER.debug("EventHandler#onItemCrafted: {}", event);

if (event.getPlayer().level.isClientSide) {
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> {
var itemId = event.getCrafting().getItem().getRegistryName();
var quantity = event.getCrafting().getCount();
var player = Minecraft.getInstance().player;

CraftingQueueManager.INSTANCE.removeProduct(player, itemId, quantity);
});
}
else {
// send packet
PacketHandler.sendToPlayer((ServerPlayer)event.getPlayer(), new QueueCommandData(RECALCULATE));
}
}

@SubscribeEvent
public void onItemSmelted(final ItemSmeltedEvent event) {
CraftTracker.LOGGER.debug("EventHandler#onItemSmelted: {}", event);

if (event.getPlayer().level.isClientSide) {
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> {
var itemId = event.getSmelting().getItem().getRegistryName();
var quantity = event.getSmelting().getCount();
var player = Minecraft.getInstance().player;

CraftingQueueManager.INSTANCE.removeProduct(player, itemId, quantity);
});
}
else {
// send packet
PacketHandler.sendToPlayer((ServerPlayer)event.getPlayer(), new QueueCommandData(RECALCULATE));
}
}

@SubscribeEvent
public void onItemPickedUp(final ItemPickupEvent event) {
CraftTracker.LOGGER.debug("EventHandler#onItemPickedUp: {}", event);

if (event.getPlayer().level.isClientSide) {
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> {
var itemId = event.getStack().getItem().getRegistryName();
var quantity = event.getStack().getCount();
var player = Minecraft.getInstance().player;

CraftingQueueManager.INSTANCE.removeProduct(player, itemId, quantity);
});
}
else {
// send packet
PacketHandler.sendToPlayer((ServerPlayer)event.getPlayer(), new QueueCommandData(RECALCULATE));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class Constants {
public static final String TRANSLATION_KEY_GUI_CRAFTLIST_SECTION_INTERMEDIATES = "crafttracker.screen.craft_list.section.intermediates";
public static final String TRANSLATION_KEY_GUI_CRAFTLIST_SECTION_MATERIALS = "crafttracker.screen.craft_list.section.materials";
public static final String TRANSLATION_KEY_GUI_CRAFTLIST_SECTION_FUEL = "crafttracker.screen.craft_list.section.fuel";
public static final String TRANSLATION_KEY_GUI_CRAFTLIST_HAVE = "crafttracker.screen.craft_list.have";
public static final String TRANSLATION_KEY_GUI_SHOPPINGLIST_TITLE = "crafttracker.screen.shopping_list.title";
public static final String TRANSLATION_KEY_BINDINGS_CATEGORY_TITLE = "key.categories.crafttracker";
public static final String TRANSLATION_KEY_BINDINGS_ADDTOQUEUE_TITLE = "key.addToQueue";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.sweetrpg.crafttracker.common.model.CraftingQueueProduct;
import com.sweetrpg.crafttracker.common.storage.CraftingQueueStorage;
import com.sweetrpg.crafttracker.common.util.RecipeUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtIo;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -73,7 +74,6 @@ public void load(Player player) {
CraftTracker.LOGGER.debug("file: {}", file);

try {
// Files.createDirectories(file);
try (InputStream in = Files.newInputStream(file, StandardOpenOption.READ)) {
var data = NbtIo.readCompressed(in);
var products = CraftingQueueStorage.load(data);
Expand All @@ -96,7 +96,7 @@ public void save(Player player) {
try {
Files.createDirectories(file);
}
catch(FileAlreadyExistsException e) {
catch (FileAlreadyExistsException e) {
// ignore
}
catch (IOException e) {
Expand Down Expand Up @@ -187,11 +187,14 @@ public void removeProduct(Player player, ResourceLocation itemId, int quantity)
int newQuantity = product.getQuantity() - quantity;
if(newQuantity < 1) {
CraftTracker.LOGGER.info("Removing item from queue storage: {}", itemId);
// CraftingQueueStorage.get(level).removeData(itemId);
this.endProducts.remove(itemId);
}
else {
CraftTracker.LOGGER.info("Adjusting quantity of item in queue storage to {}: {}", quantity, itemId);
// CraftingQueueStorage.get(level).putData(itemId, newQuantity);
this.endProducts.computeIfPresent(itemId, (k, v) -> {
var cqp = new CraftingQueueProduct(itemId, v.getRecipes(), v.getQuantity() - quantity);
return cqp;
});
}

computeAll();
Expand Down Expand Up @@ -231,9 +234,6 @@ public void computeRecipe(Recipe recipe, int recipeQuantity) {

if(RecipeUtil.areIngredientsSame(ingredients)) {
CraftTracker.LOGGER.debug("ingredients are the same: {}", ingredients);
// if(ingredients.get(0) instanceof Ingredient ingredient) {
// var item = ingredient.getItems()[0];
// var id = item.getItem().getRegistryName();
var id = recipe.getId();
CraftTracker.LOGGER.debug("id: {}", id);
if(this.intermediateProducts.containsKey(id)) {
Expand All @@ -245,7 +245,6 @@ public void computeRecipe(Recipe recipe, int recipeQuantity) {

return;
}
// }
}

ingredients.stream()
Expand Down Expand Up @@ -273,14 +272,34 @@ public void computeRecipe(Recipe recipe, int recipeQuantity) {
}
else {
CraftTracker.LOGGER.debug("subRecipes has {} items; intermediate", subRecipes.size());
// intermediate
this.intermediateProducts.compute(id, (itemId, quantity) -> {
if(quantity == null) {
return item.getCount();
}

return quantity + item.getCount();
});

// check if player already has the item
var inventory = Minecraft.getInstance().player.getInventory();
if(inventory.contains(item)) {
inventory.items.stream()
.filter((inv) -> inv.getItem().getRegistryName().equals(id))
.map((inv) -> inv.getCount())
.findFirst()
.ifPresent((count) -> {
this.intermediateProducts.compute(id, (itemId, quantity) -> {
Integer finalCount = (quantity == null ? 0 : quantity) + item.getCount() - count;
if(finalCount < 1) {
return null;
}

return finalCount;
});
});
}
else {
this.intermediateProducts.compute(id, (itemId, quantity) -> {
if(quantity == null) {
return item.getCount();
}

return quantity + item.getCount();
});
}

this.computeRecipe(subRecipes.get(0), recipeQuantity);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.sweetrpg.crafttracker.common.network;

import com.sweetrpg.crafttracker.CraftTracker;
import com.sweetrpg.crafttracker.common.network.packet.QueueCommandPacket;
import com.sweetrpg.crafttracker.common.network.packet.data.QueueCommandData;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.network.PacketDistributor;

Expand All @@ -9,6 +11,7 @@ public final class PacketHandler {
private static int disc = 0;

public static void init() {
registerPacket(new QueueCommandPacket(), QueueCommandData.class);
// registerPacket(new AddToQueuePacket(), AddToQueueData.class);
// registerPacket(new ToggleCraftListPacket(), ToggleCraftListData.class);
// registerPacket(new ToggleShoppingListPacket(), ToggleShoppingListData.class);
Expand Down
Loading

0 comments on commit 733f93f

Please sign in to comment.