Search in sources :

Example 1 with VillagerProfession

use of net.minecraft.entity.merchant.villager.VillagerProfession in project Arclight by IzzelAliz.

the class AssignProfessionTaskMixin method startExecuting.

/*
    @SuppressWarnings("UnresolvedMixinReference")
    @Redirect(method = "*(Lnet/minecraft/entity/merchant/villager/VillagerEntity;Lnet/minecraft/world/server/ServerWorld;Lnet/minecraft/entity/merchant/villager/VillagerProfession;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/merchant/villager/VillagerEntity;setVillagerData(Lnet/minecraft/entity/merchant/villager/VillagerData;)V"))
    private void arclight$careerChangeHook(VillagerEntity villagerEntity, VillagerData villagerData) {
        VillagerProfession profession = villagerData.getProfession();
        VillagerCareerChangeEvent event = CraftEventFactory.callVillagerCareerChangeEvent(villagerEntity, CraftVillager.nmsToBukkitProfession(profession), VillagerCareerChangeEvent.ChangeReason.EMPLOYED);
        if (!event.isCancelled()) {
            VillagerData newData = villagerEntity.getVillagerData().withProfession(CraftVillager.bukkitToNmsProfession(event.getProfession()));
            villagerEntity.setVillagerData(newData);
        }
    }*/
/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
protected void startExecuting(ServerWorld worldIn, VillagerEntity entityIn, long gameTimeIn) {
    GlobalPos globalpos = entityIn.getBrain().getMemory(MemoryModuleType.JOB_SITE).get();
    MinecraftServer minecraftserver = worldIn.getServer();
    minecraftserver.getWorld(globalpos.getDimension()).getPointOfInterestManager().getType(globalpos.getPos()).ifPresent((p_220390_2_) -> {
        Registry.VILLAGER_PROFESSION.stream().filter((p_220389_1_) -> {
            return p_220389_1_.getPointOfInterest() == p_220390_2_;
        }).findFirst().ifPresent((p_220388_2_) -> {
            VillagerData villagerData = entityIn.getVillagerData().withProfession(p_220388_2_);
            VillagerProfession profession = villagerData.getProfession();
            VillagerCareerChangeEvent event = CraftEventFactory.callVillagerCareerChangeEvent(entityIn, CraftVillager.nmsToBukkitProfession(profession), VillagerCareerChangeEvent.ChangeReason.EMPLOYED);
            if (!event.isCancelled()) {
                VillagerData newData = entityIn.getVillagerData().withProfession(CraftVillager.bukkitToNmsProfession(event.getProfession()));
                entityIn.setVillagerData(newData);
                entityIn.resetBrain(worldIn);
            }
        });
    });
}
Also used : GlobalPos(net.minecraft.util.math.GlobalPos) VillagerProfession(net.minecraft.entity.merchant.villager.VillagerProfession) VillagerCareerChangeEvent(org.bukkit.event.entity.VillagerCareerChangeEvent) VillagerData(net.minecraft.entity.merchant.villager.VillagerData) MinecraftServer(net.minecraft.server.MinecraftServer) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 2 with VillagerProfession

use of net.minecraft.entity.merchant.villager.VillagerProfession in project Arclight by IzzelAliz.

the class BukkitRegistry method loadVillagerProfessions.

private static void loadVillagerProfessions() {
    int i = Villager.Profession.values().length;
    List<Villager.Profession> newTypes = new ArrayList<>();
    Field key = Arrays.stream(Villager.Profession.class.getDeclaredFields()).filter(it -> it.getName().equals("key")).findAny().orElse(null);
    long keyOffset = Unsafe.objectFieldOffset(key);
    for (VillagerProfession villagerProfession : ForgeRegistries.PROFESSIONS) {
        String name = ResourceLocationUtil.standardize(villagerProfession.getRegistryName());
        Villager.Profession profession;
        try {
            profession = Villager.Profession.valueOf(name);
        } catch (Throwable t) {
            profession = null;
        }
        if (profession == null) {
            profession = EnumHelper.makeEnum(Villager.Profession.class, name, i++, ImmutableList.of(), ImmutableList.of());
            newTypes.add(profession);
            Unsafe.putObject(profession, keyOffset, CraftNamespacedKey.fromMinecraft(villagerProfession.getRegistryName()));
            ArclightMod.LOGGER.debug("Registered {} as villager profession {}", villagerProfession.getRegistryName(), profession);
        }
    }
    EnumHelper.addEnums(Villager.Profession.class, newTypes);
    ArclightMod.LOGGER.info("registry.villager-profession", newTypes.size());
}
Also used : Field(java.lang.reflect.Field) VillagerProfession(net.minecraft.entity.merchant.villager.VillagerProfession) VillagerProfession(net.minecraft.entity.merchant.villager.VillagerProfession) ArrayList(java.util.ArrayList) Villager(org.bukkit.entity.Villager)

