Blocking Cobblestone Generators?

Discussion in 'Plugin Development' started by pkt, Jan 5, 2013.

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

    pkt

    I've been looking around for a while trying to find out how to get a cobblestone generator and how to block it from making cobblestone.. I couldn't find anything, so I tried doing it myself and here is what I got:

    Code:
        @EventHandler
        public void BlockForm(BlockFromToEvent event) {
            int source = event.getBlock().getTypeId();
            Block block = event.getToBlock();
     
            if ((source == 11 || source == 10) && (block.getTypeId() == 9 || block.getTypeId() == 8)) {
                block.setType(Material.GOLD_BLOCK);  // just for testing
            }
        }
    Does anyone know a way? It seems most plugins that have blocked them have become abandoned/outdated...
     
  2. Offline

    fireblast709

    Code:java
    1. @EventHandler
    2. public void onFromTo(BlockFromToEvent event)
    3. {
    4. int id = event.getBlock().getTypeId();
    5. if(id >= 8 && id <= 11)
    6. {
    7. Block b = event.getToBlock();
    8. int toid = b.getTypeId();
    9. if(toid == 0)
    10. {
    11. if(generatesCobble(id, b))
    12. {
    13. event.setCancelled(true);
    14. }
    15. }
    16. }
    17. }
    18.  
    19. private final BlockFace[] faces = new BlockFace[]
    20. {
    21. BlockFace.SELF,
    22. BlockFace.UP,
    23. BlockFace.DOWN,
    24. BlockFace.NORTH,
    25. BlockFace.EAST,
    26. BlockFace.SOUTH,
    27. BlockFace.WEST
    28. };
    29.  
    30. public boolean generatesCobble(int id, Block b)
    31. {
    32. int mirrorID1 = (id == 8 || id == 9 ? 10 : 8);
    33. int mirrorID2 = (id == 8 || id == 9 ? 11 : 9);
    34. for(BlockFace face : faces)
    35. {
    36. Block r = b.getRelative(face, 1);
    37. if(r.getTypeId() == mirrorID1 || r.getTypeId() == mirrorID2)
    38. {
    39. return true;
    40. }
    41. }
    42. return false;
    43. }
     
  3. Offline

    pkt

Thread Status:
Not open for further replies.

Share This Page