Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a770463
WIP: tracking + calc + UI work; drop Codex battle export
Apr 22, 2026
45b39dd
Expand DamageEngine + MoveDex coverage
Apr 22, 2026
94e9a39
Calc accuracy pass: types, DB coverage, abilities, items, crit
Apr 22, 2026
5b7b9a4
Merge branch 'claude/hungry-snyder-726149' into dev
Apr 22, 2026
e8ee592
Merge branch 'claude/brave-sanderson-4f4327' into dev
Apr 22, 2026
dcb13b8
V2 calc redesign: matchup HP bars, forecast bars, team footer
Apr 27, 2026
9da8dcc
Merge V2 calc redesign (matchup HP bars, forecast bars, team footer)
Apr 27, 2026
bc4d955
Calc panel: scale spacing and bars with text size
Apr 27, 2026
227dd41
Calc panel: default y=100 to clear Chat Plus on fresh install
May 6, 2026
7fa408c
DamageEngine: drop OHKO confidence to LOW when item/ability is inferred
May 6, 2026
37a8593
StatTracker: clear negative stages on White Herb consume
May 6, 2026
d0ba6e1
BattleStateFacade: split regional aspect off properties.species
May 6, 2026
7ce32ea
BattleMessageInterceptor: track Ogerpon Embody Aspect on switch-in
May 6, 2026
f704605
BattleSwitchHandlerMixin: restore 33% HP for Regenerator on switch-out
May 6, 2026
e7e799f
splitRegionalForm: accept nullable species id
May 6, 2026
be2b3ce
Merge B9: calc panel default y=100 to clear Chat Plus
May 6, 2026
a6b3096
Merge B7: soften OHKO confidence on inferred defensive item/ability
May 6, 2026
698b5fe
Merge B6: White Herb clears negative stat stages on consume
May 6, 2026
11b389b
Merge B2: split regional aspect off properties.species in toTruth
May 6, 2026
a173ecc
Merge B4: track Ogerpon Embody Aspect on switch-in
May 6, 2026
df7d763
Merge B5: restore 33% HP for Regenerator on switch-out
May 6, 2026
c904cf5
WIP: Ogerpon mask form + post-change form resolution + DamageEngine c…
May 6, 2026
5177e5a
feat: cycle-through manual overrides for opponent Item / Ability / Sp…
May 6, 2026
93afdcd
feat(overrides): add back arrow, MANUAL pill, surface Spread row in c…
May 6, 2026
03fcda0
feat(overrides): mega-stone form swap + speed line in compact mode
May 6, 2026
3696fb5
feat(overrides): expand cycle alternatives via species abilities + co…
May 6, 2026
6dcc83b
feat(overrides): show usage % on rows and add MANUAL pill to Spread
May 6, 2026
9d4297c
feat(calc): scroll the moves + team viewport when content overflows
May 6, 2026
d53e603
fix(overrides): hide cycle UI on real-revealed rows; purge stale over…
May 6, 2026
3e720c5
fix(calc): scroll wheel + scrollbar drag
May 6, 2026
eb5b620
chore: track build pipeline tools and ignore local clutter
May 6, 2026
3dab09d
feat(database): add 7 new species; refresh Smogon fallback data
May 6, 2026
75c6362
feat(ui): hide calc panel and battle log on fresh installs
May 6, 2026
7b67d71
fix(ui): restore calc panel default-on; add Mod Menu toggle (v0.9.1.1)
May 7, 2026
7bf0761
fix(calc): derive player stats heuristically when party lookup fails …
May 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ __pycache__/
.DS_Store
Thumbs.db
Desktop.ini
tools/database/generated/

# Local agent / debug clutter
.claude/
.codex_tmp/
.codex_tmp_delta/
battleinfo/
*.bak
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changelog

## 0.9.1-deltacalc

- Rebrands the client mod as DeltaCalc for release packaging
- Adds the damage calculator panel and battle overlay improvements for Cobblemon Delta battles
- Includes battle-state export support for external analysis workflows
- Bundles a release icon and aligns packaged metadata with the DeltaCalc repository
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# DeltaCalc

DeltaCalc is a client-side utility mod for Cobblemon Delta on Fabric 1.21.1. It adds an in-battle damage calculator, expanded battle overlays, richer tooltips, team indicators, and optional battle-state export for external analysis tools.

## Features

