Search in sources :

Example 76 with BlockType

use of org.spongepowered.api.block.BlockType in project LanternServer by LanternPowered.

the class PlayerInteractionHandler method handleBlockPlacing.

public void handleBlockPlacing(MessagePlayInPlayerBlockPlacement message) {
    final HandType handType = message.getHandType();
    // the main hand message.
    if (handType == HandTypes.OFF_HAND) {
        return;
    }
    // Try the action of the hotbar item first
    final AbstractSlot hotbarSlot = this.player.getInventory().getHotbar().getSelectedSlot();
    final AbstractSlot offHandSlot = this.player.getInventory().getOffhand();
    // The offset can round up to 1, causing
    // an incorrect clicked block location
    final Vector3d pos2 = message.getClickOffset();
    final double dx = Math.min(pos2.getX(), 0.999);
    final double dy = Math.min(pos2.getY(), 0.999);
    final double dz = Math.min(pos2.getZ(), 0.999);
    final Location<World> clickedLocation = new Location<>(this.player.getWorld(), message.getPosition().toDouble().add(dx, dy, dz));
    final Direction face = message.getFace();
    final CauseStack causeStack = CauseStack.current();
    try (CauseStack.Frame frame = causeStack.pushCauseFrame()) {
        frame.pushCause(this.player);
        // Add context
        frame.addContext(ContextKeys.INTERACTION_FACE, face);
        frame.addContext(ContextKeys.INTERACTION_LOCATION, clickedLocation);
        frame.addContext(ContextKeys.BLOCK_LOCATION, new Location<>(clickedLocation.getExtent(), message.getPosition()));
        frame.addContext(ContextKeys.PLAYER, this.player);
        final BehaviorContextImpl context = new BehaviorContextImpl(causeStack);
        final BehaviorContext.Snapshot snapshot = context.pushSnapshot();
        if (!this.player.get(Keys.IS_SNEAKING).orElse(false)) {
            final BlockState blockState = this.player.getWorld().getBlock(message.getPosition());
            final LanternBlockType blockType = (LanternBlockType) blockState.getType();
            frame.addContext(ContextKeys.BLOCK_TYPE, blockState.getType());
            frame.addContext(ContextKeys.USED_BLOCK_STATE, blockState);
            BehaviorContext.Snapshot snapshot1 = context.pushSnapshot();
            // Try first with the main hand
            hotbarSlot.peek().ifPresent(stack -> frame.addContext(ContextKeys.USED_ITEM_STACK, stack));
            frame.addContext(ContextKeys.USED_SLOT, hotbarSlot);
            frame.addContext(ContextKeys.INTERACTION_HAND, HandTypes.MAIN_HAND);
            BehaviorResult result = context.process(blockType.getPipeline().pipeline(InteractWithBlockBehavior.class), (ctx, behavior) -> behavior.tryInteract(blockType.getPipeline(), ctx));
            if (!result.isSuccess()) {
                context.popSnapshot(snapshot1);
                snapshot1 = context.pushSnapshot();
                // Try again with the off hand
                offHandSlot.peek().ifPresent(stack -> frame.addContext(ContextKeys.USED_ITEM_STACK, stack));
                frame.addContext(ContextKeys.USED_SLOT, offHandSlot);
                frame.addContext(ContextKeys.INTERACTION_HAND, HandTypes.OFF_HAND);
                result = context.process(blockType.getPipeline().pipeline(InteractWithBlockBehavior.class), (ctx, behavior) -> behavior.tryInteract(blockType.getPipeline(), ctx));
            }
            if (result.isSuccess()) {
                snapshot1 = context.pushSnapshot();
                // We can still continue, doing other operations
                if (result == BehaviorResult.CONTINUE) {
                    handleMainHandItemInteraction(context, snapshot1);
                }
                context.accept();
                return;
            }
            context.popSnapshot(snapshot1);
            snapshot1 = context.pushSnapshot();
            if (result.isSuccess()) {
                snapshot1 = context.pushSnapshot();
                // We can still continue, doing other operations
                if (result == BehaviorResult.CONTINUE) {
                    handleOffHandItemInteraction(context, snapshot1);
                }
                context.accept();
                return;
            }
            context.popSnapshot(snapshot1);
        }
        handleItemInteraction(context, snapshot);
    }
}
Also used : MessagePlayOutEntityAnimation(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityAnimation) LanternKeys(org.lanternpowered.server.data.key.LanternKeys) Keys(org.spongepowered.api.data.key.Keys) EventContextKeys(org.spongepowered.api.event.cause.EventContextKeys) LanternBlockType(org.lanternpowered.server.block.LanternBlockType) MessagePlayInPlayerSwingArm(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInPlayerSwingArm) BehaviorContextImpl(org.lanternpowered.server.behavior.BehaviorContextImpl) Vector3d(com.flowpowered.math.vector.Vector3d) MessagePlayInOutFinishUsingItem(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutFinishUsingItem) MessagePlayInPlayerDigging(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInPlayerDigging) HandType(org.spongepowered.api.data.type.HandType) MinimumUseDurationProperty(org.lanternpowered.server.item.property.MinimumUseDurationProperty) GameModes(org.spongepowered.api.entity.living.player.gamemode.GameModes) BreakBlockBehavior(org.lanternpowered.server.block.behavior.types.BreakBlockBehavior) ItemStack(org.spongepowered.api.item.inventory.ItemStack) BehaviorContext(org.lanternpowered.server.behavior.BehaviorContext) CauseStack(org.lanternpowered.server.event.CauseStack) InteractWithItemBehavior(org.lanternpowered.server.item.behavior.types.InteractWithItemBehavior) MessagePlayOutBlockBreakAnimation(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutBlockBreakAnimation) BehaviorResult(org.lanternpowered.server.behavior.BehaviorResult) LanternWorld(org.lanternpowered.server.world.LanternWorld) InteractWithBlockBehavior(org.lanternpowered.server.block.behavior.types.InteractWithBlockBehavior) Nullable(javax.annotation.Nullable) ContextKeys(org.lanternpowered.server.behavior.ContextKeys) FinishUsingItemBehavior(org.lanternpowered.server.item.behavior.types.FinishUsingItemBehavior) Location(org.spongepowered.api.world.Location) MaximumUseDurationProperty(org.lanternpowered.server.item.property.MaximumUseDurationProperty) LanternItemType(org.lanternpowered.server.item.LanternItemType) MessagePlayInPlayerUseItem(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInPlayerUseItem) AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) BlockTypes(org.spongepowered.api.block.BlockTypes) SwingHandEntityEvent(org.lanternpowered.server.entity.event.SwingHandEntityEvent) Set(java.util.Set) LanternGame(org.lanternpowered.server.game.LanternGame) BlockState(org.spongepowered.api.block.BlockState) Objects(java.util.Objects) Direction(org.spongepowered.api.util.Direction) DualWieldProperty(org.lanternpowered.server.item.property.DualWieldProperty) Lantern(org.lanternpowered.server.game.Lantern) Vector3i(com.flowpowered.math.vector.Vector3i) World(org.spongepowered.api.world.World) BlockType(org.spongepowered.api.block.BlockType) HandTypes(org.spongepowered.api.data.type.HandTypes) Optional(java.util.Optional) MessagePlayInPlayerBlockPlacement(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInPlayerBlockPlacement) CauseStack(org.lanternpowered.server.event.CauseStack) AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) HandType(org.spongepowered.api.data.type.HandType) LanternWorld(org.lanternpowered.server.world.LanternWorld) World(org.spongepowered.api.world.World) Direction(org.spongepowered.api.util.Direction) LanternBlockType(org.lanternpowered.server.block.LanternBlockType) BehaviorContextImpl(org.lanternpowered.server.behavior.BehaviorContextImpl) BlockState(org.spongepowered.api.block.BlockState) Vector3d(com.flowpowered.math.vector.Vector3d) BehaviorResult(org.lanternpowered.server.behavior.BehaviorResult) BehaviorContext(org.lanternpowered.server.behavior.BehaviorContext) Location(org.spongepowered.api.world.Location) InteractWithBlockBehavior(org.lanternpowered.server.block.behavior.types.InteractWithBlockBehavior)

