Skip to content
This repository was archived by the owner on Jan 1, 2026. It is now read-only.

Conversation

@CodahWasTaken
Copy link
Contributor

Fix: Currency change calculation bug

Fixes the issue where players werent receiving correct change when paying with larger denominations.

Problem

When a player paid with a gold block (9g) for items costing 1-8g, they received incorrect change:

  • 1g purchase: Got 7 ingots instead of 8
  • 4g purchase: Got 1 ingot instead of 5
  • 5-8g purchase: Got 0 ingots instead of 1-4

Solution

Complete rewrite of the ItemCalculations.calculation() method with a cleaner algorithm:

  1. First pass: try to pay with exact denominations
  2. Second pass: break down smallest larger denomination if needed
  3. Calculate and provide correct change

Also fixed a bug in CalculationData.provideMaterials() where the default value was incorrect.

Files Changed

  • Core/src/net/tnemc/core/currency/calculations/ItemCalculations.java
  • Core/src/net/tnemc/core/currency/calculations/CalculationData.java

Testing

Tested with all reported scenarios that are now returning correct change amounts.

@CLAassistant
Copy link

CLAassistant commented Dec 10, 2025

CLA assistant check
All committers have signed the CLA.

@creatorfromhell creatorfromhell merged commit b556253 into TheNewEconomy:main Dec 11, 2025
2 of 3 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants