How to store and then set a block's data value?

Discussion in 'Plugin Development' started by Firefly, Feb 14, 2012.

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

    Firefly

    Hey all,

    I was just wondering how I would go about storing a blocks data value and then applying that data value to another block. I tried using getData() and setTypeAndData() however I couldn't get it to work...

    private final Map<String, Integer> ink = new HashMap<String, Integer>();
    private final Map<String, Byte> dataValue = new HashMap<String, Byte>();

    public void onPlayerInteract(PlayerImteractEvent event) {

    Action action = event.getAction();
    int mat = event.getBlock().getTypeId();
    byte data = event.getBlock().getData();
    Player player = event.getPlayer();

    if (action == Action.LEFT_CLICK_BLOCK) {
    ink.put(player.getName(), mat);
    dataValue.put(player.getName(), data);
    }

    if (action == Action.RIGHT_CLICK_BLOCK) {
    int id = ink.get(player.getName());
    byte data = dataValue.get(player.getName());

    event.getBlock().setTypeAndData(id, data, true);
    }


    Of course I skipped some of the code but the majority is there. My problem is that when I set the type and data, only the type is changed and the data is unaffected on the new block.

    Thanks,

    -Firefly
     
  2. Offline

    Jucko13

    for some reason this works perfectly fine for me. except that the "event.getBlock()" must be "event.getClickedBlock()" but i think that was just a typo here... maybe put on some places in your code an sendmessage to yourself. like this before storing the value's: player.sendmessage("" + mat + " " + data );

    EDIT: maybe other some other code is causing the problem?
     
  3. Offline

    Firefly

    No other code should interfere, and I've put message traces, and they don't return me anything for the data values.
     
  4. Offline

    Jucko13

    Maybe this? :p
    event.getClickedBlock().getState().getData().getData();

    ps. I had some problems with this too, only a long time ago. so I don't really remember and i cant find it in my own source...
     
  5. Offline

    Firefly

    I'm pretty sure there are no more methods you can apply after the first getData()
     
  6. Offline

    Jucko13

    the first getData() is returning a Material, and the second a Byte. Did you import the material class?

    and srry but im not on my own computer anymore so i cant check anything else now..
     
  7. Offline

    flatd

    I will try to look at my code and help once my computer finishes getting fixed from a virus that deleted almost everything but my codes.

    Found an example from one of my old posts it's

    Code:
        public boolean getStairsData(World world, int x, int y, int z, BlockFace dir){
            byte d = 0;
           
            if(dir == BlockFace.WEST){
                d = 0x1;
            }else if(dir == BlockFace.EAST){
                d = 0x0;
            }else if(dir == BlockFace.NORTH){
                d = 0x3;
            }else if(dir == BlockFace.SOUTH){
                d = 0x2;
            }
           
            return world.getBlockAt(x, y, z).setTypeIdAndData(67, d, false);
        }
    
    EDIT: do not use setTypeAndData like you have because you are giving the command an ID, you should be using setTypeIdAndData.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
  8. fire, i finished your plugin and made it way better. But newmie says he wont upload it becausue it will interfere with BuildersPlots (Which it wont). I hope you didnt mind if i beat you to create a working paintbrush. I think im going to release it to the public too. I can tell you 2 things: 1, your doing it wrong, 2, you only need 1 hashmap.

    -6
     
  9. Offline

    flatd

    How do you make it so u only use one hashmap?
     
  10. ill pm you, its kinda the secret sauce in my ultimate creative plugin. :D
     
  11. Offline

    Firefly

    Honestly, you shouldn't have wasted your time making your own paintbrush. Since my plugin has every single tool and all the features that we will ever need. So honesty I don't see why you went off and made your own :p

    Oh and yes it would interfere with Plots since my Tools plugin communicates directly with Plots to block tool activity outside of Plots.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
  12. well, your paintbrush doesnt work. so yeah. and i didnt just make a paintbrush, i made a plugin that probably replaces all creative server plugins (except voxelsniper, but im working on that right now )

    -6 :rolleyes:
     
Thread Status:
Not open for further replies.

Share This Page