Advertisement
Guest User

Utils.java

a guest
Aug 23rd, 2012
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. /*
  2. Copyright (C) 2011 by Matthew D Moss
  3.  
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10.  
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13.  
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. THE SOFTWARE.
  21. */
  22.  
  23. package org.simiancage.bukkit.DwarfForge;
  24.  
  25.  
  26. import net.minecraft.server.ItemStack;
  27. import net.minecraft.server.RecipesFurnace;
  28.  
  29. import org.bukkit.Material;
  30. import org.bukkit.block.Block;
  31. import org.bukkit.block.BlockFace;
  32. import org.bukkit.craftbukkit.inventory.CraftItemStack;
  33.  
  34. class Utils {
  35.  
  36. static final short SECS = 20; // 20 server ticks
  37. static final short MINS = 60 * SECS;
  38.  
  39. // Logs are usually considered a typical fuel, but the Dwarfs were not
  40. // stupid. Cook logs into charcoal, a much more efficient fuel.
  41. static private boolean isTypicalFuel(Material m) {
  42. switch (m) {
  43. case COAL:
  44. case WOOD:
  45. case SAPLING:
  46. case STICK:
  47. case LAVA_BUCKET:
  48. case BLAZE_ROD:
  49. return true;
  50. default:
  51. return false;
  52. }
  53. }
  54.  
  55. static private boolean isCraftedFuel(Material m) {
  56. switch (m) {
  57. case FENCE:
  58. case WOOD_STAIRS:
  59. case TRAP_DOOR:
  60. case CHEST:
  61. case LOCKED_CHEST:
  62. case WOOD_DOOR:
  63. case TORCH:
  64. return true;
  65. default:
  66. return false;
  67. }
  68. }
  69.  
  70. static Material resultOfCooking(Material mat) {
  71. ItemStack item = RecipesFurnace.getInstance().getResult(mat.getId());
  72. return (item != null)
  73. ? new CraftItemStack(item).getType()
  74. : null;
  75. }
  76.  
  77. static boolean canCook(Material m) {
  78. return resultOfCooking(m) != null;
  79. }
  80.  
  81. static boolean canBurn(Material m) {
  82. return isTypicalFuel(m)
  83. || (isCraftedFuel(m) && Config.isAllowCraftedFuel());
  84. }
  85.  
  86. static BlockFace nextCardinalFace(BlockFace dir) {
  87. switch (dir) {
  88. case NORTH:
  89. return BlockFace.EAST;
  90. case EAST:
  91. return BlockFace.SOUTH;
  92. case SOUTH:
  93. return BlockFace.WEST;
  94. case WEST:
  95. return BlockFace.NORTH;
  96. default:
  97. throw new IllegalArgumentException(
  98. "Only cardinal directions permitted: received " + dir);
  99. }
  100. }
  101.  
  102. static BlockFace prevCardinalFace(BlockFace dir) {
  103. return nextCardinalFace(dir).getOppositeFace();
  104. }
  105.  
  106. static boolean isBlockOfType(Block block, Material... types) {
  107. for (Material type : types) {
  108. if (block.getType() == type) {
  109. return true;
  110. }
  111. }
  112. return false;
  113. }
  114.  
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement