Search in sources :

Example 1 with GlobalPos

use of net.minecraft.util.math.GlobalPos in project Arclight by IzzelAliz.

the class InteractWithDoorTaskMixin method func_220434_a.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
private void func_220434_a(ServerWorld serverWorld, List<BlockPos> blockPosList, Set<BlockPos> blockPosSet, int i, LivingEntity livingEntity, Brain<?> brain) {
    blockPosSet.forEach((blockPos) -> {
        int j = blockPosList.indexOf(blockPos);
        BlockState blockstate = serverWorld.getBlockState(blockPos);
        Block block = blockstate.getBlock();
        if (BlockTags.WOODEN_DOORS.contains(block) && block instanceof DoorBlock) {
            boolean flag = j >= i;
            // CraftBukkit start - entities opening doors
            EntityInteractEvent event = new EntityInteractEvent(((LivingEntityBridge) livingEntity).bridge$getBukkitEntity(), CraftBlock.at(livingEntity.world, blockPos));
            Bukkit.getPluginManager().callEvent(event);
            if (event.isCancelled()) {
                return;
            }
            // CaftBukkit end
            ((DoorBlock) block).toggleDoor(serverWorld, blockPos, flag);
            GlobalPos globalpos = GlobalPos.of(serverWorld.getDimension().getType(), blockPos);
            if (!brain.getMemory(MemoryModuleType.field_225462_q).isPresent() && flag) {
                brain.setMemory(MemoryModuleType.field_225462_q, Sets.newHashSet(globalpos));
            } else {
                brain.getMemory(MemoryModuleType.field_225462_q).ifPresent((globalPosSet) -> {
                    if (flag) {
                        globalPosSet.add(globalpos);
                    } else {
                        globalPosSet.remove(globalpos);
                    }
                });
            }
        }
    });
    InteractWithDoorTask.func_225449_a(serverWorld, blockPosList, i, livingEntity, brain);
}
Also used : GlobalPos(net.minecraft.util.math.GlobalPos) BlockState(net.minecraft.block.BlockState) DoorBlock(net.minecraft.block.DoorBlock) Block(net.minecraft.block.Block) CraftBlock(org.bukkit.craftbukkit.v.block.CraftBlock) EntityInteractEvent(org.bukkit.event.entity.EntityInteractEvent) DoorBlock(net.minecraft.block.DoorBlock) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 2 with GlobalPos

use of net.minecraft.util.math.GlobalPos 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)

Aggregations

GlobalPos (net.minecraft.util.math.GlobalPos)2 Overwrite (org.spongepowered.asm.mixin.Overwrite)2 Block (net.minecraft.block.Block)1 BlockState (net.minecraft.block.BlockState)1 DoorBlock (net.minecraft.block.DoorBlock)1 VillagerData (net.minecraft.entity.merchant.villager.VillagerData)1 VillagerProfession (net.minecraft.entity.merchant.villager.VillagerProfession)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 CraftBlock (org.bukkit.craftbukkit.v.block.CraftBlock)1 EntityInteractEvent (org.bukkit.event.entity.EntityInteractEvent)1 VillagerCareerChangeEvent (org.bukkit.event.entity.VillagerCareerChangeEvent)1