Search in sources :

Example 1 with TileEntityCarrier

use of org.spongepowered.api.block.tileentity.carrier.TileEntityCarrier in project AdamantineShield by Karanum.

the class PlayerInspectListener method onBlockSecondaryInteract.

@Listener
public void onBlockSecondaryInteract(InteractBlockEvent.Secondary.MainHand e, @First Player p) {
    if (!plugin.getInspectManager().isInspector(p))
        return;
    e.setCancelled(true);
    BlockSnapshot block = e.getTargetBlock();
    if (!block.getLocation().isPresent())
        return;
    Location<World> loc = block.getLocation().get();
    p.sendMessage(Text.of(TextColors.BLUE, "Querying database, please wait..."));
    Runnable task = null;
    if (loc.getTileEntity().isPresent()) {
        if (loc.getTileEntity().get() instanceof MultiBlockCarrier) {
            task = () -> {
                MultiBlockCarrier carrier = (MultiBlockCarrier) loc.getTileEntity().get();
                plugin.getInspectManager().inspectContainer(p, block.getWorldUniqueId(), carrier.getLocation().getBlockPosition());
            };
        } else if (loc.getTileEntity().get() instanceof TileEntityCarrier) {
            task = () -> plugin.getInspectManager().inspectContainer(p, block.getWorldUniqueId(), loc.getBlockPosition());
        }
    } else {
        task = () -> plugin.getInspectManager().inspect(p, block.getWorldUniqueId(), loc.getBlockPosition().add(e.getTargetSide().asBlockOffset()));
    }
    if (task != null)
        plugin.getThreadPool().execute(task);
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) TileEntityCarrier(org.spongepowered.api.block.tileentity.carrier.TileEntityCarrier) World(org.spongepowered.api.world.World) MultiBlockCarrier(org.spongepowered.api.item.inventory.MultiBlockCarrier) Listener(org.spongepowered.api.event.Listener)

Example 2 with TileEntityCarrier

use of org.spongepowered.api.block.tileentity.carrier.TileEntityCarrier 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 3 with TileEntityCarrier

use of org.spongepowered.api.block.tileentity.carrier.TileEntityCarrier 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)

Aggregations

TileEntityCarrier (org.spongepowered.api.block.tileentity.carrier.TileEntityCarrier)3 World (org.spongepowered.api.world.World)3 BlockState (org.spongepowered.api.block.BlockState)2 BlockType (org.spongepowered.api.block.BlockType)2 TileEntity (org.spongepowered.api.block.tileentity.TileEntity)2 ItemType (org.spongepowered.api.item.ItemType)2 Inventory (org.spongepowered.api.item.inventory.Inventory)2 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)1 DataView (org.spongepowered.api.data.DataView)1 Listener (org.spongepowered.api.event.Listener)1 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1 MultiBlockCarrier (org.spongepowered.api.item.inventory.MultiBlockCarrier)1