Search in sources :

Example 6 with BlockSnapshot

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

the class CursedMineListener method onBlockPlace.

@Listener
public void onBlockPlace(ChangeBlockEvent.Place event, @Named(NamedCause.SOURCE) Player player) {
    Optional<CursedMineInstance> optInst = manager.getApplicableZone(player);
    if (!optInst.isPresent()) {
        return;
    }
    for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
        BlockType originalType = transaction.getFinal().getState().getType();
        BlockType finalType = transaction.getFinal().getState().getType();
        if (isRedstoneTransition(originalType, finalType)) {
            continue;
        }
        event.setCancelled(true);
        break;
    }
}
Also used : BlockType(org.spongepowered.api.block.BlockType) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Listener(org.spongepowered.api.event.Listener)

Example 7 with BlockSnapshot

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

the class CursedMineListener method onItemDrop.

@Listener
public void onItemDrop(DropItemEvent.Destruct event, @Named(NamedCause.SOURCE) BlockSpawnCause spawnCause, @Named(NamedCause.NOTIFIER) Player player) {
    if (!Probability.getChance(4)) {
        return;
    }
    BlockSnapshot blockSnapshot = spawnCause.getBlockSnapshot();
    Optional<Location<World>> optLocation = blockSnapshot.getLocation();
    if (!optLocation.isPresent()) {
        return;
    }
    Location<World> loc = optLocation.get();
    Optional<CursedMineInstance> optInst = manager.getApplicableZone(loc);
    if (!optInst.isPresent()) {
        return;
    }
    CursedMineInstance inst = optInst.get();
    if (!inst.hasrecordForPlayerAt(player, loc)) {
        return;
    }
    List<ItemStackSnapshot> itemStacks = new ArrayList<>();
    Iterator<Entity> entityIterator = event.getEntities().iterator();
    while (entityIterator.hasNext()) {
        Entity entity = entityIterator.next();
        if (entity instanceof Item) {
            ItemStackSnapshot snapshot = ((Item) entity).item().get();
            itemStacks.add(snapshot);
            entityIterator.remove();
        }
    }
    int times = 1;
    Optional<ModifierService> optService = Sponge.getServiceManager().provide(ModifierService.class);
    if (optService.isPresent()) {
        ModifierService service = optService.get();
        if (service.isActive(Modifiers.DOUBLE_CURSED_ORES)) {
            times *= 2;
        }
    }
    for (ItemStackSnapshot stackSnapshot : itemStacks) {
        int quantity = Math.min(stackSnapshot.getCount() * Probability.getRangedRandom(4, 8), stackSnapshot.getType().getMaxStackQuantity());
        for (int i = 0; i < times; ++i) {
            ItemStack stack = stackSnapshot.createStack();
            stack.setQuantity(quantity);
            player.getInventory().offer(stack);
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) ModifierService(com.skelril.skree.service.ModifierService) World(org.spongepowered.api.world.World) Item(org.spongepowered.api.entity.Item) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Example 8 with BlockSnapshot

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

the class WildernessWorldWrapper method onBlockPlace.

@Listener
public void onBlockPlace(ChangeBlockEvent.Place event, @Named(NamedCause.SOURCE) Player player) {
    for (Transaction<BlockSnapshot> block : event.getTransactions()) {
        Optional<Location<World>> optLoc = block.getFinal().getLocation();
        if (!optLoc.isPresent() || !isApplicable(optLoc.get())) {
            continue;
        }
        Location<World> loc = optLoc.get();
        BlockState finalState = block.getFinal().getState();
        if (config.getDropAmplificationConfig().amplifies(finalState)) {
            // Allow creative mode players to still place blocks
            if (player.getGameModeData().type().get().equals(GameModes.CREATIVE)) {
                continue;
            }
            BlockType originalType = block.getOriginal().getState().getType();
            if (ore().contains(originalType)) {
                continue;
            }
            try {
                Vector3d origin = loc.getPosition();
                World world = loc.getExtent();
                for (int i = 0; i < 40; ++i) {
                    ParticleEffect effect = ParticleEffect.builder().type(ParticleTypes.MAGIC_CRITICAL_HIT).velocity(new Vector3d(Probability.getRangedRandom(-1, 1), Probability.getRangedRandom(-.7, .7), Probability.getRangedRandom(-1, 1))).quantity(1).build();
                    world.spawnParticles(effect, origin.add(.5, .5, .5));
                }
            } catch (Exception ex) {
                player.sendMessage(/* ChatTypes.SYSTEM, */
                Text.of(TextColors.RED, "You find yourself unable to place that block."));
            }
            block.setValid(false);
        }
    }
}
Also used : ParticleEffect(org.spongepowered.api.effect.particle.ParticleEffect) BlockState(org.spongepowered.api.block.BlockState) BlockType(org.spongepowered.api.block.BlockType) 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)

Example 9 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)

