Search in sources :

Example 1 with SpongeCareer

use of org.spongepowered.common.entity.SpongeCareer in project SpongeForge by SpongePowered.

the class SpongeForgeVillagerRegistry method registerForgeCareer.

public static void registerForgeCareer(VillagerRegistry.VillagerCareer career) {
    final VillagerRegistry.VillagerProfession villagerProfession = ((IMixinVillagerCareer) career).getProfession();
    final Optional<Profession> spongeProfession = getProfession(villagerProfession);
    spongeProfession.ifPresent(profession -> {
        Career suggestedCareer = new SpongeCareer(((IMixinVillagerCareer) career).getId(), career.getName(), profession, new SpongeTranslation("entity.Villager." + career.getName()));
        SpongeCareer registeredCareer = validateCareer(career, suggestedCareer);
        CareerRegistryModule.getInstance().registerCareer(registeredCareer);
    });
    if (!spongeProfession.isPresent()) {
        SpongeImpl.getLogger().debug("Delaying registration of career {} until its profession {} is registered with Forge.", career.getName(), villagerProfession.getRegistryName());
    }
}
Also used : IMixinVillagerCareer(org.spongepowered.mod.interfaces.IMixinVillagerCareer) SpongeProfession(org.spongepowered.common.entity.SpongeProfession) Profession(org.spongepowered.api.data.type.Profession) SpongeTranslation(org.spongepowered.common.text.translation.SpongeTranslation) VillagerRegistry(net.minecraftforge.fml.common.registry.VillagerRegistry) SpongeCareer(org.spongepowered.common.entity.SpongeCareer) Career(org.spongepowered.api.data.type.Career) SpongeCareer(org.spongepowered.common.entity.SpongeCareer) IMixinVillagerCareer(org.spongepowered.mod.interfaces.IMixinVillagerCareer)

Example 2 with SpongeCareer

use of org.spongepowered.common.entity.SpongeCareer 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)

Example 3 with SpongeCareer

use of org.spongepowered.common.entity.SpongeCareer in project SpongeCommon by SpongePowered.

the class ProfessionRegistryModule method registerCareerForProfession.

@SuppressWarnings({ "unchecked", "rawtypes" })
public void registerCareerForProfession(Career career) {
    SpongeProfession profession = (SpongeProfession) checkNotNull(career).getProfession();
    List<SpongeCareer> careers = (List) profession.getUnderlyingCareers();
    boolean isRegistered = false;
    final SpongeCareer spongeCareer = (SpongeCareer) career;
    for (SpongeCareer professionCareer : careers) {
        if (spongeCareer.type == professionCareer.type) {
            isRegistered = true;
        }
    }
    if (!isRegistered) {
        if (!careers.contains(spongeCareer)) {
            careers.add(spongeCareer);
            Collections.sort(careers, CareerRegistryModule.CAREER_COMPARATOR);
        }
    }
}
Also used : SpongeProfession(org.spongepowered.common.entity.SpongeProfession) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) SpongeCareer(org.spongepowered.common.entity.SpongeCareer)

Aggregations

SpongeCareer (org.spongepowered.common.entity.SpongeCareer)3 SpongeProfession (org.spongepowered.common.entity.SpongeProfession)3 ImmutableList (com.google.common.collect.ImmutableList)2 Career (org.spongepowered.api.data.type.Career)2 List (java.util.List)1 EntityVillager (net.minecraft.entity.passive.EntityVillager)1 VillagerRegistry (net.minecraftforge.fml.common.registry.VillagerRegistry)1 Profession (org.spongepowered.api.data.type.Profession)1 TradeOfferListMutator (org.spongepowered.api.item.merchant.TradeOfferListMutator)1 VillagerRegistry (org.spongepowered.api.item.merchant.VillagerRegistry)1 SpongeTranslation (org.spongepowered.common.text.translation.SpongeTranslation)1 IMixinVillagerCareer (org.spongepowered.mod.interfaces.IMixinVillagerCareer)1