getBlockTypeIdAt = deprectet

Discussion in 'Plugin Development' started by re4ly, Oct 3, 2013.

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

    re4ly

    Code:java
    1. int blockid = 0;
    2. blockid = world.getBlockTypeIdAt((int)x, (int)y, (int)z);


    "The method getBlockTypeIdAt(int, int, int) from the type World is deprecated"

    How do I have to change it?
     
  2. Offline

    Cyberpew

    Currently stuck in the same position at the moment.
    However, it appears that getBlockAt() is similar to it, however getBlockAt() does not grab the int of the ID. So, that won't work... I want to grab the block ID. UNLESS, maybe with getBlockAt I can grab the actual block name instead of the ID quite possibly?
     
  3. Offline

    re4ly

    The same @ getTypeId(); "The method getTypeId() from the type Block is deprecated"
     
  4. Offline

    desht

    This is all part of the plan to make numeric material ID's a thing of the past (driven by Mojang, not just the Bukkit team). The idea being that material ID's will be dynamically allocated by servers, making it far easier for mods/plugins to register new materials, with no chance of conflict.

    For now, that code will continue to work. What you can do to futureproof it is look at ways of always using Bukkit Material rather than integer material ID's. E.g.:
    PHP:
    Material mat world.getBlockAt(xyz).getType();
    ... which will of course need a bit of refactoring in your plugin.
     
    MrSnare likes this.
  5. Offline

    Cyberpew

    desht
    Is it possible to get block types via name? Say, I want to grab BLOCK_OBSIDIAN instead of the ID 49.
    Code:java
    1. public void onPlayerMoveEvent(PlayerMoveEvent event) {
    2. Player player = (Player) sender;
    3. Location loc = player.getLocation();
    4. loc.setY(loc.getY() -2);
    5. Block block = loc.getWorld().getBlockAt(loc);
    6. if(block == BLOCK_OBSIDIAN) {
    7.  
    8. }
    9. }
    10. }

    Kind of a noob at this.
     
  6. Offline

    re4ly

    What is the Material.<name> for Stationary Water?
     
  7. Offline

    Cyberpew

    STATIONARY_WATER
     
  8. Offline

    re4ly

  9. Offline

    MrSnare

    yes

    Code:java
    1. if(block.getType() == Material.BLOCK_OBSIDIAN){
    2. //stuff
    3. }
     
    Cyberpew likes this.
  10. Offline

    Skye

    I have to bump this... the biggest reason to use this method before was because it was thread-safe and didn't load blocks into cache. Is there a non-deprecated alternative? I can't even do this with a ChunkSnapshot anymore, and I need to count a lot of blocks.
     
  11. Offline

    xTrollxDudex

    Skye
    Release 2 updates it to Chunk#getBlock(int, int, int)
     
  12. Offline

    Skye

    That would return a Block object, which is what I don't want to do when counting over 100K blocks a second.
     
  13. Offline

    xTrollxDudex

    Skye
    ...

    What are you even trying to do with the counting of blocks? Find all the air blocks in a chunk?
     
  14. Offline

    desht

    Skye no alternative right now, other than to use NMS code, which has its own problems.

    It may be worth creating a JIRA ticket for it, asking for a method called (say) world.getBlockMaterialAt(int, int, int) which just returns the material at the given location and doesn't create a block object.
     
    Skye likes this.
  15. Offline

    Skye

    Thank you, I will do that. :)
     
  16. Offline

    xTrollxDudex

    Time for a PR. Skye link the ticket so I can refer back to it.
     
Thread Status:
Not open for further replies.

Share This Page