Example 77 with BlockType

use of org.spongepowered.api.block.BlockType in project LanternServer by LanternPowered.

the class LanternWorld method digBlock.

private boolean digBlock(int x, int y, int z, @Nullable GameProfile profile, @Nullable ItemStack itemStack) {
    final LanternBlockType blockType = ((LanternBlockType) getBlockType(x, y, z));
    final BehaviorPipeline<Behavior> pipeline = blockType.getPipeline();
    final CauseStack causeStack = CauseStack.current();
    try (CauseStack.Frame frame = causeStack.pushCauseFrame()) {
        frame.addContext(ContextKeys.BLOCK_LOCATION, new Location<>(this, x, y, z));
        frame.addContext(ContextKeys.BLOCK_TYPE, blockType);
        if (profile != null) {
            frame.addContext(EventContextKeys.PLAYER_SIMULATED, profile);
        }
        if (itemStack != null) {
            frame.addContext(ContextKeys.USED_ITEM_STACK, itemStack);
        }
        final BehaviorContextImpl context = new BehaviorContextImpl(causeStack);
        // Just pass an object trough to make sure that a value is present when successful
        if (context.process(pipeline.pipeline(BreakBlockBehavior.class), (ctx, behavior) -> behavior.tryBreak(pipeline, ctx)).isSuccess()) {
            context.accept();
            return true;
        }
        context.revert();
        return false;
    }
}
Also used : LanternEntity(org.lanternpowered.server.entity.LanternEntity) AnvilChunkIOService(org.lanternpowered.server.data.io.anvil.AnvilChunkIOService) WorldStorage(org.spongepowered.api.world.storage.WorldStorage) WorldConfig(org.lanternpowered.server.config.world.WorldConfig) RuleHolder(org.lanternpowered.server.world.rules.RuleHolder) SoundCategory(org.spongepowered.api.effect.sound.SoundCategory) BookView(org.spongepowered.api.text.BookView) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ChunkIOService(org.lanternpowered.server.data.io.ChunkIOService) LanternChunkManager(org.lanternpowered.server.world.chunk.LanternChunkManager) MutableBiomeVolumeWorker(org.spongepowered.api.world.extent.worker.MutableBiomeVolumeWorker) Map(java.util.Map) GameProfile(org.spongepowered.api.profile.GameProfile) VecHelper(org.lanternpowered.server.util.VecHelper) LanternSoundType(org.lanternpowered.server.effect.sound.LanternSoundType) Path(java.nio.file.Path) InteractWithBlockBehavior(org.lanternpowered.server.block.behavior.types.InteractWithBlockBehavior) MessagePlayOutParticleEffect(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutParticleEffect) RuleType(org.lanternpowered.server.world.rules.RuleType) Location(org.spongepowered.api.world.Location) AbstractViewer(org.lanternpowered.server.effect.AbstractViewer) HardnessProperty(org.spongepowered.api.data.property.block.HardnessProperty) LanternWeather(org.lanternpowered.server.world.weather.LanternWeather) Extent(org.spongepowered.api.world.extent.Extent) UnbreakableProperty(org.spongepowered.api.data.property.block.UnbreakableProperty) ArchetypeVolume(org.spongepowered.api.world.extent.ArchetypeVolume) DataContainer(org.spongepowered.api.data.DataContainer) Set(java.util.Set) Weathers(org.spongepowered.api.world.weather.Weathers) BlockAction(org.lanternpowered.server.block.action.BlockAction) BlockState(org.spongepowered.api.block.BlockState) Direction(org.spongepowered.api.util.Direction) ConstructEntityEvent(org.spongepowered.api.event.entity.ConstructEntityEvent) AbstractExtent(org.lanternpowered.server.world.extent.AbstractExtent) World(org.spongepowered.api.world.World) MessagePlayOutRecord(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutRecord) Player(org.spongepowered.api.entity.living.player.Player) EntityProtocolType(org.lanternpowered.server.network.entity.EntityProtocolType) ObservedChunkManager(org.lanternpowered.server.entity.living.player.ObservedChunkManager) BehaviorPipeline(org.lanternpowered.server.behavior.pipeline.BehaviorPipeline) ImmutableValue(org.spongepowered.api.data.value.immutable.ImmutableValue) Vector3d(com.flowpowered.math.vector.Vector3d) AABB(org.spongepowered.api.util.AABB) GameModes(org.spongepowered.api.entity.living.player.gamemode.GameModes) Supplier(java.util.function.Supplier) Key(org.spongepowered.api.data.key.Key) ArrayList(java.util.ArrayList) Vector2i(com.flowpowered.math.vector.Vector2i) LanternTitles(org.lanternpowered.server.text.title.LanternTitles) Lists(com.google.common.collect.Lists) CauseStack(org.lanternpowered.server.event.CauseStack) ExtentViewDownsize(org.lanternpowered.server.world.extent.ExtentViewDownsize) Text(org.spongepowered.api.text.Text) Nullable(javax.annotation.Nullable) ContextKeys(org.lanternpowered.server.behavior.ContextKeys) MessagePlayOutStopSounds(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutStopSounds) Context(org.spongepowered.api.service.context.Context) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) InvalidDataException(org.spongepowered.api.data.persistence.InvalidDataException) SpawnEntityEvent(org.spongepowered.api.event.entity.SpawnEntityEvent) Scoreboard(org.spongepowered.api.scoreboard.Scoreboard) IOException(java.io.IOException) DataHolder(org.spongepowered.api.data.DataHolder) Entity(org.spongepowered.api.entity.Entity) Message(org.lanternpowered.server.network.message.Message) LanternMutableBlockVolumeWorker(org.lanternpowered.server.world.extent.worker.LanternMutableBlockVolumeWorker) DataView(org.spongepowered.api.data.DataView) Vector3i(com.flowpowered.math.vector.Vector3i) PortalAgent(org.spongepowered.api.world.PortalAgent) EventContextKeys(org.spongepowered.api.event.cause.EventContextKeys) LanternBlockType(org.lanternpowered.server.block.LanternBlockType) LanternChunkPreGenerateTask(org.lanternpowered.server.world.pregen.LanternChunkPreGenerateTask) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) EntityProtocolManager(org.lanternpowered.server.network.entity.EntityProtocolManager) LanternChunkTicketManager(org.lanternpowered.server.world.chunk.LanternChunkTicketManager) SPACE_MIN(org.lanternpowered.server.world.chunk.LanternChunkLayout.SPACE_MIN) Behavior(org.lanternpowered.server.behavior.Behavior) EntitySnapshot(org.spongepowered.api.entity.EntitySnapshot) ChatType(org.spongepowered.api.text.chat.ChatType) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) BreakBlockBehavior(org.lanternpowered.server.block.behavior.types.BreakBlockBehavior) ParticleEffect(org.spongepowered.api.effect.particle.ParticleEffect) TileEntity(org.spongepowered.api.block.tileentity.TileEntity) Locale(java.util.Locale) ChunkPreGenerate(org.spongepowered.api.world.ChunkPreGenerate) Title(org.spongepowered.api.text.title.Title) MergeFunction(org.spongepowered.api.data.merge.MergeFunction) LanternChunk.fixEntityYSection(org.lanternpowered.server.world.chunk.LanternChunk.fixEntityYSection) Dimension(org.spongepowered.api.world.Dimension) MutableBlockVolumeWorker(org.spongepowered.api.world.extent.worker.MutableBlockVolumeWorker) SPACE_MAX(org.lanternpowered.server.world.chunk.LanternChunkLayout.SPACE_MAX) ImmutableSet(com.google.common.collect.ImmutableSet) User(org.spongepowered.api.entity.living.player.User) SoundType(org.spongepowered.api.effect.sound.SoundType) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ChunkLoadingTicket(org.lanternpowered.server.world.chunk.ChunkLoadingTicket) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Sponge(org.spongepowered.api.Sponge) Tuple(org.spongepowered.api.util.Tuple) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) LanternEntityType(org.lanternpowered.server.entity.LanternEntityType) LanternGame(org.lanternpowered.server.game.LanternGame) WorldGenerator(org.spongepowered.api.world.gen.WorldGenerator) Cause(org.spongepowered.api.event.cause.Cause) List(java.util.List) Lantern(org.lanternpowered.server.game.Lantern) Explosion(org.spongepowered.api.world.explosion.Explosion) Transform(org.spongepowered.api.entity.Transform) BlockType(org.spongepowered.api.block.BlockType) DataManipulator(org.spongepowered.api.data.manipulator.DataManipulator) Optional(java.util.Optional) RecordType(org.spongepowered.api.effect.sound.record.RecordType) ScheduledBlockUpdate(org.spongepowered.api.block.ScheduledBlockUpdate) LanternChatType(org.lanternpowered.server.text.chat.LanternChatType) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) ChatTypes(org.spongepowered.api.text.chat.ChatTypes) WeatherUniverse(org.lanternpowered.api.world.weather.WeatherUniverse) Keys(org.spongepowered.api.data.key.Keys) ScoreboardIO(org.lanternpowered.server.data.io.ScoreboardIO) LanternChunk(org.lanternpowered.server.world.chunk.LanternChunk) BehaviorContextImpl(org.lanternpowered.server.behavior.BehaviorContextImpl) BiomeType(org.spongepowered.api.world.biome.BiomeType) HashMap(java.util.HashMap) DataTransactionResult(org.spongepowered.api.data.DataTransactionResult) Function(java.util.function.Function) BlockChangeFlag(org.spongepowered.api.world.BlockChangeFlag) ImmutableList(com.google.common.collect.ImmutableList) EntityTypes(org.spongepowered.api.entity.EntityTypes) PlaceBlockBehavior(org.lanternpowered.server.block.behavior.types.PlaceBlockBehavior) Rule(org.lanternpowered.server.world.rules.Rule) Logger(org.slf4j.Logger) Weather(org.spongepowered.api.world.weather.Weather) Iterator(java.util.Iterator) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) BaseValue(org.spongepowered.api.data.value.BaseValue) Chunk(org.spongepowered.api.world.Chunk) Consumer(java.util.function.Consumer) LanternMutableBiomeVolumeWorker(org.lanternpowered.server.world.extent.worker.LanternMutableBiomeVolumeWorker) LanternDimensionType(org.lanternpowered.server.world.dimension.LanternDimensionType) Difficulty(org.spongepowered.api.world.difficulty.Difficulty) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer) Property(org.spongepowered.api.data.Property) IGeneratorType(org.lanternpowered.server.world.gen.IGeneratorType) EntityType(org.spongepowered.api.entity.EntityType) MessageChannel(org.spongepowered.api.text.channel.MessageChannel) Collections(java.util.Collections) CauseStack(org.lanternpowered.server.event.CauseStack) BehaviorContextImpl(org.lanternpowered.server.behavior.BehaviorContextImpl) InteractWithBlockBehavior(org.lanternpowered.server.block.behavior.types.InteractWithBlockBehavior) Behavior(org.lanternpowered.server.behavior.Behavior) BreakBlockBehavior(org.lanternpowered.server.block.behavior.types.BreakBlockBehavior) PlaceBlockBehavior(org.lanternpowered.server.block.behavior.types.PlaceBlockBehavior) LanternBlockType(org.lanternpowered.server.block.LanternBlockType)

