Getting craftbukkit block objects from a block object.

Discussion in 'Plugin Development' started by fullwall, Feb 18, 2011.

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

    fullwall

    Basically, I am making a plugin that requires access to the craftbukkit block object (the one that bukkit builds upon). I am trying to do this from onPlayerMove, but can't seem to cast the block object to a net.minecraft.Block object. For entities I'd use CraftEntity.getHandle(), but there is no such method in the block class.

    Does anyone know how to do this?
     
  2. Offline

    Redecouverte

    a CraftBlock is not directly linked to a block object but to a chunk object

    Code:
            org.bukkit.block.Block bb;
            Block b = Block.byId[bb.getTypeId()];
    afaik minecraft creates a block instance only for each block type/material, not for each actual existing block
     
  3. Offline

    fullwall

    Then how do I get to the block object (from net.minecraft) from a bukkit block object?
     
  4. Offline

    Redecouverte

  5. Offline

    fullwall

    EDIT: Can you put this into context for me?
     
  6. Offline

    Redecouverte

    Minecraft server creates for each block type (grass, stone, dirt, etc) an instance of "Block", unlike Bukkit which does create an instance of "Block" (the bukkit one) for each pair of world,x,y,z
     
  7. Offline

    fullwall

    Will changes I make to the block object be updated in the server?
    --- merged: Feb 18, 2011 2:33 PM ---
    Doesn't look like it :/ there goes that idea.
    --- merged: Feb 18, 2011 2:33 PM ---
    Thanks for your help!
     
  8. Offline

    Redecouverte

    a minecraft block has these values:

    Code:
      textureId; id, strength; durability; frictionFactor; name; etc
    i don't know what you are planning to do, but any change will affect ALL blocks of this type on the server

    changing values like id, etc will surely mess up the whole world
    --- merged: Feb 18, 2011 2:36 PM ---
    wannna share what you are trying to do? maybe we can figure something out
     
  9. Offline

    fullwall

    frictionFactor - my friend wanted to a plugin to change friction for blocks. I just tried setting it to 0.1 - couldn't see any discernable difference.
     
  10. Offline

    Redecouverte

    lowering the value will raise the friction,
    to disable friction set frictionFactor to 1.0
    --- merged: Feb 18, 2011 2:45 PM ---
    its used like that:
    Code:
    f2 = Block.byId[i].frictionFactor * 0.91F;
    
    this.motX *= f2;
    this.motZ *= f2;
     
  11. Offline

    fullwall

    So, if I put friction over 1.0, it'll get lower? How come glass has a friction value of 0.98 then...
     
  12. Offline

    Redecouverte

    motX = motX * Block.byId.frictionFactor * 0.91;


    motX = motX * 1.0 * 0.91 = motX * 0.91
    motX = motX * 0.1 * 0.91 = motX * 0.091

    motX = motX * 1.1 * 0.91 = motX * 1.001

    that's basic math :)
    --- merged: Feb 18, 2011 3:29 PM ---
    glass having 0.98 makes sense, as normally there's less friction on glass than on stone,etc
    --- merged: Feb 18, 2011 3:33 PM ---
    but afaik all blocks use 0.6 for friction atm
     
  13. Offline

    fullwall

    I'm not stupid XD. Thanks for telling me default block values, I'll try it out. But when I set friction to 0.1, movement was still the same... I'll see if 2.0 makes a difference :)
    --- merged: Feb 19, 2011 10:51 AM ---
    Changing the values had no effect.
     
  14. Offline

    Redecouverte

    yes, you are right.
    sorry for the confusion

    it seems that the friction code is not used for players
     
Thread Status:
Not open for further replies.

Share This Page