media_te6h

Make me a mod that predicted vault item using these files and also add configuration screen mod menu intergration and keybind for activation also change the maven group to vault.roll in the files

📎 7 files 42,455 chars
📄
VaultRollSynchronizer.java
java 170 lines
▶
/*
 * Copyright (c) 2014-2026 Wurst-Imperium and contributors.
 *
 * This source code is subject to the terms of the GNU General Public
 * License, version 3. If a copy of the GPL was not distributed with this
 * file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
 */
package net.wurstclient.hacks.vaultroll;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.function.BooleanSupplier;

public final class VaultRollSynchronizer
{
	public static final int INITIAL_SEARCH_HORIZON = 1_000;
	public static final int EXTENDED_SEARCH_HORIZON = 100_000;
	public static final int MAXIMUM_SEARCH_HORIZON = 1_000_000;
	private static final int MAX_STORED_CANDIDATES = 50;
	
	private VaultRollSynchronizer()
	{}
	
	/** Search for a consecutive observation window from opening zero. */
	public static Result synchronize(long worldSeed, VaultRollMode mode,
		List observations, int searchBound,
		BooleanSupplier cancelled)
	{
		Objects.requireNonNull(mode);
		if(observations == null || observations.isEmpty())
			return Result.noMatch(0);
		if(searchBound < 1)
			throw new IllegalArgumentException("Search bound must be positive");
		for(VaultRollObservation observation : observations)
			if(observation.mode() != mode)
				throw new IllegalArgumentException("Mixed Vault modes");
			
		ArrayDeque window =
			new ArrayDeque<>(observations.size());
		VaultRollRandom random = VaultRollRandom.forSequence(worldSeed, mode);
		ArrayList candidates = new ArrayList<>();
		boolean moreCandidates = false;
		for(int opening = 0; opening < searchBound; opening++)
		{
			if((opening & 0x3FF) == 0 && cancelled.getAsBoolean())
				return Result.cancelled(opening);
			window.addLast(VaultRollPredictor.nextOpening(random, mode));
			if(window.size() > observations.size())
				window.removeFirst();
			if(window.size() != observations.size()
				|| !matches(window, observations))
				continue;
			long first = (long)opening - observations.size() + 1;
			if(candidates.size() < MAX_STORED_CANDIDATES)
				candidates.add(first);
			else
				moreCandidates = true;
		}
		if(candidates.isEmpty())
			return Result.noMatch(searchBound);
		if(candidates.size() == 1 && !moreCandidates)
			return Result.unique(candidates.get(0), searchBound);
		return Result.ambiguous(candidates, moreCandidates, searchBound);
	}
	
	/**
	 * Search forward from the known next opening for the earliest opening that
	 * matches the newest observation. This is the multiplayer gap-recovery
	 * path: another player may have consumed openings in between.
	 */
	public static RecoveryResult recover(long worldSeed, VaultRollMode mode,
		long startOpening, VaultRollObservation observation, int horizon,
		BooleanSupplier cancelled)
	{
		if(startOpening < 0 || horizon < 0)
			throw new IllegalArgumentException("Invalid recovery range");
		Objects.requireNonNull(observation);
		if(observation.mode() != mode)
			throw new IllegalArgumentException("Mixed Vault modes");
		VaultRollRandom random = VaultRollRandom.forSequence(worldSeed, mode);
		VaultRollPredictor.advance(random, mode, startOpening);
		for(int offset = 0; offset <= horizon; offset++)
		{
			if((offset & 0x3FF) == 0 && cancelled.getAsBoolean())
				return RecoveryResult.cancelled(offset);
			VaultRollOpening opening =
				VaultRollPredictor.nextOpening(random, mode);
			if(observation.matches(opening))
				return RecoveryResult.found(startOpening + offset, offset,
					offset + 1);
		}
		return RecoveryResult.noMatch(horizon + 1);
	}
	
	private static boolean matches(ArrayDeque actual,
		List expected)
	{
		int index = 0;
		for(VaultRollOpening opening : actual)
			if(!expected.get(index++).matches(opening))
				return false;
		return true;
	}
	
	public enum Status
	{
		NO_MATCH,
		UNIQUE,
		AMBIGUOUS,
		CANCELLED
	}
	
	public record Result(Status status, long uniqueFirstOpening,
		List candidateOpenings, boolean moreCandidates,
		int searchedOpenings)
	{
		public Result
		{
			candidateOpenings = Collections
				.unmodifiableList(new ArrayList<>(candidateOpenings));
		}
		
		private static Result noMatch(int searched)
		{
			return new Result(Status.NO_MATCH, -1, List.of(), false, searched);
		}
		
		private static Result unique(long opening, int searched)
		{
			return new Result(Status.UNIQUE, opening, List.of(opening), false,
				searched);
		}
		
		private static Result ambiguous(List openings, boolean more,
			int searched)
		{
			return new Result(Status.AMBIGUOUS, -1, openings, more, searched);
		}
		
		private static Result cancelled(int searched)
		{
			return new Result(Status.CANCELLED, -1, List.of(), false, searched);
		}
	}
	
	public record RecoveryResult(Status status, long matchedOpening,
		long skippedOpenings, int searchedOpenings)
	{
		private static RecoveryResult found(long opening, long skipped,
			int searched)
		{
			return new RecoveryResult(Status.UNIQUE, opening, skipped,
				searched);
		}
		
		private static RecoveryResult noMatch(int searched)
		{
			return new RecoveryResult(Status.NO_MATCH, -1, -1, searched);
		}
		
		private static RecoveryResult cancelled(int searched)
		{
			return new RecoveryResult(Status.CANCELLED, -1, -1, searched);
		}
	}
}
📄
VaultRollStack.java
java 65 lines
▶
/*
 * Copyright (c) 2014-2026 Wurst-Imperium and contributors.
 *
 * This source code is subject to the terms of the GNU General Public
 * License, version 3. If a copy of the GPL was not distributed with this
 * file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
 */
