2021-08-24 21:15:43 +02:00
|
|
|
package com.minelittlepony.unicopia.entity;
|
2021-08-24 21:14:18 +02:00
|
|
|
|
2021-08-24 22:33:11 +02:00
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
|
|
|
|
import com.minelittlepony.unicopia.UTags;
|
2021-11-05 14:18:32 +01:00
|
|
|
import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
|
2021-08-24 21:44:52 +02:00
|
|
|
import com.minelittlepony.unicopia.item.GemstoneItem;
|
2021-08-24 21:14:18 +02:00
|
|
|
import com.minelittlepony.unicopia.item.UItems;
|
|
|
|
import net.fabricmc.fabric.api.object.builder.v1.trade.TradeOfferHelper;
|
2021-08-24 22:33:11 +02:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.item.Item;
|
2021-08-24 21:14:18 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.item.Items;
|
2021-08-24 22:33:11 +02:00
|
|
|
import net.minecraft.tag.ItemTags;
|
|
|
|
import net.minecraft.tag.Tag;
|
|
|
|
import net.minecraft.util.Util;
|
2021-08-24 21:14:18 +02:00
|
|
|
import net.minecraft.village.TradeOffer;
|
2021-08-24 22:33:11 +02:00
|
|
|
import net.minecraft.village.TradeOffers;
|
2021-08-24 21:14:18 +02:00
|
|
|
import net.minecraft.village.VillagerProfession;
|
|
|
|
|
|
|
|
public interface UTradeOffers {
|
|
|
|
static void bootstrap() {
|
|
|
|
TradeOfferHelper.registerVillagerOffers(VillagerProfession.MASON, 1, factories -> {
|
2021-08-24 22:33:11 +02:00
|
|
|
factories.add(buyForEmeralds(UItems.GEMSTONE, 1, 1, 30, 2, 0.05F));
|
2021-08-24 21:14:18 +02:00
|
|
|
});
|
|
|
|
TradeOfferHelper.registerVillagerOffers(VillagerProfession.LIBRARIAN, 1, factories -> {
|
2021-08-24 22:33:11 +02:00
|
|
|
factories.add(buyForEmeralds(UItems.GEMSTONE, 2, 1, 20, 1, 0.05F));
|
|
|
|
factories.add(buyForEmeralds(UItems.PEGASUS_FEATHER, 20, 5, 50, 3, 0.15F));
|
|
|
|
factories.add(buyForEmeralds(UItems.GRYPHON_FEATHER, 20, 3, 50, 2, 0.12F));
|
2021-08-24 21:14:18 +02:00
|
|
|
});
|
|
|
|
TradeOfferHelper.registerVillagerOffers(VillagerProfession.CARTOGRAPHER, 1, factories -> {
|
2021-08-24 22:33:11 +02:00
|
|
|
factories.add(buyForEmeralds(UItems.GEMSTONE, 3, 1, 20, 1, 0.05F));
|
2021-08-24 21:14:18 +02:00
|
|
|
});
|
2021-08-24 21:44:52 +02:00
|
|
|
|
|
|
|
TradeOfferHelper.registerWanderingTraderOffers(1, factories -> {
|
2021-08-24 22:33:11 +02:00
|
|
|
factories.add(buyTiered(UItems.GEMSTONE, 30, UItems.GOLDEN_FEATHER, 1, UItems.GOLDEN_WING, 1, 30, 2, 0.05F));
|
2021-12-29 17:11:32 +01:00
|
|
|
factories.add((e, rng) -> new TradeOffer(new ItemStack(UItems.GEMSTONE, 3), GemstoneItem.enchant(UItems.GEMSTONE.getDefaultStack(), SpellType.REGISTRY.getRandom(rng)), 20, 1, 0.05F));
|
2021-08-24 22:33:11 +02:00
|
|
|
factories.add(buy(UItems.GEMSTONE, 20, UItems.HAY_FRIES, 5, 50, 3, 0.06F));
|
|
|
|
factories.add(buy(Items.WHEAT, 17, UItems.HAY_BURGER, 1, 10, 6, 0.08F));
|
|
|
|
factories.add(buy(ItemTags.SMALL_FLOWERS, 2, UItems.DAFFODIL_DAISY_SANDWICH, 1, 10, 6, 0.08F));
|
|
|
|
factories.add(buy(UItems.ZAP_APPLE, 45, UItems.ZAP_APPLE_JAM_JAR, 5, 50, 3, 0.07F));
|
|
|
|
factories.add(buy(UItems.CIDER, 1, UItems.FRIENDSHIP_BRACELET, 1, 6, 1, 0.05F));
|
2021-08-24 22:33:41 +02:00
|
|
|
factories.add(buy(UItems.GEMSTONE, 5, UTags.FRESH_APPLES, 2, 12, 3, 0.05F));
|
2021-08-24 22:33:11 +02:00
|
|
|
factories.add(new JarredItemTradeOfferFactory());
|
2021-08-24 21:44:52 +02:00
|
|
|
});
|
2021-08-24 22:33:11 +02:00
|
|
|
TradeOfferHelper.registerWanderingTraderOffers(2, factories -> {
|
|
|
|
factories.add(buy(UItems.COOKED_ZAP_APPLE, 45, UItems.ZAP_APPLE_JAM_JAR, 15, 50, 7, 0.17F));
|
|
|
|
factories.add(buy(UItems.CRYSTAL_HEART, 1, UItems.MUSIC_DISC_CRUSADE, 1, 10, 6, 0.08F));
|
|
|
|
factories.add(buy(UItems.PEGASUS_AMULET, 1, UItems.ALICORN_AMULET, 1, 2, 6, 0.05F));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private static TradeOffers.Factory buyForEmeralds(Item item, int count, int returnCount, int maxUses, int experience, float priceChange) {
|
|
|
|
return buy(item, count, Items.EMERALD, returnCount, maxUses, experience, priceChange);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static TradeOffers.Factory buy(Item item, int count, Item returnItem, int returnCount, int maxUses, int experience, float priceChange) {
|
|
|
|
return (e, rng) -> new TradeOffer(new ItemStack(item, count), new ItemStack(returnItem, returnCount), maxUses, experience, priceChange);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static TradeOffers.Factory buyTiered(Item item, int count, Item intermediate, int intermediatCount, Item returnItem, int returnCount, int maxUses, int experience, float priceChange) {
|
|
|
|
return (e, rng) -> new TradeOffer(new ItemStack(item, count), new ItemStack(intermediate, intermediatCount), new ItemStack(returnItem, returnCount), maxUses, experience, priceChange);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static TradeOffers.Factory buy(Tag<Item> item, int count, Item returnItem, int returnCount, int maxUses, int experience, float priceChange) {
|
|
|
|
return (e, rng) -> new TradeOffer(new ItemStack(item.getRandom(rng), count), new ItemStack(returnItem, returnCount), maxUses, experience, priceChange);
|
|
|
|
}
|
|
|
|
|
2021-08-25 14:22:11 +02:00
|
|
|
@SuppressWarnings("unused")
|
2021-08-24 22:33:11 +02:00
|
|
|
private static TradeOffers.Factory buy(Tag<Item> item, int count, Tag<Item> returnItem, int returnCount, int maxUses, int experience, float priceChange) {
|
|
|
|
return (e, rng) -> new TradeOffer(new ItemStack(item.getRandom(rng), count), new ItemStack(returnItem.getRandom(rng), returnCount), maxUses, experience, priceChange);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static TradeOffers.Factory buy(Item item, int count, Tag<Item> returnItem, int returnCount, int maxUses, int experience, float priceChange) {
|
|
|
|
return (e, rng) -> new TradeOffer(new ItemStack(item, count), new ItemStack(returnItem.getRandom(rng), returnCount), maxUses, experience, priceChange);
|
|
|
|
}
|
|
|
|
|
|
|
|
static class JarredItemTradeOfferFactory implements TradeOffers.Factory {
|
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public TradeOffer create(Entity entity, Random rng) {
|
|
|
|
TradeOffers.Factory factory = Util.getRandom(TradeOffers.WANDERING_TRADER_TRADES.get(1), rng);
|
|
|
|
|
|
|
|
if (factory == this) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
TradeOffer offer = factory.create(entity, rng);
|
|
|
|
|
|
|
|
return new TradeOffer(offer.getOriginalFirstBuyItem(), offer.getSecondBuyItem(), UItems.FILLED_JAR.withContents(offer.getSellItem()), offer.getUses(), offer.getMaxUses(), offer.getMerchantExperience(), offer.getPriceMultiplier(), offer.getDemandBonus());
|
|
|
|
}
|
2021-08-24 21:14:18 +02:00
|
|
|
}
|
|
|
|
}
|