use of org.spongepowered.api.event.block.CollideBlockEvent in project SpongeCommon by SpongePowered.
the class SpongeCommonEventFactory method handleCollideBlockEvent.
public static boolean handleCollideBlockEvent(Block block, net.minecraft.world.World world, BlockPos pos, IBlockState state, net.minecraft.entity.Entity entity, Direction direction) {
if (pos.getY() <= 0) {
return false;
}
final PhaseTracker phaseTracker = PhaseTracker.getInstance();
try (StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
Sponge.getCauseStackManager().pushCause(entity);
if (!(entity instanceof EntityPlayer)) {
IMixinEntity spongeEntity = (IMixinEntity) entity;
Optional<User> user = spongeEntity.getCreatorUser();
if (user.isPresent()) {
Sponge.getCauseStackManager().addContext(EventContextKeys.OWNER, user.get());
}
}
// TODO: Add target side support
CollideBlockEvent event = SpongeEventFactory.createCollideBlockEvent(Sponge.getCauseStackManager().getCurrentCause(), (BlockState) state, new Location<>((World) world, VecHelper.toVector3d(pos)), direction);
boolean cancelled = SpongeImpl.postEvent(event);
if (!cancelled) {
IMixinEntity spongeEntity = (IMixinEntity) entity;
if (!pos.equals(spongeEntity.getLastCollidedBlockPos())) {
final PhaseData peek = phaseTracker.getCurrentPhaseData();
final Optional<User> notifier = peek.context.getNotifier();
if (notifier.isPresent()) {
IMixinChunk spongeChunk = (IMixinChunk) world.getChunkFromBlockCoords(pos);
spongeChunk.addTrackedBlockPosition(block, pos, notifier.get(), PlayerTracker.Type.NOTIFIER);
}
}
}
return cancelled;
}
}
Aggregations