- Live damage calculation panel for active battle states (left-click and drag the header to reposition; position is saved automatically)
- Battle info overlays for weather, terrain, side conditions, and boosts
- Team indicators and enriched Pokemon move/tooltips
- Battle log enhancements
- Optional structured battle export for external tooling

## Requirements

- Minecraft 1.21.1
- Fabric Loader
- Fabric API
- Fabric Language Kotlin
- Cobblemon 1.7.3+1.21.1
- Java 21

## Installation

1. Install Fabric Loader for Minecraft 1.21.1.
2. Add Fabric API, Fabric Language Kotlin, Cobblemon, and DeltaCalc to your `mods` folder.
3. Launch the game and configure DeltaCalc through Mod Menu if you have it installed.

## Notes For Release

- The internal mod id remains `cobblemonextendedbattleui` for compatibility with the current codebase.
- Set `MODRINTH_PROJECT_SLUG` in [`CobblemonExtendedBattleUI.kt`](/Z:/Cb%20delta/DeltaCalc/src/main/kotlin/com/cobblemonextendedbattleui/CobblemonExtendedBattleUI.kt:1) after the Modrinth project is created if you want in-game update checks.
16 changes: 16 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ dependencies {
modCompileOnly("me.shedaniel.cloth:cloth-config-fabric:${property("cloth_config_version")}") {
exclude(group = "net.fabricmc.fabric-api")
}

testImplementation(kotlin("test"))
testImplementation("org.junit.jupiter:junit-jupiter:5.10.2")
}

