Placing tile entities from Clipboard

Discussion in 'Programming Help' started by Creeoer, Nov 25, 2016.

  1. Creeoer

    Creeoer New Member

    Hello,

    In my plugin I have a system in which an array of baseBlocks is loaded from a clipboard and then "placed" in the world by modifying existing blocks.
    Code (Text):

                HashMap<Block,BaseBlock> blocks = new HashMap<>();
                List<Block> originalBlocks = new ArrayList<>();

                //Find and store blocks to change
                for(int x=0;x<sizeX;x++){
                    for(int y=0;y<sizeY;y++){
                        for(int z=0;z<sizeZ;z++){
                            blocks.put(l.clone().add(x, y, z).getBlock(), blockArray[x][y][z]);
                            originalBlocks.add(l.clone().add(x, y, z).getBlock());
                        }
                    }
                }

                Collections.sort(originalBlocks, (o1, o2) -> Double.compare(o1.getY(), o2.getY()));

                final int size = blocks.size();
                final int blocksPerSecond = config.getInt("Options.blocksPerSecond");
                new BukkitRunnable(){
                    int place=0;
                    @Override
                    public void run(){
                        for(int i=0;i<blocksPerSecond;i++){
                            if(place < size) {
                                //For each BaseBlock get the vector of the player and place the corresponding block
                                Block block = originalBlocks.get(place);
                                BaseBlock base = blocks.get(block);
                                if(Material.getMaterial(base.getType()) != Material.AIR){
                                    p.playSound(l, Sound.BLOCK_ANVIL_PLACE, 1, 0);


                                    block.setTypeId(base.getType());

                                    block.setMetadata(base.getNbtId(), base.getId());
                                    block.get
                                }
                                place+=1;
                            }else{
                                p.sendMessage(ChatColor.GREEN + "Building completed!");
                                this.cancel();
                                return;
                            }

                        }

    They are associated with a block in the real world and I was wondering how you guys edited the data of signs, chest, etc. This is due to the fact that signs would be placed blank and chests wouldn't have their original items in it.

    Do I need to use nms? Does baseBlock.getNbtData(); have something to do with it? Thanks
  2. wizjany

    wizjany Administrator Developer

    what's wrong with the prebuilt clipboard class?
  3. Creeoer

    Creeoer New Member

    There is nothing wrong with it, it's just that I need to paste it block by block. I have all the blocks loaded up fine, it's just that I can't manipulate the tile entities properly with the data given to me.
  4. wizjany

    wizjany Administrator Developer

    i don't know what your problem is, you're going to have to provide more code.

    tile entities (in the worldedit api) extend baseblock, so an array of baseblocks can contain tileentities. likewise, the world object (in the worldedit api) handles the extra data on these tile entities by copying nbt tags in.

    it seems to me that your problem is that you're trying to mix apis and set worldedit base blocks into a bukkit world using just id/data. this is completely opposite the purpose of the worldedit library, and i can't really help you because the bukkit api has pretty limited support for setting data on tile entities.
  5. Creeoer

    Creeoer New Member

    Sorry for not being clear. What I'm asking is what are the native worldedit methods for placing a baseblock in the world?
  6. wizjany

    wizjany Administrator Developer