Clean up Smelting checks.

Now uses recipes to check if an item is the result of smelting.
This commit is contained in:
GJ 2013-10-31 14:29:06 -04:00
parent 88296da0af
commit a9d51dad34
5 changed files with 43 additions and 88 deletions

View File

@ -2,6 +2,7 @@ package com.gmail.nossr50.skills.smelting;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.experience.ExperienceConfig;
@ -49,14 +50,9 @@ public class Smelting {
public static double fluxMiningChance = AdvancedConfig.getInstance().getFluxMiningChance();
protected static int getResourceXp(ItemStack smelting) {
MaterialData data = smelting.getData();
Material resourceType = smelting.getType();
int xp = ExperienceConfig.getInstance().getXp(SkillType.SMELTING, resourceType != Material.GLOWING_REDSTONE_ORE ? resourceType : Material.REDSTONE_ORE);
if (xp == 0 && ModUtils.isCustomOreBlock(smelting)) {
xp = ModUtils.getCustomSmeltingBlock(smelting).getSmeltingXpGain();
}
return xp;
return ModUtils.isCustomOre(data) ? ModUtils.getCustomBlock(data).getSmeltingXpGain() : ExperienceConfig.getInstance().getXp(SkillType.SMELTING, resourceType != Material.GLOWING_REDSTONE_ORE ? resourceType : Material.REDSTONE_ORE);
}
}

View File

@ -75,21 +75,7 @@ public final class BlockUtils {
* @return true if the block is an ore, false otherwise
*/
public static boolean isOre(BlockState blockState) {
switch (blockState.getType()) {
case COAL_ORE:
case DIAMOND_ORE:
case GLOWING_REDSTONE_ORE:
case GOLD_ORE:
case IRON_ORE:
case LAPIS_ORE:
case QUARTZ_ORE:
case REDSTONE_ORE:
case EMERALD_ORE:
return true;
default:
return ModUtils.isCustomOreBlock(blockState);
}
return MaterialUtils.isOre(blockState.getData());
}
/**

View File

@ -1,27 +1,23 @@
package com.gmail.nossr50.util;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.CoalType;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.inventory.FurnaceRecipe;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.material.Coal;
import org.bukkit.material.Dye;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.mods.CustomArmorConfig;
import com.gmail.nossr50.config.mods.CustomBlockConfig;
import com.gmail.nossr50.config.mods.CustomToolConfig;
import com.gmail.nossr50.config.party.ItemWeightConfig;
import com.gmail.nossr50.locale.LocaleLoader;
public class ItemUtils {
public final class ItemUtils {
private ItemUtils() {}
/**
* Checks if the item is a bow.
@ -509,21 +505,7 @@ public class ItemUtils {
return false;
}
switch (item.getType()) {
case COAL_ORE:
case DIAMOND_ORE:
case GLOWING_REDSTONE_ORE:
case GOLD_ORE:
case IRON_ORE:
case LAPIS_ORE:
case REDSTONE_ORE:
case EMERALD_ORE:
case QUARTZ_ORE:
return true;
default:
return Config.getInstance().getBlockModsEnabled() && CustomBlockConfig.getInstance().isCustomOre(item.getData());
}
return MaterialUtils.isOre(item.getData());
}
public static boolean isSmelted(ItemStack item) {
@ -531,33 +513,14 @@ public class ItemUtils {
return false;
}
switch (item.getType()) {
case COAL:
return ((Coal) item.getData()).getType() == CoalType.COAL;
case DIAMOND:
case REDSTONE:
case GOLD_INGOT:
case IRON_INGOT:
case EMERALD:
case QUARTZ:
return true;
case INK_SACK:
return ((Dye) item.getData()).getColor() == DyeColor.BLUE;
default:
List<Recipe> recipeList = mcMMO.p.getServer().getRecipesFor(item);
for (Recipe recipe : recipeList) {
for (Recipe recipe : mcMMO.p.getServer().getRecipesFor(item)) {
if (recipe instanceof FurnaceRecipe) {
return Config.getInstance().getBlockModsEnabled() && CustomBlockConfig.getInstance().isCustomOre(((FurnaceRecipe) recipe).getInput().getData());
return MaterialUtils.isOre(((FurnaceRecipe) recipe).getInput().getData());
}
}
return false;
}
}
/**
* Check if an item is sharable.

View File

@ -0,0 +1,25 @@
package com.gmail.nossr50.util;
import org.bukkit.material.MaterialData;
public final class MaterialUtils {
private MaterialUtils() {}
protected static boolean isOre(MaterialData data) {
switch (data.getItemType()) {
case COAL_ORE:
case DIAMOND_ORE:
case GLOWING_REDSTONE_ORE:
case GOLD_ORE:
case IRON_ORE:
case LAPIS_ORE:
case QUARTZ_ORE:
case REDSTONE_ORE:
case EMERALD_ORE:
return true;
default:
return ModUtils.isCustomOre(data);
}
}
}

View File

@ -7,6 +7,7 @@ import org.bukkit.block.BlockState;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
@ -55,8 +56,8 @@ public final class ModUtils {
return CustomBlockConfig.getInstance().getCustomBlock(blockState.getData());
}
public static CustomBlock getCustomSmeltingBlock(ItemStack smelting) {
return CustomBlockConfig.getInstance().getCustomBlock(smelting.getData());
public static CustomBlock getCustomBlock(MaterialData data) {
return CustomBlockConfig.getInstance().getCustomBlock(data);
}
/**
@ -129,24 +130,8 @@ public final class ModUtils {
return customBlocksEnabled && CustomBlockConfig.getInstance().isCustomLog(blockState.getData());
}
/**
* Check if a custom block is an ore block.
*
* @param blockState The BlockState of the block to check
* @return true if the block represents an ore, false otherwise
*/
public static boolean isCustomOreBlock(BlockState blockState) {
return customBlocksEnabled && CustomBlockConfig.getInstance().isCustomOre(blockState.getData());
}
/**
* Check if a custom block is an ore block.
*
* @param item The ItemStack of the block to check
* @return true if the block represents an ore, false otherwise
*/
public static boolean isCustomOreBlock(ItemStack item) {
return customBlocksEnabled && CustomBlockConfig.getInstance().isCustomOre(item.getData());
public static boolean isCustomOre(MaterialData data) {
return customBlocksEnabled && CustomBlockConfig.getInstance().isCustomOre(data);
}
/**