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