Search in sources :

Example 1 with VillagerData

use of net.minecraft.entity.merchant.villager.VillagerData 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 VillagerData

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

the class ChangeJobTaskMixin method arclight$careerChangeHook.

@Redirect(method = "startExecuting", 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) {
    VillagerCareerChangeEvent event = CraftEventFactory.callVillagerCareerChangeEvent(villagerEntity, CraftVillager.nmsToBukkitProfession(VillagerProfession.NONE), // 这里本来是 EMPLOYED 但是我怀疑他打错了
    VillagerCareerChangeEvent.ChangeReason.LOSING_JOB);
    if (!event.isCancelled()) {
        VillagerData newData = villagerEntity.getVillagerData().withProfession(CraftVillager.bukkitToNmsProfession(event.getProfession()));
        villagerEntity.setVillagerData(newData);
    }
}
Also used : VillagerCareerChangeEvent(org.bukkit.event.entity.VillagerCareerChangeEvent) VillagerData(net.minecraft.entity.merchant.villager.VillagerData) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

VillagerData (net.minecraft.entity.merchant.villager.VillagerData)2 VillagerCareerChangeEvent (org.bukkit.event.entity.VillagerCareerChangeEvent)2 VillagerProfession (net.minecraft.entity.merchant.villager.VillagerProfession)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 GlobalPos (net.minecraft.util.math.GlobalPos)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1 Redirect (org.spongepowered.asm.mixin.injection.Redirect)1