From e955843b7514b185ec157cfa8ef91a0b0aebd768 Mon Sep 17 00:00:00 2001 From: Calclavia Date: Sat, 27 Dec 2014 13:30:53 +0800 Subject: [PATCH] Reworked resource generator --- .../resonantinduction/core/CoreContent.scala | 5 +- .../core/ResonantInduction.scala | 2 + .../core/resource/ResourceFactory.scala | 510 ++++++++---------- .../content/BlockDecoration.scala | 2 +- .../resource/content/BlockFluidMaterial.scala | 44 ++ .../resource/content/BlockFluidMixture.scala | 57 ++ .../core/resource/content/FluidColored.scala | 16 + .../core/resource/content/ItemDust.scala | 9 + .../resource/content/ItemRefinedDust.scala | 9 + .../core/resource/content/ItemResource.scala | 12 + .../core/resource/content/ItemRubble.scala | 9 + .../mech/process/mixer/TileMixer.scala | 2 +- 12 files changed, 401 insertions(+), 276 deletions(-) rename src/main/scala/resonantinduction/core/{ => resource}/content/BlockDecoration.scala (97%) create mode 100644 src/main/scala/resonantinduction/core/resource/content/BlockFluidMaterial.scala create mode 100644 src/main/scala/resonantinduction/core/resource/content/BlockFluidMixture.scala create mode 100644 src/main/scala/resonantinduction/core/resource/content/FluidColored.scala create mode 100644 src/main/scala/resonantinduction/core/resource/content/ItemDust.scala create mode 100644 src/main/scala/resonantinduction/core/resource/content/ItemRefinedDust.scala create mode 100644 src/main/scala/resonantinduction/core/resource/content/ItemResource.scala create mode 100644 src/main/scala/resonantinduction/core/resource/content/ItemRubble.scala diff --git a/src/main/scala/resonantinduction/core/CoreContent.scala b/src/main/scala/resonantinduction/core/CoreContent.scala index dcd2899f2..906fce70a 100644 --- a/src/main/scala/resonantinduction/core/CoreContent.scala +++ b/src/main/scala/resonantinduction/core/CoreContent.scala @@ -4,7 +4,8 @@ import net.minecraft.block.Block import net.minecraft.init.{Blocks, Items} import net.minecraft.item.ItemStack import resonant.lib.mod.content.ContentHolder -import resonantinduction.core.content.BlockDecoration +import resonantinduction.core.resource.content.BlockDecoration +import resonantinduction.core.resource.ResourceFactory /** * The core contents of Resonant Induction @@ -22,7 +23,7 @@ object CoreContent extends ContentHolder override def postInit() { //Generate resources - + ResourceFactory.generateAll() recipes += shaped(new ItemStack(decoration, 8, 3), "XXX", "XCX", "XXX", 'X', Blocks.cobblestone, 'C', new ItemStack(Items.coal, 1, 1)) recipes +=(new ItemStack(decoration, 3), new ItemStack(decoration, 1, 5), 5) diff --git a/src/main/scala/resonantinduction/core/ResonantInduction.scala b/src/main/scala/resonantinduction/core/ResonantInduction.scala index d2754d317..cb91d4a31 100644 --- a/src/main/scala/resonantinduction/core/ResonantInduction.scala +++ b/src/main/scala/resonantinduction/core/ResonantInduction.scala @@ -13,6 +13,7 @@ import resonant.lib.mod.loadable.LoadableHandler import resonantinduction.archaic.ArchaicContent import resonantinduction.atomic.AtomicContent import resonantinduction.core.handler.TextureHookHandler +import resonantinduction.core.resource.ResourceFactory import resonantinduction.electrical.ElectricalContent import resonantinduction.mechanical.{MechanicalContent, MicroblockHighlightHandler} @@ -43,6 +44,7 @@ final object ResonantInduction MinecraftForge.EVENT_BUS.register(TextureHookHandler) MinecraftForge.EVENT_BUS.register(MicroblockHighlightHandler) + MinecraftForge.EVENT_BUS.register(ResourceFactory) loadables.applyModule(proxy) loadables.applyModule(packetHandler) diff --git a/src/main/scala/resonantinduction/core/resource/ResourceFactory.scala b/src/main/scala/resonantinduction/core/resource/ResourceFactory.scala index 349b4b69e..5c2e95ba6 100644 --- a/src/main/scala/resonantinduction/core/resource/ResourceFactory.scala +++ b/src/main/scala/resonantinduction/core/resource/ResourceFactory.scala @@ -3,31 +3,261 @@ package resonantinduction.core.resource import java.awt._ import java.awt.image.BufferedImage import java.io.InputStream -import java.util.{List, _} +import java.util.List import javax.imageio.ImageIO -import cpw.mods.fml.common.registry.{GameRegistry, LanguageRegistry} +import cpw.mods.fml.common.eventhandler.SubscribeEvent +import cpw.mods.fml.common.registry.LanguageRegistry import cpw.mods.fml.relauncher.{Side, SideOnly} import net.minecraft.block.Block import net.minecraft.client.Minecraft import net.minecraft.init.{Blocks, Items} -import net.minecraft.item.{Item, ItemStack} 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.fluids.{FluidContainerRegistry, FluidRegistry, FluidStack} import net.minecraftforge.oredict.OreDictionary import resonant.api.recipe.MachineRecipes import resonant.lib.factory.resources.RecipeType -import resonant.lib.prefab.tile.{BlockFluidMaterial, BlockFluidMixture, FluidColored} +import resonant.lib.prefab.item.ItemFluidBucket import resonant.lib.utility.LanguageUtility -import resonantinduction.core.{Reference, ResonantInduction, Settings} +import resonant.lib.wrapper.StringWrapper._ +import resonantinduction.core.resource.content._ +import resonantinduction.core.{CoreContent, Reference, Settings} + +import scala.collection.convert.wrapAll._ +import scala.collection.mutable /** * @author Calclavia */ object ResourceFactory { + /** + * A list of materials + */ + val materials = mutable.Set.empty[String] + + val blackList = Array("uranium") + + /** + * Reference to color of material + */ + val materialColorCache = mutable.Map.empty[String, Integer] + /** + * Reference to computed color tint of auto-generated ores + */ + val iconColorCache = mutable.Map.empty[IIcon, Integer] + val moltenFluidMap = mutable.Map.empty[String, Block] + val mixtureFluidMap = mutable.Map.empty[String, Block] + val moltenBucketMap = mutable.Map.empty[String, Item] + val mixtureBucketMap = mutable.Map.empty[String, Item] + val rubbleMap = mutable.Map.empty[String, Item] + val dustMap = mutable.Map.empty[String, Item] + val refinedDustMap = mutable.Map.empty[String, Item] + + def generate(materialName: String) + { + val nameCaps: String = LanguageUtility.capitalizeFirst(materialName) + var localizedName: String = materialName + val list: List[ItemStack] = OreDictionary.getOres("ingot" + nameCaps) + + //Fix the material name + if (list.size > 0) + { + val firstOreItemStack = list(0) + localizedName = firstOreItemStack.getDisplayName.trim + + if (LanguageUtility.getLocal(localizedName) != null && LanguageUtility.getLocal(localizedName) != "") + localizedName = LanguageUtility.getLocal(localizedName) + + localizedName.replace(LanguageUtility.getLocal("misc.resonantinduction.ingot"), "").replaceAll("^ ", "").replaceAll(" $", "") + } + + //Generate molten fluid + val fluidMolten = new FluidColored(ResourceFactory.materialNameToMolten(materialName)).setDensity(7).setViscosity(5000).setTemperature(273 + 1538) + FluidRegistry.registerFluid(fluidMolten) + LanguageRegistry.instance.addStringLocalization(fluidMolten.getUnlocalizedName, LanguageUtility.getLocal("tooltip.molten") + " " + localizedName) + val blockFluidMaterial = new BlockFluidMaterial(fluidMolten) + CoreContent.manager.newBlock("molten" + nameCaps, blockFluidMaterial) + moltenFluidMap += (materialName -> blockFluidMaterial) + + //Generate molten bucket + val moltenBucket = new ItemFluidBucket + FluidContainerRegistry.registerFluidContainer(fluidMolten, new ItemStack(moltenBucket)) + moltenBucketMap += materialName -> moltenBucket + + //Generate mixture fluid + val fluidMixture = new FluidColored(ResourceFactory.materialNameToMixture(materialName)) + FluidRegistry.registerFluid(fluidMixture) + val blockFluidMixture: BlockFluidMixture = new BlockFluidMixture(fluidMixture) + LanguageRegistry.instance.addStringLocalization(fluidMixture.getUnlocalizedName, localizedName + " " + LanguageUtility.getLocal("tooltip.mixture")) + CoreContent.manager.newBlock("mixture" + nameCaps, blockFluidMixture) + mixtureFluidMap += materialName -> blockFluidMixture + + //Generate mixture bucket + val mixtureBucket = new ItemFluidBucket + FluidContainerRegistry.registerFluidContainer(fluidMixture, new ItemStack(mixtureBucket)) + mixtureBucketMap += materialName -> mixtureBucket + + //Generate rubble, dust and refined dust + val rubble = new ItemStack(CoreContent.manager.newItem("rubble" + materialName.capitalizeFirst, new ItemRubble)) + val dust = new ItemStack(CoreContent.manager.newItem("dust" + materialName.capitalizeFirst, new ItemDust)) + val refinedDust = new ItemStack(CoreContent.manager.newItem("refinedDust" + materialName.capitalizeFirst, new ItemRefinedDust)) + + //Register rubble, dust and refined dust to OreDictionary + OreDictionary.registerOre("rubble" + nameCaps, rubble) + OreDictionary.registerOre("dirtyDust" + nameCaps, dust) + OreDictionary.registerOre("dust" + nameCaps, refinedDust) + + //Add recipes + MachineRecipes.INSTANCE.addRecipe(RecipeType.SMELTER.name, new FluidStack(fluidMolten, FluidContainerRegistry.BUCKET_VOLUME), "ingot" + nameCaps) + MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER.name, "rubble" + nameCaps, dust, dust) + MachineRecipes.INSTANCE.addRecipe(RecipeType.MIXER.name, "dirtyDust" + nameCaps, refinedDust) + FurnaceRecipes.smelting.func_151394_a(dust, OreDictionary.getOres("ingot" + nameCaps).get(0).copy, 0.7f) + FurnaceRecipes.smelting.func_151394_a(refinedDust, OreDictionary.getOres("ingot" + nameCaps).get(0).copy, 0.7f) + + if (OreDictionary.getOres("ore" + nameCaps).size > 0) + MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER.name, "ore" + nameCaps, "rubble" + nameCaps) + } + + def generateAll() + { + //Add vanilla ores into ore dictionary + OreDictionary.registerOre("ingotGold", Items.gold_ingot) + OreDictionary.registerOre("ingotIron", Items.iron_ingot) + OreDictionary.registerOre("oreGold", Blocks.gold_ore) + OreDictionary.registerOre("oreIron", Blocks.iron_ore) + OreDictionary.registerOre("oreLapis", Blocks.lapis_ore) + + //Add vanilla ore processing recipes + MachineRecipes.INSTANCE.addRecipe(RecipeType.SMELTER.name, new FluidStack(FluidRegistry.LAVA, FluidContainerRegistry.BUCKET_VOLUME), new ItemStack(Blocks.stone)) + MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER.name, Blocks.cobblestone, Blocks.gravel) + MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER.name, Blocks.stone, Blocks.cobblestone) + MachineRecipes.INSTANCE.addRecipe(RecipeType.SAWMILL.name, Blocks.log, new ItemStack(Blocks.planks, 7, 0)) + MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER.name, Blocks.gravel, Blocks.sand) + MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER.name, Blocks.glass, Blocks.sand) + + //Clean material set by removing invalid materials + materials --= materials.filter(m => OreDictionary.getOres("ore" + m.capitalizeFirst).size > 0) + //Call generate() on all materials + materials.foreach(generate) + } + + @SideOnly(Side.CLIENT) + def computeColors() + { + for (material <- materials) + { + for (ingotStack <- OreDictionary.getOres("ingot" + LanguageUtility.capitalizeFirst(material))) + { + materialColorCache += material -> getAverageColor(ingotStack) + } + + if (!materialColorCache.contains(material)) + { + materialColorCache += material -> 0xFFFFFF + } + } + } + + /** + * Gets the average color of this item by looking at each pixel of the texture. + * + * @param itemStack - The 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(icon) + } + var iconString: String = icon.getIconName + if (iconString != null && !iconString.contains("MISSING_ICON_ITEM")) + { + iconString = (if (iconString.contains(":")) iconString.replace(":", ":" + Reference.itemTextureDirectory) else Reference.itemTextureDirectory + 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 + + for (x <- 0 until width; y <- 0 until 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 + } + } + } + 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 => + { + Reference.logger.fine("Failed to compute colors for: " + item) + } + } + return 0xFFFFFF + } + + @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.contains(materialName)) + { + Settings.config.load() + val allowMaterial = Settings.config.get("Resource-Generator", "Enable " + oreDictName, true).getBoolean(true) + Settings.config.save() + + if (!allowMaterial && !blackList.contains(materialName)) + { + return + } + materials += materialName + } + } + } + + @SubscribeEvent + @SideOnly(Side.CLIENT) + def reloadTextures(e: TextureStitchEvent.Post) + { + computeColors() + } + def moltenToMaterial(fluidName: String): String = { return fluidNameToMaterial(fluidName, "molten") @@ -58,21 +288,6 @@ object ResourceFactory 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", "")) @@ -82,258 +297,9 @@ object ResourceFactory { if (name != null && materialColorCache.containsKey(name)) { - return materialColorCache.get(name) + return materialColorCache(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 - } -} - -class ResourceFactory -{ - /** - * A list of materials - */ - private[core] final val materials: Set[String] = new HashSet[_] - /** - * Reference to color of material - */ - private[core] final val materialColorCache: HashMap[String, Integer] = new HashMap[String, Integer] - /** - * Reference to computed color tint of auto-generated ores - */ - private[core] final val iconColorCache: HashMap[IIcon, Integer] = new HashMap[IIcon, Integer] - private[core] final val moltenFluidMap: HashMap[String, Block] = new HashMap[_, _] - private[core] final val mixtureFluidMap: HashMap[String, Block] = new HashMap[_, _] - private[core] final val moltenBucketMap: HashMap[String, Item] = new HashMap[_, _] - private[core] final val mixtureBucketMap: HashMap[String, Item] = new HashMap[_, _] - private[core] final val rubbleMap: HashMap[String, Item] = new HashMap[_, _] - private[core] final val dustMap: HashMap[String, Item] = new HashMap[_, _] - private[core] final val refinedDustMap: HashMap[String, Item] = new HashMap[_, _] - - def generate(materialName: String) - { - val nameCaps: String = LanguageUtility.capitalizeFirst(materialName) - var localizedName: String = materialName - val list: List[ItemStack] = OreDictionary.getOres("ingot" + nameCaps) - if (list.size > 0) - { - val `type`: ItemStack = list.get(0) - localizedName = `type`.getDisplayName.trim - if (LanguageUtility.getLocal(localizedName) != null && LanguageUtility.getLocal(localizedName) ne "") - { - localizedName = LanguageUtility.getLocal(localizedName) - } - localizedName.replace(LanguageUtility.getLocal("misc.resonantinduction.ingot"), "").replaceAll("^ ", "").replaceAll(" $", "") - } - val fluidMolten: FluidColored = new FluidColored(ResourceFactory.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) - moltenFluidMap.put(materialName, blockFluidMaterial) - FluidContainerRegistry.registerFluidContainer(fluidMolten, moltenBucketMap.getStackFromMaterial(materialName)) - val fluidMixture: FluidColored = new FluidColored(ResourceFactory.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) - mixtureFluidMap.put(materialName, blockFluidMixture) - FluidContainerRegistry.registerFluidContainer(fluidMixture, ResonantInduction.itemBucketMixture.getStackFromMaterial(materialName)) - MachineRecipes.INSTANCE.addRecipe(RecipeType.SMELTER.name, new FluidStack(fluidMolten, FluidContainerRegistry.BUCKET_VOLUME), "ingot" + nameCaps) - val dust: ItemStack = ResonantInduction.itemDust.getStackFromMaterial(materialName) - val rubble: ItemStack = ResonantInduction.itemRubble.getStackFromMaterial(materialName) - val refinedDust: ItemStack = 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) - 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", Items.gold_ingot) - OreDictionary.registerOre("ingotIron", Items.iron_ingot) - OreDictionary.registerOre("oreGold", Blocks.gold_ore) - OreDictionary.registerOre("oreIron", Blocks.iron_ore) - OreDictionary.registerOre("oreLapis", Blocks.lapis_ore) - MachineRecipes.INSTANCE.addRecipe(RecipeType.SMELTER.name, new FluidStack(FluidRegistry.LAVA, FluidContainerRegistry.BUCKET_VOLUME), new ItemStack(Blocks.stone)) - MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER.name, Blocks.cobblestone, Blocks.gravel) - MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER.name, Blocks.stone, Blocks.cobblestone) - MachineRecipes.INSTANCE.addRecipe(RecipeType.SAWMILL.name, Blocks.log, new ItemStack(Blocks.planks, 7, 0)) - MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER.name, Blocks.gravel, Blocks.sand) - MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER.name, Blocks.glass, Blocks.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.keySet) - { - val totalR: Int = 0 - val totalG: Int = 0 - val totalB: Int = 0 - val colorCount: Int = 0 - import scala.collection.JavaConversions._ - 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 - The itemSstack - * @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.itemTextureDirectory) else Reference.itemTextureDirectory + 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 => - { - Reference.logger.fine("Failed to compute colors for: " + item) - } - } - return 0xFFFFFF - } - - @ForgeSubscribe 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.CONFIGURATION.load - val allowMaterial: Boolean = Settings.CONFIGURATION.get("Resource_Generator", "Enable " + oreDictName, true).getBoolean(true) - Settings.CONFIGURATION.save - if (!allowMaterial || OreDetectionBlackList.isIngotBlackListed("ingot" + oreDictName) || OreDetectionBlackList.isOreBlackListed("ore" + oreDictName)) - { - return - } - materials.put(materialName, ({ResourceFactory.maxID += 1; ResourceFactory.maxID - 1})) - } - } - } - - @ForgeSubscribe @SideOnly(Side.CLIENT) def reloadTextures(e: TextureStitchEvent.Post) - { - computeColors - } } \ No newline at end of file diff --git a/src/main/scala/resonantinduction/core/content/BlockDecoration.scala b/src/main/scala/resonantinduction/core/resource/content/BlockDecoration.scala similarity index 97% rename from src/main/scala/resonantinduction/core/content/BlockDecoration.scala rename to src/main/scala/resonantinduction/core/resource/content/BlockDecoration.scala index bc1fd330f..52f4d6361 100644 --- a/src/main/scala/resonantinduction/core/content/BlockDecoration.scala +++ b/src/main/scala/resonantinduction/core/resource/content/BlockDecoration.scala @@ -1,4 +1,4 @@ -package resonantinduction.core.content +package resonantinduction.core.resource.content import java.util.List diff --git a/src/main/scala/resonantinduction/core/resource/content/BlockFluidMaterial.scala b/src/main/scala/resonantinduction/core/resource/content/BlockFluidMaterial.scala new file mode 100644 index 000000000..d242e6810 --- /dev/null +++ b/src/main/scala/resonantinduction/core/resource/content/BlockFluidMaterial.scala @@ -0,0 +1,44 @@ +package resonantinduction.core.resource.content + +import cpw.mods.fml.relauncher.{Side, SideOnly} +import net.minecraft.block.material.Material +import net.minecraft.world.{IBlockAccess, World} +import net.minecraftforge.fluids.{BlockFluidFinite, Fluid, FluidContainerRegistry, FluidStack} + +/** + * Fluid class uses for molten materials. + * + * @author Calclavia + */ +class BlockFluidMaterial(fluid: Fluid) extends BlockFluidFinite(fluid, Material.lava) +{ + def setQuanta(world: World, x: Int, y: Int, z: Int, quanta: Int) + { + if (quanta > 0) + { + world.setBlockMetadataWithNotify(x, y, z, quanta, 3) + } + else + { + world.setBlockToAir(x, y, z) + } + } + + override def drain(world: World, x: Int, y: Int, z: Int, doDrain: Boolean): FluidStack = + { + val stack: FluidStack = new FluidStack(getFluid, (FluidContainerRegistry.BUCKET_VOLUME * this.getFilledPercentage(world, x, y, z)).toInt) + if (doDrain) + { + world.setBlockToAir(x, y, z) + } + return stack + } + + @SideOnly(Side.CLIENT) + override def colorMultiplier(access: IBlockAccess, x: Int, y: Int, z: Int): Int = + { + return getFluid.getColor + } + + override def canDrain(world: World, x: Int, y: Int, z: Int): Boolean = true +} \ No newline at end of file diff --git a/src/main/scala/resonantinduction/core/resource/content/BlockFluidMixture.scala b/src/main/scala/resonantinduction/core/resource/content/BlockFluidMixture.scala new file mode 100644 index 000000000..740539ec1 --- /dev/null +++ b/src/main/scala/resonantinduction/core/resource/content/BlockFluidMixture.scala @@ -0,0 +1,57 @@ +package resonantinduction.core.resource.content + +import cpw.mods.fml.relauncher.{Side, SideOnly} +import net.minecraft.block.material.Material +import net.minecraft.item.ItemStack +import net.minecraft.world.{IBlockAccess, World} +import net.minecraftforge.fluids.{BlockFluidFinite, Fluid, FluidContainerRegistry, FluidStack} +import resonant.api.recipe.MachineRecipes +import resonant.lib.factory.resources.RecipeType + +/** + * @author Calclavia + */ +class BlockFluidMixture(fluid: Fluid) extends BlockFluidFinite(fluid, Material.water) +{ + def setQuanta(world: World, x: Int, y: Int, z: Int, quanta: Int) + { + if (quanta > 0 && quanta <= quantaPerBlock) + { + world.setBlockMetadataWithNotify(x, y, z, quanta, 3) + } + else + { + world.setBlockToAir(x, y, z) + } + } + + override def drain(world: World, x: Int, y: Int, z: Int, doDrain: Boolean): FluidStack = + { + val stack: FluidStack = new FluidStack(getFluid, (FluidContainerRegistry.BUCKET_VOLUME * this.getFilledPercentage(world, x, y, z)).asInstanceOf[Int]) + if (doDrain) + { + world.setBlockToAir(x, y, z) + } + return stack + } + + @SideOnly(Side.CLIENT) override def colorMultiplier(access: IBlockAccess, x: Int, y: Int, z: Int): Int = getFluid.getColor() + + def mix(world: World, x: Int, y: Int, z: Int, stack: ItemStack): Boolean = + { + if (MachineRecipes.INSTANCE.getOutput(RecipeType.MIXER.name, stack).length > 0 && getQuantaValue(world, x, y, z) < quantaPerBlock) + { + if (getQuantaValue(world, x, y, z) < quantaPerBlock) + { + world.setBlockMetadataWithNotify(x, y, z, getQuantaValue(world, x, y, z) + 1, 3) + world.markBlockForUpdate(x, y, z) + return true + } + } + return false + } + + override def canDrain(world: World, x: Int, y: Int, z: Int): Boolean = true + + def getQuantaPerBlock: Int = quantaPerBlock +} \ No newline at end of file diff --git a/src/main/scala/resonantinduction/core/resource/content/FluidColored.scala b/src/main/scala/resonantinduction/core/resource/content/FluidColored.scala new file mode 100644 index 000000000..802ab91e9 --- /dev/null +++ b/src/main/scala/resonantinduction/core/resource/content/FluidColored.scala @@ -0,0 +1,16 @@ +package resonantinduction.core.resource.content + +import net.minecraftforge.fluids.Fluid + +class FluidColored(fluidName: String) extends Fluid(fluidName) +{ + var color = 0xFFFFFF + + def setColor(color: Int): FluidColored = + { + this.color = color + return this + } + + override def getColor = color +} \ No newline at end of file diff --git a/src/main/scala/resonantinduction/core/resource/content/ItemDust.scala b/src/main/scala/resonantinduction/core/resource/content/ItemDust.scala new file mode 100644 index 000000000..a0d43caf7 --- /dev/null +++ b/src/main/scala/resonantinduction/core/resource/content/ItemDust.scala @@ -0,0 +1,9 @@ +package resonantinduction.core.resource.content + +/** + * @author Calclavia + */ +class ItemDust extends ItemResource + { + + } diff --git a/src/main/scala/resonantinduction/core/resource/content/ItemRefinedDust.scala b/src/main/scala/resonantinduction/core/resource/content/ItemRefinedDust.scala new file mode 100644 index 000000000..b437eed22 --- /dev/null +++ b/src/main/scala/resonantinduction/core/resource/content/ItemRefinedDust.scala @@ -0,0 +1,9 @@ +package resonantinduction.core.resource.content + +/** + * @author Calclavia + */ +class ItemRefinedDust extends ItemResource + { + + } diff --git a/src/main/scala/resonantinduction/core/resource/content/ItemResource.scala b/src/main/scala/resonantinduction/core/resource/content/ItemResource.scala new file mode 100644 index 000000000..c79131425 --- /dev/null +++ b/src/main/scala/resonantinduction/core/resource/content/ItemResource.scala @@ -0,0 +1,12 @@ +package resonantinduction.core.resource.content + +import net.minecraft.item.Item + +/** + * A class used by rubble, dusts and refined dusts + * @author Calclavia + */ +abstract class ItemResource extends Item +{ + +} diff --git a/src/main/scala/resonantinduction/core/resource/content/ItemRubble.scala b/src/main/scala/resonantinduction/core/resource/content/ItemRubble.scala new file mode 100644 index 000000000..977f30d65 --- /dev/null +++ b/src/main/scala/resonantinduction/core/resource/content/ItemRubble.scala @@ -0,0 +1,9 @@ +package resonantinduction.core.resource.content + +/** + * @author Calclavia + */ +class ItemRubble extends ItemResource +{ + +} diff --git a/src/main/scala/resonantinduction/mechanical/mech/process/mixer/TileMixer.scala b/src/main/scala/resonantinduction/mechanical/mech/process/mixer/TileMixer.scala index c582a1bbe..44745e715 100644 --- a/src/main/scala/resonantinduction/mechanical/mech/process/mixer/TileMixer.scala +++ b/src/main/scala/resonantinduction/mechanical/mech/process/mixer/TileMixer.scala @@ -18,11 +18,11 @@ import resonant.api.recipe.MachineRecipes import resonant.lib.factory.resources.RecipeType import resonant.engine.ResonantEngine import resonant.lib.`type`.Timer -import resonant.lib.prefab.tile.BlockFluidMixture import resonant.lib.render.RenderUtility import resonant.lib.transform.rotation.Quaternion import resonant.lib.transform.vector.Vector3 import resonantinduction.core.Reference +import resonantinduction.core.resource.content.BlockFluidMixture import resonantinduction.mechanical.mech.TileMechanical import scala.collection.JavaConversions._