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();
}
}
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);
});
}
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;
}
}
}
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;
}
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());
}
}
}
Aggregations