use of net.minecraft.world.level.block.FallingBlock in project SpongeCommon by SpongePowered.
the class FallingBlockMixin method impl$checkFallable.
@Redirect(method = "tick(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/core/BlockPos;Ljava/util/Random;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/core/BlockPos;getY()I"))
public int impl$checkFallable(final BlockPos pos, final BlockState state, final ServerLevel world, final BlockPos samePos, final Random random, final CallbackInfo ci) {
if (pos.getY() < 0) {
return pos.getY();
}
if (!ShouldFire.CONSTRUCT_ENTITY_EVENT_PRE) {
return pos.getY();
}
final EntityType<org.spongepowered.api.entity.FallingBlock> fallingBlock = EntityTypes.FALLING_BLOCK.get();
final org.spongepowered.api.world.server.ServerWorld spongeWorld = (org.spongepowered.api.world.server.ServerWorld) world;
final BlockSnapshot snapshot = spongeWorld.createSnapshot(pos.getX(), pos.getY(), pos.getZ());
try (final CauseStackManager.StackFrame frame = PhaseTracker.getCauseStackManager().pushCauseFrame()) {
frame.pushCause(snapshot);
frame.addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.FALLING_BLOCK);
final ConstructEntityEvent.Pre event = SpongeEventFactory.createConstructEntityEventPre(frame.currentCause(), ServerLocation.of((org.spongepowered.api.world.server.ServerWorld) world, pos.getX() + 0.5D, pos.getY(), pos.getZ() + 0.5D), new Vector3d(0, 0, 0), fallingBlock);
if (SpongeCommon.post(event)) {
return -1;
}
return pos.getY();
}
}
Aggregations