Netherwart drops a clean stone block when broken

Discussion in 'Plugin Development' started by leland22, Aug 3, 2014.

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

    leland22

    I have no clue what the issue could be as no where in the plugin does anything drop a clean stone block but whenever I break the netherwart it drops one. Any help would be amazing!

    Code:java
    1. My plugin is to change farming around some and it works for wheat netherwart, I have no clue why. Any help would be appreciated!
    2.  
    3. Instead of dropping netherwart its dropping a cleanstone
    4.  
    5. Code:
    6. [syntax=java]package plugins.leland;
    7.  
    8. import org.bukkit.Location;
    9. import org.bukkit.Material;
    10. import org.bukkit.block.Block;
    11. import org.bukkit.enchantments.Enchantment;
    12. import org.bukkit.entity.Player;
    13. import org.bukkit.event.EventHandler;
    14. import org.bukkit.event.Listener;
    15. import org.bukkit.event.block.BlockBreakEvent;
    16. import org.bukkit.event.block.BlockPistonExtendEvent;
    17. import org.bukkit.event.block.BlockPistonRetractEvent;
    18. import org.bukkit.inventory.ItemStack;
    19.  
    20. public class Events implements Listener{
    21.  
    22. public Events(Main plugin){
    23. plugin.getServer().getPluginManager().registerEvents(this, plugin);
    24. }
    25.  
    26. @SuppressWarnings("deprecation")
    27. @EventHandler
    28. public void onWheatBreak(BlockBreakEvent e){
    29.  
    30. //Setting variables
    31. Block b = e.getBlock();
    32. Player p = e.getPlayer();
    33. Location loc = b.getLocation();
    34. ItemStack tool = p.getItemInHand();
    35. int amount = 0;
    36. ItemStack drop = new ItemStack(Material.AIR);
    37.  
    38. //Changing the material that is dropped depending on the type of block that is broken
    39. if(b.getType()== Material.CROPS){
    40. drop.setType(Material.WHEAT);
    41. if(b.getType()== Material.CARROT){
    42. drop.setType(Material.CARROT_ITEM);
    43. if(b.getType()== Material.POTATO){
    44. drop.setType(Material.POTATO_ITEM);
    45. if(b.getType()== Material.NETHER_WARTS){
    46. drop.setType(Material.NETHER_WARTS);
    47. }
    48. }
    49. }
    50. }
    51.  
    52. //Checking to see what type of block it is
    53. if(b.getType()== Material.CROPS || b.getType()== Material.CARROT || b.getType()== Material.POTATO || b.getType()== Material.NETHER_WARTS)
    54. {
    55.  
    56. //Checking for enchantment and if its fortune applying a benefit
    57. if(tool.containsEnchantment(Enchantment.LOOT_BONUS_BLOCKS)){
    58. int level = tool.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS);
    59. amount = level;
    60. }
    61. //Breaking the crop with a fist so its cancelled
    62. if(p.getItemInHand().getType() == Material.AIR){
    63. e.setCancelled(true);
    64. b.setType(Material.AIR);
    65. }
    66. //Wood and stone hoe so you only get 1 wheat + enchantment benefit
    67. else if(p.getItemInHand().getType() == Material.WOOD_HOE || p.getItemInHand().getType() == Material.STONE_HOE){
    68. drop.setAmount(amount);
    69. b.getWorld().dropItemNaturally(loc, drop);
    70. tool.setDurability((short) (tool.getDurability() + 1));
    71. p.updateInventory();
    72.  
    73. }
    74. //Iron and Gold hoe so 2 wheat are dropped + enchantment benefit
    75. else if(p.getItemInHand().getType() == Material.IRON_HOE || p.getItemInHand().getType() == Material.GOLD_HOE){
    76. amount = amount + 1;
    77. drop.setAmount(amount);
    78. b.getWorld().dropItemNaturally(loc, drop);
    79. tool.setDurability((short) (tool.getDurability() + 1));
    80. p.updateInventory();
    81. }
    82. //Diamond hoe so 3 wheat are dropped + enchantment benefit
    83. else if(p.getItemInHand().getType() == Material.DIAMOND_HOE){
    84. amount = amount + 2;
    85. drop.setAmount(amount);
    86. b.getWorld().dropItemNaturally(loc, drop);
    87. tool.setDurability((short) (tool.getDurability() + 1));
    88. p.updateInventory();
    89. }
    90.  
    91. }
    92. }
    93.  
    94.  
    95. //Making sure the users can't circumvent the plugin by using water
    96. @EventHandler
    97. public void pistonRetractEvent(BlockPistonRetractEvent e){
    98. Block b = e.getBlock();
    99.  
    100. if(b.getType() == Material.CROPS){
    101. e.setCancelled(true);
    102. }
    103. }
    104.  
    105. //Making sure the users can't circumvent the plugin by using water
    106. @EventHandler
    107. public void pistonExtendEvent(BlockPistonExtendEvent e){
    108. Block b = e.getBlock();
    109.  
    110. if(b.getType() == Material.CROPS){
    111. e.setCancelled(true);
    112. }
    113. }
    114. }
    115. [/syntax]
    116.  
    117. EDIT:
    118. Only doesn't work for netherwart
    119.  
    120. -Leland
     
  2. When you initialize the integer amount, set it to 1. If you set it to 0, it will bug a little bit.
     
  3. Offline

    zDylann

    Material.NETHER_WARTS refers to the nether wart block. Bukkit/Minecraft does not recognize that block as an ItemStack so its reverted to stone. Use Material.NETHER_WARTS to check the block, but use Material.NETHER_STALK when dropping the item.
     
    To175 likes this.
  4. Offline

    To175

    Thanks zDylann
     
Thread Status:
Not open for further replies.

Share This Page