Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
paulyhedral committed Nov 28, 2024
1 parent cada0ba commit e0ec32f
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 130 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG/1.18/current.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
- `[FIX]` Fixed how recipes are looked up, so that some intermediates and raw materials
show up correctly
- `[NEW]` Enable shopping list display
- `[NEW]` Enable populating the shopping list
- `[FIX]` Fixed issue with keybinds triggering all the time
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ public static void removeProduct(ResourceLocation itemId, int quantity) {
CraftingQueueManager.INSTANCE.removeProduct(player, itemId, quantity);
}

public static void pickupItem(ResourceLocation itemId, int quantity) {
var player = Minecraft.getInstance().player;

CraftingQueueManager.INSTANCE.removeProduct(player, itemId, quantity);
CraftingQueueManager.INSTANCE.computeAll();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
import com.sweetrpg.crafttracker.common.lib.Constants;
import com.sweetrpg.crafttracker.common.manager.CraftingQueueManager;
import com.sweetrpg.crafttracker.common.registry.ModKeyBindings;
import com.sweetrpg.crafttracker.common.util.InventoryUtil;
import mezz.jei.api.constants.VanillaTypes;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.client.gui.IIngameOverlay;
import net.minecraftforge.registries.ForgeRegistries;

Expand Down Expand Up @@ -63,19 +65,19 @@ public class CraftQueueOverlay {
GuiComponent.fill(poseStack, x + 2, y + 2, olWidth - 2, olHeight - 2, backgroundColor);

GuiComponent.drawCenteredString(poseStack, gui.getFont(),
new TranslatableComponent(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_TITLE),
new TranslatableComponent(Constants.TRANSLATION_KEY_GUI_CRAFT_QUEUE_TITLE),
(x + olWidth - 8) / 2, y + 6, TITLE_COLOR);

// if products list is empty, display "empty" message
if(products.isEmpty()) {
GuiComponent.drawCenteredString(poseStack, gui.getFont(),
new TranslatableComponent(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_EMPTY),
new TranslatableComponent(Constants.TRANSLATION_KEY_GUI_CRAFT_QUEUE_EMPTY),
(x + olWidth - 8) / 2, (y + olHeight - 6) / 2, MESSAGE_COLOR);
return;
}

var helpText = String.format("%s [%s]",
I18n.get(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_HELP),
I18n.get(Constants.TRANSLATION_KEY_GUI_CRAFT_QUEUE_HELP),
ModKeyBindings.OPEN_QUEUE_MANAGER_MAPPING.getTranslatedKeyMessage().getString());
GuiComponent.drawCenteredString(poseStack, gui.getFont(), helpText,
(x + olWidth - 8) / 2, olHeight - TEXT_HEIGHT, HELP_COLOR);
Expand All @@ -87,7 +89,7 @@ public class CraftQueueOverlay {

// title
GuiComponent.drawString(poseStack, gui.getFont(),
new TranslatableComponent(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_SECTION_PRODUCTS),
new TranslatableComponent(Constants.TRANSLATION_KEY_GUI_CRAFT_QUEUE_SECTION_PRODUCTS),
x + SECTION_X_OFFSET, yPos, SECTION_COLOR);
yPos += TEXT_HEIGHT + 2;
CraftTracker.LOGGER.trace("yPos (after product title): {}", yPos);
Expand All @@ -110,7 +112,8 @@ public class CraftQueueOverlay {
CraftTracker.LOGGER.trace("yPos (product item {}): {}", i, yPos);
}

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

// SECTION: intermediates

Expand All @@ -120,7 +123,7 @@ public class CraftQueueOverlay {

// title
GuiComponent.drawString(poseStack, gui.getFont(),
new TranslatableComponent(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_SECTION_INTERMEDIATES),
new TranslatableComponent(Constants.TRANSLATION_KEY_GUI_CRAFT_QUEUE_SECTION_INTERMEDIATES),
x + SECTION_X_OFFSET, yPos, SECTION_COLOR);
yPos += TEXT_HEIGHT + 2;
CraftTracker.LOGGER.trace("yPos (after intermediates title): {}", yPos);
Expand All @@ -133,15 +136,7 @@ public class CraftQueueOverlay {
var stack = item.getDefaultInstance();
stack.setCount(inter.getQuantity());

int playerHasQuantity = 0;
if(inventory.contains(stack)) {
playerHasQuantity = inventory.items.stream()
.filter(inv -> inv.getItem().getRegistryName().equals(inter.getItemId()))
.map(inv -> inv.getCount())
.findFirst()
.orElse(0);
}

int playerHasQuantity = InventoryUtil.getQuantityOf(player, inter.getItemId());
if(playerHasQuantity >= inter.getQuantity()) {
// don't need to display this intermediate, since the user doesn't need to make it
continue;
Expand All @@ -153,7 +148,7 @@ public class CraftQueueOverlay {

final int lambdaYpos = yPos;
if(playerHasQuantity > 0) {
var countText = I18n.get(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_HAVE, playerHasQuantity);
var countText = I18n.get(Constants.TRANSLATION_KEY_GUI_HAVE, playerHasQuantity);
var text = String.format("%s [%s]",
item.getDescription().getString(MAX_STRING_LENGTH - countText.length() - 3),
countText);
Expand All @@ -178,7 +173,7 @@ public class CraftQueueOverlay {

// title
GuiComponent.drawString(poseStack, gui.getFont(),
new TranslatableComponent(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_SECTION_MATERIALS),
new TranslatableComponent(Constants.TRANSLATION_KEY_GUI_CRAFT_QUEUE_SECTION_MATERIALS),
x + SECTION_X_OFFSET, yPos, SECTION_COLOR);
yPos += TEXT_HEIGHT + 2;
CraftTracker.LOGGER.trace("yPos (after materials title): {}", yPos);
Expand All @@ -191,15 +186,7 @@ public class CraftQueueOverlay {
var stack = item.getDefaultInstance();
stack.setCount(m.getQuantity());

int playerHasQuantity = 0;
if(inventory.contains(stack)) {
playerHasQuantity = inventory.items.stream()
.filter(inv -> inv.getItem().getRegistryName().equals(m.getItemId()))
.map(inv -> inv.getCount())
.findFirst()
.orElse(0);
}

int playerHasQuantity = InventoryUtil.getQuantityOf(player, m.getItemId());
if(playerHasQuantity >= m.getQuantity()) {
// don't need to display this intermediate, since the user doesn't need to make it
continue;
Expand All @@ -211,7 +198,7 @@ public class CraftQueueOverlay {

final int lambdaYpos = yPos;
if(playerHasQuantity > 0) {
var countText = I18n.get(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_HAVE, playerHasQuantity);
var countText = I18n.get(Constants.TRANSLATION_KEY_GUI_HAVE, playerHasQuantity);
var text = String.format("%s [%s]",
item.getDescription().getString(MAX_STRING_LENGTH - countText.length() - 3),
countText);
Expand All @@ -236,7 +223,7 @@ public class CraftQueueOverlay {

// title
GuiComponent.drawString(poseStack, gui.getFont(),
new TranslatableComponent(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_SECTION_FUEL),
new TranslatableComponent(Constants.TRANSLATION_KEY_GUI_CRAFT_QUEUE_SECTION_FUEL),
x + SECTION_X_OFFSET, yPos, SECTION_COLOR);
yPos += TEXT_HEIGHT + 2;
CraftTracker.LOGGER.trace("yPos: {}", yPos);
Expand All @@ -249,15 +236,7 @@ public class CraftQueueOverlay {
var stack = item.getDefaultInstance();
stack.setCount(f.getQuantity());

int playerHasQuantity = 0;
if(inventory.contains(stack)) {
playerHasQuantity = inventory.items.stream()
.filter(inv -> inv.getItem().getRegistryName().equals(f.getItemId()))
.map(inv -> inv.getCount())
.findFirst()
.orElse(0);
}

int playerHasQuantity = InventoryUtil.getQuantityOf(player, f.getItemId());
if(playerHasQuantity >= f.getQuantity()) {
// don't need to display this intermediate, since the user doesn't need to make it
continue;
Expand All @@ -269,7 +248,7 @@ public class CraftQueueOverlay {

final int lambdaYpos = yPos;
if(playerHasQuantity > 0) {
var countText = I18n.get(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_HAVE, playerHasQuantity);
var countText = I18n.get(Constants.TRANSLATION_KEY_GUI_HAVE, playerHasQuantity);
var text = String.format("%s [%s]",
item.getDescription().getString(MAX_STRING_LENGTH - countText.length() - 3),
countText);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtIo;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
Expand Down Expand Up @@ -37,33 +36,6 @@ public class CraftingQueueManager {
private Map<ResourceLocation, Integer> rawMaterials = new HashMap<>();
private Map<ResourceLocation, Integer> fuel = new HashMap<>();

private ServerPlayer player;
// private CraftingQueueStorage storage;

// public static CraftingQueueManager get(ServerPlayer player, Level level) {
// CraftTracker.LOGGER.debug("CraftingQueueManager#get: {}, level: {}", player, level);
//
// if(INSTANCE == null) {
// var storage = CraftingQueueStorage.get(level);
// INSTANCE = new CraftingQueueManager(player, storage);
// }
//
// return INSTANCE;
// }
//
// CraftingQueueManager(ServerPlayer player, CraftingQueueStorage storage) {
// CraftTracker.LOGGER.debug("CraftingQueueManager: {}, level: {}", player, storage);
//
// this.player = player;
//
// storage.getAll().stream()
// .map((data) -> {
// var recipes = RecipeUtil.getRecipesFor(data.getItemId());
// return new CraftingQueueProduct(data.getItemId(), recipes, data.getQuantity());
// })
// .forEach((p) -> this.endProducts.put(p.getItemId(), p));
//

public CraftingQueueManager() {
}

Expand Down Expand Up @@ -118,8 +90,6 @@ public void save(Player player) {
}
}

/// / this.storage = new CraftingQueueStorage();
// }
public List<ProductItem> getEndProducts() {
return endProducts.entrySet()
.stream()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
package com.sweetrpg.crafttracker.common.registry;

import com.mojang.blaze3d.platform.InputConstants;
import com.sweetrpg.crafttracker.common.lib.Constants;
import net.minecraft.client.KeyMapping;
import net.minecraftforge.client.ClientRegistry;
import net.minecraftforge.client.settings.KeyConflictContext;

public class ModKeyBindings {

public static final String KEY_CATEGORIES_CRAFT_TRACKER = "key.categories.crafttracker";
public static final String KEY_ADD_TO_QUEUE = "key.addToQueue";
public static final String KEY_TOGGLE_CRAFT_LIST = "key.toggleCraftList";
public static final String KEY_TOGGLE_SHOPPING_LIST = "key.toggleShoppingList";
public static final String KEY_OPEN_QUEUE_MANAGER = "key.openQueueManager";
public static final String KEY_POPULATE_SHOPPING_LIST = "key.populateShoppingList";

public static final KeyMapping ADD_TO_QUEUE_MAPPING = new KeyMapping(KEY_ADD_TO_QUEUE, KeyConflictContext.GUI, InputConstants.Type.KEYSYM, InputConstants.KEY_Q, KEY_CATEGORIES_CRAFT_TRACKER);
public static final KeyMapping TOGGLE_CRAFT_LIST_MAPPING = new KeyMapping(KEY_TOGGLE_CRAFT_LIST, KeyConflictContext.GUI, InputConstants.Type.KEYSYM, InputConstants.KEY_RSHIFT | InputConstants.KEY_L, KEY_CATEGORIES_CRAFT_TRACKER);
public static final KeyMapping TOGGLE_SHOPPING_LIST_MAPPING = new KeyMapping(KEY_TOGGLE_SHOPPING_LIST, KeyConflictContext.GUI, InputConstants.Type.KEYSYM, InputConstants.KEY_RSHIFT | InputConstants.KEY_S, KEY_CATEGORIES_CRAFT_TRACKER);
public static final KeyMapping OPEN_QUEUE_MANAGER_MAPPING = new KeyMapping(KEY_OPEN_QUEUE_MANAGER, KeyConflictContext.GUI, InputConstants.Type.KEYSYM, InputConstants.KEY_RSHIFT | InputConstants.KEY_M, KEY_CATEGORIES_CRAFT_TRACKER);
public static final KeyMapping POPULATE_SHOPPING_LIST_MAPPING = new KeyMapping(KEY_POPULATE_SHOPPING_LIST, KeyConflictContext.GUI, InputConstants.Type.KEYSYM, InputConstants.KEY_RSHIFT | InputConstants.KEY_P, KEY_CATEGORIES_CRAFT_TRACKER);
public static final KeyMapping ADD_TO_QUEUE_MAPPING = new KeyMapping(Constants.TRANSLATION_KEY_BINDINGS_ADDTOQUEUE_TITLE, KeyConflictContext.GUI, InputConstants.Type.KEYSYM, InputConstants.KEY_Q, Constants.KEY_BINDINGS_CATEGORY_TITLE);
public static final KeyMapping TOGGLE_CRAFT_QUEUE_MAPPING = new KeyMapping(Constants.TRANSLATION_KEY_BINDINGS_TOGGLE_CRAFT_QUEUE_TITLE, KeyConflictContext.GUI, InputConstants.Type.KEYSYM, InputConstants.KEY_RSHIFT | InputConstants.KEY_L, Constants.KEY_BINDINGS_CATEGORY_TITLE);
public static final KeyMapping TOGGLE_SHOPPING_LIST_MAPPING = new KeyMapping(Constants.TRANSLATION_KEY_BINDINGS_TOGGLE_SHOPPING_LIST_TITLE, KeyConflictContext.GUI, InputConstants.Type.KEYSYM, InputConstants.KEY_RSHIFT | InputConstants.KEY_S, Constants.KEY_BINDINGS_CATEGORY_TITLE);
public static final KeyMapping OPEN_QUEUE_MANAGER_MAPPING = new KeyMapping(Constants.TRANSLATION_KEY_BINDINGS_OPEN_QMGR_TITLE, KeyConflictContext.GUI, InputConstants.Type.KEYSYM, InputConstants.KEY_RSHIFT | InputConstants.KEY_M, Constants.KEY_BINDINGS_CATEGORY_TITLE);
public static final KeyMapping POPULATE_SHOPPING_LIST_MAPPING = new KeyMapping(Constants.TRANSLATION_KEY_BINDINGS_POPULATE_SHOPPING_LIST_TITLE, KeyConflictContext.GUI, InputConstants.Type.KEYSYM, InputConstants.KEY_RSHIFT | InputConstants.KEY_P, Constants.KEY_BINDINGS_CATEGORY_TITLE);
public static final KeyMapping CLEAR_SHOPPING_LIST_MAPPING = new KeyMapping(Constants.TRANSLATION_KEY_BINDINGS_CLEAR_SHOPPING_LIST_TITLE, KeyConflictContext.GUI, InputConstants.Type.KEYSYM, InputConstants.KEY_RSHIFT | InputConstants.KEY_K, Constants.KEY_BINDINGS_CATEGORY_TITLE);

public static void init() {
ClientRegistry.registerKeyBinding(ADD_TO_QUEUE_MAPPING);
ClientRegistry.registerKeyBinding(TOGGLE_CRAFT_LIST_MAPPING);
ClientRegistry.registerKeyBinding(TOGGLE_CRAFT_QUEUE_MAPPING);
ClientRegistry.registerKeyBinding(TOGGLE_SHOPPING_LIST_MAPPING);
ClientRegistry.registerKeyBinding(OPEN_QUEUE_MANAGER_MAPPING);
ClientRegistry.registerKeyBinding(POPULATE_SHOPPING_LIST_MAPPING);
ClientRegistry.registerKeyBinding(CLEAR_SHOPPING_LIST_MAPPING);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,11 @@ public class CraftingQueueStorage extends SavedData {
private @Nullable UUID ownerId;
private Vec3 craftingQueuePosition;
private boolean craftingQueueVisible;
private Vec3 shoppingListPosition;
private boolean shoppingListVisible;
// private Map<ResourceLocation, CraftingQueueData> queueData = Maps.newConcurrentMap();
private Map<ResourceLocation, CraftingQueueProduct> products = new HashMap<>();

public CraftingQueueStorage() {
}

// public static CraftingQueueStorage get(Level world) {
// CraftTracker.LOGGER.debug("CraftingQueueStorage#get: {}", world);
//
// if (!(world instanceof ServerLevel)) {
// throw new RuntimeException("Tried to access crafting queue data from the client. This should not happen...");
// }
//
// ServerLevel overworld = world.getServer().getLevel(Level.OVERWORLD);
//
// DimensionDataStorage storage = overworld.getDataStorage();
// return storage.computeIfAbsent(CraftingQueueStorage::load, CraftingQueueStorage::new, Constants.STORAGE_CRAFTING_QUEUE);
// }

public void putData(Map<ResourceLocation, CraftingQueueProduct> products) {
CraftTracker.LOGGER.debug("CraftingQueueStorage#putData: {}", products);

Expand All @@ -67,8 +51,6 @@ public static Map<ResourceLocation, CraftingQueueProduct> load(CompoundTag nbt)
store.ownerId = NBTUtil.getUniqueId(nbt, Keys.OWNER_ID);
store.craftingQueuePosition = NBTUtil.getVector3d(nbt);
store.craftingQueueVisible = nbt.getBoolean(Keys.CRAFTING_QUEUE_VISIBLE);
store.shoppingListPosition = NBTUtil.getVector3d(nbt);
store.shoppingListVisible = nbt.getBoolean(Keys.SHOPPING_LIST_VISIBLE);

ListTag list = nbt.getList(Keys.QUEUE_DATA, Tag.TAG_COMPOUND);

Expand All @@ -94,8 +76,6 @@ public CompoundTag save(CompoundTag compound) {
NBTUtil.putUniqueId(compound, Keys.OWNER_ID, this.ownerId);
NBTUtil.putVector3d(compound, this.craftingQueuePosition);
compound.putBoolean(Keys.CRAFTING_QUEUE_VISIBLE, this.craftingQueueVisible);
NBTUtil.putVector3d(compound, this.shoppingListPosition);
compound.putBoolean(Keys.SHOPPING_LIST_VISIBLE, this.shoppingListVisible);

ListTag list = new ListTag();

Expand All @@ -117,7 +97,6 @@ public CompoundTag save(CompoundTag compound) {
static class Keys {
static String OWNER_ID = "owner_id";
static String CRAFTING_QUEUE_VISIBLE = "crafting_queue_visible";
static String SHOPPING_LIST_VISIBLE = "shopping_list_visible";
static String QUEUE_DATA = "queue_data";
static String ITEM_ID = "item_id";
static String QUANTITY = "quantity";
Expand Down
Loading

0 comments on commit e0ec32f

Please sign in to comment.