tasks.processResources {
Expand Down Expand Up @@ -78,6 +81,13 @@ tasks.named<net.fabricmc.loom.task.RemapJarTask>("remapJar") {
archiveFileName.set("deltacalc.jar")
}

val prismJar by tasks.registering(Copy::class) {
dependsOn(tasks.named<net.fabricmc.loom.task.RemapJarTask>("remapJar"))
from(tasks.named<net.fabricmc.loom.task.RemapJarTask>("remapJar").flatMap { it.archiveFile })
into(layout.buildDirectory.dir("libs"))
rename { "deltacalc-prism.jar" }
}

tasks.named<org.gradle.jvm.tasks.Jar>("sourcesJar") {
archiveFileName.set("deltacalc-sources.jar")
}
Expand All @@ -91,10 +101,12 @@ val purgePrototypeArtifacts by tasks.registering(Delete::class) {

tasks.named("build") {
dependsOn(purgePrototypeArtifacts)
dependsOn(prismJar)
}

tasks.named("assemble") {
dependsOn(purgePrototypeArtifacts)
dependsOn(prismJar)
}

tasks.named("clean") {
Expand All @@ -106,6 +118,10 @@ tasks.named("clean") {
}
}

tasks.test {
useJUnitPlatform()
}

loom {
accessWidenerPath.set(file("src/main/resources/cobblemonextendedbattleui.accesswidener"))
mixin {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ yarn_mappings=1.21.1+build.3
loader_version=0.17.2
fabric_version=0.116.6+1.21.1

mod_version=0.9.1-deltacalc
mod_version=0.9.1.2-deltacalc
maven_group=com.cobblemonextendedbattleui
archives_base_name=deltacalc

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import com.cobblemonextendedbattleui.TeamIndicatorUI;
import com.cobblemonextendedbattleui.BattleStateTracker;
import com.cobblemonextendedbattleui.PanelConfig;
import com.cobblemonextendedbattleui.battle.messages.MessageParser;
import com.cobblemonextendedbattleui.battle.state.PokemonRegistry;
import com.cobblemonextendedbattleui.calc.DebugDumper;
import net.minecraft.client.MinecraftClient;

import java.util.UUID;
Expand Down Expand Up @@ -80,6 +83,9 @@ private void onHandlePre(BattleHealthChangePacket packet, MinecraftClient client

if (hpChange > 0.5f) {
DamageTracker.INSTANCE.recordDamage(pokemonName, hpChange);
DebugDumper.INSTANCE.recordActualDamage(
uuid, pokemonName, oldPercent, newPercent, maxHp, isFlat);
inferLifeOrbFromSelfDamage(uuid, pokemonName, hpChange);
} else if (hpChange < -0.5f) {
DamageTracker.INSTANCE.recordHealing(pokemonName, -hpChange);
}
Expand All @@ -100,4 +106,35 @@ private void onHandlePre(BattleHealthChangePacket packet, MinecraftClient client
// Silent fail to avoid breaking gameplay
}
}

/**
* Infer Life Orb when an attacker takes ~10% self-damage immediately after using a move.
* Cobblemon's `cobblemon.battle.damage.lifeorb` translation key handles the explicit case,
* but Delta builds may not always emit it. This is a fallback so the calc's item-aware
* damage modifiers (Life Orb's +30% multiplier) actually fire.
*
* Filters to avoid false positives:
* - Target must be the most recent move's user (i.e. self-damage on the attacker).
* - The move must still be resolving (lastMoveResolved=false) so this isn't a hazard tick.
* - Damage delta in [9.0, 11.0]% — tight enough to exclude:
* * Iron Barbs / Rough Skin (12.5%)
* * Rocky Helmet (16.67%)
* * Brave Bird / Flare Blitz / Wood Hammer recoil (33%)
* * Take Down / Submission recoil (25%)
* - setItem with HELD is no-op when an item is already revealed, so confirmed items win.
*/
private void inferLifeOrbFromSelfDamage(UUID targetUuid, String targetName, float damagePct) {
if (damagePct < 9.0f || damagePct > 11.0f) return;
if (MessageParser.INSTANCE.getLastMoveResolved()) return;
String attacker = MessageParser.INSTANCE.getLastMoveUser();
String moveName = MessageParser.INSTANCE.getLastMoveName();
if (attacker == null || moveName == null) return;

UUID attackerUuid = PokemonRegistry.INSTANCE.resolvePokemonUuid(attacker, null);
if (attackerUuid == null || !attackerUuid.equals(targetUuid)) return;

// Don't overwrite a confirmed item — setItem(HELD) is no-op when already set.
BattleStateTracker.INSTANCE.setItem(
attacker, "Life Orb", BattleStateTracker.ItemStatus.HELD, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* Intercept raw battle messages for EBU's state tracking and custom log, then prevent
* Cobblemon's default handler from populating its own message queue when the custom log is active.
*/
@Mixin(value = BattleMessageHandler.class, remap = false)
@Mixin(value = BattleMessageHandler.class, priority = 2000, remap = false)
public class BattleMessageHandlerMixin {

@Inject(method = "handle", at = @At("HEAD"), cancellable = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

import com.cobblemon.mod.common.client.CobblemonClient;
import com.cobblemon.mod.common.client.battle.ClientBattle;
import com.cobblemon.mod.common.client.battle.ClientBattlePokemon;
import com.cobblemon.mod.common.client.net.battle.BattleSwitchPokemonHandler;
import com.cobblemon.mod.common.net.messages.client.battle.BattleSwitchPokemonPacket;
import com.cobblemon.mod.common.net.messages.client.battle.BattleInitializePacket;
import com.cobblemonextendedbattleui.BattleStateTracker;
import com.cobblemonextendedbattleui.DamageTracker;
import com.cobblemonextendedbattleui.PanelConfig;
import com.cobblemonextendedbattleui.battle.state.AbilityItemTracker;
import net.minecraft.client.MinecraftClient;

import java.util.UUID;
Expand All @@ -33,6 +35,35 @@ private void onHandlePre(BattleSwitchPokemonPacket packet, MinecraftClient clien
// Skip if no tracking is needed
if (!needsStateTracking && !needsDamageTracking) return;

// Regenerator restores 33% HP to the OUTGOING Pokemon on switch-out.
// At HEAD inject the slot still holds the active (outgoing) Pokemon, so
// packet.getPnx() resolves to it. Gated on >0% HP because Regenerator
// does not trigger from a KO-forced switch (faint message zeros HP first).
if (needsStateTracking && needsDamageTracking) {
try {
ClientBattle battle = CobblemonClient.INSTANCE.getBattle();
if (battle != null) {
var slotResult = battle.getPokemonFromPNX(packet.getPnx());
if (slotResult != null) {
ClientBattlePokemon outgoing = slotResult.getSecond().getBattlePokemon();
if (outgoing != null) {
UUID outgoingUuid = outgoing.getUuid();
String ability = AbilityItemTracker.INSTANCE.getRevealedAbility(outgoingUuid);
if (ability != null && ability.equalsIgnoreCase("Regenerator")) {
Float currentHp = DamageTracker.INSTANCE.getLastKnownHpPercent(outgoingUuid);
if (currentHp != null && currentHp > 0f) {
float restored = Math.min(100f, currentHp + 33.33f);
DamageTracker.INSTANCE.updateHpPercent(outgoingUuid, restored);
}
}
}
}
}
} catch (Exception e) {
// Silent fail to avoid breaking gameplay
}
}

try {
BattleInitializePacket.ActiveBattlePokemonDTO newPokemon = packet.getNewPokemon();
if (newPokemon == null) return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.cobblemonextendedbattleui.mixin;

import com.cobblemonextendedbattleui.BattleLog;
import com.cobblemonextendedbattleui.BattleMessageInterceptor;
import com.cobblemonextendedbattleui.BoostTraceLog;
import com.cobblemonextendedbattleui.PanelConfig;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Collection;
import java.util.List;

/**
* DeltaClient short-circuits Cobblemon's native BattleMessageHandler and appends
* incoming battle messages directly into ClientBattleMessageQueue via a synthetic
* deltaclient$add(Collection) method. Hook that path so battle state tracking and
* the custom log still see the same raw messages.
*/
@Pseudo
@Mixin(targets = "com.cobblemon.mod.common.client.battle.ClientBattleMessageQueue", remap = false)
public class DeltaClientBattleMessageQueueMixin {

@Inject(
method = "deltaclient$add(Ljava/util/Collection;)V",
at = @At("HEAD"),
require = 0
)
private void cobblemonextendedbattleui$processDeltaQueuedMessages(Collection<?> messages, CallbackInfo ci) {
if (messages == null || messages.isEmpty()) {
return;
}

List<Text> textMessages = messages.stream()
.filter(Text.class::isInstance)
.map(Text.class::cast)
.toList();

if (textMessages.isEmpty()) {
return;
}

boolean containsBoostMessage = textMessages.stream().anyMatch(text ->
text != null && (
text.getString().contains(" rose") ||
text.getString().contains(" fell") ||
text.getString().contains("stat changes")
)
);
if (containsBoostMessage) {
BoostTraceLog.INSTANCE.append("delta queue received " + textMessages.size() + " messages: " + textMessages);
}

if (PanelConfig.INSTANCE.needsBattleStateTracking()) {
BattleMessageInterceptor.INSTANCE.processMessages(textMessages);
}

if (PanelConfig.INSTANCE.getEnableBattleLog()) {
BattleLog.INSTANCE.processMessages(textMessages);
}
}
}
20 changes: 4 additions & 16 deletions src/main/java/com/deltacalc/battle/BattleTracker.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.deltacalc.battle;

import com.cobblemon.mod.common.client.CobblemonClient;
import com.deltacalc.config.DeltaCalcConfig;
import com.deltacalc.inference.ConfidenceBand;
import com.deltacalc.inference.GuessState;
import com.deltacalc.inference.GuessValue;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.UUID;
import net.minecraft.client.MinecraftClient;
Expand Down Expand Up @@ -37,13 +37,13 @@ public void tick(MinecraftClient client) {
String screenName = screen == null ? "<none>" : screen.getClass().getName();
if (!screenName.equals(lastScreenName)) {
lastScreenName = screenName;
logger.info("DeltaCalc screen changed to {}", screenName);
logger.debug("DeltaCalc screen changed to {}", screenName);
}

boolean battleActive = config.demoBattleForced() || isLikelyBattleScreen(screen);
boolean battleActive = config.demoBattleForced() || CobblemonClient.INSTANCE.getBattle() != null;
if (battleActive && currentSnapshot == null) {
currentSnapshot = createDemoSnapshot();
logger.info("DeltaCalc entered battle context using {}", config.demoBattleForced() ? "forced demo snapshot" : "screen heuristic");
logger.info("DeltaCalc entered battle context using {}", config.demoBattleForced() ? "forced demo snapshot" : "Cobblemon ClientBattle");
return;
}

Expand Down Expand Up @@ -93,18 +93,6 @@ public void cycleDemoReveal() {
logger.info("DeltaCalc cycled demo reveal state to step {}", demoRevealStep);
}

private boolean isLikelyBattleScreen(Screen screen) {
if (screen == null) {
return false;
}

String className = screen.getClass().getName().toLowerCase(Locale.ROOT);
String title = screen.getTitle() == null ? "" : screen.getTitle().getString().toLowerCase(Locale.ROOT);
return className.contains("battle")
|| className.contains("cobblemon")
|| title.contains("battle");
}

private ActiveMonSnapshot withOpponentReveal(ActiveMonSnapshot opponent, String move, String item, String ability) {
List<String> knownMoves = move == null ? opponent.knownMoves() : List.of(move);
GuessValue<String> revealedItem = item == null
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/com/deltacalc/calc/MoveDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@ public record MoveDefinition(
String type,
int power,
MoveCategory category,
boolean fallback
boolean fallback,
int minHits,
int maxHits
) {
public MoveDefinition(String name, String type, int power, MoveCategory category, boolean fallback) {
this(name, type, power, category, fallback, 1, 1);
}

public boolean isMultiHit() {
return maxHits > 1;
}
}

26 changes: 26 additions & 0 deletions src/main/java/com/deltacalc/calc/MoveDex.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,32 @@ public final class MoveDex {
register(new MoveDefinition("Will-O-Wisp", "fire", 0, MoveCategory.STATUS, false));
register(new MoveDefinition("Fire Blast", "fire", 110, MoveCategory.SPECIAL, false));
register(new MoveDefinition("Air Slash", "flying", 75, MoveCategory.SPECIAL, false));
register(new MoveDefinition("Bullet Seed", "grass", 25, MoveCategory.PHYSICAL, false, 2, 5));
register(new MoveDefinition("Rock Blast", "rock", 25, MoveCategory.PHYSICAL, false, 2, 5));
register(new MoveDefinition("Icicle Spear", "ice", 25, MoveCategory.PHYSICAL, false, 2, 5));
register(new MoveDefinition("Pin Missile", "bug", 25, MoveCategory.PHYSICAL, false, 2, 5));
register(new MoveDefinition("Tail Slap", "normal", 25, MoveCategory.PHYSICAL, false, 2, 5));
register(new MoveDefinition("Scale Shot", "dragon", 25, MoveCategory.PHYSICAL, false, 2, 5));
register(new MoveDefinition("Water Shuriken", "water", 15, MoveCategory.SPECIAL, false, 2, 5));
register(new MoveDefinition("Double Kick", "fighting", 30, MoveCategory.PHYSICAL, false, 2, 2));
register(new MoveDefinition("Bonemerang", "ground", 50, MoveCategory.PHYSICAL, false, 2, 2));
register(new MoveDefinition("Dual Chop", "dragon", 40, MoveCategory.PHYSICAL, false, 2, 2));
register(new MoveDefinition("Gear Grind", "steel", 50, MoveCategory.PHYSICAL, false, 2, 2));
register(new MoveDefinition("Dragon Darts", "dragon", 50, MoveCategory.PHYSICAL, false, 2, 2));
register(new MoveDefinition("Double Iron Bash", "steel", 60, MoveCategory.PHYSICAL, false, 2, 2));
register(new MoveDefinition("Triple Kick", "fighting", 10, MoveCategory.PHYSICAL, false, 3, 3));
register(new MoveDefinition("Triple Axel", "ice", 20, MoveCategory.PHYSICAL, false, 3, 3));
register(new MoveDefinition("Surging Strikes", "water", 25, MoveCategory.PHYSICAL, false, 3, 3));
register(new MoveDefinition("Population Bomb", "normal", 20, MoveCategory.PHYSICAL, false, 1, 10));
// Delta signature multi-hit moves (from cobblemon-delta team-builder data).
register(new MoveDefinition("Twin Cross", "dragon", 50, MoveCategory.PHYSICAL, false, 2, 2));
register(new MoveDefinition("Lumen Cascade", "normal", 50, MoveCategory.SPECIAL, false, 2, 2));
register(new MoveDefinition("Searing Claws", "fire", 35, MoveCategory.PHYSICAL, false, 2, 2));
register(new MoveDefinition("Dual Divide", "bug", 40, MoveCategory.PHYSICAL, false, 2, 2));
register(new MoveDefinition("Tomahawk Volley", "fire", 20, MoveCategory.PHYSICAL, false, 2, 5));
register(new MoveDefinition("Wretched Stab", "ghost", 20, MoveCategory.PHYSICAL, false, 2, 5));
register(new MoveDefinition("Divine Volley", "fighting", 20, MoveCategory.PHYSICAL, false, 1, 6));
register(new MoveDefinition("Quillstorm", "fire", 20, MoveCategory.PHYSICAL, false, 1, 3));
}

private MoveDex() {
Expand Down
Loading