Skip to content

Commit

Permalink
limit item types per storage core (1k default)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pilzinsel64 committed Jan 10, 2025
1 parent a029d16 commit 7aabf84
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,26 @@
@Config(modid = Reference.MOD_ID)
public class EZConfiguration {

@Config.Name("capacityStorageBasic")
@Config.Comment("Count of items that the basic storage box can hold.")
@Config.DefaultInt(400)
@Config.RangeInt(min = 1)
public static int basicCapacity;

@Config.Name("capacityStorageCondensed")
@Config.Comment("Count of items that the condensed storage box can hold.")
@Config.DefaultInt(4000)
@Config.RangeInt(min = 1)
public static int condensedCapacity;

@Config.Name("capacityStorageHyper")
@Config.Comment("Count of items that the hyper storage box can hold.")
@Config.DefaultInt(400000)
@Config.RangeInt(min = 1)
public static int hyperCapacity;

@Config.Comment("The maximum amount of different items that can be stored within one storage box.\nThe default value tries to ensure the NBT data wont get too large wich would normally lead to world corruption.")
@Config.DefaultInt(1000)
@Config.RangeInt(min = 1)
public static int maxItemTypes;

public static void init() {
try {
ConfigurationManager.registerConfig(EZConfiguration.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import org.joml.Math;

import com.zerofall.ezstorage.configuration.EZConfiguration;
import com.zerofall.ezstorage.util.EZInventory;
import com.zerofall.ezstorage.util.ItemGroup;

Expand All @@ -20,7 +21,8 @@ public int getSizeInventory() {
return 0;
}
int size = core.inventory.inventory.size();
if (core.inventory.getTotalCount() < core.inventory.maxItems && core.inventory.slotCount() < 1000) {
if (core.inventory.getTotalCount() < core.inventory.maxItems
&& core.inventory.slotCount() < EZConfiguration.maxItemTypes) {
size += 1;
}
return size;
Expand Down
23 changes: 15 additions & 8 deletions src/main/java/com/zerofall/ezstorage/util/EZInventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import org.joml.Math;

import com.zerofall.ezstorage.configuration.EZConfiguration;

public class EZInventory {

public List<ItemGroup> inventory;
Expand All @@ -33,19 +35,24 @@ public void sort() {
}

private ItemStack mergeStack(ItemStack itemStack, int amount) {
boolean found = false;
for (ItemGroup group : inventory) {
if (stacksEqual(group.itemStack, itemStack)) {
group.count += amount;
itemStack.stackSize -= amount;
if (itemStack.stackSize <= 0) {
return null;
} else {
return itemStack;
}
found = true;
break;
}
}
// Needs to add a space
inventory.add(new ItemGroup(itemStack, amount));

// Add new group, if needed
if (!found) {
if (slotCount() > EZConfiguration.maxItemTypes) {
return null;
}
inventory.add(new ItemGroup(itemStack, amount));
}

// Adjust input/return stack
itemStack.stackSize -= amount;
if (itemStack.stackSize <= 0) {
return null;
Expand Down

0 comments on commit 7aabf84

Please sign in to comment.