Example 78 with BlockType

use of org.spongepowered.api.block.BlockType in project LanternServer by LanternPowered.

the class LanternWorld method interactBlock.

private boolean interactBlock(int x, int y, int z, Direction side, @Nullable GameProfile profile, @Nullable ItemStack itemStack) {
    checkNotNull(side, "side");
    final LanternBlockType blockType = ((LanternBlockType) getBlockType(x, y, z));
    final BehaviorPipeline<Behavior> pipeline = blockType.getPipeline();
    final CauseStack causeStack = CauseStack.current();
    try (CauseStack.Frame frame = causeStack.pushCauseFrame()) {
        frame.addContext(ContextKeys.INTERACTION_FACE, side);
        frame.addContext(ContextKeys.BLOCK_LOCATION, new Location<>(this, x, y, z));
        frame.addContext(ContextKeys.BLOCK_TYPE, blockType);
        if (profile != null) {
            frame.addContext(EventContextKeys.PLAYER_SIMULATED, profile);
        }
        if (itemStack != null) {
            frame.addContext(ContextKeys.USED_ITEM_STACK, itemStack);
        }
        final BehaviorContextImpl context = new BehaviorContextImpl(causeStack);
        // Just pass an object trough to make sure that a value is present when successful
        if (context.process(pipeline.pipeline(InteractWithBlockBehavior.class), (ctx, behavior) -> behavior.tryInteract(pipeline, ctx)).isSuccess()) {
            context.accept();
            return true;
        }
        context.revert();
        return false;
    }
}
Also used : LanternEntity(org.lanternpowered.server.entity.LanternEntity) AnvilChunkIOService(org.lanternpowered.server.data.io.anvil.AnvilChunkIOService) WorldStorage(org.spongepowered.api.world.storage.WorldStorage) WorldConfig(org.lanternpowered.server.config.world.WorldConfig) RuleHolder(org.lanternpowered.server.world.rules.RuleHolder) SoundCategory(org.spongepowered.api.effect.sound.SoundCategory) BookView(org.spongepowered.api.text.BookView) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ChunkIOService(org.lanternpowered.server.data.io.ChunkIOService) LanternChunkManager(org.lanternpowered.server.world.chunk.LanternChunkManager) MutableBiomeVolumeWorker(org.spongepowered.api.world.extent.worker.MutableBiomeVolumeWorker) Map(java.util.Map) GameProfile(org.spongepowered.api.profile.GameProfile) VecHelper(org.lanternpowered.server.util.VecHelper) LanternSoundType(org.lanternpowered.server.effect.sound.LanternSoundType) Path(java.nio.file.Path) InteractWithBlockBehavior(org.lanternpowered.server.block.behavior.types.InteractWithBlockBehavior) MessagePlayOutParticleEffect(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutParticleEffect) RuleType(org.lanternpowered.server.world.rules.RuleType) Location(org.spongepowered.api.world.Location) AbstractViewer(org.lanternpowered.server.effect.AbstractViewer) HardnessProperty(org.spongepowered.api.data.property.block.HardnessProperty) LanternWeather(org.lanternpowered.server.world.weather.LanternWeather) Extent(org.spongepowered.api.world.extent.Extent) UnbreakableProperty(org.spongepowered.api.data.property.block.UnbreakableProperty) ArchetypeVolume(org.spongepowered.api.world.extent.ArchetypeVolume) DataContainer(org.spongepowered.api.data.DataContainer) Set(java.util.Set) Weathers(org.spongepowered.api.world.weather.Weathers) BlockAction(org.lanternpowered.server.block.action.BlockAction) BlockState(org.spongepowered.api.block.BlockState) Direction(org.spongepowered.api.util.Direction) ConstructEntityEvent(org.spongepowered.api.event.entity.ConstructEntityEvent) AbstractExtent(org.lanternpowered.server.world.extent.AbstractExtent) World(org.spongepowered.api.world.World) MessagePlayOutRecord(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutRecord) Player(org.spongepowered.api.entity.living.player.Player) EntityProtocolType(org.lanternpowered.server.network.entity.EntityProtocolType) ObservedChunkManager(org.lanternpowered.server.entity.living.player.ObservedChunkManager) BehaviorPipeline(org.lanternpowered.server.behavior.pipeline.BehaviorPipeline) ImmutableValue(org.spongepowered.api.data.value.immutable.ImmutableValue) Vector3d(com.flowpowered.math.vector.Vector3d) AABB(org.spongepowered.api.util.AABB) GameModes(org.spongepowered.api.entity.living.player.gamemode.GameModes) Supplier(java.util.function.Supplier) Key(org.spongepowered.api.data.key.Key) ArrayList(java.util.ArrayList) Vector2i(com.flowpowered.math.vector.Vector2i) LanternTitles(org.lanternpowered.server.text.title.LanternTitles) Lists(com.google.common.collect.Lists) CauseStack(org.lanternpowered.server.event.CauseStack) ExtentViewDownsize(org.lanternpowered.server.world.extent.ExtentViewDownsize) Text(org.spongepowered.api.text.Text) Nullable(javax.annotation.Nullable) ContextKeys(org.lanternpowered.server.behavior.ContextKeys) MessagePlayOutStopSounds(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutStopSounds) Context(org.spongepowered.api.service.context.Context) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) InvalidDataException(org.spongepowered.api.data.persistence.InvalidDataException) SpawnEntityEvent(org.spongepowered.api.event.entity.SpawnEntityEvent) Scoreboard(org.spongepowered.api.scoreboard.Scoreboard) IOException(java.io.IOException) DataHolder(org.spongepowered.api.data.DataHolder) Entity(org.spongepowered.api.entity.Entity) Message(org.lanternpowered.server.network.message.Message) LanternMutableBlockVolumeWorker(org.lanternpowered.server.world.extent.worker.LanternMutableBlockVolumeWorker) DataView(org.spongepowered.api.data.DataView) Vector3i(com.flowpowered.math.vector.Vector3i) PortalAgent(org.spongepowered.api.world.PortalAgent) EventContextKeys(org.spongepowered.api.event.cause.EventContextKeys) LanternBlockType(org.lanternpowered.server.block.LanternBlockType) LanternChunkPreGenerateTask(org.lanternpowered.server.world.pregen.LanternChunkPreGenerateTask) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) EntityProtocolManager(org.lanternpowered.server.network.entity.EntityProtocolManager) LanternChunkTicketManager(org.lanternpowered.server.world.chunk.LanternChunkTicketManager) SPACE_MIN(org.lanternpowered.server.world.chunk.LanternChunkLayout.SPACE_MIN) Behavior(org.lanternpowered.server.behavior.Behavior) EntitySnapshot(org.spongepowered.api.entity.EntitySnapshot) ChatType(org.spongepowered.api.text.chat.ChatType) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) BreakBlockBehavior(org.lanternpowered.server.block.behavior.types.BreakBlockBehavior) ParticleEffect(org.spongepowered.api.effect.particle.ParticleEffect) TileEntity(org.spongepowered.api.block.tileentity.TileEntity) Locale(java.util.Locale) ChunkPreGenerate(org.spongepowered.api.world.ChunkPreGenerate) Title(org.spongepowered.api.text.title.Title) MergeFunction(org.spongepowered.api.data.merge.MergeFunction) LanternChunk.fixEntityYSection(org.lanternpowered.server.world.chunk.LanternChunk.fixEntityYSection) Dimension(org.spongepowered.api.world.Dimension) MutableBlockVolumeWorker(org.spongepowered.api.world.extent.worker.MutableBlockVolumeWorker) SPACE_MAX(org.lanternpowered.server.world.chunk.LanternChunkLayout.SPACE_MAX) ImmutableSet(com.google.common.collect.ImmutableSet) User(org.spongepowered.api.entity.living.player.User) SoundType(org.spongepowered.api.effect.sound.SoundType) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ChunkLoadingTicket(org.lanternpowered.server.world.chunk.ChunkLoadingTicket) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Sponge(org.spongepowered.api.Sponge) Tuple(org.spongepowered.api.util.Tuple) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) LanternEntityType(org.lanternpowered.server.entity.LanternEntityType) LanternGame(org.lanternpowered.server.game.LanternGame) WorldGenerator(org.spongepowered.api.world.gen.WorldGenerator) Cause(org.spongepowered.api.event.cause.Cause) List(java.util.List) Lantern(org.lanternpowered.server.game.Lantern) Explosion(org.spongepowered.api.world.explosion.Explosion) Transform(org.spongepowered.api.entity.Transform) BlockType(org.spongepowered.api.block.BlockType) DataManipulator(org.spongepowered.api.data.manipulator.DataManipulator) Optional(java.util.Optional) RecordType(org.spongepowered.api.effect.sound.record.RecordType) ScheduledBlockUpdate(org.spongepowered.api.block.ScheduledBlockUpdate) LanternChatType(org.lanternpowered.server.text.chat.LanternChatType) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) ChatTypes(org.spongepowered.api.text.chat.ChatTypes) WeatherUniverse(org.lanternpowered.api.world.weather.WeatherUniverse) Keys(org.spongepowered.api.data.key.Keys) ScoreboardIO(org.lanternpowered.server.data.io.ScoreboardIO) LanternChunk(org.lanternpowered.server.world.chunk.LanternChunk) BehaviorContextImpl(org.lanternpowered.server.behavior.BehaviorContextImpl) BiomeType(org.spongepowered.api.world.biome.BiomeType) HashMap(java.util.HashMap) DataTransactionResult(org.spongepowered.api.data.DataTransactionResult) Function(java.util.function.Function) BlockChangeFlag(org.spongepowered.api.world.BlockChangeFlag) ImmutableList(com.google.common.collect.ImmutableList) EntityTypes(org.spongepowered.api.entity.EntityTypes) PlaceBlockBehavior(org.lanternpowered.server.block.behavior.types.PlaceBlockBehavior) Rule(org.lanternpowered.server.world.rules.Rule) Logger(org.slf4j.Logger) Weather(org.spongepowered.api.world.weather.Weather) Iterator(java.util.Iterator) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) BaseValue(org.spongepowered.api.data.value.BaseValue) Chunk(org.spongepowered.api.world.Chunk) Consumer(java.util.function.Consumer) LanternMutableBiomeVolumeWorker(org.lanternpowered.server.world.extent.worker.LanternMutableBiomeVolumeWorker) LanternDimensionType(org.lanternpowered.server.world.dimension.LanternDimensionType) Difficulty(org.spongepowered.api.world.difficulty.Difficulty) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer) Property(org.spongepowered.api.data.Property) IGeneratorType(org.lanternpowered.server.world.gen.IGeneratorType) EntityType(org.spongepowered.api.entity.EntityType) MessageChannel(org.spongepowered.api.text.channel.MessageChannel) Collections(java.util.Collections) CauseStack(org.lanternpowered.server.event.CauseStack) BehaviorContextImpl(org.lanternpowered.server.behavior.BehaviorContextImpl) InteractWithBlockBehavior(org.lanternpowered.server.block.behavior.types.InteractWithBlockBehavior) Behavior(org.lanternpowered.server.behavior.Behavior) BreakBlockBehavior(org.lanternpowered.server.block.behavior.types.BreakBlockBehavior) PlaceBlockBehavior(org.lanternpowered.server.block.behavior.types.PlaceBlockBehavior) LanternBlockType(org.lanternpowered.server.block.LanternBlockType)

