1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved BlockOps : commands for /setblock, /fill, /clone

Discussion in 'Development' started by PsyOps, Jul 16, 2017.

  1. PsyOps

    PsyOps Silverfish

    Messages:
    16
    Thanks to WinterBuild7074 and his quick plugin that he made me, it peaked my interest and I started writting my own module. I am super nub and barely got into minecraft in general when i picked up a copy of Minecraft PE. My php skills are novice but I do have some experience with programming in general ( a little ).

    So far I rewrote the quick plugin that was made for me originally by WinterBuild7074 and so far I have /setblock and /fill written but at very basic levels. I may include all that hollow and mask options later If my brain doesn't blow up.

    This is mainly for fun and for myself but I will offer it to anyone who asks- not that my work will turn heads or anything =).

    anywho my questions to start this off is:
    Is there some kind of fill command already implemented into the core? Cause I basically just made a loop to send the setBlock() command for each block.
    How do I grab block info from $x,$y,$z ? Like what block is at that coord? - nevermind on this question, i did some digging to find out.
     
    Last edited: Jul 17, 2017
  2. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    getBlock($pos, $level = null)->getId() or ->getName()?
     
  3. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    that will probably get the block at the givin coords ^^^
     
  4. PsyOps

    PsyOps Silverfish

    Messages:
    16
    I used:

    $clonedBlock = $sender->getLevel()->getBlock(new Vector3($nextX, $nextY, $nextZ));

    The main php to plugin. If anyone can look it over and tell me if im doing anything wrong or there is a better way of writing please let me know. But as of right now it is working.
    https://pastebin.com/Kg24mkJ9
     
  5. PsyOps

    PsyOps Silverfish

    Messages:
    16
    in this line:
    $sender->getLevel()->setBlock(new Vector3($x, $y, $z), $blockobj, true, true);
    what are the bools at the end for?
     
  6. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    There first bool, when true sends the block updates directly to players.... NOT. This argument is not being used in the function anymore and you can set it to anything you like.

    If the second bool is true, the block will update it's 6 neighbour blocks (up, down, north, south, east and west). For example when someone breaks the block supporting a wall sign, the last argument is true so that the wall sign updates and that makes it break and fall down since it doesn't have any support.
    You don't have to define the two bools if the second bool is true.
     
  7. PsyOps

    PsyOps Silverfish

    Messages:
    16
    On MCPE the /setblock command has oldBlockHandeling with an option to :
    • destroy – Destroys the original block as if done by The Player, before placing the new block
    does that second bool do that, or is there a way to get/omit that effect from happening? or is this something I just cant do?
     
  8. PsyOps

    PsyOps Silverfish

    Messages:
    16
    Ok my apologies for not cracking open the pocketmine source first.
    I see:
    * If $direct is true, it'll send changes directly to players. if false, it'll be queued
    * and the best way to send queued changes will be done in the next tick.
    * This way big changes can be sent on a single chunk update packet instead of thousands of packets.
    *
    * If $update is true, it'll get the neighbour blocks (6 sides) and update them.
    * If you are doing big changes, you might want to set this to false, then update manually.

    Now I am wondering if I want to add the block break, do i do something like useBreakOn() for the option to "destroy".?

    ** UPDATE **
    Yes that is what I was looking for: My code to make old block explode is:
    $item = null;
    $sender->getLevel()->useBreakOn(new Vector3($x, $y, $z), $item, $sender, true);
     
    Last edited: Jul 17, 2017
  9. PsyOps

    PsyOps Silverfish

    Messages:
    16
    Well dunno what's going on. I moved the code and now it doesn't work. The code reaches that spot but isnt breaking block. Anyone know if I am doing wrong or is there a better way to poof a block.
    Plugin Code
    Line 151. The message gets displayed : "Block should explode!"

    ** UPDATE **
    Again a noob error. Blocks explode when in creative mode. So I have to figure that one out.
     
    Last edited: Jul 17, 2017
  10. PsyOps

    PsyOps Silverfish

    Messages:
    16
    I have the block object recorded from the place I am cloning :
    $blockobj = $sender->getLevel()->getBlock(new Vector3($printX, $printY, $printZ));
    How do I grab the meta variable from $blockobj to pass it along to the setblock.
    I tried : $blockobj->getMetadata() and didnt work.
     
  11. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    $block->getDamage()
     
    PsyOps likes this.
  12. PsyOps

    PsyOps Silverfish

    Messages:
    16
    Are you not able to place frames and signs when you copy over?
    Signs with text, chests with items placed inside, frames with items, etc..
     
    Last edited: Jul 18, 2017
  13. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    You can use MagicWE if you want to fill, setblocks, etc.
     
  14. PsyOps

    PsyOps Silverfish

    Messages:
    16
    I don't mind writing this plugin cause I like coding even though I'm not all that good at it. But I was looking for something specifically for sending commands like /setblock, /fill, and /clone so that I could use it with the plugin TapToDo. This way it can kinda work like a generic type command block and I can make big doors and maybe moving platforms n stuff. I am not sure what is out there already but so far the plugin doesnt seem to be too much of a task so far. So we will see how it goes.

    I do have a question of what is a block vs a Tile?
    Is there a way to copy over a sign that stays attached to another block, and maybe keep it's text? same with chest, how do you copy over a chest with items still in it?

    If these questions have been asked before I apologize. I am new to minecraft in general and im just feeling around trying to find my way. Even though I may ask nub questions I do keep researching as I code to try and solve it myself.

    Any help is appreciated =). Thnx in advance.
     
  15. PsyOps

    PsyOps Silverfish

    Messages:
    16
    I just noticed the facepalm section. Subforum link is a bit hidden, as it almost looks like the header to this forum. I will head there instead. Didn't mean to nub this forum up hehe.
     
    jasonwynn10 likes this.
  16. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    1. A tile is a block entity
    2. Copying tile entities is not very complex as it is essentially creating a new tile of the same type at the new location, copying the nbt of the original, then deleting the original
     
  17. PsyOps

    PsyOps Silverfish

    Messages:
    16
    nbt? I'm looking this stuff up now to try and finish up the base module.

    If anyone is interested: https://pastebin.com/Kg24mkJ9

    I have all functions of the 3 commands working (except for transfering sign txt, chest contents and stuff like that ).

    SETBLOCK
    ----------------------------------------------------------------------------------------------------------------------------
    /setblock <position: x y z> <tileName: string> [tileData: int] [oldBlockHandling]
    ----------------------------------------------------------------------------------------------------------------------------
    -- oldBlockHandling ---
    * destroy – Destroys the original block as if done by The Player, before placing the new block
    * keep – Only replaces air blocks with the new block
    * replace – Replaces without regards of old block. No dropping of block or content. This is the default

    FILL
    ----------------------------------------------------------------------------------------------------------------------------
    /fill <from: x y z> <to: x y z> <tileName: string> [tileData:int] [oldBlockHandling]
    ----------------------------------------------------------------------------------------------------------------------------
    -- oldBlockHandling ---
    * destroy – Replace all blocks, drops blocks and contents as if mined with unenchanted diamond pickaxe or shovel.
    * hollow – Replace only the blocks on the outer edge of the region. Drops all inner blocks as if they were mined, and replaced them with air blocks.
    * keep – Only replace the air blocks in the fill region with the specified block.
    * outline – Only replace the outer edge of region with specified block. Leave all inner blocks as they were.
    * replace – Replace all blocks, with no dropping of current blocks. This is the default.

    Clone
    ----------------------------------------------------------------------------------------------------------------------------
    command: /clone <begin x y z> <end x y z> <destination: x y z> [maskMode] [cloneMode] <tileName: string> [tileData:int]
    ----------------------------------------------------------------------------------------------------------------------------
    -- Legal values for maskMode are:
    * filtered – Only blocks matching tileName is copied.
    * masked – Only non-air blocks are copied.
    * replace – All blocks are copied as-is. This is the default.

    -- Legal values for cloneMode are:
    * force – Force moving of blocks even if regions overlap.
    * move – Move only non-air blocks, and replace them with air-blocks. If filtering is done, this only applies to the filtered blocks.
    * normal – Do not force or move blocks from source region. This is the default.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.