Example 10 with BlockSnapshot

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

the class MixinMinecraftServer method onServerTickEnd.

@Inject(method = "tick", at = @At(value = "RETURN"))
public void onServerTickEnd(CallbackInfo ci) {
    int lastAnimTick = SpongeCommonEventFactory.lastAnimationPacketTick;
    int lastPrimaryTick = SpongeCommonEventFactory.lastPrimaryPacketTick;
    int lastSecondaryTick = SpongeCommonEventFactory.lastSecondaryPacketTick;
    if (SpongeCommonEventFactory.lastAnimationPlayer != null) {
        EntityPlayerMP player = SpongeCommonEventFactory.lastAnimationPlayer.get();
        if (player != null && lastAnimTick != lastPrimaryTick && lastAnimTick != lastSecondaryTick && lastAnimTick != 0 && lastAnimTick - lastPrimaryTick > 3 && lastAnimTick - lastSecondaryTick > 3) {
            BlockSnapshot blockSnapshot = BlockSnapshot.NONE;
            EnumFacing side = null;
            final RayTraceResult result = SpongeImplHooks.rayTraceEyes(player, SpongeImplHooks.getBlockReachDistance(player) + 1);
            // Hit non-air block
            if (result != null && result.getBlockPos() != null) {
                blockSnapshot = new Location<>((World) player.world, VecHelper.toVector3d(result.getBlockPos())).createSnapshot();
                side = result.sideHit;
            }
            Sponge.getCauseStackManager().pushCause(player);
            if (!player.getHeldItemMainhand().isEmpty()) {
                if (SpongeCommonEventFactory.callInteractItemEventPrimary(player, player.getHeldItemMainhand(), EnumHand.MAIN_HAND, result == null ? null : VecHelper.toVector3d(result.hitVec), blockSnapshot).isCancelled()) {
                    SpongeCommonEventFactory.lastAnimationPacketTick = 0;
                    Sponge.getCauseStackManager().popCause();
                    return;
                }
            }
            if (side != null) {
                SpongeCommonEventFactory.callInteractBlockEventPrimary(player, blockSnapshot, EnumHand.MAIN_HAND, side, VecHelper.toVector3d(result.hitVec));
            } else {
                SpongeCommonEventFactory.callInteractBlockEventPrimary(player, EnumHand.MAIN_HAND, result == null ? null : VecHelper.toVector3d(result.hitVec));
            }
            Sponge.getCauseStackManager().popCause();
        }
    }
    SpongeCommonEventFactory.lastAnimationPacketTick = 0;
    TimingsManager.FULL_SERVER_TICK.stopTiming();
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) RayTraceResult(net.minecraft.util.math.RayTraceResult) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) Location(org.spongepowered.api.world.Location) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)144 World (org.spongepowered.api.world.World)64 Listener (org.spongepowered.api.event.Listener)61 Location (org.spongepowered.api.world.Location)27 BlockState (org.spongepowered.api.block.BlockState)21 BlockPos (net.minecraft.util.math.BlockPos)20 Entity (org.spongepowered.api.entity.Entity)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)17 BlockType (org.spongepowered.api.block.BlockType)15 Direction (org.spongepowered.api.util.Direction)15 SpongeBlockSnapshot (org.spongepowered.common.block.SpongeBlockSnapshot)14 Vector3d (com.flowpowered.math.vector.Vector3d)13 ArrayList (java.util.ArrayList)13 ChangeBlockEvent (org.spongepowered.api.event.block.ChangeBlockEvent)13 Player (org.spongepowered.api.entity.living.player.Player)12 User (org.spongepowered.api.entity.living.player.User)11 LocatableBlock (org.spongepowered.api.world.LocatableBlock)11