Search in sources :

Example 1 with EntityInteractEvent

use of org.bukkit.event.entity.EntityInteractEvent in project Arclight by IzzelAliz.

the class TripWireBlockMixin method updateState.

// @formatter:on
/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
private void updateState(World worldIn, BlockPos pos) {
    BlockState blockstate = worldIn.getBlockState(pos);
    boolean flag = blockstate.get(POWERED);
    boolean flag1 = false;
    List<? extends Entity> list = worldIn.getEntitiesWithinAABBExcludingEntity((Entity) null, blockstate.getShape(worldIn, pos).getBoundingBox().offset(pos));
    if (!list.isEmpty()) {
        for (Entity entity : list) {
            if (!entity.doesEntityNotTriggerPressurePlate()) {
                flag1 = true;
                break;
            }
        }
    }
    if (flag != flag1 && flag1 && (Boolean) blockstate.get(TripWireBlock.ATTACHED)) {
        org.bukkit.block.Block block = CraftBlock.at(worldIn, pos);
        boolean allowed = false;
        // If all of the events are cancelled block the tripwire trigger, else allow
        for (Object object : list) {
            if (object != null) {
                Cancellable cancellable;
                if (object instanceof PlayerEntity) {
                    cancellable = CraftEventFactory.callPlayerInteractEvent((PlayerEntity) object, Action.PHYSICAL, pos, null, null, null);
                } else if (object instanceof Entity) {
                    cancellable = new EntityInteractEvent(((EntityBridge) object).bridge$getBukkitEntity(), block);
                    Bukkit.getPluginManager().callEvent((EntityInteractEvent) cancellable);
                } else {
                    continue;
                }
                if (!cancellable.isCancelled()) {
                    allowed = true;
                    break;
                }
            }
        }
        if (!allowed) {
            return;
        }
    }
    if (flag1 != flag) {
        blockstate = blockstate.with(POWERED, flag1);
        worldIn.setBlockState(pos, blockstate, 3);
        this.notifyHook(worldIn, pos, blockstate);
    }
    if (flag1) {
        worldIn.getPendingBlockTicks().scheduleTick(new BlockPos(pos), (Block) (Object) this, this.tickRate(worldIn));
    }
}
Also used : Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) BlockState(net.minecraft.block.BlockState) Cancellable(org.bukkit.event.Cancellable) BlockPos(net.minecraft.util.math.BlockPos) EntityInteractEvent(org.bukkit.event.entity.EntityInteractEvent) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 2 with EntityInteractEvent

use of org.bukkit.event.entity.EntityInteractEvent in project Arclight by IzzelAliz.

the class PressurePlateBlockMixin method computeRedstoneStrength.

// @formatter:on
/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
protected int computeRedstoneStrength(World worldIn, BlockPos pos) {
    AxisAlignedBB axisalignedbb = PRESSURE_AABB.offset(pos);
    List<? extends Entity> list;
    switch(this.sensitivity) {
        case EVERYTHING:
            list = worldIn.getEntitiesWithinAABBExcludingEntity(null, axisalignedbb);
            break;
        case MOBS:
            list = worldIn.getEntitiesWithinAABB(LivingEntity.class, axisalignedbb);
            break;
        default:
            return 0;
    }
    if (!list.isEmpty()) {
        for (Entity entity : list) {
            if (this.getRedstoneStrength(worldIn.getBlockState(pos)) == 0) {
                Cancellable cancellable;
                if (entity instanceof PlayerEntity) {
                    cancellable = CraftEventFactory.callPlayerInteractEvent((PlayerEntity) entity, Action.PHYSICAL, pos, null, null, null);
                } else {
                    cancellable = new EntityInteractEvent(((EntityBridge) entity).bridge$getBukkitEntity(), CraftBlock.at(worldIn, pos));
                    Bukkit.getPluginManager().callEvent((EntityInteractEvent) cancellable);
                }
                // We only want to block turning the plate on if all events are cancelled
                if (cancellable.isCancelled()) {
                    continue;
                }
            }
            if (!entity.doesEntityNotTriggerPressurePlate()) {
                return 15;
            }
        }
    }
    return 0;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) LivingEntity(net.minecraft.entity.LivingEntity) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) Cancellable(org.bukkit.event.Cancellable) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) EntityInteractEvent(org.bukkit.event.entity.EntityInteractEvent) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 3 with EntityInteractEvent

use of org.bukkit.event.entity.EntityInteractEvent 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 4 with EntityInteractEvent

use of org.bukkit.event.entity.EntityInteractEvent in project Arclight by IzzelAliz.

the class BreakBlockGoalMixin method arclight$removeBlock.

// @formatter:on
@Inject(method = "tick", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;removeBlock(Lnet/minecraft/util/math/BlockPos;Z)Z"))
public void arclight$removeBlock(CallbackInfo ci, World world, BlockPos pos, BlockPos pos1) {
    EntityInteractEvent event = new EntityInteractEvent(((MobEntityBridge) this.entity).bridge$getBukkitEntity(), CraftBlock.at(world, pos1));
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        ci.cancel();
    }
}
Also used : EntityInteractEvent(org.bukkit.event.entity.EntityInteractEvent) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 5 with EntityInteractEvent

use of org.bukkit.event.entity.EntityInteractEvent in project Arclight by IzzelAliz.

the class RedstoneOreBlockMixin_1_14 method arclight$entityInteract.

@Inject(method = "onEntityWalk", cancellable = true, at = @At(value = "HEAD"))
public void arclight$entityInteract(World worldIn, BlockPos pos, Entity entityIn, CallbackInfo ci) {
    if (entityIn instanceof PlayerEntity) {
        PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(((PlayerEntity) entityIn), Action.PHYSICAL, pos, null, null, null);
        if (event.isCancelled()) {
            ci.cancel();
            return;
        }
    } else {
        EntityInteractEvent event = new EntityInteractEvent(((EntityBridge) entityIn).bridge$getBukkitEntity(), CraftBlock.at(worldIn, pos));
        Bukkit.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            ci.cancel();
            return;
        }
    }
    arclight$entity = entityIn;
}
Also used : PlayerInteractEvent(org.bukkit.event.player.PlayerInteractEvent) EntityInteractEvent(org.bukkit.event.entity.EntityInteractEvent) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

EntityInteractEvent (org.bukkit.event.entity.EntityInteractEvent)10 PlayerEntity (net.minecraft.entity.player.PlayerEntity)7 Cancellable (org.bukkit.event.Cancellable)5 Inject (org.spongepowered.asm.mixin.injection.Inject)5 EntityBridge (io.izzel.arclight.common.bridge.entity.EntityBridge)4 Entity (net.minecraft.entity.Entity)4 Overwrite (org.spongepowered.asm.mixin.Overwrite)3 BlockState (net.minecraft.block.BlockState)2 CraftBlock (org.bukkit.craftbukkit.v.block.CraftBlock)2 PlayerInteractEvent (org.bukkit.event.player.PlayerInteractEvent)2 ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)1 AbstractButtonBlock (net.minecraft.block.AbstractButtonBlock)1 Block (net.minecraft.block.Block)1 DoorBlock (net.minecraft.block.DoorBlock)1 LivingEntity (net.minecraft.entity.LivingEntity)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 BlockPos (net.minecraft.util.math.BlockPos)1 GlobalPos (net.minecraft.util.math.GlobalPos)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1 Block (org.bukkit.block.Block)1