Skip to content

Commit

Permalink
Updated Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Estecka committed Nov 6, 2024
1 parent 3ffc0b8 commit 0a49137
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ Disabling all rules effectively disables the mod.
Minecraft permanently saves any create map, and lock their structures from appearing on other exploration maps.
To prevent daily rerolls from throwing away endless amounts of unsold maps, those trades are handled differently.

Cartographers will remember each map they sell, and offer it again it the next time the same map trade comes up.
The gamerule `shiftingWares.allowMapReroll` (disabled by default) will allow them to forget a map, after it has been sold at least once.

The map's item name, (or preferably, its translation key), is used to tell apart different types of maps.
Since 1.20.5, the `item_name` is preferred over the `custom_name`.

By default, map trades will never be rerolled. They may only be rerolled if gamerule `shiftingWares.allowMapReroll` is enabled, and if the trade has been used at least once.

## Technical details
- If a villager is unable to generate all registered trades for a level, it will be replaced with an empty trade. With vanilla trades, this should only ever happen to cartographers, who are unable to generate explorer maps in worlds with no structures.
Expand All @@ -40,6 +35,7 @@ Placeholder trades will never take the place of a valid trade; they will only sh
- Depleted rerolls have a chance to yield duplicate trades.

## For developpers
By default, shifting-Wares assumes 2 trades per level, and pulls its trade pools from the same place as Vanilla.
By default, shifting-Wares assumes 2 trades per level, and pulls its trade pools from the same place as Vanilla. Mods can override this by using the `shifting-wares` entry-point, and implementing [`ITradeLayoutProvider`](./src/main/java/fr/estecka/shiftingwares/api/ITradeLayoutProvider.java).

If you have a mod that changes any of that, Shifting-Wares has an API you can use to specify the trade pools and layout that should be used instead.
If your mod contains custom implementation of map trade factories, or other similar items, you can communicate extra data to Shifting-Wares by implementing the same methods defined in [`IShiftingTradeFactory`](./src/main/java/fr/estecka/shiftingwares/api/IShiftingTradeFactory.java).
No dependency on Shifting-Wares is required, you only need to provide methods with the appropriate prototypes in your factories.
3 changes: 1 addition & 2 deletions src/main/java/fr/estecka/shiftingwares/TradeShuffler.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public TradeShuffler(VillagerEntity villager, boolean depletedOnly)
}

static public List<TradeOffers.Factory[]> GetTradeLayout(VillagerEntity villager){
var providers = FabricLoader.getInstance().getEntrypoints("shifting-wares", ITradeLayoutProvider.class);
var providers = FabricLoader.getInstance().getEntrypoints(ShiftingWares.MODID, ITradeLayoutProvider.class);

for (var p : providers) {
var layout = p.GetTradeLayout(villager);
Expand All @@ -67,7 +67,6 @@ public void Reroll(){
}

// Fix uninitialized trades, and update used trades.
// TODO: handle map trades differently
for (TradeOffer offer : offers){
ShiftingTradeData data = ITradeOfferDuck.Of(offer).shiftingwares$GetTradeData();
FixTradeData(data, offer.getSellItem());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

/**
* Must be implemented by mods that want to change how many trades are available
* to each villager level, or who don't want to use the trades defined in
* {@link net.minecraft.village.TradeOffers#PROFESSION_TO_LEVELED_TRADE} nor in
* {@link net.minecraft.village.TradeOffers#REBALANCED_PROFESSION_TO_LEVELED_TRADE}
* to each villager level, or who don't want villagers to use the trades defined
* in {@link net.minecraft.village.TradeOffers#PROFESSION_TO_LEVELED_TRADE} nor
* in {@link net.minecraft.village.TradeOffers#REBALANCED_PROFESSION_TO_LEVELED_TRADE}
*/
public interface ITradeLayoutProvider
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public class WrapperFactoryMixin
@Shadow private @Final Map<VillagerType, TradeOffers.Factory> typeToFactory;

/**
* The returned ids may not match the factory that created it, but this
* works for the purpose of avoiding duplicatas, since the trade offers only
* needs to be associated with the outer-most factory.
* The returned id may not match the factory that eventually creates the
* trade, but this still works for the purpose of avoiding duplicatas, since
* trade offers only needs to be associated with the outer-most factory.
*/
@Override
public Identifier shiftingwares$GetTradeId(){
Expand Down

0 comments on commit 0a49137

Please sign in to comment.