Replace Block With Rotation

Discussion in 'Plugin Development' started by Bionicrm, Jan 14, 2014.

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

    Bionicrm

    So I run this method of mine when someone breaks another block.

    The intended behavior is to set the block that you broke with the block in your hand. However, if the block you broke are stairs that are facing east, for example, and the block in your hand are stairs also, the stairs should change its type but still be facing east. The same should apply for wood logs or any other rotatable blocks.

    In other words, if sandstone stairs are facing south, and the block in my hand is a cobblestone stair, the sandstone stairs should become cobblestone stairs, but the cobblestone stairs should be facing south, too, rather than always the default west.

    The actual result is that the block you replace with the block in your hand changes its type properly, but the rotation is not changed. I have tried other methods that included adding:
    Code:java
    1. MaterialData toReplaceData = toReplace.getState().getData();
    2. itemInHand.setData(toReplaceData);

    However, if you want to replace an oak wood log with a spruce wood log, the type doesn't change due to something with the MaterialData.

    (Also, sorry about improper plural/singular nouns and using "is" vs. "are"... it's hard to convert a single block to a single... stairs :/ )
     
  2. Offline

    Bionicrm

    Sorry 'bout the kinda necro, but I forgot to bump this. I still never figured this one out :(
     
  3. Offline

    Niknea

  4. Offline

    Bionicrm

    What about it?
     
  5. Offline

    Niknea

    Bionicrm Use that event, then get the block placed.
     
  6. Offline

    Bionicrm

    Niknea
    It's not a block place event, it's a block break event. If you really wanna take a look at what I'm doing, look here for the method, here for the event, and here for a visual demonstration.
     
  7. Offline

    Niknea

    Bionicrm Don't copy code, always make your own, therefore you know what's happening in the code, and you get some good practice in Java. For that you would need to use the BlockBreakEvent, then get the players item in hand and set the block they broke to the item in hand.
     
  8. Offline

    Bionicrm

    Lol, that is my code. MicroTools is my plugin.
     
  9. Offline

    Niknea

    Bionicrm Oh, then how do you not know how to remake something in your own plugin? :confused:
     
  10. Offline

    Bionicrm

    The reason I'm asking the question is because what the plugin currently does is not what I want it to do. When you place, say, sandstone stairs on cobblestone stairs facing SOUTH, the new sandstone stairs face EAST by default. However, I want the sandstone stairs to face SOUTH, just like the cobblestone stairs. Of course this situation would vary.
    And even though it does not do exactly what I wanted it to do, it still works perfectly for blocks that don't have a rotation to them, so the plugin is still released.
     
  11. Offline

    Niknea

    Bionicrm Alright, do what I said, then get the way they are looking, after that place the block.
     
  12. Offline

    Bionicrm

    :confused: The direction that the player is facing is irrelevant. All I want to do is make the block that you broke the block in your hand, but when the block you broke becomes the block in your hand, the rotation of the new block is the same as the old block. :|
     
  13. Offline

    Niknea

    Bionicrm Not sure if this would work, however get the location of the BLOCK broke, the x y z and f, then set the new block at those EXACT coordinates, as I said, I have no idea if it would work, but give it a shot ;)
     
  14. Offline

    AnorZaken

  15. Offline

    xize

    hmm not sure though but anyways it questions me to now:p

    if I would compare a stair like a sign block.setData() would actually only handle the rotation for me, but since stairs got both and sub data values and rotations so it confuses me a bit:p

    however I suspect that block.getData() may is the face or direction of that stair and block.getState().setData(); what handles the materials and sub data, I think if you do BlockFace face = BlockFace.valueOf(block.getData()) you can get the face from that but maybe thats unneeded.
     
Thread Status:
Not open for further replies.

Share This Page