Search in sources :

Example 61 with BlockSnapshot

use of org.spongepowered.api.block.BlockSnapshot 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)

Example 62 with BlockSnapshot

use of org.spongepowered.api.block.BlockSnapshot in project SpongeCommon by SpongePowered.

the class InteractionPacketState method getFrameModifier.

@Override
public BiConsumer<CauseStackManager.StackFrame, InteractionPacketContext> getFrameModifier() {
    return super.getFrameModifier().andThen((frame, context) -> {
        final ItemStack usedStack = context.getItemUsed();
        final HandType usedHand = context.getHandUsed();
        final ItemStackSnapshot usedSnapshot = ItemStackUtil.snapshotOf(usedStack);
        final BlockSnapshot targetBlock = context.getTargetBlock();
        frame.addContext(EventContextKeys.USED_ITEM, usedSnapshot);
        frame.addContext(EventContextKeys.USED_HAND, usedHand);
        frame.addContext(EventContextKeys.BLOCK_HIT, targetBlock);
    });
}
Also used : HandType(org.spongepowered.api.data.type.HandType) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Example 63 with BlockSnapshot

use of org.spongepowered.api.block.BlockSnapshot in project SpongeCommon by SpongePowered.

the class ServerPlayerMixin method impl$onReturnSleep.

@Inject(method = "startSleepInBed", at = @At(value = "RETURN"), cancellable = true)
private void impl$onReturnSleep(final BlockPos param0, final CallbackInfoReturnable<Either<Player.BedSleepingProblem, Unit>> cir) {
    final Either<Player.BedSleepingProblem, Unit> returnValue = cir.getReturnValue();
    if (returnValue.left().isPresent()) {
        switch(returnValue.left().get()) {
            case NOT_POSSIBLE_HERE:
            case TOO_FAR_AWAY:
            case NOT_POSSIBLE_NOW:
            case OBSTRUCTED:
            case NOT_SAFE:
                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.createSleepingEventFailed(currentCause, snapshot, (Living) this))) {
                    final Either<Player.BedSleepingProblem, Unit> var5 = super.shadow$startSleepInBed(param0).ifRight((param0x) -> {
                        this.shadow$awardStat(Stats.SLEEP_IN_BED);
                        CriteriaTriggers.SLEPT_IN_BED.trigger((net.minecraft.server.level.ServerPlayer) (Object) this);
                    });
                    ((ServerLevel) this.level).updateSleepingPlayerList();
                    cir.setReturnValue(var5);
                }
                break;
            case // ignore
            OTHER_PROBLEM:
                break;
        }
    }
}
Also used : ServerWorld(org.spongepowered.api.world.server.ServerWorld) ServerLevel(net.minecraft.server.level.ServerLevel) Living(org.spongepowered.api.entity.living.Living) Cause(org.spongepowered.api.event.Cause) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Unit(net.minecraft.util.Unit) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 64 with BlockSnapshot

use of org.spongepowered.api.block.BlockSnapshot in project TriggerReactor by wysohn.

the class ClickTriggerManager method handleClick.

private void handleClick(InteractBlockEvent e) {
    Player player = e.getCause().first(Player.class).orElse(null);
    BlockSnapshot clicked = e.getTargetBlock();
    Location<World> loc = clicked.getLocation().orElse(null);
    if (loc == null)
        return;
    ClickTrigger trigger = getTriggerForLocation(loc);
    if (trigger == null)
        return;
    Map<String, Object> varMap = new HashMap<>();
    varMap.put("player", player);
    varMap.put("block", clicked);
    varMap.put("item", player.getItemInHand(HandTypes.MAIN_HAND).orElse(ItemStack.of(ItemTypes.AIR, 1)));
    if (e instanceof InteractBlockEvent.Primary.MainHand)
        varMap.put("click", "left");
    else if (e instanceof InteractBlockEvent.Secondary.MainHand)
        varMap.put("click", "right");
    else
        varMap.put("click", "unknown");
    trigger.activate(e, varMap);
    return;
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) HashMap(java.util.HashMap) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) World(org.spongepowered.api.world.World) InteractBlockEvent(org.spongepowered.api.event.block.InteractBlockEvent)

Example 65 with BlockSnapshot

use of org.spongepowered.api.block.BlockSnapshot in project Skree by Skelril.

the class AntiJumpListener method onBlockPlace.

@Listener(order = Order.POST)
@IsCancelled(value = Tristate.TRUE)
public void onBlockPlace(ChangeBlockEvent.Place event, @Root Player player) {
    final Location<World> playerLoc = player.getLocation();
    for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
        Optional<Location<World>> optLoc = transaction.getOriginal().getLocation();
        if (!optLoc.isPresent()) {
            continue;
        }
        Location<World> blockLoc = optLoc.get();
        final int blockY = blockLoc.getBlockY();
        if (Math.abs(player.getVelocity().getY()) > UPWARDS_VELOCITY && playerLoc.getY() > blockY) {
            Task.builder().execute(() -> {
                Vector3d position = player.getLocation().getPosition();
                if (position.getY() >= (blockY + LEAP_DISTANCE)) {
                    if (playerLoc.getPosition().distanceSquared(blockLoc.getPosition()) > Math.pow(RADIUS, 2)) {
                        return;
                    }
                    player.sendMessage(Text.of(TextColors.RED, "Hack jumping detected."));
                    player.setLocation(playerLoc.setPosition(new Vector3d(position.getX(), blockY, position.getZ())));
                }
            }).delayTicks(4).submit(SkreePlugin.inst());
        }
    }
}
Also used : Vector3d(com.flowpowered.math.vector.Vector3d) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener) IsCancelled(org.spongepowered.api.event.filter.IsCancelled)

Aggregations

BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)150 World (org.spongepowered.api.world.World)67 Listener (org.spongepowered.api.event.Listener)66 Location (org.spongepowered.api.world.Location)26 BlockState (org.spongepowered.api.block.BlockState)22 Entity (org.spongepowered.api.entity.Entity)21 BlockPos (net.minecraft.util.math.BlockPos)20 CauseStackManager (org.spongepowered.api.event.CauseStackManager)19 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)18 IBlockState (net.minecraft.block.state.IBlockState)18 Transaction (org.spongepowered.api.data.Transaction)18 BlockType (org.spongepowered.api.block.BlockType)15 Player (org.spongepowered.api.entity.living.player.Player)15 Direction (org.spongepowered.api.util.Direction)15 ChangeBlockEvent (org.spongepowered.api.event.block.ChangeBlockEvent)14 SpongeBlockSnapshot (org.spongepowered.common.block.SpongeBlockSnapshot)14 Vector3d (com.flowpowered.math.vector.Vector3d)13 ArrayList (java.util.ArrayList)13 User (org.spongepowered.api.entity.living.player.User)11 ItemStack (org.spongepowered.api.item.inventory.ItemStack)11