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