Search in sources :

Example 71 with BlockType

use of org.spongepowered.api.block.BlockType in project AdamantineShield by Karanum.

the class RollbackManager method performRemoval.

private void performRemoval(LookupLine line) {
    World w = Sponge.getServer().getWorld(line.getWorld()).orElse(null);
    if (w == null)
        return;
    if (line.getTarget() instanceof ItemType) {
        Optional<TileEntity> te = w.getTileEntity(line.getPos());
        if (te.isPresent() && te.get() instanceof TileEntityCarrier) {
            TileEntityCarrier c = (TileEntityCarrier) te.get();
            Inventory i = c.getInventory();
            Inventory slot = i.query(QueryOperationTypes.INVENTORY_PROPERTY.of(SlotIndex.of(line.getSlot())));
            slot.set(ItemStack.of(ItemTypes.NONE, 0));
        }
    } else if (line.getTarget() instanceof BlockType) {
        BlockState block = BlockState.builder().blockType(BlockTypes.AIR).build();
        w.setBlock(line.getPos(), block);
    }
}
Also used : TileEntity(org.spongepowered.api.block.tileentity.TileEntity) BlockState(org.spongepowered.api.block.BlockState) BlockType(org.spongepowered.api.block.BlockType) ItemType(org.spongepowered.api.item.ItemType) TileEntityCarrier(org.spongepowered.api.block.tileentity.carrier.TileEntityCarrier) World(org.spongepowered.api.world.World) Inventory(org.spongepowered.api.item.inventory.Inventory)

Example 72 with BlockType

use of org.spongepowered.api.block.BlockType in project TotalEconomy by Erigitic.

the class ShopManager method onChestPlace.

/**
 * Prevents chests from being placed next to chest shops.
 *
 * @param event Place block
 */
@Listener
public void onChestPlace(ChangeBlockEvent.Place event) {
    BlockSnapshot blockSnapshot = event.getTransactions().get(0).getDefault();
    BlockType blockType = blockSnapshot.getState().getType();
    Location location = blockSnapshot.getLocation().get();
    if (blockType.equals(BlockTypes.CHEST) && isPlacedNextToShop(location)) {
        event.setCancelled(true);
    }
}
Also used : BlockType(org.spongepowered.api.block.BlockType) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Example 73 with BlockType

use of org.spongepowered.api.block.BlockType in project core by CubeEngine.

the class BlockTypeParser method parse.

@Override
public BlockType parse(Class aClass, CommandInvocation invocation) throws ParserException {
    String arg = invocation.consume(1);
    BlockType item = Sponge.getRegistry().getType(BlockType.class, arg.toLowerCase()).orElse(null);
    if (item == null) {
        throw new TranslatedParserException(i18n.translate(invocation.getContext(Locale.class), NEGATIVE, "ItemType {input#item} not found!", arg));
    }
    return item;
}
Also used : BlockType(org.spongepowered.api.block.BlockType) TranslatedParserException(org.cubeengine.libcube.service.command.TranslatedParserException)

Example 74 with BlockType

use of org.spongepowered.api.block.BlockType in project core by CubeEngine.

the class BlockTypeParser method suggest.

@Override
public List<String> suggest(Class type, CommandInvocation invocation) {
    ArrayList<String> list = new ArrayList<>();
    String token = invocation.currentToken().toLowerCase();
    if (MINECRAFT.startsWith(token)) {
        list.add(MINECRAFT);
    }
    boolean startMc = token.startsWith(MINECRAFT);
    for (BlockType bType : Sponge.getRegistry().getAllOf(BlockType.class)) {
        if (bType.getId().startsWith(token)) {
            if (!bType.getId().startsWith(MINECRAFT) || startMc) {
                list.add(bType.getId());
            }
        }
        if (bType.getId().startsWith(MINECRAFT + token)) {
            list.add(bType.getId().substring(MINECRAFT.length()));
        }
    }
    return list;
}
Also used : BlockType(org.spongepowered.api.block.BlockType) ArrayList(java.util.ArrayList)

Example 75 with BlockType

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

the class SlabItemInteractionBehavior method tryInteract.

