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());
}
}
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());
}
}
}
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);
}
}
}
Aggregations