Search in sources :

Example 1 with TradeOfferListMutator

use of org.spongepowered.api.item.merchant.TradeOfferListMutator in project SpongeCommon by SpongePowered.

the class SpongeVillagerRegistry method addMutators.

@Override
public VillagerRegistry addMutators(Career career, int level, TradeOfferListMutator generator, TradeOfferListMutator... generators) {
    checkArgument(level > 0, "Career level must be at least greater than zero!");
    checkNotNull(career, "Career cannot be null!");
    checkNotNull(generator, "Generator cannot be null!");
    checkNotNull(generators, "Generators cannot be null!");
    Multimap<Integer, TradeOfferListMutator> multimap = this.careerGeneratorMap.get(career);
    List<TradeOfferListMutator> list = new ArrayList<>();
    list.add(generator);
    for (TradeOfferListMutator element : generators) {
        list.add(checkNotNull(element, "TradeOfferListMutator cannot be null!"));
    }
    if (multimap == null) {
        multimap = ArrayListMultimap.create(3, list.size());
        this.careerGeneratorMap.put(career, multimap);
    }
    multimap.putAll(level, list);
    return this;
}
Also used : TradeOfferListMutator(org.spongepowered.api.item.merchant.TradeOfferListMutator) ArrayList(java.util.ArrayList)

Example 2 with TradeOfferListMutator

use of org.spongepowered.api.item.merchant.TradeOfferListMutator in project SpongeCommon by SpongePowered.

the class SpongeVillagerRegistry method registerVanillaTrades.

static void registerVanillaTrades() {
    VillagerRegistry instance = getInstance();
    for (Career career : CareerRegistryModule.getInstance().getAll()) {
        SpongeCareer spongeCareer = (SpongeCareer) career;
        EntityVillager.ITradeList[][] careerLevels = EntityVillager.DEFAULT_TRADE_LIST_MAP[((SpongeProfession) spongeCareer.getProfession()).type][spongeCareer.type];
        for (int level = 0; level < careerLevels.length; level++) {
            EntityVillager.ITradeList[] offers = careerLevels[level];
            ImmutableList.Builder<TradeOfferListMutator> builder = ImmutableList.builder();
            for (int i = 0; i < offers.length; i++) {
                builder.add(generatorFor(offers[i]));
            }
            instance.setMutators(career, level + 1, builder.build());
        }
    }
}
Also used : TradeOfferListMutator(org.spongepowered.api.item.merchant.TradeOfferListMutator) SpongeProfession(org.spongepowered.common.entity.SpongeProfession) ImmutableList(com.google.common.collect.ImmutableList) VillagerRegistry(org.spongepowered.api.item.merchant.VillagerRegistry) EntityVillager(net.minecraft.entity.passive.EntityVillager) SpongeCareer(org.spongepowered.common.entity.SpongeCareer) Career(org.spongepowered.api.data.type.Career) SpongeCareer(org.spongepowered.common.entity.SpongeCareer)

Aggregations

TradeOfferListMutator (org.spongepowered.api.item.merchant.TradeOfferListMutator)2 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 EntityVillager (net.minecraft.entity.passive.EntityVillager)1 Career (org.spongepowered.api.data.type.Career)1 VillagerRegistry (org.spongepowered.api.item.merchant.VillagerRegistry)1 SpongeCareer (org.spongepowered.common.entity.SpongeCareer)1 SpongeProfession (org.spongepowered.common.entity.SpongeProfession)1