Search in sources :

Example 81 with BlockType

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

the class RollbackManager method performAddition.

// TODO: Set proper causes for block changes caused by rollback/undo
private void performAddition(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();
            ItemType type = (ItemType) line.getTarget();
            ItemStack stack = ItemStack.builder().fromContainer(line.getDataAsView()).itemType(type).quantity(line.getCount()).build();
            Inventory slot = i.query(QueryOperationTypes.INVENTORY_PROPERTY.of(SlotIndex.of(line.getSlot())));
            slot.set(stack);
        }
    } else if (line.getTarget() instanceof BlockType) {
        BlockState block = null;
        if (line.getDataAsView() == null) {
            block = BlockState.builder().blockType((BlockType) line.getTarget()).build();
            w.setBlock(line.getPos(), block);
        } else {
            DataView blockData = line.getDataAsView();
            DataView blockState = blockData.getView(DataQuery.of("BlockState")).orElse(null);
            block = BlockState.builder().build(blockState).orElse(null);
            if (block != null)
                w.setBlock(line.getPos(), block);
        }
    }
}
Also used : TileEntity(org.spongepowered.api.block.tileentity.TileEntity) DataView(org.spongepowered.api.data.DataView) 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) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Inventory(org.spongepowered.api.item.inventory.Inventory)

Example 82 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 83 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 84 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 85 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)

Aggregations

BlockType (org.spongepowered.api.block.BlockType)91 World (org.spongepowered.api.world.World)34 BlockState (org.spongepowered.api.block.BlockState)23 Listener (org.spongepowered.api.event.Listener)21 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 Optional (java.util.Optional)12 Player (org.spongepowered.api.entity.living.player.Player)12 List (java.util.List)10 Set (java.util.Set)10 Direction (org.spongepowered.api.util.Direction)10 Vector3d (com.flowpowered.math.vector.Vector3d)9 ArrayList (java.util.ArrayList)9 Keys (org.spongepowered.api.data.key.Keys)9 Sponge (org.spongepowered.api.Sponge)8 LanternBlockType (org.lanternpowered.server.block.LanternBlockType)7 Text (org.spongepowered.api.text.Text)7 HashMap (java.util.HashMap)6