Search in sources :

Example 1 with SpongeProfession

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

the class MixinVillagerRegistry method register.

/**
 * @author gabizou - July 1st, 2017
 * @reason Rewrite the register method to join Sponge's villager registrations with forge's.
 * For some auspiciouos reason, when trying to write a redirect, the redirect will fail...
 *
 * @param prof The profession being registered
 * @param id The id being registered
 */
@Overwrite
private void register(VillagerRegistry.VillagerProfession prof, int id) {
    this.REGISTRY.register(id, ((IMixinVillagerProfession) prof).getName(), prof);
    final int professionId = this.REGISTRY.getIDForObject(prof);
    final IMixinVillagerProfession mixinProfession = (IMixinVillagerProfession) prof;
    final SpongeProfession spongeProfession = new SpongeProfession(professionId, mixinProfession.getId(), mixinProfession.getProfessionName());
    final SpongeProfession registeredProfession = SpongeForgeVillagerRegistry.validateProfession(prof, spongeProfession);
    ProfessionRegistryModule.getInstance().registerAdditionalCatalog(registeredProfession);
}
Also used : SpongeProfession(org.spongepowered.common.entity.SpongeProfession) IMixinVillagerProfession(org.spongepowered.mod.interfaces.IMixinVillagerProfession) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 2 with SpongeProfession

use of org.spongepowered.common.entity.SpongeProfession 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 3 with SpongeProfession

use of org.spongepowered.common.entity.SpongeProfession 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 4 with SpongeProfession

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

SpongeProfession (org.spongepowered.common.entity.SpongeProfession)4 SpongeCareer (org.spongepowered.common.entity.SpongeCareer)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 Overwrite (org.spongepowered.asm.mixin.Overwrite)1 SpongeTranslation (org.spongepowered.common.text.translation.SpongeTranslation)1 IMixinVillagerCareer (org.spongepowered.mod.interfaces.IMixinVillagerCareer)1 IMixinVillagerProfession (org.spongepowered.mod.interfaces.IMixinVillagerProfession)1