Example 79 with BlockType

use of org.spongepowered.api.block.BlockType in project LanternServer by LanternPowered.

the class ProcessorPlayOutParticleEffect method getBlockState.

private static int getBlockState(LanternParticleEffect effect, Optional<BlockState> defaultBlockState) {
    final Optional<BlockState> blockState = effect.getOption(ParticleOptions.BLOCK_STATE);
    if (blockState.isPresent()) {
        return BlockRegistryModule.get().getStateInternalIdAndData(blockState.get());
    } else {
        final Optional<ItemStackSnapshot> optSnapshot = effect.getOption(ParticleOptions.ITEM_STACK_SNAPSHOT);
        if (optSnapshot.isPresent()) {
            final ItemStackSnapshot snapshot = optSnapshot.get();
            final Optional<BlockType> blockType = snapshot.getType().getBlock();
            if (blockType.isPresent()) {
                final BlockState state;
                if (blockType.get().getDefaultState().getTraits().isEmpty()) {
                    state = blockType.get().getDefaultState();
                } else {
                    final BlockState.Builder builder = BlockState.builder().blockType(blockType.get());
                    // noinspection unchecked
                    snapshot.getValues().forEach(value -> builder.add((Key) value.getKey(), value.get()));
                    state = builder.build();
                }
                return BlockRegistryModule.get().getStateInternalIdAndData(state);
            } else {
                return 0;
            }
        } else {
            return BlockRegistryModule.get().getStateInternalIdAndData(defaultBlockState.get());
        }
    }
}
Also used : BlockState(org.spongepowered.api.block.BlockState) BlockType(org.spongepowered.api.block.BlockType) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) Key(org.spongepowered.api.data.key.Key)

