Solved Setting a block

Discussion in 'Plugin Development' started by Forseth11, Jan 8, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Forseth11

    Does anyone know if there is a method to set a block at a location. If not how would I change a block. I know how to change a block, but what if it is a torch, a chest, stairs, slabs, or redstone. How would I set the chests contents, how would I set a torch to face a certain way, how to I set stairs to be upside down and face a certain way, and how would I set slabs and redstone. I know how to set the stairs and slabs, but I am unsure of any of the others.
     
  2. Offline

    Xephiro

    You can use

    Code:java
    1. Location loc = ....
    2.  
    3. Block block = loc.getBlock();
    4. block.setType(Material.XXXXXX);


    This change the block at loc position to any material.
     
  3. Offline

    Forseth11

    Xephiro Please read my whole post. Plus setting type is not efficient. What if it has a durability. You would use setTypeID(int, boolean, byte)
     
  4. Offline

    HyrulesLegend

    ID's are becoming deprecated.
     
  5. Offline

    Forseth11

    Max_The_Link_Fan It still works. Not all items are listed in the Material type. The only time IDs can really cause an error is if you put one in that does not exist.
     
  6. Offline

    Xephiro

  7. Offline

    Forseth11

    Xephiro How would you set a block using the info from a block. And how would inventories help. How do I set a blocks facing direction? Would metaData help at all?

    EDIT: Those links you gave me are mostly for 'Item' not 'Block'
     
  8. Offline

    Xephiro


    If you need change the block info of a RedStone, Torch and other Items Places as a Block you have an especifics classes to get and edit his information.

    For example:
    With RedStone class you only can have if this redstone are powered or not.
    But with Torch you can change the Facing Direction

    Is very extensive explain every class but you can use apidoc to find all this clases and his methods
     
  9. Offline

    Forseth11

    Xephiro So for every special item I have to do something like what I did with Stairs. Where you have a variable called torch or Redstone. Something like that.
     
  10. Offline

    Xephiro

    Forseth11
    You can use the sentence instanceof to have the especific class

    For example:

    If que get a Block but you unkown if this is a Torch or Stair or RedStone you can use

    Code:java
    1. if (block instanceof Stair)
    2. {
    3. ...... Some code about the stair
    4. }
    5. else if (block instanceof Redstone)
    6. {
    7. ...... Some code about the redstone
    8. }
    9. else if (block instanceof Torch)
    10. {
    11. ...... Some code about the torch
    12. }
    13. else ...................... With anothers



    Can this answer your question?
    Sorry but i'm learning English and i try to understand all the questins and explain the more better possible my answers.

    :D
     
  11. Offline

    Forseth11

    Xephiro Yes I know. That is what I did for stairs. Can you list all possible things that I would have to include?
    1. Stairs
    2. Slabs
    3. Redstone
    4. Torch - Does this cover redstone torch?
    5. Button
    6. Lever
    7. Doors
    8. Trap doors
    9. Signs
    10. Beds
    11. Item frames
    12. Fence gate
    13. Vines
    14. Rails
     
  12. Offline

    Compressions

    Forseth11 You would have to set the type and data.
     
  13. Offline

    Xephiro

    Bed, Cake, Cauldron, Coal, CocoaPlant, Command, Crops, Diode, DirectionalContainer, Door, Dye, FlowerPot, Gate, Leaves, LongGrass, Mushroom, NetherWarts, PistonBaseMaterial, PistonExtensionMaterial, PressurePlate, Pumpkin, Rails, RedstoneWire, Sandstone, Sign, SimpleAttachableMaterialData, Skull, SpawnEgg, Stairs, TexturedMaterial, Tree, Tripwire, Vine, WoodenStep, Wool, Button, Ladder, Lever, Torch, TrapDoor, TripwireHook, RedstoneTorch (This is the torch for redstone)
     
  14. Offline

    Forseth11

    Xephiro WOW. That is a lot. I guess when I finish the method setBlock(Block b) I will post it here for others to use.

    Compressions Would data contain which way it is facing and things like that? I thought it only held durability. Otherwise I know. That is what I am using.
     
  15. Offline

    bobacadodl

    Forseth11
    Data contains the way it is facing. you dont need to have a case for each of those.
     
  16. Offline

    Forseth11

    bobacadodl Are you sersious? So does that mean that it also contain the amount of growth of wheat?
     
  17. Offline

    bobacadodl

  18. Offline

    Xephiro


    Yes, but if you need an especific information of this Block (redstone.isPowered() for example) you need cast the block. Or i'm wrong?
     
  19. Offline

    bobacadodl

    Xephiro
    Yes, but he just wants to be able to set the blocks, with the data retained.

    Forseth11
    Blocks such as chests and furnaces, you will need to handle manually. Since the inventories are separate
     
  20. Offline

    nuclearmissile

    Code:
    public void chestSet(Location l){
            l.getBlock().setType(Material.CHEST);
            Inventory chestInv = ((Chest)l.getBlock()).getInventory();
            chestInv.addItem(BLAHBLAHBLAH);
        }
    That should let you fill up a chest. May not be perfect code.
     
  21. Offline

    Forseth11

Thread Status:
Not open for further replies.

Share This Page