Search in sources :

Example 1 with FallingBlock

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();
    }
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) FallingBlock(net.minecraft.world.level.block.FallingBlock) ConstructEntityEvent(org.spongepowered.api.event.entity.ConstructEntityEvent) Vector3d(org.spongepowered.math.vector.Vector3d) CauseStackManager(org.spongepowered.api.event.CauseStackManager) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

FallingBlock (net.minecraft.world.level.block.FallingBlock)1 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)1 CauseStackManager (org.spongepowered.api.event.CauseStackManager)1 ConstructEntityEvent (org.spongepowered.api.event.entity.ConstructEntityEvent)1 Redirect (org.spongepowered.asm.mixin.injection.Redirect)1 Vector3d (org.spongepowered.math.vector.Vector3d)1