-
Notifications
You must be signed in to change notification settings - Fork 0
26.2 Clumping Mechanics and Mega Stacks
This document provides an exhaustive technical and mathematical breakdown of the ground item aggregation, search radius math, 64-bit overflow prevention, and heap allocation optimizations in Item Clumps for Minecraft 26.2.
| Property | Specification |
|---|---|
| System Name | Ground Item Mega-Stack Aggregator |
| Target Class | net.minecraft.world.entity.item.ItemEntity |
| Default Merge Cap |
9,999 items (Configurable up to |
| Search Radius ( |
Horizontal |
| Tick Overhead |
setItem()-only dispatch) |
| Memory Allocation | Zero object allocations on search & absorption (copyWithCount(int)) |
| Controlling GameRules |
item_clumps:enable_clumping, item_clumps:max_clump_size, item_clumps:merge_radius
|
In vanilla Minecraft, dropped items call mergeWithNeighbours() during their tick cycle, searching for nearby items of the same type. However, vanilla strictly prohibits merging if the target entity's item count would exceed itemStack.getMaxStackSize() (typically 64, or 16 for ender pearls / eggs).
Item Clumps intercepts this check via ItemEntityMixin.java to lift this artificial constraint while preserving strict data component safety.
ββββββββββββββββββββββββββββββββ
β ItemEntity A Ticks In β
ββββββββββββββββ¬ββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββ
β Fast-Path Validation β
β - Matching player target? β
β - Identical DataComponents? β
ββββββββββββββββ¬ββββββββββββββββ
β (Pass)
βΌ
ββββββββββββββββββββββββββββββββ
β In-Flight Magnet Check β
β (Is either item magnetized?) β
ββββββββββββββββ¬ββββββββββββββββ
β (No)
βΌ
ββββββββββββββββββββββββββββββββ
β 64-Bit Arithmetic Sum β
β S = (long) A + (long) B β
ββββββββββββββββ¬ββββββββββββββββ
β
βββββββββββββββββ΄ββββββββββββββββ
β β
S <= maxClumpSize S > maxClumpSize
β β
βΌ βΌ
βββββββββββββββββββββ βββββββββββββββββββββ
β Complete Merge β β Partial Merge β
β Larger absorbs β β Fill entity A to β
β smaller entity; β β maxClumpSize; β
β Younger age kept. β β B keeps remainder.β
βββββββββββββββββββββ βββββββββββββββββββββ
Vanilla searches a tiny bounding box:
Item Clumps dynamically expands the horizontal bounding box using a zero-allocation @Redirect injection:
Where:
-
$r = \text{DynamicGameRuleManager}.\text{getInt}(\text{level}, \text{MERGE_RADIUS}) \in [1, 10]$ blocks. -
$y = 0.0$ (vertical search height is strictly preserved to prevent items on different vertical floors or hoppers from cross-merging).
When two massive clumps merge under large server configurations (e.g. max clump cap set to int addition can overflow into negative integers (
Item Clumps computes the sum in 64-bit precision:
-
Full Absorption (
$S \le \text{maxClumpSize}$ ):$$\text{count}_{\text{merged}} = (\text{int}),S$$ -
Partial Absorption (
$S > \text{maxClumpSize}$ ):$$\Delta = \text{maxClumpSize} - \text{thisCount}$$ $$\text{thisCount}' = \text{maxClumpSize}, \quad \text{otherCount}' = \text{otherCount} - \Delta$$
Items never merge unless all Data Components (enchantments, damaged durability, custom names, trims, potion effects) are 100% bitwise identical:
From ItemEntityMixin.java in Minecraft 26.2:
@Inject(method = "tryToMerge", at = @At("HEAD"), cancellable = true)
private void item_clumps$customMerge(ItemEntity other, CallbackInfo ci) {
ItemStack thisStack = this.getItem();
ItemStack otherStack = other.getItem();
// Fast-path exit before GameRule lookups
if (!Objects.equals(this.target, ((ItemEntityMixin)(Object)other).target) ||
!ItemStack.isSameItemSameComponents(thisStack, otherStack)) {
return;
}
if (!DynamicGameRuleManager.getBoolean(this.level(), ItemClumpsFabric.ENABLE_CLUMPING)) return;
// Magnet mod in-flight protection
if (net.fabricmc.loader.api.FabricLoader.getInstance().isModLoaded("magnet")) {
try {
java.lang.reflect.Method isMagnetizedMethod;
try {
isMagnetizedMethod = this.getClass().getMethod("ig_magnet$isMagnetized");
} catch (NoSuchMethodException e) {
isMagnetizedMethod = this.getClass().getMethod("ig$isMagnetized");
}
if ((boolean) isMagnetizedMethod.invoke(this) || (boolean) isMagnetizedMethod.invoke(other)) {
ci.cancel();
return;
}
} catch (Throwable ignored) {}
}
int thisCount = thisStack.getCount();
int otherCount = otherStack.getCount();
int maxClump = (ItemClumpsFabric.MAX_CLUMP_SIZE == null)
? thisStack.getMaxStackSize()
: DynamicGameRuleManager.getInt(this.level(), ItemClumpsFabric.MAX_CLUMP_SIZE);
long sum = (long) thisCount + (long) otherCount;
if (sum > (long) maxClump) {
int spaceLeft = maxClump - thisCount;
if (spaceLeft > 0) {
ItemStack thisCopy = thisStack.copyWithCount(maxClump);
this.setItem(thisCopy);
ItemStack otherCopy = otherStack.copyWithCount(otherCount - spaceLeft);
other.setItem(otherCopy);
this.pickupDelay = Math.max(this.pickupDelay, ((ItemEntityMixin)(Object)other).pickupDelay);
this.age = Math.min(this.age, ((ItemEntityMixin)(Object)other).age);
}
ci.cancel();
return;
}
// Full Merge: larger stack absorbs the smaller stack
if (otherCount < thisCount) {
ItemStack thisCopy = thisStack.copyWithCount((int) sum);
this.setItem(thisCopy);
this.pickupDelay = Math.max(this.pickupDelay, ((ItemEntityMixin)(Object)other).pickupDelay);
this.age = Math.min(this.age, ((ItemEntityMixin)(Object)other).age);
other.discard();
} else {
ItemStack otherCopy = otherStack.copyWithCount((int) sum);
other.setItem(otherCopy);
((ItemEntityMixin)(Object)other).pickupDelay = Math.max(((ItemEntityMixin)(Object)other).pickupDelay, this.pickupDelay);
((ItemEntityMixin)(Object)other).age = Math.min(((ItemEntityMixin)(Object)other).age, this.age);
this.discard();
}
ci.cancel();
}Item Clumps is engineered with β€οΈ by Dasik (Rifaditya) | Licensed under GNU General Public License v3.0 (GPL-3.0-or-later).
π Repository Source Disclaimer: The documentation in this Wiki reflects the current source code state in the repository, which may include recent unreleased commits or developmental features ahead of public release builds on CurseForge and Modrinth.
- 26.2 Hub
- 26.2 Mega-Stack Clumping
- 26.2 Smart Pickup System
- 26.2 Hopper Integration
- 26.2 Despawn Age Rules
- 26.2 Holographic Labels
- 26.2 Mod Compatibility
- 26.2 GameRules Table
- 26.2 Commands & Admin
- 26.2 Advancements
- 26.2 Configuration
- 26.2 ModVersionGuard
- 26.2 Architecture & Mixins
- 26.2 Developer Setup
- 26.2 API & Addons
- 26.2 FAQ & Diagnostics
- 26.1.2 Hub
- 26.1.2 Mega-Stack Clumping
- 26.1.2 Smart Pickup System
- 26.1.2 Hopper Integration
- 26.1.2 Despawn Age Rules
- 26.1.2 Holographic Labels
- 26.1.2 GameRules Table
- 26.1.2 Commands & Admin
- 26.1.2 Advancements
- 26.1.2 Configuration
- 26.1.2 Architecture & Mixins
- 26.1.2 Developer Setup
- 26.1.2 API & Addons
- 26.1.2 FAQ & Diagnostics