More vanilla friendly methods to update trades

This commit is contained in:
Lulu13022002
2022-10-16 16:12:49 +02:00
parent 9db4bb7ac6
commit 533bc0c468
2 changed files with 66 additions and 12 deletions

View File

@@ -98,6 +98,34 @@ public class CraftVillager extends CraftAbstractVillager implements Villager {
}
// Paper start
@Override
public boolean increaseLevel(int amount) {
Preconditions.checkArgument(amount > 0, "Level earned must be positive");
int supposedFinalLevel = this.getVillagerLevel() + amount;
Preconditions.checkArgument(net.minecraft.world.entity.npc.VillagerData.MIN_VILLAGER_LEVEL <= supposedFinalLevel && supposedFinalLevel <= net.minecraft.world.entity.npc.VillagerData.MAX_VILLAGER_LEVEL,
"Final level reached after the donation (%d) must be between [%d, %d]".formatted(supposedFinalLevel, net.minecraft.world.entity.npc.VillagerData.MIN_VILLAGER_LEVEL, net.minecraft.world.entity.npc.VillagerData.MAX_VILLAGER_LEVEL));
it.unimi.dsi.fastutil.ints.Int2ObjectMap<net.minecraft.world.entity.npc.VillagerTrades.ItemListing[]> trades =
net.minecraft.world.entity.npc.VillagerTrades.TRADES.get(this.getHandle().getVillagerData().getProfession());
if (trades == null || trades.isEmpty()) {
this.getHandle().setVillagerData(this.getHandle().getVillagerData().setLevel(supposedFinalLevel));
return false;
}
while (amount > 0) {
this.getHandle().increaseMerchantCareer();
amount--;
}
return true;
}
@Override
public boolean addTrades(int amount) {
Preconditions.checkArgument(amount > 0, "Number of trades unlocked must be positive");
return this.getHandle().updateTrades(amount);
}
@Override
public int getRestocksToday() {
return getHandle().numberOfRestocksToday;