Example 3 with VillagerProfession

use of net.minecraft.entity.merchant.villager.VillagerProfession in project Werewolves by TeamLapen.

the class ModVillage method registerProfessions.

static void registerProfessions(IForgeRegistry<VillagerProfession> registry) {
    VillagerProfession werewolf_expert = new FactionVillagerProfession("werewolf_expert", werewolf_faction, ImmutableSet.of(), ImmutableSet.of(), null) {

        @Override
        public IFaction<?> getFaction() {
            return WReference.WEREWOLF_FACTION;
        }
    }.setRegistryName(REFERENCE.MODID, "werewolf_expert");
    registry.register(werewolf_expert);
    VillagerTrades.TRADES.computeIfAbsent(werewolf_expert, trades -> new Int2ObjectOpenHashMap<>()).putAll(getWerewolfTrades());
}
Also used : WReference(de.teamlapen.werewolves.util.WReference) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) Arrays(java.util.Arrays) ImmutableSet(com.google.common.collect.ImmutableSet) FactionVillagerProfession(de.teamlapen.vampirism.entity.FactionVillagerProfession) ImmutableMap(com.google.common.collect.ImmutableMap) UtilLib.getNull(de.teamlapen.lib.lib.util.UtilLib.getNull) Set(java.util.Set) IForgeRegistry(net.minecraftforge.registries.IForgeRegistry) PointOfInterestType(net.minecraft.village.PointOfInterestType) VillagerTrades(net.minecraft.entity.merchant.villager.VillagerTrades) VillagerProfession(net.minecraft.entity.merchant.villager.VillagerProfession) Block(net.minecraft.block.Block) ObjectHolder(net.minecraftforge.registries.ObjectHolder) Map(java.util.Map) REFERENCE(de.teamlapen.werewolves.util.REFERENCE) BlockState(net.minecraft.block.BlockState) IFaction(de.teamlapen.vampirism.api.entity.factions.IFaction) FactionPointOfInterestType(de.teamlapen.vampirism.world.FactionPointOfInterestType) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) FactionVillagerProfession(de.teamlapen.vampirism.entity.FactionVillagerProfession) VillagerProfession(net.minecraft.entity.merchant.villager.VillagerProfession) FactionVillagerProfession(de.teamlapen.vampirism.entity.FactionVillagerProfession) IFaction(de.teamlapen.vampirism.api.entity.factions.IFaction)

Aggregations

VillagerProfession (net.minecraft.entity.merchant.villager.VillagerProfession)3 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 UtilLib.getNull (de.teamlapen.lib.lib.util.UtilLib.getNull)1 IFaction (de.teamlapen.vampirism.api.entity.factions.IFaction)1 FactionVillagerProfession (de.teamlapen.vampirism.entity.FactionVillagerProfession)1 FactionPointOfInterestType (de.teamlapen.vampirism.world.FactionPointOfInterestType)1 REFERENCE (de.teamlapen.werewolves.util.REFERENCE)1 WReference (de.teamlapen.werewolves.util.WReference)1 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Map (java.util.Map)1 Set (java.util.Set)1 Block (net.minecraft.block.Block)1 BlockState (net.minecraft.block.BlockState)1 VillagerData (net.minecraft.entity.merchant.villager.VillagerData)1 VillagerTrades (net.minecraft.entity.merchant.villager.VillagerTrades)1 MinecraftServer (net.minecraft.server.MinecraftServer)1