Skip to content

Commit

Permalink
1.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
WildWeazel committed Aug 31, 2014
1 parent 9c2d018 commit d9a5874
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: SmOres
main: com.bergecraft.smores.Smores
version: 0.1
version: 1.0
description: manages smelting and ore behavior
author: WildWeazel
depends: [BergModCore]
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.bergecraft</groupId>
<artifactId>SmOres</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.0</version>
<packaging>jar</packaging>

<name>SmOres</name>
Expand Down
46 changes: 38 additions & 8 deletions src/main/java/com/bergecraft/smores/Smores.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public void onEnable() {
}


/**
* Removes the ability to cook any of SMELTED_ITEMS in a furnace
*/
@Bergification(opt="furnace_can_smelt", def="true")
public void removeFurnaceRecipes() {
Iterator<Recipe> it = getServer().recipeIterator();
Expand All @@ -85,8 +88,11 @@ public void removeFurnaceRecipes() {
}
}

/**
* If an ore is broken by a player, reproduce the break manually and drop the block type
*/
@Bergification(opt="ores_drop_self", def="true")
@EventHandler(ignoreCancelled=true, priority = EventPriority.HIGH)
@EventHandler(ignoreCancelled=true, priority = EventPriority.HIGHEST)
public void onOreBreak(BlockBreakEvent e) {
Block broken = e.getBlock();
Material mat = getOreMaterial(broken.getType());
Expand All @@ -101,8 +107,11 @@ public void onOreBreak(BlockBreakEvent e) {
}
}

/**
* If an ore is broken by an explosion, reproduce the break manually and drop the block type
*/
@Bergification(opt="ores_drop_self", def="true")
@EventHandler(ignoreCancelled=true, priority = EventPriority.HIGH)
@EventHandler(ignoreCancelled=true, priority = EventPriority.HIGHEST)
public void onOreExplode(EntityExplodeEvent e) {
Iterator<Block> it = e.blockList().iterator();
while(it.hasNext()) {
Expand All @@ -123,34 +132,48 @@ public void onOreExplode(EntityExplodeEvent e) {
}
}

/**
* Treat gold as an intermediate material between stone and iron.
* Stone tools break gold but not iron, while gold tools break iron lapis and gold.
*/
@Bergification(opt="gold_as_bronze", def="true")
@EventHandler(ignoreCancelled=true, priority = EventPriority.NORMAL)
@EventHandler(ignoreCancelled=true, priority = EventPriority.HIGH)
public void onGoldOreBreak(BlockBreakEvent e) {
Block broken = e.getBlock();
Material mat = broken.getType();
ItemStack tool = e.getPlayer().getItemInHand();
Material toolType = tool.getType();

if((toolType == Material.STONE_PICKAXE && mat == Material.GOLD_ORE || mat == Material.GOLD_BLOCK) || (toolType == Material.GOLD_PICKAXE &&
(mat == Material.IRON_ORE || mat == Material.IRON_BLOCK || mat == Material.GOLD_ORE || mat == Material.GOLD_BLOCK))) {
if((toolType == Material.STONE_PICKAXE && mat == Material.GOLD_ORE || mat == Material.GOLD_BLOCK)
|| (toolType == Material.GOLD_PICKAXE && (mat == Material.LAPIS_ORE || mat == Material.LAPIS_BLOCK
|| mat == Material.IRON_ORE || mat == Material.IRON_BLOCK || mat == Material.GOLD_ORE || mat == Material.GOLD_BLOCK))) {
wearTool(tool);
broken.breakNaturally();
dropBlockAsMaterial(broken, mat);
e.setCancelled(true);
} else if (toolType == Material.STONE_PICKAXE &&
(mat == Material.LAPIS_ORE || mat == Material.LAPIS_BLOCK || mat == Material.IRON_ORE || mat == Material.IRON_BLOCK)) {
} else if (toolType == Material.STONE_PICKAXE && (mat == Material.IRON_ORE || mat == Material.IRON_BLOCK)) {
wearTool(tool);
dropBlockAsMaterial(broken, null);
e.setCancelled(true);
}
}

/**
* Removes a block and drops a single item in its place, as if broken
* @param b The block to remove
* @param m The material to drop
*/
private void dropBlockAsMaterial(Block b, Material m) {
b.setType(Material.AIR);
if(m != null) {
b.getWorld().dropItemNaturally(b.getLocation(), new ItemStack(m));
mLog.fine("Dropped " + b + " as " + m);
}
}

/**
* @param m The material to check
* @return The material of an ore block, or null otherwise
*/
private Material getOreMaterial(Material m) {
if(ORES.contains(m)) {
if(m == Material.GLOWING_REDSTONE_ORE) {
Expand All @@ -161,6 +184,13 @@ private Material getOreMaterial(Material m) {
return null;
}

/**
* Modifies the durability of a tool taking Unbreaking into account,
* assuming the event IS CANCELED. Bukkit seems to cache and invert side effects
* of canceled events, so to result in the tool losing durability anyway it must
* be incremented during the event handler.
* @param tool The tool to wear
*/
private void wearTool(ItemStack tool) {
if(r.nextInt(tool.getEnchantmentLevel(Enchantment.DURABILITY) + 1) == 0) {
tool.setDurability((short) (tool.getDurability() + 1));
Expand Down

0 comments on commit d9a5874

Please sign in to comment.