package net.wurstclient.hacks.vaultroll;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

public record VaultRollStack(String itemId, int count,
	List enchantments, String note)
{
	public VaultRollStack
	{
		itemId = Objects.requireNonNull(itemId);
		if(count < 1)
			throw new IllegalArgumentException("count must be positive");
		enchantments = Collections.unmodifiableList(
			new ArrayList<>(Objects.requireNonNull(enchantments)));
	}
	
	public static VaultRollStack plain(String itemId)
	{
		return plain(itemId, 1);
	}
	
	public static VaultRollStack plain(String itemId, int count)
	{
		return new VaultRollStack(itemId, count, List.of(), null);
	}
	
	public String describe()
	{
		StringBuilder result =
			new StringBuilder(itemId).append('x').append(count);
		if(note != null && !note.isBlank())
			result.append(" [").append(note).append(']');
		for(Enchantment enchantment : enchantments)
			result.append(" [").append(shortId(enchantment.id())).append(' ')
				.append(enchantment.level()).append(']');
		return result.toString();
	}
	
	private static String shortId(String id)
	{
		int colon = id.lastIndexOf(':');
		return colon < 0 ? id : id.substring(colon + 1);
	}
	
	public record Enchantment(String id, int level)
	{
		public Enchantment
		{
			Objects.requireNonNull(id);
			if(level < 1)
				throw new IllegalArgumentException("level must be positive");
		}
	}
}
📄
VaultRollRandom.java
java 135 lines
▶
/*
 * Copyright (c) 2014-2026 Wurst-Imperium and contributors.
 *
 * This source code is subject to the terms of the GNU General Public
 * License, version 3. If a copy of the GPL was not distributed with this
 * file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
 */
package net.wurstclient.hacks.vaultroll;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/** Exact XoroshiroRandomSource/RandomSequence behavior used by loot tables. */
public final class VaultRollRandom
{
	private static final long SILVER_RATIO_64 = 0x6A09E667F3BCC909L;
	private static final long GOLDEN_RATIO_64 = 0x9E3779B97F4A7C15L;
	private static final long MIX_CONST_1 = 0xBF58476D1CE4E5B9L;
	private static final long MIX_CONST_2 = 0x94D049BB133111EBL;
	
	private long s0;
	private long s1;
	
	private VaultRollRandom(long s0, long s1)
	{
		if((s0 | s1) == 0L)
		{
			s0 = GOLDEN_RATIO_64;
			s1 = SILVER_RATIO_64;
		}
		this.s0 = s0;
		this.s1 = s1;
	}
	
	public static VaultRollRandom forSequence(long worldSeed,
		VaultRollMode mode)
	{
		long lo = ((long)worldSeed) ^ SILVER_RATIO_64;
		long hi = lo + GOLDEN_RATIO_64;
		byte[] digest;
		try
		{
			MessageDigest md5 = MessageDigest.getInstance("MD5");
			digest =
				md5.digest(mode.sequenceId().getBytes(StandardCharsets.UTF_8));
		}catch(NoSuchAlgorithmException e)
		{
			throw new IllegalStateException("MD5 unavailable", e);
		}
		long keyLo = readBigEndianLong(digest, 0);
		long keyHi = readBigEndianLong(digest, 8);
		return new VaultRollRandom(mixStafford13(lo ^ keyLo),
			mixStafford13(hi ^ keyHi));
	}
	
	public long nextLong()
	{
		long a = s0;
		long b = s1;
		long result = Long.rotateLeft(a + b, 17) + a;
		b ^= a;
		s0 = Long.rotateLeft(a, 49) ^ b ^ (b << 21);
		s1 = Long.rotateLeft(b, 28);
		return result;
	}
	
	public int nextIntRaw()
	{
		return (int)nextLong();
	}
	
	/** XoroshiroRandomSource.nextInt(bound), using Lemire rejection. */
	public int nextInt(int bound)
	{
		if(bound <= 0)
			throw new IllegalArgumentException("Bound must be positive");
		int unsignedBound = bound;
		long l = Integer.toUnsignedLong(nextIntRaw());
		long m = l * unsignedBound;
		long n = m & 0xFFFFFFFFL;
		if(n < unsignedBound)
		{
			int j =
				Integer.remainderUnsigned(~unsignedBound + 1, unsignedBound);
			while(n < Integer.toUnsignedLong(j))
			{
				l = Integer.toUnsignedLong(nextIntRaw());
				m = l * unsignedBound;
				n = m & 0xFFFFFFFFL;
			}
		}
		return (int)(m >>> 32);
	}
	
	public float nextFloat()
	{
		return (nextLong() >>> 40) * 5.9604645E-8F;
	}
	
	public double nextDouble()
	{
		return (nextLong() >>> 11) * 1.1102230246251565E-16D;
	}
	
	public int nextIntInclusive(int min, int max)
	{
		if(min >= max)
			return min;
		return nextInt(max - min + 1) + min;
	}
	
	public float nextFloat(float min, float max)
	{
		if(min >= max)
			return min;
		return nextFloat() * (max - min) + min;
	}
	
	private static long mixStafford13(long value)
	{
		value = (value ^ (value >>> 30)) * MIX_CONST_1;
		value = (value ^ (value >>> 27)) * MIX_CONST_2;
		return value ^ (value >>> 31);
	}
	
	private static long readBigEndianLong(byte[] bytes, int offset)
	{
		long result = 0L;
		for(int i = 0; i < 8; i++)
			result = (result << 8) | (bytes[offset + i] & 0xFFL);
		return result;
	}
}
📄
VaultRollPredictor.java
java 749 lines
▶
/*
 * Copyright (c) 2014-2026 Wurst-Imperium and contributors.
 *
 * This source code is subject to the terms of the GNU General Public
 * License, version 3. If a copy of the GPL was not distributed with this
 * file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
 */
package net.wurstclient.hacks.vaultroll;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.function.BooleanSupplier;

/**
 * Pure Java port of the 26.2 trial-chamber Vault loot sequences.
 *
 * 

* The loot functions intentionally live here instead of calling the * client loot-table registry. A client registry does not own the server's * random-sequence state, while this class needs to consume exactly the same * Xoroshiro stream as the server. *

*/ public final class VaultRollPredictor { private static final List ON_RANDOM_LOOT = List.of( enchantment("protection", 10, 4, 1, 11, 12, 11, Support.ARMOR, null, "armor"), enchantment("fire_protection", 5, 4, 10, 8, 18, 8, Support.ARMOR, null, "armor"), enchantment("feather_falling", 5, 4, 5, 6, 11, 6, Support.FOOT, null, null), enchantment("blast_protection", 2, 4, 5, 8, 13, 8, Support.ARMOR, null, "armor"), enchantment("projectile_protection", 5, 4, 3, 6, 9, 6, Support.ARMOR, null, "armor"), enchantment("respiration", 2, 3, 10, 10, 40, 10, Support.HEAD, null, null), enchantment("aqua_affinity", 2, 1, 1, 0, 41, 0, Support.HEAD, null, null), enchantment("thorns", 1, 3, 10, 20, 60, 20, Support.ARMOR, Support.CHEST, null), enchantment("depth_strider", 2, 3, 10, 10, 25, 10, Support.FOOT, null, "boots"), enchantment("sharpness", 10, 5, 1, 11, 21, 11, Support.SHARP_WEAPON, Support.MELEE, "damage"), enchantment("smite", 5, 5, 5, 8, 25, 8, Support.WEAPON, Support.MELEE, "damage"), enchantment("bane_of_arthropods", 5, 5, 5, 8, 25, 8, Support.WEAPON, Support.MELEE, "damage"), enchantment("knockback", 5, 2, 5, 20, 55, 20, Support.MELEE, null, null), enchantment("fire_aspect", 2, 2, 10, 20, 60, 20, Support.FIRE_ASPECT, Support.MELEE, null), enchantment("looting", 2, 3, 15, 9, 65, 9, Support.MELEE, null, null), enchantment("sweeping_edge", 2, 3, 5, 9, 20, 9, Support.SWEEPING, null, null), enchantment("efficiency", 10, 5, 1, 10, 51, 10, Support.MINING, null, null), enchantment("silk_touch", 1, 1, 15, 0, 65, 0, Support.MINING_LOOT, null, "mining"), enchantment("unbreaking", 5, 3, 5, 8, 55, 8, Support.DURABILITY, null, null), enchantment("fortune", 2, 3, 15, 9, 65, 9, Support.MINING_LOOT, null, "mining"), enchantment("power", 10, 5, 1, 10, 16, 10, Support.BOW, null, null), enchantment("punch", 2, 2, 12, 20, 37, 20, Support.BOW, null, null), enchantment("flame", 2, 1, 20, 0, 50, 0, Support.BOW, null, null), enchantment("infinity", 1, 1, 20, 0, 50, 0, Support.BOW, null, "bow"), enchantment("luck_of_the_sea", 2, 3, 15, 9, 65, 9, Support.FISHING, null, null), enchantment("lure", 2, 3, 15, 9, 65, 9, Support.FISHING, null, null), enchantment("loyalty", 5, 3, 12, 7, 50, 0, Support.TRIDENT, null, "riptide"), enchantment("impaling", 2, 5, 1, 8, 21, 8, Support.TRIDENT, null, "damage"), enchantment("riptide", 2, 3, 17, 7, 50, 0, Support.TRIDENT, null, "riptide"), enchantment("channeling", 1, 1, 25, 0, 50, 0, Support.TRIDENT, null, null), enchantment("multishot", 2, 1, 20, 0, 50, 0, Support.CROSSBOW, null, "crossbow"), enchantment("quick_charge", 5, 3, 12, 20, 50, 0, Support.CROSSBOW, null, null), enchantment("piercing", 10, 4, 1, 10, 50, 0, Support.CROSSBOW, null, "crossbow"), enchantment("density", 5, 5, 5, 8, 25, 8, Support.MACE, null, "damage"), enchantment("breach", 2, 4, 15, 9, 65, 9, Support.MACE, null, "damage"), enchantment("lunge", 5, 3, 5, 8, 25, 8, Support.LUNGE, null, null), enchantment("binding_curse", 1, 1, 25, 0, 50, 0, Support.EQUIPPABLE, null, null), enchantment("vanishing_curse", 1, 1, 25, 0, 50, 0, Support.VANISHING, null, null), enchantment("frost_walker", 2, 2, 10, 10, 25, 10, Support.FOOT, null, "boots"), enchantment("mending", 2, 1, 25, 25, 75, 25, Support.DURABILITY, null, null)); private static final List NORMAL_RARE = List.of(item("emerald", 3, setCount(uniform(2, 4))), item("shield", 3, setDamage(uniform(0.5F, 1.0F))), item("bow", 3, enchantWithLevels(uniform(5, 15))), item("crossbow", 2, enchantWithLevels(uniform(5, 20))), item("iron_axe", 2, enchantWithLevels(uniform(0, 10))), item("iron_chestplate", 2, enchantWithLevels(uniform(0, 10))), item("golden_carrot", 2, setCount(uniform(1, 2))), item("book", 2, enchantRandomly("sharpness", "bane_of_arthropods", "efficiency", "fortune", "silk_touch", "feather_falling")), item("book", 2, enchantRandomly("riptide", "loyalty", "channeling", "impaling", "mending")), item("diamond_chestplate", 1, enchantWithLevels(uniform(5, 15))), item("diamond_axe", 1, enchantWithLevels(uniform(5, 15)))); private static final List NORMAL_COMMON = List.of(item("arrow", 4, setCount(uniform(2, 8))), item("tipped_arrow", 4, setCount(uniform(2, 8)), setPotion("poison")), item("emerald", 4, setCount(uniform(2, 4))), item("wind_charge", 3, setCount(uniform(1, 3))), item("iron_ingot", 3, setCount(uniform(1, 4))), item("honey_bottle", 3, setCount(uniform(1, 2))), item("ominous_bottle", 2, setCount(constant(1)), setOminousBottleAmplifier(uniform(0, 1))), item("wind_charge", 1, setCount(uniform(4, 12))), item("diamond", 1, setCount(uniform(1, 2)))); private static final List NORMAL_UNIQUE = List.of( item("golden_apple", 4), item("bolt_armor_trim_smithing_template", 3), item("guster_banner_pattern", 2), item("music_disc_precipice", 2), item("trident", 1)); private static final List OMINOUS_RARE = List.of(item("emerald_block", 5), item("iron_block", 4), item("crossbow", 4, enchantWithLevels(uniform(5, 20))), item("golden_apple", 3), item("diamond_axe", 3, enchantWithLevels(uniform(10, 20))), item("diamond_chestplate", 3, enchantWithLevels(uniform(10, 20))), item("book", 2, enchantRandomly("knockback", "punch", "smite", "looting", "multishot")), item("book", 2, enchantRandomly("breach", "density")), item("book", 2, setEnchantment("wind_burst", 1)), item("diamond_block", 1)); private static final List OMINOUS_COMMON = List.of( item("emerald", 5, setCount(uniform(4, 10))), item("wind_charge", 4, setCount(uniform(8, 12))), item("tipped_arrow", 3, setCount(uniform(4, 12)), setPotion("strong_slowness")), item("diamond", 2, setCount(uniform(2, 3))), item("ominous_bottle", 1, setCount(constant(1)), setOminousBottleAmplifier(uniform(2, 4)))); private static final List OMINOUS_UNIQUE = List.of(item("enchanted_golden_apple", 3), item("flow_armor_trim_smithing_template", 3), item("flow_banner_pattern", 2), item("music_disc_creator", 1), item("heavy_core", 1)); private static final Set NORMAL_LOOT_ITEM_IDS = possibleLootItemIds(NORMAL_RARE, NORMAL_COMMON, NORMAL_UNIQUE); private static final Set OMINOUS_LOOT_ITEM_IDS = possibleLootItemIds(OMINOUS_RARE, OMINOUS_COMMON, OMINOUS_UNIQUE); private VaultRollPredictor() {} public static List itemIds() { Set result = new LinkedHashSet<>(); addItemIds(result, NORMAL_RARE); addItemIds(result, NORMAL_COMMON); addItemIds(result, NORMAL_UNIQUE); addItemIds(result, OMINOUS_RARE); addItemIds(result, OMINOUS_COMMON); addItemIds(result, OMINOUS_UNIQUE); result.add("enchanted_book"); return List.copyOf(result); } /** * Returns whether an item ID can be emitted by the selected vanilla Vault * loot table. This is used by automatic capture to reject unrelated item * entities near a Vault. */ public static boolean isPossibleLootItem(VaultRollMode mode, String itemId) { if(mode == null || itemId == null) return false; String normalized = normalizeItemId(itemId); return (mode == VaultRollMode.OMINOUS ? OMINOUS_LOOT_ITEM_IDS : NORMAL_LOOT_ITEM_IDS).contains(normalized); } private static Set possibleLootItemIds(List... pools) { Set result = new LinkedHashSet<>(); for(List pool : pools) for(LootEntry entry : pool) { // The Vault tables enchant their book entries, so the emitted // item is an enchanted book rather than a plain book. if(entry.itemId().equals("minecraft:book")) result.add("minecraft:enchanted_book"); else result.add(entry.itemId()); } return Collections.unmodifiableSet(result); } private static void addItemIds(Set result, List entries) { for(LootEntry entry : entries) result.add(shortId(entry.itemId())); } public static VaultRollOpening predictOpening(long worldSeed, VaultRollMode mode, long openingIndex) { if(openingIndex < 0) throw new IllegalArgumentException( "openingIndex must not be negative"); VaultRollRandom random = VaultRollRandom.forSequence(worldSeed, mode); advance(random, mode, openingIndex); return nextOpening(random, mode); } public static List predictOpenings(long worldSeed, VaultRollMode mode, long firstOpening, int count) { if(firstOpening < 0 || count < 0) throw new IllegalArgumentException("Invalid opening range"); VaultRollRandom random = VaultRollRandom.forSequence(worldSeed, mode); advance(random, mode, firstOpening); ArrayList result = new ArrayList<>(count); for(int i = 0; i < count; i++) result.add(nextOpening(random, mode)); return Collections.unmodifiableList(result); } public static void advance(VaultRollRandom random, VaultRollMode mode, long openingCount) { for(long i = 0; i < openingCount; i++) nextOpening(random, mode); } public static VaultRollOpening nextOpening(VaultRollRandom random, VaultRollMode mode) { List result = new ArrayList<>(); List rarePool = mode == VaultRollMode.OMINOUS ? OMINOUS_RARE : NORMAL_RARE; List commonPool = mode == VaultRollMode.OMINOUS ? OMINOUS_COMMON : NORMAL_COMMON; List uniquePool = mode == VaultRollMode.OMINOUS ? OMINOUS_UNIQUE : NORMAL_UNIQUE; // reward(_ominous).json selects the nested rare/common table with // weights 8 and 2. This selection consumes one RNG call. List firstPool = random.nextInt(10) < 8 ? rarePool : commonPool; result.add(choose(firstPool, random).create(random)); int commonRolls = random.nextIntInclusive(1, 3); for(int i = 0; i < commonRolls; i++) result.add(choose(commonPool, random).create(random)); float uniqueChance = mode == VaultRollMode.OMINOUS ? 0.75F : 0.25F; if(random.nextFloat() < uniqueChance) result.add(choose(uniquePool, random).create(random)); return new VaultRollOpening(result); } static List enchantments() { return ON_RANDOM_LOOT; } public static TargetHit findTarget(long worldSeed, VaultRollMode mode, long firstOpening, int horizon, String itemId, Integer minimumCount, BooleanSupplier cancelled) { if(firstOpening < 0 || horizon < 0) throw new IllegalArgumentException("Invalid target search range"); String target = normalizeItemId(itemId); VaultRollRandom random = VaultRollRandom.forSequence(worldSeed, mode); advance(random, mode, firstOpening); for(int offset = 0; offset <= horizon; offset++) { if((offset & 0x3FF) == 0 && cancelled.getAsBoolean()) return null; VaultRollOpening opening = nextOpening(random, mode); Integer count = opening.aggregate().get(target); if(count != null && (minimumCount == null || count >= minimumCount)) return new TargetHit(offset, firstOpening + offset, opening); } return null; } public static String normalizeItemId(String input) { return VaultRollObservation.normalizeItemId(input); } public static Long tryParseSeed(String input) { if(input == null) return null; String value = input.trim(); if(value.matches("-?\\d+")) { try { return Long.parseLong(value); }catch(NumberFormatException e) { return null; } } return value.isEmpty() ? null : (long)value.hashCode(); } public static String shortId(String id) { int colon = id.lastIndexOf(':'); return colon < 0 ? id : id.substring(colon + 1); } public static String formatItem(String id) { StringBuilder result = new StringBuilder(); for(String word : shortId(id).replace('_', ' ').split(" ")) { if(word.isEmpty()) continue; if(result.length() > 0) result.append(' '); result.append(Character.toUpperCase(word.charAt(0))) .append(word.substring(1)); } return result.toString(); } public record TargetHit(long offset, long absoluteOpening, VaultRollOpening opening) {} private static LootEntry choose(List entries, VaultRollRandom random) { if(entries.size() == 1) return entries.get(0); int totalWeight = 0; for(LootEntry entry : entries) totalWeight += entry.weight(); int choice = random.nextInt(totalWeight); for(LootEntry entry : entries) { choice -= entry.weight(); if(choice < 0) return entry; } throw new IllegalStateException("Weighted loot selection overflow"); } private static LootEntry item(String id, int weight, LootFunction... functions) { return new LootEntry("minecraft:" + id, weight, List.of(functions)); } private static Num uniform(int min, int max) { return Num.uniform(min, max); } private static Num uniform(float min, float max) { return Num.uniform(min, max); } private static Num constant(int value) { return Num.constant(value); } private static LootFunction setCount(Num count) { return (random, stack) -> stack.count = count.getInt(random); } private static LootFunction setDamage(Num damage) { return (random, stack) -> stack.note = "damage=" + damage.getFloat(random); } private static LootFunction setPotion(String potion) { return (random, stack) -> stack.note = "potion=minecraft:" + potion; } private static LootFunction setOminousBottleAmplifier(Num amplifier) { return (random, stack) -> stack.note = "amplifier=" + amplifier.getInt(random); } private static LootFunction setEnchantment(String id, int level) { return (random, stack) -> { stack.itemId = "minecraft:enchanted_book"; stack.enchantments .add(new VaultRollStack.Enchantment("minecraft:" + id, level)); }; } private static LootFunction enchantRandomly(String... ids) { return (random, stack) -> { int index = random.nextInt(ids.length); EnchantmentInfo info = findEnchantment(ids[index]); if(info == null) throw new IllegalStateException( "Missing enchantment: " + ids[index]); int level = random.nextIntInclusive(1, info.maxLevel()); if(stack.itemId.equals("minecraft:book")) stack.itemId = "minecraft:enchanted_book"; stack.enchantments .add(new VaultRollStack.Enchantment(info.id(), level)); }; } private static LootFunction enchantWithLevels(Num levels) { return (random, stack) -> { List enchantments = selectEnchantments(stack.itemId, levels.getInt(random), random); if(stack.itemId.equals("minecraft:book") && !enchantments.isEmpty()) stack.itemId = "minecraft:enchanted_book"; stack.enchantments.addAll(enchantments); }; } private static List selectEnchantments( String item, int level, VaultRollRandom random) { List picked = new ArrayList<>(); int enchantability = enchantability(item); if(enchantability <= 0) return picked; boolean book = item.equals("minecraft:book"); int cost = level + 1 + random.nextInt(enchantability / 4 + 1) + random.nextInt(enchantability / 4 + 1); float factor = (random.nextFloat() + random.nextFloat() - 1.0F) * 0.15F; cost = Math.max(1, Math.round(cost + cost * factor)); List available = availableEnchantments(cost, item, book); if(available.isEmpty()) return picked; AvailableEnchantment first = weightedEnchantment(available, random); if(first == null) return picked; picked.add( new VaultRollStack.Enchantment(first.info().id(), first.level())); while(random.nextInt(50) <= cost) { if(!picked.isEmpty()) { VaultRollStack.Enchantment last = picked.get(picked.size() - 1); available = available.stream() .filter(entry -> entry.info() .compatibleWith(findEnchantment(last.id()))) .toList(); } if(available.isEmpty()) break; AvailableEnchantment next = weightedEnchantment(available, random); if(next == null) break; picked.add( new VaultRollStack.Enchantment(next.info().id(), next.level())); cost /= 2; } return picked; } private static List availableEnchantments(int cost, String item, boolean book) { List result = new ArrayList<>(); for(EnchantmentInfo info : ON_RANDOM_LOOT) { if(!book && !info.isPrimary(item)) continue; int level = info.levelAt(cost); if(level > 0) result.add(new AvailableEnchantment(info, level)); } return result; } private static AvailableEnchantment weightedEnchantment( List entries, VaultRollRandom random) { int total = 0; for(AvailableEnchantment entry : entries) total += entry.info().weight(); int choice = random.nextInt(total); for(AvailableEnchantment entry : entries) { choice -= entry.info().weight(); if(choice < 0) return entry; } return null; } private static int enchantability(String item) { return switch(item) { case "minecraft:book", "minecraft:bow", "minecraft:crossbow" -> 1; case "minecraft:iron_axe" -> 14; case "minecraft:iron_chestplate" -> 9; case "minecraft:diamond_axe", "minecraft:diamond_chestplate" -> 10; default -> 0; }; } private static EnchantmentInfo findEnchantment(String input) { String id = input.contains(":") ? input : "minecraft:" + input; for(EnchantmentInfo info : ON_RANDOM_LOOT) if(info.id().equals(id)) return info; return null; } private static EnchantmentInfo enchantment(String id, int weight, int maxLevel, int minBase, int minPer, int maxBase, int maxPer, Support supported, Support primary, String exclusiveSet) { return new EnchantmentInfo("minecraft:" + id, weight, maxLevel, minBase, minPer, maxBase, maxPer, supported, primary, exclusiveSet); } private record AvailableEnchantment(EnchantmentInfo info, int level) {} public record EnchantmentInfo(String id, int weight, int maxLevel, int minCostBase, int minCostPer, int maxCostBase, int maxCostPer, Support supported, Support primary, String exclusiveSet) { public EnchantmentInfo { Objects.requireNonNull(id); Objects.requireNonNull(supported); if(weight < 1 || maxLevel < 1) throw new IllegalArgumentException("Invalid enchantment data"); } private int minCost(int level) { return minCostBase + minCostPer * (level - 1); } private int maxCost(int level) { return maxCostBase + maxCostPer * (level - 1); } private int levelAt(int cost) { for(int level = maxLevel; level >= 1; level--) if(cost >= minCost(level) && cost <= maxCost(level)) return level; return 0; } private boolean isPrimary(String item) { return supports(item) && (primary == null || primary.supports(item)); } private boolean supports(String item) { return supported.supports(item); } private boolean compatibleWith(EnchantmentInfo other) { return other != null && !id.equals(other.id) && !excludes(exclusiveSet, other.id) && !excludes(other.exclusiveSet, id); } private static boolean excludes(String set, String id) { if(set == null) return false; return switch(set) { case "armor" -> id.equals("minecraft:protection") || id.equals("minecraft:fire_protection") || id.equals("minecraft:blast_protection") || id.equals("minecraft:projectile_protection"); case "damage" -> id.equals("minecraft:sharpness") || id.equals("minecraft:smite") || id.equals("minecraft:bane_of_arthropods") || id.equals("minecraft:impaling") || id.equals("minecraft:density") || id.equals("minecraft:breach"); case "riptide" -> id.equals("minecraft:loyalty") || id.equals("minecraft:channeling") || id.equals("minecraft:riptide"); case "bow" -> id.equals("minecraft:infinity") || id.equals("minecraft:mending"); case "crossbow" -> id.equals("minecraft:multishot") || id.equals("minecraft:piercing"); case "boots" -> id.equals("minecraft:frost_walker") || id.equals("minecraft:depth_strider"); case "mining" -> id.equals("minecraft:fortune") || id.equals("minecraft:silk_touch"); default -> false; }; } } public enum Support { ARMOR, FOOT, HEAD, CHEST, SHARP_WEAPON, WEAPON, MELEE, FIRE_ASPECT, SWEEPING, MINING, MINING_LOOT, DURABILITY, BOW, CROSSBOW, FISHING, TRIDENT, MACE, LUNGE, EQUIPPABLE, VANISHING; private boolean supports(String item) { boolean chest = item.equals("minecraft:iron_chestplate") || item.equals("minecraft:diamond_chestplate"); boolean axe = item.equals("minecraft:iron_axe") || item.equals("minecraft:diamond_axe"); return switch(this) { case ARMOR -> chest; case FOOT, HEAD, MELEE, FIRE_ASPECT, SWEEPING, FISHING, TRIDENT, MACE, LUNGE -> false; case CHEST -> chest; case SHARP_WEAPON, WEAPON, MINING, MINING_LOOT -> axe; case DURABILITY, VANISHING -> chest || axe || item.equals("minecraft:bow") || item.equals("minecraft:crossbow"); case BOW -> item.equals("minecraft:bow"); case CROSSBOW -> item.equals("minecraft:crossbow"); case EQUIPPABLE -> chest; }; } } private record LootEntry(String itemId, int weight, List functions) { private LootEntry { if(weight < 1) throw new IllegalArgumentException("weight must be positive"); functions = List.copyOf(functions); } private VaultRollStack create(VaultRollRandom random) { MutableStack stack = new MutableStack(itemId); for(LootFunction function : functions) function.apply(random, stack); return new VaultRollStack(stack.itemId, stack.count, stack.enchantments, stack.note); } } private interface LootFunction { void apply(VaultRollRandom random, MutableStack stack); } private static final class MutableStack { private String itemId; private int count = 1; private final List enchantments = new ArrayList<>(); private String note; private MutableStack(String itemId) { this.itemId = itemId; } } private record Num(float min, float max, boolean integer) { private static Num constant(float value) { return new Num(value, value, true); } private static Num uniform(int min, int max) { return new Num(min, max, true); } private static Num uniform(float min, float max) { return new Num(min, max, false); } private int getInt(VaultRollRandom random) { if(integer) return random.nextIntInclusive(Math.round(min), Math.round(max)); return Math.round(getFloat(random)); } private float getFloat(VaultRollRandom random) { return random.nextFloat(min, max); } } }
📄
VaultRollOpening.java
java 39 lines
▶
/*
 * Copyright (c) 2014-2026 Wurst-Imperium and contributors.
 *
 * This source code is subject to the terms of the GNU General Public
 * License, version 3. If a copy of the GPL was not distributed with this
 * file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
 */
package net.wurstclient.hacks.vaultroll;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public record VaultRollOpening(List stacks)
{
	public VaultRollOpening
	{
		stacks = List.copyOf(stacks);
	}
	
	public Map aggregate()
	{
		Map result = new LinkedHashMap<>();
		for(VaultRollStack stack : stacks)
			result.merge(stack.itemId(), stack.count(), Integer::sum);
		return Collections.unmodifiableMap(result);
	}
	
	public String describe()
	{
		List descriptions = new ArrayList<>();
		for(VaultRollStack stack : stacks)
			descriptions.add(stack.describe());
		return String.join(", ", descriptions);
	}
}
📄
VaultRollObservation.java
java 216 lines
▶
/*
 * Copyright (c) 2014-2026 Wurst-Imperium and contributors.
 *
 * This source code is subject to the terms of the GNU General Public
 * License, version 3. If a copy of the GPL was not distributed with this
 * file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
 */
package net.wurstclient.hacks.vaultroll;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Collections;

/**
 * Evidence observed from one complete Vault opening.
 *
 * 

* Manual observations use {@link #items()} and may omit counts. Automatic * observations can additionally preserve the ordered item stacks. Empty * stack details are treated as wildcards for stack metadata, but item IDs and * counts are always exact. *

*/ public record VaultRollObservation(VaultRollMode mode, Map items, List stacks, boolean allowAggregateFallback) { public VaultRollObservation(VaultRollMode mode, Map items) { this(mode, items, List.of(), false); } public VaultRollObservation(VaultRollMode mode, List stacks) { this(mode, stacks, false); } public VaultRollObservation(VaultRollMode mode, List stacks, boolean allowAggregateFallback) { this(mode, aggregate(stacks), stacks, allowAggregateFallback); } public VaultRollObservation { mode = Objects.requireNonNull(mode); items = Collections.unmodifiableMap( new LinkedHashMap<>(Objects.requireNonNull(items))); stacks = List.copyOf(Objects.requireNonNull(stacks)); if(items.isEmpty() || stacks.stream().anyMatch(Objects::isNull)) throw new IllegalArgumentException( "An observation cannot be empty"); for(var entry : items.entrySet()) if(entry.getKey() == null || entry.getKey().isBlank() || entry.getValue() != null && entry.getValue() < 1) throw new IllegalArgumentException("Invalid observation item"); } public static VaultRollObservation exact(VaultRollMode mode, VaultRollOpening opening) { return new VaultRollObservation(mode, opening.stacks()); } public boolean matches(VaultRollOpening opening) { if(!stacks.isEmpty()) { List actual = opening.stacks(); if(actual.size() == stacks.size()) { boolean matches = true; for(int i = 0; i < stacks.size(); i++) if(!matchesStack(stacks.get(i), actual.get(i))) { matches = false; break; } if(matches) return true; } if(!allowAggregateFallback) return false; } Map actual = opening.aggregate(); if(!actual.keySet().equals(items.keySet())) return false; for(var entry : items.entrySet()) if(entry.getValue() != null && !entry.getValue().equals(actual.get(entry.getKey()))) return false; return true; } public String describe() { StringBuilder result = new StringBuilder(); if(!stacks.isEmpty()) { for(VaultRollStack stack : stacks) { if(result.length() > 0) result.append(", "); result.append(stack.describe()); } return result.toString(); } for(var entry : items.entrySet()) { if(result.length() > 0) result.append(", "); result.append(entry.getKey()); if(entry.getValue() != null) result.append('=').append(entry.getValue()); } return result.toString(); } public static VaultRollObservation parse(VaultRollMode mode, String input) { if(input == null || input.isBlank()) throw new IllegalArgumentException("Observation is empty"); Map items = new LinkedHashMap<>(); for(String rawPart : input.split(",")) { String part = rawPart.trim(); if(part.isEmpty()) continue; String item; Integer count = null; int equals = part.indexOf('='); if(equals >= 0) { item = part.substring(0, equals).trim(); count = parseCount(part.substring(equals + 1).trim()); }else { String[] words = part.split("\\s+"); if(words.length == 2 && isCount(words[0])) { count = parseCount(words[0]); item = words[1]; }else if(words.length == 2 && isCount(words[1])) { item = words[0]; count = parseCount(words[1]); }else if(words.length == 1) item = words[0]; else throw new IllegalArgumentException( "Use item=count, item xN, or item"); } item = normalizeItemId(item); if(item.isBlank()) throw new IllegalArgumentException("Observation item is empty"); if(items.containsKey(item)) throw new IllegalArgumentException("Duplicate item: " + item); items.put(item, count); } return new VaultRollObservation(mode, items); } private static Map aggregate(List stacks) { Map result = new LinkedHashMap<>(); for(VaultRollStack stack : Objects.requireNonNull(stacks)) result.merge(stack.itemId(), stack.count(), Integer::sum); return result; } private static boolean matchesStack(VaultRollStack observed, VaultRollStack actual) { if(!observed.itemId().equals(actual.itemId()) || observed.count() != actual.count()) return false; if(!observed.enchantments().isEmpty() && !observed.enchantments().equals(actual.enchantments())) return false; return observed.note() == null || observed.note().equals(actual.note()); } public static String normalizeItemId(String input) { String id = input.trim().toLowerCase(Locale.ROOT).replace(' ', '_'); if(!id.contains(":")) id = "minecraft:" + id; return id; } private static boolean isCount(String value) { return value.matches("\\d+"); } private static Integer parseCount(String value) { try { int count = Integer.parseInt(value); if(count < 1) throw new NumberFormatException(); return count; }catch(NumberFormatException e) { throw new IllegalArgumentException( "Count must be positive: " + value); } } }
📄
VaultRollMode.java
java 61 lines
▶
/*
 * Copyright (c) 2014-2026 Wurst-Imperium and contributors.
 *
 * This source code is subject to the terms of the GNU General Public
 * License, version 3. If a copy of the GPL was not distributed with this
 * file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
 */
package net.wurstclient.hacks.vaultroll;

import java.util.Locale;

public enum VaultRollMode
{
	NORMAL("normal", "Normal", "minecraft:chests/trial_chambers/reward"),
	OMINOUS("ominous", "Ominous",
		"minecraft:chests/trial_chambers/reward_ominous");
	
	private final String id;
	private final String displayName;
	private final String sequenceId;
	
	VaultRollMode(String id, String displayName, String sequenceId)
	{
		this.id = id;
		this.displayName = displayName;
		this.sequenceId = sequenceId;
	}
	
	public String id()
	{
		return id;
	}
	
	public String displayName()
	{
		return displayName;
	}
	
	@Override
	public String toString()
	{
		return displayName;
	}
	
	public String sequenceId()
	{
		return sequenceId;
	}
	
	public static VaultRollMode parse(String input)
	{
		if(input == null)
			return null;
		String value = input.trim().toLowerCase(Locale.ROOT);
		for(VaultRollMode mode : values())
			if(mode.id.equals(value))
				return mode;
		return null;
	}
}
Kodari AI
KodariOct 6 at 10:26 am 4
VaultRollPredictor
A Minecraft Fabric mod that predicts Vault loot outcomes using the world seed and Xoroshiro random sequence. It includes a configuration screen with Mod Menu integration, a keybind for activation, and a comprehensive prediction system that analyzes past Vault openings to forecast future rewards. The mod features automatic item capture, manual observation entry, and a recovery system for multiplayer gaps. It supports both normal and ominous Vault modes, with a search algorithm that synchronizes observations to the correct opening position. The configuration screen allows users to set the world seed, select the Vault mode, and manage prediction settings. The keybind provides quick access to the prediction interface, displaying predicted items and their probabilities.
  1. Port the supplied vault-roll predictor into a new Fabric project and set the Gradle/Maven group to vault.roll.

  2. Add YACL configuration with ModMenu access.

  3. Add a client keybind that opens a vault prediction screen and displays the next predicted reward.

Created a client-side Vault Roll Predictor for Fabric 1.21.11. It ports the supplied predictor classes into the vault.roll package and sets the Gradle/Maven group to vault.roll.

The YACL settings screen is available through ModMenu. Configure the world seed, Vault mode, opening index, target item, and search horizon, then press P (also configurable under Controls) to print the predicted opening and target search result in chat. The seed and opening index must be entered manually; the mod doesn’t discover or synchronize them automatically. YACL and ModMenu are included in manifest.kod.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
15 1,711
src/client/java/vault/roll/VaultRollClient.java
package vault.roll;

import java.util.concurrent.CompletableFuture;

import org.lwjgl.glfw.GLFW;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

public final class VaultRollClient implements ClientModInitializer
{
	private static final KeyBinding.Category CATEGORY =
		KeyBinding.Category.create(Identifier.of("vaultroll", "main"));
	private static final KeyBinding PREDICT_KEY = new KeyBinding(
		"key.vaultroll.predict", GLFW.GLFW_KEY_P, CATEGORY);
	
	@Override
	public void onInitializeClient()
	{
		VaultRollConfig.HANDLER.load();
		KeyBindingHelper.registerKeyBinding(PREDICT_KEY);
		ClientTickEvents.END_CLIENT_TICK.register(client -> {
			while(PREDICT_KEY.wasPressed())
				predict(client);
		});
	}
	
	private static void predict(MinecraftClient client)
	{
		if(client.player == null)
			return;
		VaultRollConfig config = VaultRollConfig.get();
		Long seed = VaultRollPredictor.tryParseSeed(config.worldSeed);
		if(seed == null)
		{
			client.player.sendMessage(Text.literal(
				"Vault Roll: enter a valid numeric seed or world seed phrase in the config."),
				false);
			return;
		}
		if(config.mode == null || config.openingIndex < 0
			|| config.openingIndex > VaultRollSynchronizer.MAXIMUM_SEARCH_HORIZON
			|| config.searchHorizon < 0
			|| config.searchHorizon > VaultRollSynchronizer.MAXIMUM_SEARCH_HORIZON
			|| config.targetItem == null || config.targetItem.isBlank())
		{
			client.player.sendMessage(Text.literal(
				"Vault Roll: check the mode, opening index, target item, and search horizon in the config."),
				false);
			return;
		}
		
		VaultRollMode mode = config.mode;
		long openingIndex = config.openingIndex;
		int horizon = config.searchHorizon;
		String targetItem = VaultRollPredictor.normalizeItemId(config.targetItem);
		client.player.sendMessage(Text.literal("Vault Roll: calculating predictions..."),
			false);
		CompletableFuture
			.supplyAsync(() -> new Prediction(
				VaultRollPredictor.predictOpening(seed, mode, openingIndex),
				VaultRollPredictor.findTarget(seed, mode, openingIndex, horizon,
					targetItem, null, () -> false)))
			.whenComplete((prediction, error) -> client.execute(() -> {
				if(client.player == null)
					return;
				if(error != null)
				{
					Throwable cause = error.getCause() == null ? error
						: error.getCause();
					client.player.sendMessage(Text.literal(
						"Vault Roll: prediction failed: " + cause.getMessage()), false);
					return;
				}
				client.player.sendMessage(Text.literal("Opening " + openingIndex
					+ " (" + mode.displayName() + "): "
					+ prediction.opening().describe()), false);
				VaultRollPredictor.TargetHit hit = prediction.target();
				if(hit == null)
					client.player.sendMessage(Text.literal("No "
						+ VaultRollPredictor.formatItem(targetItem) + " found in the next "
						+ (horizon + 1) + " openings."), false);
				else
					client.player.sendMessage(Text.literal("Next "
						+ VaultRollPredictor.formatItem(targetItem) + ": opening "
						+ hit.absoluteOpening() + " (" + hit.offset()
						+ " openings ahead): " + hit.opening().describe()), false);
			}));
	}
	
	private record Prediction(VaultRollOpening opening,
		VaultRollPredictor.TargetHit target)
	{}
}