@Override
public BehaviorResult tryInteract(BehaviorPipeline<Behavior> pipeline, BehaviorContext context) {
    final Optional<Location<World>> optLocation = context.getContext(ContextKeys.INTERACTION_LOCATION);
    if (!optLocation.isPresent()) {
        return BehaviorResult.CONTINUE;
    }
    final BlockType halfSlabType = this.halfSlabType.get();
    final BlockType doubleSlabType = this.doubleSlabType.get();
    Location<World> location = optLocation.get();
    final Direction blockFace = context.getContext(ContextKeys.INTERACTION_FACE).get().getOpposite();
    final LanternBlockType blockType = (LanternBlockType) context.getContext(ContextKeys.ITEM_TYPE).get().getBlock().get();
    if (blockType != halfSlabType) {
        return BehaviorResult.PASS;
    }
    BlockState state = location.getBlock();
    final BlockState.Builder stateBuilder = BlockState.builder();
    stateBuilder.blockType(blockType);
    context.getContext(ContextKeys.USED_ITEM_STACK).ifPresent(itemStack -> itemStack.getValues().forEach(value -> stateBuilder.add((Key) value.getKey(), value.get())));
    BlockState blockState = stateBuilder.build();
    BlockSnapshotBuilder snapshotBuilder = null;
    boolean success = false;
    if (state.getType() == blockType) {
        if (state.getTraitValue(this.variantTrait).get().equals(blockState.getTraitValue(this.variantTrait).get())) {
            final PortionType portionType = state.getTraitValue(LanternEnumTraits.PORTION_TYPE).get();
            if ((blockFace == Direction.DOWN && portionType == PortionTypes.BOTTOM) || (blockFace == Direction.UP && portionType == PortionTypes.TOP)) {
                snapshotBuilder = BlockSnapshotBuilder.create().blockState(doubleSlabType.getDefaultState());
                success = true;
            }
        }
    } else if (location.getProperty(ReplaceableProperty.class).get().getValue()) {
        success = true;
    }
    if (!success) {
        location = location.add(blockFace.getOpposite().asBlockOffset());
        state = location.getBlock();
        if (state.getType() == blockType) {
            if (state.getTraitValue(this.variantTrait).get().equals(blockState.getTraitValue(this.variantTrait).get())) {
                final PortionType portionType = state.getTraitValue(LanternEnumTraits.PORTION_TYPE).get();
                if ((blockFace == Direction.DOWN && portionType == PortionTypes.TOP) || (blockFace == Direction.UP && portionType == PortionTypes.BOTTOM)) {
                    snapshotBuilder = BlockSnapshotBuilder.create().blockState(doubleSlabType.getDefaultState());
                    success = true;
                }
            }
        } else if (location.getProperty(ReplaceableProperty.class).get().getValue()) {
            success = true;
        }
    }
    if (success) {
        if (snapshotBuilder == null) {
            PortionType portionType;
            if (blockFace == Direction.UP) {
                portionType = PortionTypes.TOP;
            } else if (blockFace == Direction.DOWN) {
                portionType = PortionTypes.BOTTOM;
            } else {
                final double y = location.getY() - location.getBlockY();
                if (y >= 0.5) {
                    portionType = PortionTypes.TOP;
                } else {
                    portionType = PortionTypes.BOTTOM;
                }
            }
            snapshotBuilder = BlockSnapshotBuilder.create().blockState(halfSlabType.getDefaultState()).add(Keys.PORTION_TYPE, portionType);
        }
        final BlockSnapshotBuilder snapshotBuilder1 = snapshotBuilder;
        snapshotBuilder1.location(location);
        context.getContext(ContextKeys.USED_ITEM_STACK).ifPresent(itemStack -> itemStack.getValues().forEach(value -> snapshotBuilder1.add((Key) value.getKey(), value.get())));
        context.addBlockChange(snapshotBuilder1.build());
        context.getContext(ContextKeys.PLAYER).ifPresent(player -> {
            if (!player.get(Keys.GAME_MODE).orElse(GameModes.NOT_SET).equals(GameModes.CREATIVE)) {
                context.requireContext(ContextKeys.USED_SLOT).poll(1);
            }
        });
        return BehaviorResult.SUCCESS;
    }
    return BehaviorResult.FAIL;
}
Also used : ContextKeys(org.lanternpowered.server.behavior.ContextKeys) PortionTypes(org.spongepowered.api.data.type.PortionTypes) Location(org.spongepowered.api.world.Location) Keys(org.spongepowered.api.data.key.Keys) PortionType(org.spongepowered.api.data.type.PortionType) LanternBlockType(org.lanternpowered.server.block.LanternBlockType) BehaviorPipeline(org.lanternpowered.server.behavior.pipeline.BehaviorPipeline) EnumTrait(org.spongepowered.api.block.trait.EnumTrait) Behavior(org.lanternpowered.server.behavior.Behavior) GameModes(org.spongepowered.api.entity.living.player.gamemode.GameModes) Supplier(java.util.function.Supplier) Key(org.spongepowered.api.data.key.Key) BlockState(org.spongepowered.api.block.BlockState) Direction(org.spongepowered.api.util.Direction) BehaviorContext(org.lanternpowered.server.behavior.BehaviorContext) BlockSnapshotBuilder(org.lanternpowered.server.block.BlockSnapshotBuilder) InteractWithItemBehavior(org.lanternpowered.server.item.behavior.types.InteractWithItemBehavior) World(org.spongepowered.api.world.World) BehaviorResult(org.lanternpowered.server.behavior.BehaviorResult) BlockType(org.spongepowered.api.block.BlockType) Optional(java.util.Optional) LanternEnumTraits(org.lanternpowered.server.block.trait.LanternEnumTraits) ReplaceableProperty(org.spongepowered.api.data.property.block.ReplaceableProperty) PortionType(org.spongepowered.api.data.type.PortionType) World(org.spongepowered.api.world.World) Direction(org.spongepowered.api.util.Direction) LanternBlockType(org.lanternpowered.server.block.LanternBlockType) BlockState(org.spongepowered.api.block.BlockState) LanternBlockType(org.lanternpowered.server.block.LanternBlockType) BlockType(org.spongepowered.api.block.BlockType) ReplaceableProperty(org.spongepowered.api.data.property.block.ReplaceableProperty) Location(org.spongepowered.api.world.Location) BlockSnapshotBuilder(org.lanternpowered.server.block.BlockSnapshotBuilder)

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