use of org.spongepowered.api.world.server.ServerWorld in project SpongeCommon by SpongePowered.
the class VillagerMixin method impl$callPreSleepingEvent.
@Inject(method = "startSleeping", at = @At("HEAD"), cancellable = true)
private void impl$callPreSleepingEvent(BlockPos param0, CallbackInfo ci) {
final Cause currentCause = Sponge.server().causeStackManager().currentCause();
final BlockSnapshot snapshot = ((ServerWorld) this.level).createSnapshot(param0.getX(), param0.getY(), param0.getZ());
if (Sponge.eventManager().post(SpongeEventFactory.createSleepingEventPre(currentCause, snapshot, (Living) this))) {
ci.cancel();
}
}
use of org.spongepowered.api.world.server.ServerWorld in project SpongeCommon by SpongePowered.
the class PlayerMixin method impl$postSleepingEvent.
@Redirect(method = "tick()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;isSleeping()Z"))
private boolean impl$postSleepingEvent(final net.minecraft.world.entity.player.Player self) {
if (self.isSleeping()) {
if (!((LevelBridge) this.level).bridge$isFake()) {
final CauseStackManager csm = PhaseTracker.getCauseStackManager();
csm.pushCause(this);
final BlockPos bedLocation = this.shadow$getSleepingPos().get();
final BlockSnapshot snapshot = ((ServerWorld) this.level).createSnapshot(bedLocation.getX(), bedLocation.getY(), bedLocation.getZ());
SpongeCommon.post(SpongeEventFactory.createSleepingEventTick(csm.currentCause(), snapshot, (Living) this));
csm.popCause();
}
return true;
}
return false;
}
use of org.spongepowered.api.world.server.ServerWorld in project SpongeCommon by SpongePowered.
the class FireworkRocketItemMixin method impl$throwConstructPreEvent.
/**
* Private method for bridging the duplicate between
* {@link #spongeImpl$ThrowPreBeforeSpawning(World, PlayerEntity, Hand, CallbackInfoReturnable, ItemStack)} and
* {@link #spongeImpl$ThrowPrimeEventsIfCancelled(ItemUseContext, CallbackInfoReturnable)}
* since both follow the same logic, but differ in how they are called.
*
* @param world The world
* @param player The player
* @param usedItem The used item
* @return True if the event is cancelled and the callback needs to be cancelled
*/
private boolean impl$throwConstructPreEvent(final Level world, final net.minecraft.world.entity.player.Player player, final ItemStack usedItem) {
if (ShouldFire.CONSTRUCT_ENTITY_EVENT_PRE && !((LevelBridge) world).bridge$isFake()) {
try (final CauseStackManager.StackFrame frame = PhaseTracker.getCauseStackManager().pushCauseFrame()) {
frame.addContext(EventContextKeys.USED_ITEM, ItemStackUtil.snapshotOf(usedItem));
frame.addContext(EventContextKeys.PROJECTILE_SOURCE, (ProjectileSource) player);
frame.pushCause(player);
final ConstructEntityEvent.Pre event = SpongeEventFactory.createConstructEntityEventPre(frame.currentCause(), ServerLocation.of((ServerWorld) world, player.getX(), player.getY(), player.getZ()), new Vector3d(0, 0, 0), EntityTypes.FIREWORK_ROCKET.get());
return SpongeCommon.post(event);
}
}
return false;
}
Aggregations