Example 80 with BlockType

use of org.spongepowered.api.block.BlockType in project Nucleus by NucleusPowered.

the class BlockInfoCommand method executeCommand.

@Override
public CommandResult executeCommand(Player player, CommandContext args) throws Exception {
    BlockRay<World> bl = BlockRay.from(player).distanceLimit(10).stopFilter(BlockRay.continueAfterFilter(BlockRay.onlyAirFilter(), 1)).build();
    Optional<BlockRayHit<World>> ob = bl.end();
    // If the last block is not air...
    if (ob.isPresent() && ob.get().getLocation().getBlockType() != BlockTypes.AIR) {
        BlockRayHit<World> brh = ob.get();
        // get the information.
        BlockState b = brh.getLocation().getBlock();
        BlockType it = b.getType();
        List<Text> lt = new ArrayList<>();
        lt.add(plugin.getMessageProvider().getTextMessageWithFormat("command.blockinfo.id", it.getId(), it.getTranslation().get()));
        lt.add(plugin.getMessageProvider().getTextMessageWithFormat("command.iteminfo.extendedid", b.getId()));
        if (args.hasAny("e") || args.hasAny("extended")) {
            Collection<Property<?, ?>> cp = b.getApplicableProperties();
            if (!cp.isEmpty()) {
                cp.forEach(x -> {
                    if (x.getValue() != null) {
                        DataScanner.getText(player, "command.blockinfo.property.item", x.getKey().toString(), x.getValue()).ifPresent(lt::add);
                    }
                });
            }
            Collection<BlockTrait<?>> cb = b.getTraits();
            if (!cb.isEmpty()) {
                cb.forEach(x -> b.getTraitValue(x).ifPresent(v -> DataScanner.getText(player, "command.blockinfo.traits.item", x.getName(), v).ifPresent(lt::add)));
            }
        }
        Sponge.getServiceManager().provideUnchecked(PaginationService.class).builder().contents(lt).padding(Text.of(TextColors.GREEN, "-")).title(plugin.getMessageProvider().getTextMessageWithFormat("command.blockinfo.list.header", String.valueOf(brh.getBlockX()), String.valueOf(brh.getBlockY()), String.valueOf(brh.getBlockZ()))).sendTo(player);
        return CommandResult.success();
    }
    player.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.blockinfo.none"));
    return CommandResult.empty();
}
Also used : RegisterCommand(io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand) DataScanner(io.github.nucleuspowered.nucleus.internal.DataScanner) PermissionInformation(io.github.nucleuspowered.nucleus.internal.permissions.PermissionInformation) NonnullByDefault(org.spongepowered.api.util.annotation.NonnullByDefault) HashMap(java.util.HashMap) GenericArguments(org.spongepowered.api.command.args.GenericArguments) BlockRay(org.spongepowered.api.util.blockray.BlockRay) RunAsync(io.github.nucleuspowered.nucleus.internal.annotations.RunAsync) ArrayList(java.util.ArrayList) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) Map(java.util.Map) SuggestedLevel(io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel) BlockTrait(org.spongepowered.api.block.trait.BlockTrait) Permissions(io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions) TextColors(org.spongepowered.api.text.format.TextColors) BlockRayHit(org.spongepowered.api.util.blockray.BlockRayHit) CommandResult(org.spongepowered.api.command.CommandResult) BlockTypes(org.spongepowered.api.block.BlockTypes) Collection(java.util.Collection) Sponge(org.spongepowered.api.Sponge) PaginationService(org.spongepowered.api.service.pagination.PaginationService) CommandElement(org.spongepowered.api.command.args.CommandElement) BlockState(org.spongepowered.api.block.BlockState) List(java.util.List) AbstractCommand(io.github.nucleuspowered.nucleus.internal.command.AbstractCommand) World(org.spongepowered.api.world.World) BlockType(org.spongepowered.api.block.BlockType) Property(org.spongepowered.api.data.Property) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) BlockTrait(org.spongepowered.api.block.trait.BlockTrait) ArrayList(java.util.ArrayList) NonnullByDefault(org.spongepowered.api.util.annotation.NonnullByDefault) CommandResult(org.spongepowered.api.command.CommandResult) Text(org.spongepowered.api.text.Text) World(org.spongepowered.api.world.World) BlockState(org.spongepowered.api.block.BlockState) BlockType(org.spongepowered.api.block.BlockType) PaginationService(org.spongepowered.api.service.pagination.PaginationService) Property(org.spongepowered.api.data.Property) BlockRayHit(org.spongepowered.api.util.blockray.BlockRayHit)

Aggregations

BlockType (org.spongepowered.api.block.BlockType)80 World (org.spongepowered.api.world.World)34 Listener (org.spongepowered.api.event.Listener)21 BlockState (org.spongepowered.api.block.BlockState)18 Location (org.spongepowered.api.world.Location)17 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)16 ItemStack (org.spongepowered.api.item.inventory.ItemStack)14 Vector3i (com.flowpowered.math.vector.Vector3i)12 Player (org.spongepowered.api.entity.living.player.Player)12 Optional (java.util.Optional)11 Direction (org.spongepowered.api.util.Direction)10 Vector3d (com.flowpowered.math.vector.Vector3d)9 Keys (org.spongepowered.api.data.key.Keys)9 ArrayList (java.util.ArrayList)8 List (java.util.List)7 Set (java.util.Set)7 LanternBlockType (org.lanternpowered.server.block.LanternBlockType)7 Text (org.spongepowered.api.text.Text)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6