diff --git a/src/main/scala/resonantinduction/core/CoreContent.scala b/src/main/scala/resonantinduction/core/CoreContent.scala index 187bc7182..8786e1ef1 100644 --- a/src/main/scala/resonantinduction/core/CoreContent.scala +++ b/src/main/scala/resonantinduction/core/CoreContent.scala @@ -3,12 +3,14 @@ package resonantinduction.core import java.util.HashMap import net.minecraft.block.Block +import net.minecraft.init.{Blocks, Items} import net.minecraft.item.{Item, ItemStack} import net.minecraftforge.fluids.BlockFluidFinite import resonant.content.loader.{ContentHolder, ExplicitContentName} +import resonant.lib.ore.OreGenerator import resonantinduction.core.content.BlockIndustrialStone -import resonantinduction.core.resource.fluid.ItemOreResourceBucket -import resonantinduction.core.resource.{ItemOreResource, TileDust} +import resonantinduction.core.resource.fluid.ItemResourceBucket +import resonantinduction.core.resource.{ItemResourceDust, TileDust} /** * The core contents of Resonant Induction @@ -32,20 +34,21 @@ object CoreContent extends ContentHolder var itemCircuitBasic: Item = null var itemCircuitAdvanced: Item = null var itemCircuitElite: Item = null + var itemPlateCopper: Item = null var itemPlateTin: Item = null var itemPlateBronze: Item = null var itemPlateSteel: Item = null var itemPlateIron: Item = null var itemPlateGold: Item = null - var itemIngotCopper: Item = null - var itemIngotTin: Item = null + var itemIngotSteel: Item = null var itemIngotBronze: Item = null var itemDustSteel: Item = null var itemDustBronze: Item = null - var generationOreCopper: Nothing = null - var generationOreTin: Nothing = null + + var generationOreCopper: OreGenerator = null + var generationOreTin: OreGenerator = null val decoration: Block = new BlockIndustrialStone() @ExplicitContentName("dust") @@ -57,15 +60,15 @@ object CoreContent extends ContentHolder * Items */ @ExplicitContentName - val rubble = new ItemOreResource + val rubble = new ItemResourceDust @ExplicitContentName - val dust = new ItemOreResource + val dust = new ItemResourceDust @ExplicitContentName - val refinedDust = new ItemOreResource + val refinedDust = new ItemResourceDust @ExplicitContentName - val bucketMixture = new ItemOreResourceBucket(false) + val bucketMixture = new ItemResourceBucket(false) @ExplicitContentName - val bucketMolten = new ItemOreResourceBucket(true) + val bucketMolten = new ItemResourceBucket(true) manager.setTab(ResonantTab).setPrefix(Reference.prefix) @@ -78,16 +81,17 @@ object CoreContent extends ContentHolder * Resources */ + /** * Decoration */ - recipes += shaped(new ItemStack(decoration, 8, 3), Array[AnyRef]("XXX", "XCX", "XXX", 'X', Block.cobblestone, 'C', new ItemStack(Item.coal, 1, 1))) + recipes += shaped(new ItemStack(decoration, 8, 3), "XXX", "XCX", "XXX", 'X', Blocks.cobblestone, 'C', new ItemStack(Items.coal, 1, 1)) recipes +=(decoration, 3, new ItemStack(decoration, 1, 5), 5) recipes +=(decoration, new ItemStack(decoration, 1, 4), 5) - recipes += shaped(new ItemStack(decoration, 8, 7), Array[AnyRef]("XXX", "XVX", "XXX", 'X', new ItemStack(decoration), 'V', Block.vine)) - recipes += shaped(new ItemStack(decoration, 4), Array[AnyRef]("XX ", "XX ", " ", 'X', new ItemStack(decoration, 1, 5))) - recipes += shaped(new ItemStack(decoration, 4, 1), Array[AnyRef]("XXX", "XXX", "XX ", 'X', Block.stoneSingleSlab)) - recipes += shaped(new ItemStack(decoration, 8, 2), Array[AnyRef]("XXX", "X X", "XXX", 'X', new ItemStack(decoration, 1, 5))) - recipes += shaped(new ItemStack(decoration, 5, 10), Array[AnyRef]("IXI", "XXX", "IXI", 'X', new ItemStack(decoration, 1, 5), 'I', Item.ingotIron)) + recipes += shaped(new ItemStack(decoration, 8, 7), "XXX", "XVX", "XXX", 'X', new ItemStack(decoration), 'V', Blocks.vine) + recipes += shaped(new ItemStack(decoration, 4), "XX ", "XX ", " ", 'X', new ItemStack(decoration, 1, 5)) + recipes += shaped(new ItemStack(decoration, 4, 1), "XXX", "XXX", "XX ", 'X', Blocks.stoneSingleSlab) + recipes += shaped(new ItemStack(decoration, 8, 2), "XXX", "X X", "XXX", 'X', new ItemStack(decoration, 1, 5)) + recipes += shaped(new ItemStack(decoration, 5, 10), "IXI", "XXX", "IXI", 'X', new ItemStack(decoration, 1, 5), 'I', Items.iron_ingot) } } diff --git a/src/main/scala/resonantinduction/core/resource/ItemOreResource.java b/src/main/scala/resonantinduction/core/resource/ItemResourceDust.java similarity index 95% rename from src/main/scala/resonantinduction/core/resource/ItemOreResource.java rename to src/main/scala/resonantinduction/core/resource/ItemResourceDust.java index 641574ba7..622137d4e 100644 --- a/src/main/scala/resonantinduction/core/resource/ItemOreResource.java +++ b/src/main/scala/resonantinduction/core/resource/ItemResourceDust.java @@ -11,9 +11,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.oredict.OreDictionary; import resonant.lib.utility.LanguageUtility; -import resonantinduction.core.Reference; import resonantinduction.core.ResonantInduction; -import resonantinduction.core.ResonantTab; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -22,13 +20,11 @@ import cpw.mods.fml.relauncher.SideOnly; * * @author Calclavia */ -public class ItemOreResource extends Item +public class ItemResourceDust extends Item { - - private Block block = ResonantInduction.blockRefinedDust; - public ItemOreResource() + public ItemResourceDust() { setHasSubtypes(true); setMaxDamage(0); @@ -190,7 +186,7 @@ public class ItemOreResource extends Item /** * Auto-color based on the texture of the ingot. */ - String name = ItemOreResource.getMaterialFromStack(itemStack); + String name = ItemResourceDust.getMaterialFromStack(itemStack); if (ResourceGenerator.materialColorCache.containsKey(name)) { diff --git a/src/main/scala/resonantinduction/core/resource/ResourceGenerator.java b/src/main/scala/resonantinduction/core/resource/ResourceGenerator.java deleted file mode 100644 index a3ddb7a21..000000000 --- a/src/main/scala/resonantinduction/core/resource/ResourceGenerator.java +++ /dev/null @@ -1,470 +0,0 @@ -package resonantinduction.core.resource; - -import java.awt.Color; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map.Entry; - -import javax.imageio.ImageIO; - -import net.minecraft.block.Block; -import net.minecraft.client.Minecraft; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.FurnaceRecipes; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.util.IIcon; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.client.event.TextureStitchEvent; -import net.minecraftforge.event.ForgeSubscribe; -import net.minecraftforge.fluids.BlockFluidFinite; -import net.minecraftforge.fluids.FluidContainerRegistry; -import net.minecraftforge.fluids.FluidRegistry; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.oredict.OreDictionary; -import net.minecraftforge.oredict.OreDictionary.OreRegisterEvent; -import resonant.api.recipe.MachineRecipes; -import resonant.lib.config.Config; -import resonant.lib.utility.LanguageUtility; -import resonant.lib.utility.nbt.IVirtualObject; -import resonant.lib.utility.nbt.NBTUtility; -import resonant.lib.utility.nbt.SaveManager; -import resonantinduction.core.Reference; -import resonantinduction.core.ResonantInduction; -import resonantinduction.core.ResonantInduction.RecipeType; -import resonantinduction.core.Settings; -import resonantinduction.core.prefab.FluidColored; -import resonantinduction.core.resource.fluid.BlockFluidMaterial; -import resonantinduction.core.resource.fluid.BlockFluidMixture; - -import com.google.common.collect.HashBiMap; - -import cpw.mods.fml.common.registry.GameRegistry; -import cpw.mods.fml.common.registry.LanguageRegistry; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -/** - * Generates the resources based on available ores in Resonant Induction - * @author Calclavia - */ -public class ResourceGenerator implements IVirtualObject -{ - public static final ResourceGenerator INSTANCE = new ResourceGenerator(); - public static final HashBiMap materials = HashBiMap.create(); - static final HashMap materialColorCache = new HashMap(); - static final HashMap iconColorCache = new HashMap(); - - static - { - OreDetectionBlackList.addIngot("ingotRefinedIron"); - OreDetectionBlackList.addIngot("ingotUranium"); - SaveManager.registerClass("resourceGenerator", ResourceGenerator.class); - SaveManager.register(INSTANCE); - } - - @Config(category = "Resource_Generator", key = "Enable_All") - public static boolean ENABLED = true; - @Config(category = "Resource_Generator", key = "Enabled_All_Fluids") - public static boolean ENABLE_FLUIDS = true; - /** - * A list of material names. They are all camelCase reference of ore dictionary names without - * the "ore" or "ingot" prefix. - *

- * Name, ID - */ - static int maxID = 0; - @Config(comment = "Allow the Resource Generator to make ore dictionary compatible recipes?") - private static boolean allowOreDictCompatibility = true; - - public static void generate(String materialName) - { - // Caps version of the name - String nameCaps = LanguageUtility.capitalizeFirst(materialName); - String localizedName = materialName; - - List list = OreDictionary.getOres("ingot" + nameCaps); - - if (list.size() > 0) - { - ItemStack type = list.get(0); - localizedName = type.getDisplayName().trim(); - - if (LanguageUtility.getLocal(localizedName) != null && LanguageUtility.getLocal(localizedName) != "") - { - localizedName = LanguageUtility.getLocal(localizedName); - } - - localizedName.replace(LanguageUtility.getLocal("misc.resonantinduction.ingot"), "").replaceAll("^ ", "").replaceAll(" $", ""); - } - if (ENABLE_FLUIDS) - { - /** Generate molten fluids */ - FluidColored fluidMolten = new FluidColored(materialNameToMolten(materialName)); - fluidMolten.setDensity(7); - fluidMolten.setViscosity(5000); - fluidMolten.setTemperature(273 + 1538); - FluidRegistry.registerFluid(fluidMolten); - LanguageRegistry.instance().addStringLocalization(fluidMolten.getUnlocalizedName(), LanguageUtility.getLocal("tooltip.molten") + " " + localizedName); - BlockFluidMaterial blockFluidMaterial = new BlockFluidMaterial(fluidMolten); - GameRegistry.registerBlock(blockFluidMaterial, "molten" + nameCaps); - ResonantInduction.blockMoltenFluid.put(getID(materialName), blockFluidMaterial); - FluidContainerRegistry.registerFluidContainer(fluidMolten, ResonantInduction.itemBucketMolten.getStackFromMaterial(materialName)); - - /** Generate dust mixture fluids */ - FluidColored fluidMixture = new FluidColored(materialNameToMixture(materialName)); - FluidRegistry.registerFluid(fluidMixture); - BlockFluidMixture blockFluidMixture = new BlockFluidMixture(fluidMixture); - LanguageRegistry.instance().addStringLocalization(fluidMixture.getUnlocalizedName(), localizedName + " " + LanguageUtility.getLocal("tooltip.mixture")); - GameRegistry.registerBlock(blockFluidMixture, "mixture" + nameCaps); - ResonantInduction.blockMixtureFluids.put(getID(materialName), blockFluidMixture); - FluidContainerRegistry.registerFluidContainer(fluidMixture, ResonantInduction.itemBucketMixture.getStackFromMaterial(materialName)); - - if (allowOreDictCompatibility) - { - MachineRecipes.INSTANCE.addRecipe(RecipeType.SMELTER.name(), new FluidStack(fluidMolten, FluidContainerRegistry.BUCKET_VOLUME), "ingot" + nameCaps); - } - else - { - MachineRecipes.INSTANCE.addRecipe(RecipeType.SMELTER.name(), new FluidStack(fluidMolten, FluidContainerRegistry.BUCKET_VOLUME), "ingot" + nameCaps); - } - } - - ItemStack dust = ResonantInduction.itemDust.getStackFromMaterial(materialName); - ItemStack rubble = ResonantInduction.itemRubble.getStackFromMaterial(materialName); - ItemStack refinedDust = ResonantInduction.itemRefinedDust.getStackFromMaterial(materialName); - - if (allowOreDictCompatibility) - { - OreDictionary.registerOre("rubble" + nameCaps, ResonantInduction.itemRubble.getStackFromMaterial(materialName)); - OreDictionary.registerOre("dirtyDust" + nameCaps, ResonantInduction.itemDust.getStackFromMaterial(materialName)); - OreDictionary.registerOre("dust" + nameCaps, ResonantInduction.itemRefinedDust.getStackFromMaterial(materialName)); - - MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER.name(), "rubble" + nameCaps, dust, dust); - MachineRecipes.INSTANCE.addRecipe(RecipeType.MIXER.name(), "dirtyDust" + nameCaps, refinedDust); - } - else - { - MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER.name(), rubble, dust, dust); - MachineRecipes.INSTANCE.addRecipe(RecipeType.MIXER.name(), dust, refinedDust); - } - - FurnaceRecipes.smelting().addSmelting(dust.itemID, dust.getItemDamage(), OreDictionary.getOres("ingot" + nameCaps).get(0).copy(), 0.7f); - ItemStack smeltResult = OreDictionary.getOres("ingot" + nameCaps).get(0).copy(); - FurnaceRecipes.smelting().addSmelting(refinedDust.itemID, refinedDust.getItemDamage(), smeltResult, 0.7f); - - if (OreDictionary.getOres("ore" + nameCaps).size() > 0) - { - MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER.name(), "ore" + nameCaps, "rubble" + nameCaps); - } - } - - public static void generateOreResources() - { - OreDictionary.registerOre("ingotGold", Item.ingotGold); - OreDictionary.registerOre("ingotIron", Item.ingotIron); - - OreDictionary.registerOre("oreGold", Block.oreGold); - OreDictionary.registerOre("oreIron", Block.oreIron); - OreDictionary.registerOre("oreLapis", Block.oreLapis); - - // Vanilla fluid recipes - MachineRecipes.INSTANCE.addRecipe(RecipeType.SMELTER.name(), new FluidStack(FluidRegistry.LAVA, FluidContainerRegistry.BUCKET_VOLUME), new ItemStack(Block.stone)); - - // Vanilla crusher recipes - MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER.name(), Block.cobblestone, Block.gravel); - MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER.name(), Block.stone, Block.cobblestone); - MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER.name(), Block.chest, new ItemStack(Block.planks, 7, 0)); - - // Vanilla grinder recipes - MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER.name(), Block.cobblestone, Block.sand); - MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER.name(), Block.gravel, Block.sand); - MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER.name(), Block.glass, Block.sand); - - - - Iterator it = materials.keySet().iterator(); - while (it.hasNext()) - { - String materialName = it.next(); - String nameCaps = LanguageUtility.capitalizeFirst(materialName); - - if (OreDictionary.getOres("ore" + nameCaps).size() > 0) - { - generate(materialName); - } - else - { - it.remove(); - } - } - } - - @SideOnly(Side.CLIENT) - public static void computeColors() - { - for (String material : materials.keySet()) - { - // Compute color - int totalR = 0; - int totalG = 0; - int totalB = 0; - - int colorCount = 0; - - for (ItemStack ingotStack : OreDictionary.getOres("ingot" + LanguageUtility.capitalizeFirst(material))) - { - Item theIngot = ingotStack.getItem(); - int color = getAverageColor(ingotStack); - materialColorCache.put(material, color); - } - - if (!materialColorCache.containsKey(material)) - { - materialColorCache.put(material, 0xFFFFFF); - } - } - } - - /** - * Gets the average color of this item. - * - * @param itemStack - * @return The RGB hexadecimal color code. - */ - @SideOnly(Side.CLIENT) - public static int getAverageColor(ItemStack itemStack) - { - int totalR = 0; - int totalG = 0; - int totalB = 0; - - int colorCount = 0; - Item item = itemStack.getItem(); - - try - { - IIcon icon = item.getIconIndex(itemStack); - - if (iconColorCache.containsKey(icon)) - { - return iconColorCache.get(icon); - } - - String iconString = icon.getIconName(); - - if (iconString != null && !iconString.contains("MISSING_ICON_ITEM")) - { - iconString = (iconString.contains(":") ? iconString.replace(":", ":" + Reference.ITEM_TEXTURE_DIRECTORY) : Reference.ITEM_TEXTURE_DIRECTORY + iconString) + ".png"; - ResourceLocation textureLocation = new ResourceLocation(iconString); - - InputStream inputstream = Minecraft.getMinecraft().getResourceManager().getResource(textureLocation).getInputStream(); - BufferedImage bufferedimage = ImageIO.read(inputstream); - - int width = bufferedimage.getWidth(); - int height = bufferedimage.getWidth(); - - for (int x = 0; x < width; x++) - { - for (int y = 0; y < height; y++) - { - Color rgb = new Color(bufferedimage.getRGB(x, y)); - - /** Ignore things that are too dark. Standard luma calculation. */ - double luma = 0.2126 * rgb.getRed() + 0.7152 * rgb.getGreen() + 0.0722 * rgb.getBlue(); - - if (luma > 40) - { - totalR += rgb.getRed(); - totalG += rgb.getGreen(); - totalB += rgb.getBlue(); - colorCount++; - } - } - } - } - - if (colorCount > 0) - { - totalR /= colorCount; - totalG /= colorCount; - totalB /= colorCount; - int averageColor = new Color(totalR, totalG, totalB).brighter().getRGB(); - iconColorCache.put(icon, averageColor); - return averageColor; - } - } - catch (Exception e) - { - ResonantInduction.LOGGER.fine("Failed to compute colors for: " + item); - } - - return 0xFFFFFF; - } - - public static String moltenToMaterial(String fluidName) - { - return fluidNameToMaterial(fluidName, "molten"); - } - - public static String materialNameToMolten(String fluidName) - { - return materialNameToFluid(fluidName, "molten"); - } - - public static String mixtureToMaterial(String fluidName) - { - return fluidNameToMaterial(fluidName, "mixture"); - } - - public static String materialNameToMixture(String fluidName) - { - return materialNameToFluid(fluidName, "mixture"); - } - - public static String fluidNameToMaterial(String fluidName, String type) - { - return LanguageUtility.decapitalizeFirst(LanguageUtility.underscoreToCamel(fluidName).replace(type, "")); - } - - public static String materialNameToFluid(String materialName, String type) - { - return type + "_" + LanguageUtility.camelToLowerUnderscore(materialName); - } - - public static BlockFluidFinite getMixture(String name) - { - return ResonantInduction.blockMixtureFluids.get(getID(name)); - } - - public static BlockFluidFinite getMolten(String name) - { - return ResonantInduction.blockMoltenFluid.get(getID(name)); - } - - public static int getID(String name) - { - if (!materials.containsKey(name)) - { - ResonantInduction.LOGGER.severe("Trying to get invalid material name " + name); - return 0; - } - - return materials.get(name); - } - - public static String getName(int id) - { - return materials.inverse().get(id); - } - - public static String getName(ItemStack itemStack) - { - return LanguageUtility.decapitalizeFirst(OreDictionary.getOreName(OreDictionary.getOreID(itemStack)).replace("dirtyDust", "").replace("dust", "").replace("ore", "").replace("ingot", "")); - } - - public static int getColor(String name) - { - if (name != null && materialColorCache.containsKey(name)) - { - return materialColorCache.get(name); - } - - return 0xFFFFFF; - } - - @Deprecated - public static List getMaterials() - { - List returnMaterials = new ArrayList(); - - for (int i = 0; i < materials.size(); i++) - { - returnMaterials.add(getName(i)); - } - - return returnMaterials; - } - - // TODO: Generate teh resource here instead of elsewhere... - @ForgeSubscribe - public void oreRegisterEvent(OreRegisterEvent evt) - { - if (evt.Name.startsWith("ingot")) - { - String oreDictName = evt.Name.replace("ingot", ""); - String materialName = LanguageUtility.decapitalizeFirst(oreDictName); - - if (!materials.containsKey(materialName)) - { - Settings.config.load(); - boolean allowMaterial = Settings.config.get("Resource_Generator", "Enable " + oreDictName, true).getBoolean(true); - Settings.config.save(); - - if (!allowMaterial || OreDetectionBlackList.isIngotBlackListed("ingot" + oreDictName) || OreDetectionBlackList.isOreBlackListed("ore" + oreDictName)) - { - return; - } - - materials.put(materialName, maxID++); - } - } - } - - @ForgeSubscribe - @SideOnly(Side.CLIENT) - public void reloadTextures(TextureStitchEvent.Post e) - { - computeColors(); - } - - @Override - public void save(NBTTagCompound nbt) - { - NBTTagList list = new NBTTagList(); - - for (Entry entry : materials.entrySet()) - { - NBTTagCompound node = new NBTTagCompound(); - node.setString("materialName", entry.getKey()); - node.setInteger("materialID", entry.getValue()); - list.appendTag(node); - } - - nbt.setTag("materialIDMap", list); - } - - @Override - public void load(NBTTagCompound nbt) - { - if (nbt.hasKey("materialIDMap")) - { - materials.clear(); - NBTTagList nbtList = nbt.getTagList("materialIDMap"); - - for (int i = 0; i < nbtList.tagCount(); ++i) - { - NBTTagCompound node = (NBTTagCompound) nbtList.tagAt(i); - materials.put(node.getString("materialName"), node.getInteger("materialID")); - } - } - } - - @Override - public File getSaveFile() - { - return new File(NBTUtility.getSaveDirectory(), "Resource_Generator.dat"); - } - - @Override - public void setSaveFile(File file) - { - - } -} diff --git a/src/main/scala/resonantinduction/core/resource/ResourceGenerator.scala b/src/main/scala/resonantinduction/core/resource/ResourceGenerator.scala new file mode 100644 index 000000000..baaed9b9a --- /dev/null +++ b/src/main/scala/resonantinduction/core/resource/ResourceGenerator.scala @@ -0,0 +1,361 @@ +package resonantinduction.core.resource + +import java.awt.Color +import java.awt.image.BufferedImage +import java.io.InputStream +import java.util.{ArrayList, HashMap, Iterator, List} +import javax.imageio.ImageIO + +import cpw.mods.fml.common.eventhandler.SubscribeEvent +import cpw.mods.fml.common.registry.{GameRegistry, LanguageRegistry} +import cpw.mods.fml.relauncher.{Side, SideOnly} +import net.minecraft.block.Block +import net.minecraft.client.Minecraft +import net.minecraft.item.crafting.FurnaceRecipes +import net.minecraft.item.{Item, ItemStack} +import net.minecraft.util.{IIcon, ResourceLocation} +import net.minecraftforge.client.event.TextureStitchEvent +import net.minecraftforge.fluids.{BlockFluidFinite, FluidContainerRegistry, FluidRegistry, FluidStack} +import net.minecraftforge.oredict.OreDictionary +import resonant.api.recipe.MachineRecipes +import resonant.lib.config.Config +import resonant.lib.utility.LanguageUtility +import resonantinduction.core.ResonantInduction.RecipeType +import resonantinduction.core.prefab.FluidColored +import resonantinduction.core.resource.fluid.{BlockFluidMaterial, BlockFluidMixture} +import resonantinduction.core.{CoreContent, Reference, ResonantInduction, Settings} +import scala.collection.JavaConversions._ + +import scala.collection.mutable + +/** + * Generates the resources based on available ores in Resonant Induction + * @author Calclavia + */ +object ResourceGenerator +{ + private final val materials = mutable.Set.empty[String] + private final val materialColorCache: HashMap[String, Integer] = new HashMap[String, Integer] + private final val iconColorCache: HashMap[IIcon, Integer] = new HashMap[IIcon, Integer] + + @Config(category = "resource-generator") + var enableAll: Boolean = true + @Config(category = "resource-generator") + var enableAllFluids: Boolean = true + + /** + * A list of material names. They are all camelCase reference of ore dictionary names without + * the "ore" or "ingot" prefix. + *

+ * Name, ID + */ + private[resource] var maxID: Int = 0 + @Config(category = "resource-generator", comment = "Allow the Resource Generator to make ore dictionary compatible recipes?") + private val allowOreDictCompatibility: Boolean = true + + def generate(materialName: String) + { + val nameCaps = LanguageUtility.capitalizeFirst(materialName) + var localizedName = materialName + + val list = OreDictionary.getOres("ingot" + nameCaps) + + if (list.size > 0) + { + localizedName = list.get(0).getDisplayName.trim + if (LanguageUtility.getLocal(localizedName) != null && LanguageUtility.getLocal(localizedName) != "") + { + localizedName = LanguageUtility.getLocal(localizedName) + } + + localizedName.replace(LanguageUtility.getLocal("misc.resonantinduction.ingot"), "").replaceAll("^ ", "").replaceAll(" #", "") + } + + if (enableAllFluids) + { + val fluidMolten: FluidColored = new FluidColored(materialNameToMolten(materialName)) + fluidMolten.setDensity(7) + fluidMolten.setViscosity(5000) + fluidMolten.setTemperature(273 + 1538) + FluidRegistry.registerFluid(fluidMolten) + LanguageRegistry.instance.addStringLocalization(fluidMolten.getUnlocalizedName, LanguageUtility.getLocal("tooltip.molten") + " " + localizedName) + val blockFluidMaterial: BlockFluidMaterial = new BlockFluidMaterial(fluidMolten) + GameRegistry.registerBlock(blockFluidMaterial, "molten" + nameCaps) + ResonantInduction.blockMoltenFluid.put(getID(materialName), blockFluidMaterial) + FluidContainerRegistry.registerFluidContainer(fluidMolten, CoreContent.BucketMolten.getStackFromMaterial(materialName)) + val fluidMixture: FluidColored = new FluidColored(materialNameToMixture(materialName)) + FluidRegistry.registerFluid(fluidMixture) + val blockFluidMixture: BlockFluidMixture = new BlockFluidMixture(fluidMixture) + LanguageRegistry.instance.addStringLocalization(fluidMixture.getUnlocalizedName, localizedName + " " + LanguageUtility.getLocal("tooltip.mixture")) + GameRegistry.registerBlock(blockFluidMixture, "mixture" + nameCaps) + ResonantInduction.blockMixtureFluids.put(getID(materialName), blockFluidMixture) + FluidContainerRegistry.registerFluidContainer(fluidMixture, CoreContent.BucketMixture.getStackFromMaterial(materialName)) + + if (allowOreDictCompatibility) + { + MachineRecipes.INSTANCE.addRecipe(RecipeType.SMELTER.name, new FluidStack(fluidMolten, FluidContainerRegistry.BUCKET_VOLUME), "ingot" + nameCaps) + } + else + { + MachineRecipes.INSTANCE.addRecipe(RecipeType.SMELTER.name, new FluidStack(fluidMolten, FluidContainerRegistry.BUCKET_VOLUME), "ingot" + nameCaps) + } + } + + val dust: ItemStack = CoreContent.dust.getStackFromMaterial(materialName) + val rubble: ItemStack = CoreContent.rubble.getStackFromMaterial(materialName) + val refinedDust: ItemStack = CoreContent.refinedDust.getStackFromMaterial(materialName) + if (allowOreDictCompatibility) + { + OreDictionary.registerOre("rubble" + nameCaps, CoreContent.rubble.getStackFromMaterial(materialName)) + OreDictionary.registerOre("dirtyDust" + nameCaps, CoreContent.dust.getStackFromMaterial(materialName)) + OreDictionary.registerOre("dust" + nameCaps, CoreContent.refinedDust.getStackFromMaterial(materialName)) + MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER.name, "rubble" + nameCaps, dust, dust) + MachineRecipes.INSTANCE.addRecipe(RecipeType.MIXER.name, "dirtyDust" + nameCaps, refinedDust) + } + else + { + MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER.name, rubble, dust, dust) + MachineRecipes.INSTANCE.addRecipe(RecipeType.MIXER.name, dust, refinedDust) + } + FurnaceRecipes.smelting.addSmelting(dust.itemID, dust.getItemDamage, OreDictionary.getOres("ingot" + nameCaps).get(0).copy, 0.7f) + val smeltResult: ItemStack = OreDictionary.getOres("ingot" + nameCaps).get(0).copy + FurnaceRecipes.smelting.addSmelting(refinedDust.itemID, refinedDust.getItemDamage, smeltResult, 0.7f) + if (OreDictionary.getOres("ore" + nameCaps).size > 0) + { + MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER.name, "ore" + nameCaps, "rubble" + nameCaps) + } + } + + def generateOreResources + { + OreDictionary.registerOre("ingotGold", Item.ingotGold) + OreDictionary.registerOre("ingotIron", Item.ingotIron) + OreDictionary.registerOre("oreGold", Block.oreGold) + OreDictionary.registerOre("oreIron", Block.oreIron) + OreDictionary.registerOre("oreLapis", Block.oreLapis) + MachineRecipes.INSTANCE.addRecipe(RecipeType.SMELTER.name, new FluidStack(FluidRegistry.LAVA, FluidContainerRegistry.BUCKET_VOLUME), new ItemStack(Block.stone)) + MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER.name, Block.cobblestone, Block.gravel) + MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER.name, Block.stone, Block.cobblestone) + MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER.name, Block.chest, new ItemStack(Block.planks, 7, 0)) + MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER.name, Block.cobblestone, Block.sand) + MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER.name, Block.gravel, Block.sand) + MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER.name, Block.glass, Block.sand) + val it: Iterator[String] = materials.keySet.iterator + while (it.hasNext) + { + val materialName: String = it.next + val nameCaps: String = LanguageUtility.capitalizeFirst(materialName) + if (OreDictionary.getOres("ore" + nameCaps).size > 0) + { + generate(materialName) + } + else + { + it.remove + } + } + } + + @SideOnly(Side.CLIENT) + def computeColors + { + for (material <- materials) + { + val totalR: Int = 0 + val totalG: Int = 0 + val totalB: Int = 0 + val colorCount: Int = 0 + for (ingotStack <- OreDictionary.getOres("ingot" + LanguageUtility.capitalizeFirst(material))) + { + val theIngot: Item = ingotStack.getItem + val color: Int = getAverageColor(ingotStack) + materialColorCache.put(material, color) + } + if (!materialColorCache.containsKey(material)) + { + materialColorCache.put(material, 0xFFFFFF) + } + } + } + + /** + * Gets the average color of this item. + * + * @param itemStack + * @return The RGB hexadecimal color code. + */ + @SideOnly(Side.CLIENT) def getAverageColor(itemStack: ItemStack): Int = + { + var totalR: Int = 0 + var totalG: Int = 0 + var totalB: Int = 0 + var colorCount: Int = 0 + val item: Item = itemStack.getItem + try + { + val icon: IIcon = item.getIconIndex(itemStack) + if (iconColorCache.containsKey(icon)) + { + return iconColorCache.get(icon) + } + var iconString: String = icon.getIconName + if (iconString != null && !iconString.contains("MISSING_ICON_ITEM")) + { + iconString = (if (iconString.contains(":")) iconString.replace(":", ":" + Reference.ITEM_TEXTURE_DIRECTORY) else Reference.ITEM_TEXTURE_DIRECTORY + iconString) + ".png" + val textureLocation: ResourceLocation = new ResourceLocation(iconString) + val inputstream: InputStream = Minecraft.getMinecraft.getResourceManager.getResource(textureLocation).getInputStream + val bufferedimage: BufferedImage = ImageIO.read(inputstream) + val width: Int = bufferedimage.getWidth + val height: Int = bufferedimage.getWidth + { + var x: Int = 0 + while (x < width) + { + { + { + var y: Int = 0 + while (y < height) + { + { + val rgb: Color = new Color(bufferedimage.getRGB(x, y)) + val luma: Double = 0.2126 * rgb.getRed + 0.7152 * rgb.getGreen + 0.0722 * rgb.getBlue + if (luma > 40) + { + totalR += rgb.getRed + totalG += rgb.getGreen + totalB += rgb.getBlue + colorCount += 1 + } + } + ({y += 1; y - 1 }) + } + } + } + ({x += 1; x - 1 }) + } + } + } + if (colorCount > 0) + { + totalR /= colorCount + totalG /= colorCount + totalB /= colorCount + val averageColor: Int = new Color(totalR, totalG, totalB).brighter.getRGB + iconColorCache.put(icon, averageColor) + return averageColor + } + } + catch + { + case e: Exception => + { + ResonantInduction.LOGGER.fine("Failed to compute colors for: " + item) + } + } + return 0xFFFFFF + } + + def moltenToMaterial(fluidName: String): String = + { + return fluidNameToMaterial(fluidName, "molten") + } + + def materialNameToMolten(fluidName: String): String = + { + return materialNameToFluid(fluidName, "molten") + } + + def mixtureToMaterial(fluidName: String): String = + { + return fluidNameToMaterial(fluidName, "mixture") + } + + def materialNameToMixture(fluidName: String): String = + { + return materialNameToFluid(fluidName, "mixture") + } + + def fluidNameToMaterial(fluidName: String, `type`: String): String = + { + return LanguageUtility.decapitalizeFirst(LanguageUtility.underscoreToCamel(fluidName).replace(`type`, "")) + } + + def materialNameToFluid(materialName: String, `type`: String): String = + { + return `type` + "_" + LanguageUtility.camelToLowerUnderscore(materialName) + } + + def getMixture(name: String): BlockFluidFinite = + { + return ResonantInduction.blockMixtureFluids.get(getID(name)) + } + + def getMolten(name: String): BlockFluidFinite = + { + return ResonantInduction.blockMoltenFluid.get(getID(name)) + } + + def getName(id: Int): String = + { + return materials.inverse.get(id) + } + + def getName(itemStack: ItemStack): String = + { + return LanguageUtility.decapitalizeFirst(OreDictionary.getOreName(OreDictionary.getOreID(itemStack)).replace("dirtyDust", "").replace("dust", "").replace("ore", "").replace("ingot", "")) + } + + def getColor(name: String): Int = + { + if (name != null && materialColorCache.containsKey(name)) + { + return materialColorCache.get(name) + } + return 0xFFFFFF + } + + @Deprecated def getMaterials: List[String] = + { + val returnMaterials: List[String] = new ArrayList[String] + { + var i: Int = 0 + while (i < materials.size) + { + { + returnMaterials.add(getName(i)) + } + ({i += 1; i - 1 }) + } + } + return returnMaterials + } + + @SubscribeEvent + def oreRegisterEvent(evt: OreDictionary.OreRegisterEvent) + { + if (evt.Name.startsWith("ingot")) + { + val oreDictName: String = evt.Name.replace("ingot", "") + val materialName: String = LanguageUtility.decapitalizeFirst(oreDictName) + if (!materials.containsKey(materialName)) + { + Settings.config.load + val allowMaterial: Boolean = Settings.config.get("Resource_Generator", "Enable " + oreDictName, true).getBoolean(true) + Settings.config.save + if (!allowMaterial || OreDetectionBlackList.isIngotBlackListed("ingot" + oreDictName) || OreDetectionBlackList.isOreBlackListed("ore" + oreDictName)) + { + return + } + materials.put(materialName, ({maxID += 1; maxID - 1 })) + } + } + } + + @SubscribeEvent + @SideOnly(Side.CLIENT) + def reloadTextures(e: TextureStitchEvent.Post) + { + computeColors + } + +} \ No newline at end of file diff --git a/src/main/scala/resonantinduction/core/resource/TileDust.scala b/src/main/scala/resonantinduction/core/resource/TileDust.scala index 46fd27d55..f52a079dd 100644 --- a/src/main/scala/resonantinduction/core/resource/TileDust.scala +++ b/src/main/scala/resonantinduction/core/resource/TileDust.scala @@ -53,7 +53,7 @@ class TileDust extends TileMaterial(Material.sand) override def onPlaced(entityLiving: EntityLivingBase, itemStack: ItemStack) { - name = ItemOreResource.getMaterialFromStack(itemStack) + name = ItemResourceDust.getMaterialFromStack(itemStack) } override def onPostBlockPlaced(world: World, x: Int, y: Int, z: Int, metadata: Int) diff --git a/src/main/scala/resonantinduction/core/resource/fluid/ItemOreResourceBucket.java b/src/main/scala/resonantinduction/core/resource/fluid/ItemOreResourceBucket.java deleted file mode 100644 index 6296dc06f..000000000 --- a/src/main/scala/resonantinduction/core/resource/fluid/ItemOreResourceBucket.java +++ /dev/null @@ -1,290 +0,0 @@ -package resonantinduction.core.resource.fluid; - -import java.util.List; - -import net.minecraft.block.material.Material; -import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumMovingObjectType; -import net.minecraft.util.MovingObjectPosition; -import net.minecraft.world.World; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.Event; -import net.minecraftforge.event.entity.player.FillBucketEvent; -import net.minecraftforge.fluids.BlockFluidFinite; -import net.minecraftforge.fluids.FluidRegistry; -import resonant.lib.utility.LanguageUtility; -import resonantinduction.core.Reference; -import resonantinduction.core.ResonantTab; -import resonantinduction.core.resource.ItemOreResource; -import resonantinduction.core.resource.ResourceGenerator; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -/** Modified version of the MC bucket to meet the needs of a dynamic fluid registry system - * - * @author Darkguardsman */ -public class ItemOreResourceBucket extends Item -{ - final boolean isMolten; - - public ItemOreResourceBucket(int id, String name, boolean isMolten) - { - super(id); - this.isMolten = isMolten; - setMaxStackSize(1); - setUnlocalizedName(Reference.PREFIX + name); - setTextureName(Reference.PREFIX + name); - setCreativeTab(ResonantTab.CORE); - setHasSubtypes(true); - setMaxDamage(0); - } - - @Override - public String getItemDisplayName(ItemStack is) - { - String material = getMaterialFromStack(is); - - if (material != null) - { - String fluidID = isMolten ? ResourceGenerator.materialNameToMolten(material) : ResourceGenerator.materialNameToMixture(material); - - if (fluidID != null && FluidRegistry.getFluid(fluidID) != null) - { - String fluidName = FluidRegistry.getFluid(fluidID).getLocalizedName(); - return (LanguageUtility.getLocal(this.getUnlocalizedName() + ".name")).replace("%v", fluidName).replace(" ", " "); - } - - return material; - } - - return null; - } - - /** Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, - * world, entityPlayer */ - @Override - public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer entityPlayer) - { - String materialName = ResourceGenerator.getName(itemStack.getItemDamage()); - if (materialName != null) - { - BlockFluidFinite molten_block = ResourceGenerator.getMolten(materialName); - BlockFluidFinite mix_block = ResourceGenerator.getMixture(materialName); - int fluidID = isMolten ? molten_block != null ? molten_block.blockID : 0 : mix_block != null ? mix_block.blockID : 0; - - if (fluidID > 0) - { - MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(world, entityPlayer, false); - - if (movingobjectposition == null) - { - return itemStack; - } - else - { - FillBucketEvent event = new FillBucketEvent(entityPlayer, itemStack, world, movingobjectposition); - if (MinecraftForge.EVENT_BUS.post(event)) - { - return itemStack; - } - - if (event.getResult() == Event.Result.ALLOW) - { - if (entityPlayer.capabilities.isCreativeMode) - { - return itemStack; - } - - if (--itemStack.stackSize <= 0) - { - return event.result; - } - - if (!entityPlayer.inventory.addItemStackToInventory(event.result)) - { - entityPlayer.dropPlayerItem(event.result); - } - - return itemStack; - } - - if (movingobjectposition.typeOfHit == EnumMovingObjectType.TILE) - { - int i = movingobjectposition.blockX; - int j = movingobjectposition.blockY; - int k = movingobjectposition.blockZ; - - if (!world.canMineBlock(entityPlayer, i, j, k)) - { - return itemStack; - } - - if (fluidID == 0) - { - if (!entityPlayer.canPlayerEdit(i, j, k, movingobjectposition.sideHit, itemStack)) - { - return itemStack; - } - - if (world.getBlockMaterial(i, j, k) == Material.water && world.getBlockMetadata(i, j, k) == 0) - { - world.setBlockToAir(i, j, k); - - if (entityPlayer.capabilities.isCreativeMode) - { - return itemStack; - } - - if (--itemStack.stackSize <= 0) - { - return new ItemStack(Item.bucketWater); - } - - if (!entityPlayer.inventory.addItemStackToInventory(new ItemStack(Item.bucketWater))) - { - entityPlayer.dropPlayerItem(new ItemStack(Item.bucketWater.itemID, 1, 0)); - } - - return itemStack; - } - - if (world.getBlockMaterial(i, j, k) == Material.lava && world.getBlockMetadata(i, j, k) == 0) - { - world.setBlockToAir(i, j, k); - - if (entityPlayer.capabilities.isCreativeMode) - { - return itemStack; - } - - if (--itemStack.stackSize <= 0) - { - return new ItemStack(Item.bucketLava); - } - - if (!entityPlayer.inventory.addItemStackToInventory(new ItemStack(Item.bucketLava))) - { - entityPlayer.dropPlayerItem(new ItemStack(Item.bucketLava.itemID, 1, 0)); - } - - return itemStack; - } - } - else - { - if (fluidID < 0) - { - return new ItemStack(Item.bucketEmpty); - } - - if (movingobjectposition.sideHit == 0) - { - --j; - } - - if (movingobjectposition.sideHit == 1) - { - ++j; - } - - if (movingobjectposition.sideHit == 2) - { - --k; - } - - if (movingobjectposition.sideHit == 3) - { - ++k; - } - - if (movingobjectposition.sideHit == 4) - { - --i; - } - - if (movingobjectposition.sideHit == 5) - { - ++i; - } - - if (!entityPlayer.canPlayerEdit(i, j, k, movingobjectposition.sideHit, itemStack)) - { - return itemStack; - } - - if (this.tryPlaceContainedLiquid(world, i, j, k, fluidID) && !entityPlayer.capabilities.isCreativeMode) - { - return new ItemStack(Item.bucketEmpty); - } - } - } - } - } - } - return itemStack; - } - - /** Attempts to place the liquid contained inside the bucket. */ - public boolean tryPlaceContainedLiquid(World world, int x, int y, int z, int fluidID) - { - if (fluidID <= 0) - { - return false; - } - else - { - Material material = world.getBlockMaterial(x, y, z); - boolean flag = !material.isSolid(); - - if (!world.isAirBlock(x, y, z) && !flag) - { - return false; - } - else - { - - if (!world.isRemote && flag && !material.isLiquid()) - { - world.destroyBlock(x, y, z, true); - } - - world.setBlock(x, y, z, fluidID, 8, 3); - - return true; - } - } - } - - public ItemStack getStackFromMaterial(String name) - { - ItemStack itemStack = new ItemStack(this); - itemStack.setItemDamage(ResourceGenerator.getID(name)); - return itemStack; - } - - public static String getMaterialFromStack(ItemStack itemStack) - { - return ResourceGenerator.getName(itemStack.getItemDamage()); - } - - @Override - public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List) - { - for (String materialName : ResourceGenerator.materials.keySet()) - { - par3List.add(getStackFromMaterial(materialName)); - } - } - - @Override - @SideOnly(Side.CLIENT) - public int getColorFromItemStack(ItemStack itemStack, int par2) - { - /** Auto-color based on the texture of the ingot. */ - String name = ItemOreResource.getMaterialFromStack(itemStack); - return ResourceGenerator.getColor(name); - } -} diff --git a/src/main/scala/resonantinduction/core/resource/fluid/ItemResourceBucket.scala b/src/main/scala/resonantinduction/core/resource/fluid/ItemResourceBucket.scala new file mode 100644 index 000000000..6490d4af3 --- /dev/null +++ b/src/main/scala/resonantinduction/core/resource/fluid/ItemResourceBucket.scala @@ -0,0 +1,236 @@ +package resonantinduction.core.resource.fluid + +import java.util.List + +import cpw.mods.fml.common.eventhandler.Event +import cpw.mods.fml.relauncher.{Side, SideOnly} +import net.minecraft.block.Block +import net.minecraft.block.material.Material +import net.minecraft.creativetab.CreativeTabs +import net.minecraft.entity.player.EntityPlayer +import net.minecraft.init.Items +import net.minecraft.item.{Item, ItemStack} +import net.minecraft.util.MovingObjectPosition +import net.minecraft.world.World +import net.minecraftforge.common.MinecraftForge +import net.minecraftforge.event.entity.player.FillBucketEvent +import net.minecraftforge.fluids.{BlockFluidFinite, FluidRegistry} +import resonant.lib.utility.LanguageUtility +import resonantinduction.core.resource.ResourceGenerator + +/** Modified version of the MC bucket to meet the needs of a dynamic fluid registry system + * + * @author Calclavia */ +class ItemResourceBucket(isMolten: Boolean) extends Item +{ + setMaxStackSize(1) + setHasSubtypes(true) + setMaxDamage(0) + + def getMaterialFromStack(itemStack: ItemStack): String = + { + return ResourceGenerator.getName(itemStack.getItemDamage) + } + + override def getItemStackDisplayName(stack: ItemStack): String = + { + val material: String = getMaterialFromStack(stack) + if (material != null) + { + val fluidID: String = if (isMolten) ResourceGenerator.materialNameToMolten(material) else ResourceGenerator.materialNameToMixture(material) + if (fluidID != null && FluidRegistry.getFluid(fluidID) != null) + { + val fluidName: String = FluidRegistry.getFluid(fluidID).getLocalizedName + return (LanguageUtility.getLocal(this.getUnlocalizedName + ".name")).replace("%v", fluidName).replace(" ", " ") + } + return material + } + return null + } + + /** Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, + * world, entityPlayer */ + override def onItemRightClick(itemStack: ItemStack, world: World, entityPlayer: EntityPlayer): ItemStack = + { + val materialName: String = ResourceGenerator.getName(itemStack.getItemDamage) + if (materialName != null) + { + val moltenBlock: BlockFluidFinite = ResourceGenerator.getMolten(materialName) + val mixBlock: BlockFluidFinite = ResourceGenerator.getMixture(materialName) + val fluid: Block = if (isMolten) if (moltenBlock != null) moltenBlock else null else if (mixBlock != null) mixBlock else null + if (fluid != null) + { + val movingobjectposition: MovingObjectPosition = this.getMovingObjectPositionFromPlayer(world, entityPlayer, false) + if (movingobjectposition == null) + { + return itemStack + } + else + { + val event: FillBucketEvent = new FillBucketEvent(entityPlayer, itemStack, world, movingobjectposition) + if (MinecraftForge.EVENT_BUS.post(event)) + { + return itemStack + } + if (event.getResult eq Event.Result.ALLOW) + { + if (entityPlayer.capabilities.isCreativeMode) + { + return itemStack + } + if (({itemStack.stackSize -= 1; itemStack.stackSize }) <= 0) + { + return event.result + } + if (!entityPlayer.inventory.addItemStackToInventory(event.result)) + { + entityPlayer.dropPlayerItemWithRandomChoice(event.result, false) + } + return itemStack + } + if (movingobjectposition.typeOfHit eq MovingObjectPosition.MovingObjectType.BLOCK) + { + var i: Int = movingobjectposition.blockX + var j: Int = movingobjectposition.blockY + var k: Int = movingobjectposition.blockZ + if (!world.canMineBlock(entityPlayer, i, j, k)) + { + return itemStack + } + if (fluid == null) + { + if (!entityPlayer.canPlayerEdit(i, j, k, movingobjectposition.sideHit, itemStack)) + { + return itemStack + } + if (world.getBlock(i, j, k).getMaterial eq Material.water && world.getBlockMetadata(i, j, k) == 0) + { + world.setBlockToAir(i, j, k) + if (entityPlayer.capabilities.isCreativeMode) + { + return itemStack + } + if (({itemStack.stackSize -= 1; itemStack.stackSize }) <= 0) + { + return new ItemStack(Items.water_bucket) + } + if (!entityPlayer.inventory.addItemStackToInventory(new ItemStack(Items.water_bucket))) + { + entityPlayer.dropPlayerItemWithRandomChoice(new ItemStack(Items.water_bucket, 1, 0), false) + } + return itemStack + } + if (world.getBlock(i, j, k).getMaterial eq Material.lava && world.getBlockMetadata(i, j, k) == 0) + { + world.setBlockToAir(i, j, k) + if (entityPlayer.capabilities.isCreativeMode) + { + return itemStack + } + if (({itemStack.stackSize -= 1; itemStack.stackSize }) <= 0) + { + return new ItemStack(Items.lava_bucket) + } + if (!entityPlayer.inventory.addItemStackToInventory(new ItemStack(Items.lava_bucket))) + { + entityPlayer.dropPlayerItemWithRandomChoice(new ItemStack(Items.lava_bucket, 1, 0), false) + } + return itemStack + } + } + else + { + if (fluid != null) + { + return new ItemStack(Items.bucket) + } + if (movingobjectposition.sideHit == 0) + { + j -= 1 + } + if (movingobjectposition.sideHit == 1) + { + j += 1 + } + if (movingobjectposition.sideHit == 2) + { + k -= 1 + } + if (movingobjectposition.sideHit == 3) + { + k += 1 + } + if (movingobjectposition.sideHit == 4) + { + i -= 1 + } + if (movingobjectposition.sideHit == 5) + { + i += 1 + } + if (!entityPlayer.canPlayerEdit(i, j, k, movingobjectposition.sideHit, itemStack)) + { + return itemStack + } + if (this.tryPlaceContainedLiquid(world, i, j, k, fluid) && !entityPlayer.capabilities.isCreativeMode) + { + return new ItemStack(Items.bucket) + } + } + } + } + } + } + return itemStack + } + + /** Attempts to place the liquid contained inside the bucket. */ + def tryPlaceContainedLiquid(world: World, x: Int, y: Int, z: Int, fluidID: Block): Boolean = + { + if (fluidID == null) + { + return false + } + else + { + val material: Material = world.getBlock(x, y, z).getMaterial + val flag: Boolean = !material.isSolid + if (!world.isAirBlock(x, y, z) && !flag) + { + return false + } + else + { + if (!world.isRemote && flag && !material.isLiquid) + { + world.setBlockToAir(x, y, z) + } + world.setBlock(x, y, z, fluidID, 8, 3) + return true + } + } + } + + def getStackFromMaterial(name: String): ItemStack = + { + val itemStack: ItemStack = new ItemStack(this) + itemStack.setItemDamage(ResourceGenerator.getID(name)) + return itemStack + } + + override def getSubItems(item: Item, tabs: CreativeTabs, list: List[_]) + { + import scala.collection.JavaConversions._ + for (materialName <- ResourceGenerator.materials.keySet) + { + list.add(getStackFromMaterial(materialName)) + } + } + + @SideOnly(Side.CLIENT) + override def getColorFromItemStack(itemStack: ItemStack, par2: Int): Int = + { + val name = ResourceGenerator.getMaterialFromStack(itemStack) + return ResourceGenerator.getColor(name) + } +} \ No newline at end of file