forked from BRNSystems/Server_storage
		
	Update polymer
This commit is contained in:
		@@ -4,18 +4,18 @@ org.gradle.jvmargs=-Xmx1G
 | 
			
		||||
# check these on https://modmuss50.me/fabric.html
 | 
			
		||||
 | 
			
		||||
minecraft_version=1.21
 | 
			
		||||
yarn_mappings=1.21+build.1
 | 
			
		||||
yarn_mappings=1.21+build.2
 | 
			
		||||
loader_version=0.15.11
 | 
			
		||||
 | 
			
		||||
# Fabric API
 | 
			
		||||
fabric_version=0.100.1+1.21
 | 
			
		||||
fabric_version=0.100.3+1.21
 | 
			
		||||
 | 
			
		||||
# Mod Properties
 | 
			
		||||
mod_version=2.6
 | 
			
		||||
mod_version=2.6.1
 | 
			
		||||
maven_group=systems.brn
 | 
			
		||||
archives_base_name=Server_storage
 | 
			
		||||
 | 
			
		||||
# 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
 | 
			
		||||
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.RecipeEntry;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
public class CraftingEntry {
 | 
			
		||||
    public final ItemStack itemStack;
 | 
			
		||||
    public final RecipeEntry<CraftingRecipe> recipeEntry;
 | 
			
		||||
    public final ArrayList<MyCraftingRecipe> myCraftingRecipeEntries;
 | 
			
		||||
    public CraftingEntry(ItemStack itemStack, RecipeEntry<CraftingRecipe> recipeEntry) {
 | 
			
		||||
        this.itemStack = itemStack;
 | 
			
		||||
        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 {
 | 
			
		||||
            // Sort by count in descending order
 | 
			
		||||
            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
 | 
			
		||||
                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 java.util.ArrayList;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
 | 
			
		||||
public class Util {
 | 
			
		||||
@@ -24,7 +26,7 @@ public class Util {
 | 
			
		||||
            ItemStack slotStack = inventory.getStack(i);
 | 
			
		||||
            if (!slotStack.isEmpty()) {
 | 
			
		||||
                Item itemName = slotStack.getItem();
 | 
			
		||||
                pages.add(String.valueOf(itemName) + " " + slotStack.getCount());
 | 
			
		||||
                pages.add(itemName + " " + slotStack.getCount());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return stringToBookContent(String.join(System.lineSeparator(), pages));
 | 
			
		||||
@@ -112,46 +114,81 @@ public class Util {
 | 
			
		||||
            int maxAmount = -1;
 | 
			
		||||
            boolean canMake = true;
 | 
			
		||||
            for (Ingredient ingredient : recipe.value().getIngredients()) {
 | 
			
		||||
                HashMap<ItemStack, Integer> inputsTemp = new HashMap<>();
 | 
			
		||||
                for (ItemStack stack : ingredient.getMatchingStacks()) {
 | 
			
		||||
                    if (stack.isEmpty()) {
 | 
			
		||||
                        break;
 | 
			
		||||
                    } else {
 | 
			
		||||
                        //if inventory contains stack
 | 
			
		||||
                        boolean foundUsableStack = false;
 | 
			
		||||
                        for (int i = 0; i < inventory.size(); i++) {
 | 
			
		||||
                            if (inventory.getStack(i).getItem().equals(stack.getItem())) {
 | 
			
		||||
                                if (maxAmount == -1) {
 | 
			
		||||
                                    maxAmount = inventory.getStack(i).getCount();
 | 
			
		||||
                                } else {
 | 
			
		||||
                                    maxAmount = Math.min(maxAmount, inventory.getStack(i).getCount());
 | 
			
		||||
                                }
 | 
			
		||||
                        for (Map.Entry<ItemStack, Integer> entry : inputsTemp.entrySet()) {
 | 
			
		||||
                            ItemStack stackIn = entry.getKey();
 | 
			
		||||
                            Integer count = entry.getValue();
 | 
			
		||||
                            if (stackIn.getItem() == stack.getItem()) {
 | 
			
		||||
                                count += stack.getCount();
 | 
			
		||||
                                entry.setValue(count); // Update the value in the map
 | 
			
		||||
                                foundUsableStack = true;
 | 
			
		||||
                                break;
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                        if (!foundUsableStack) {
 | 
			
		||||
                            canMake = false;
 | 
			
		||||
                            break;
 | 
			
		||||
                            inputsTemp.put(stack, stack.getCount());
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            if (maxAmount > 1 && canMake) {
 | 
			
		||||
                Item outputItem = recipe.value().getResult(server.getRegistryManager()).getItem();
 | 
			
		||||
                CraftingEntry entry = new CraftingEntry(new ItemStack(outputItem, maxAmount), recipe);
 | 
			
		||||
                boolean needToAdd = true;
 | 
			
		||||
                for (int i = 0; i < craftingEntries.size(); i++) {
 | 
			
		||||
                    CraftingEntry entryLoop = craftingEntries.get(i);
 | 
			
		||||
                    if (entryLoop.itemStack.getItem().equals(outputItem)) {
 | 
			
		||||
                        needToAdd = false;
 | 
			
		||||
                        if (maxAmount > entryLoop.itemStack.getCount()) {
 | 
			
		||||
                            craftingEntries.set(i, entry);
 | 
			
		||||
                            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);
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                if (needToAdd) {
 | 
			
		||||
                    craftingEntries.add(entry);
 | 
			
		||||
                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) {
 | 
			
		||||
                    Item outputItem = recipe.value().getResult(server.getRegistryManager()).getItem();
 | 
			
		||||
                    CraftingEntry entry = new CraftingEntry(new ItemStack(outputItem, maxAmount), recipe);
 | 
			
		||||
                    boolean needToAdd = true;
 | 
			
		||||
                    for (int i = 0; i < craftingEntries.size(); i++) {
 | 
			
		||||
                        CraftingEntry entryLoop = craftingEntries.get(i);
 | 
			
		||||
                        if (entryLoop.itemStack.getItem().equals(outputItem)) {
 | 
			
		||||
                            needToAdd = false;
 | 
			
		||||
                            if (maxAmount > entryLoop.itemStack.getCount()) {
 | 
			
		||||
                                craftingEntries.set(i, entry);
 | 
			
		||||
                                break;
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    if (needToAdd) {
 | 
			
		||||
                        craftingEntries.add(entry);
 | 
			
		||||
                    }
 | 
			
		||||
                } else {
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -117,7 +117,7 @@ public class CraftingScreen extends PagedGui {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 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 (canInsertItemIntoPlayerInventory(player, outputStack) == outputStack.getCount()) {
 | 
			
		||||
                player.getInventory().insertStack(outputStack);
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,7 @@
 | 
			
		||||
  },
 | 
			
		||||
  "depends": {
 | 
			
		||||
    "fabricloader": ">=${loader_version}",
 | 
			
		||||
    "fabric": "*",
 | 
			
		||||
    "minecraft": "${minecraft_version}"
 | 
			
		||||
    "fabric": ">=${fabric_version}",
 | 
			
		||||
    "minecraft": ">=${minecraft_version}"
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user