How to set a block's byte values?

Discussion in 'Plugin Development' started by Hohahihehu, Feb 4, 2011.

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

    Hohahihehu

    This is yet another attempt to squash my cake bug. (If you ever frequent IRC, you probably know what I'm talking about)

    How do I set the byte value for a block. This is the way I'm doing it, and I'm 90% sure it's wrong.

    block.setData((byte) 0)

    What's the correct way to do it. Also, if anyone knows, what's the byte value for a full cake?
     
  2. Offline

    mjmr89

    That looks like it should work. Maybe its being really picky and wants intstead, "(byte) 0x0"? I know setData takes a byte, so as long as its cast as one it should work. As to getting the byte value of a full cake, try:

    Code:
    public void onBlockDamage(BlockDamageEvent e){
    Block b = e.getBlock();
    System.out.println("Data is: " + b.getData());
    }
    
    I haven't tested that, but it should work. Of course you need to hook into the BLOCK_DAMAGE event and stick it in the block listener. Then you just hit any block and it should tell you the value for it.
     
  3. Offline

    Dinnerbone Bukkit Team Member

    What precisely is your problem? I just tried to place a cake block through a plugin and it worked fine.
     
  4. Offline

    mjmr89

    Just tested it, the byte value of a full cake should be 0, basically however many slices have been eaten. When theres one slice left, its 5, then after that its gone completely. It sounds like you already know that though but are having a problem using a plugin to place it? Or are you trying to make a neverending cake or something?
     
  5. Offline

    Hohahihehu

    That's why it's the Infamous Cake Bug. Both sk89q and EvilSeph among others have looked at my code (though they may not remember) and couldn't find the problem. Below is my code for making a cake (without all the stuff that's unrelated, eg, getting the position, permissions, etc.)

    Code:
    Block cake = world.getBlockAt(cx, cy, cz);
    cake.setType(Material.CAKE_BLOCK);
    
    It SHOULD give me a full cake, but it doesn't. Any cake I spawn in this way only has 1 slice. The only possibility is it's somehow inheriting data values. I'll try it with the 0x0 format later, incase that makes a difference. It's the only thing left I can think of.
     
  6. Offline

    mjmr89

    I think that must be it. Although most things should, by default, have data == 0x0. Everything thats stone,dirt, cobblestone, etc so unless you're trying to replace a sign or lever or something, it should be right already.
     
  7. Why not destroy the block and spawn a cake in its place?
     
  8. Offline

    mjmr89

    That'd probably work, but you can't set damage on blocks :(
     
  9. What I ment was to replace the block with air and then spawn a cake
     
  10. Offline

    Redecouverte

    did you already check block.getData() of a cake with all slices?
     
  11. Offline

    mjmr89

    Sorry Yurij, I misunderstood. But even that all you're doing is changing the TYPE of block it is - you're not changing the data of it. At least I think thats how it works. I went to CraftBlock in Bukkit to see how setTypeId (setType just calls setTypeId after finding the id of the enumerator) is actually implemented, but of course its something like

    public boolean setTypeId(final int type) {
    return chunk.getHandle().d.e(x, y, z, type);
    }

    And I have no idea what the d and e are because its decompiled. But it doesn't look like it messes with the data at all as far as I can see.

    Redecouverte, the data of each slice is basically the amount of slices you've had. So if you've had one slice, it would be 0x0, 2 would be 0x2, and 5 slices (out of six) would be 0x5. Then if you had one more after that, it would be back to 0x0 and air.
     
Thread Status:
Not open for further replies.

Share This Page