Update polymer

This commit is contained in:
Bruno Rybársky 2024-06-18 16:07:43 +02:00
parent 58c84dbf91
commit 16d7e58b8a
7 changed files with 89 additions and 32 deletions

@ -4,18 +4,18 @@ org.gradle.jvmargs=-Xmx1G
# check these on https://modmuss50.me/fabric.html # check these on https://modmuss50.me/fabric.html
minecraft_version=1.21 minecraft_version=1.21
yarn_mappings=1.21+build.1 yarn_mappings=1.21+build.2
loader_version=0.15.11 loader_version=0.15.11
# Fabric API # Fabric API
fabric_version=0.100.1+1.21 fabric_version=0.100.3+1.21
# Mod Properties # Mod Properties
mod_version=2.6 mod_version=2.6.1
maven_group=systems.brn maven_group=systems.brn
archives_base_name=Server_storage archives_base_name=Server_storage
# Dependencies # Dependencies
polymer_version=0.9.0+1.21-rc1 polymer_version=0.9.2+1.21
server_translations_api_version=2.3.1+1.21-pre2 server_translations_api_version=2.3.1+1.21-pre2
servergui_version=1.6.0+1.21 servergui_version=1.6.0+1.21

@ -4,9 +4,12 @@ import net.minecraft.item.ItemStack;
import net.minecraft.recipe.CraftingRecipe; import net.minecraft.recipe.CraftingRecipe;
import net.minecraft.recipe.RecipeEntry; import net.minecraft.recipe.RecipeEntry;
import java.util.ArrayList;
public class CraftingEntry { public class CraftingEntry {
public final ItemStack itemStack; public final ItemStack itemStack;
public final RecipeEntry<CraftingRecipe> recipeEntry; public final RecipeEntry<CraftingRecipe> recipeEntry;
public final ArrayList<MyCraftingRecipe> myCraftingRecipeEntries;
public CraftingEntry(ItemStack itemStack, RecipeEntry<CraftingRecipe> recipeEntry) { public CraftingEntry(ItemStack itemStack, RecipeEntry<CraftingRecipe> recipeEntry) {
this.itemStack = itemStack; this.itemStack = itemStack;
this.recipeEntry = recipeEntry; this.recipeEntry = recipeEntry;

@ -0,0 +1,15 @@
package systems.brn.server_storage.lib;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.CraftingRecipe;
import net.minecraft.recipe.RecipeEntry;
import java.util.HashMap;
public class MyCraftingRecipe {
HashMap<ItemStack, Integer> inputs = new HashMap<>();
HashMap<ItemStack, Integer> outputs = new HashMap<>();
MyCraftingRecipe(RecipeEntry<CraftingRecipe> recipeEntry) {
recipeEntry.value().getIngredients()
}
}

@ -26,7 +26,9 @@ public class StorageOperations {
} else { } else {
// Sort by count in descending order // Sort by count in descending order
sortedMap = new TreeMap<>((o1, o2) -> { sortedMap = new TreeMap<>((o1, o2) -> {
int countCompare = Integer.compare(o2.getCount(), o1.getCount()); int count1 = itemStackMap.get(o1);
int count2 = itemStackMap.get(o2);
int countCompare = Integer.compare(count2, count1);
// If counts are equal, compare items alphabetically by name // If counts are equal, compare items alphabetically by name
return countCompare == 0 ? String.valueOf(o1.getItem()).compareToIgnoreCase(String.valueOf(o2.getItem())) : countCompare; return countCompare == 0 ? String.valueOf(o1.getItem()).compareToIgnoreCase(String.valueOf(o2.getItem())) : countCompare;
}); });

@ -13,7 +13,9 @@ import net.minecraft.text.Text;
import net.minecraft.util.Formatting; import net.minecraft.util.Formatting;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class Util { public class Util {
@ -24,7 +26,7 @@ public class Util {
ItemStack slotStack = inventory.getStack(i); ItemStack slotStack = inventory.getStack(i);
if (!slotStack.isEmpty()) { if (!slotStack.isEmpty()) {
Item itemName = slotStack.getItem(); Item itemName = slotStack.getItem();
pages.add(String.valueOf(itemName) + " " + slotStack.getCount()); pages.add(itemName + " " + slotStack.getCount());
} }
} }
return stringToBookContent(String.join(System.lineSeparator(), pages)); return stringToBookContent(String.join(System.lineSeparator(), pages));
@ -112,29 +114,61 @@ public class Util {
int maxAmount = -1; int maxAmount = -1;
boolean canMake = true; boolean canMake = true;
for (Ingredient ingredient : recipe.value().getIngredients()) { for (Ingredient ingredient : recipe.value().getIngredients()) {
HashMap<ItemStack, Integer> inputsTemp = new HashMap<>();
for (ItemStack stack : ingredient.getMatchingStacks()) { for (ItemStack stack : ingredient.getMatchingStacks()) {
if (stack.isEmpty()) { if (stack.isEmpty()) {
break; break;
} else { } else {
//if inventory contains stack //if inventory contains stack
boolean foundUsableStack = false; boolean foundUsableStack = false;
for (int i = 0; i < inventory.size(); i++) { for (Map.Entry<ItemStack, Integer> entry : inputsTemp.entrySet()) {
if (inventory.getStack(i).getItem().equals(stack.getItem())) { ItemStack stackIn = entry.getKey();
if (maxAmount == -1) { Integer count = entry.getValue();
maxAmount = inventory.getStack(i).getCount(); if (stackIn.getItem() == stack.getItem()) {
} else { count += stack.getCount();
maxAmount = Math.min(maxAmount, inventory.getStack(i).getCount()); entry.setValue(count); // Update the value in the map
}
foundUsableStack = true; foundUsableStack = true;
break; break;
} }
} }
if (!foundUsableStack) { if (!foundUsableStack) {
canMake = false; inputsTemp.put(stack, stack.getCount());
break;
} }
} }
} }
HashMap<ItemStack, Integer> inputs = new HashMap<>();
for (Map.Entry<ItemStack, Integer> entry : inputsTemp.entrySet()) {
ItemStack stackIn = entry.getKey();
Integer count = entry.getValue();
stackIn.setCount(count);
inputs.put(stackIn, stackIn.getCount());
}
for (int i = 0; i < inventory.size(); i++) {
ItemStack slotStack = inventory.getStack(i);
Item slotItem = slotStack.getItem();
int slotCount = slotStack.getCount();
for (Map.Entry<ItemStack, Integer> entry : inputs.entrySet()) {
ItemStack stackIn = entry.getKey();
Integer count = entry.getValue();
if (stackIn.getItem() == slotItem) {
count -= slotCount;
entry.setValue(count);
}
}
}
for (Map.Entry<ItemStack, Integer> entry : inputs.entrySet()) {
ItemStack stackIn = entry.getKey();
Integer count = entry.getValue();
if (count > 0) {
canMake = false;
} else {
int thisMaxAmount = Math.floorDivExact(Math.abs(count), stackIn.getCount());
if (maxAmount == -1) {
maxAmount = thisMaxAmount;
} else {
maxAmount = Math.min(maxAmount, thisMaxAmount);
}
}
} }
if (maxAmount > 1 && canMake) { if (maxAmount > 1 && canMake) {
Item outputItem = recipe.value().getResult(server.getRegistryManager()).getItem(); Item outputItem = recipe.value().getResult(server.getRegistryManager()).getItem();
@ -153,6 +187,9 @@ public class Util {
if (needToAdd) { if (needToAdd) {
craftingEntries.add(entry); craftingEntries.add(entry);
} }
} else {
break;
}
} }
} }
return craftingEntries; return craftingEntries;

@ -117,7 +117,7 @@ public class CraftingScreen extends PagedGui {
} }
// Add the result to the appropriate inventory // Add the result to the appropriate inventory
ItemStack outputStack = recipeEntry.value().getResult(storageScreen.getPlayer().getRegistryManager()); ItemStack outputStack = recipeEntry.value().getResult(storageScreen.getPlayer().getRegistryManager()).copy();
if (toPlayerInventory) { if (toPlayerInventory) {
if (canInsertItemIntoPlayerInventory(player, outputStack) == outputStack.getCount()) { if (canInsertItemIntoPlayerInventory(player, outputStack) == outputStack.getCount()) {
player.getInventory().insertStack(outputStack); player.getInventory().insertStack(outputStack);

@ -18,7 +18,7 @@
}, },
"depends": { "depends": {
"fabricloader": ">=${loader_version}", "fabricloader": ">=${loader_version}",
"fabric": "*", "fabric": ">=${fabric_version}",
"minecraft": "${minecraft_version}" "minecraft": ">=${minecraft_version}"
} }
} }