From e6d0cc5319035c9fa41efb65d3c19e7d35ae9008 Mon Sep 17 00:00:00 2001 From: Robert S Date: Tue, 25 Mar 2014 07:34:42 -0400 Subject: [PATCH 1/4] Created a config to disable the ore generator in total --- .../core/ResonantInduction.java | 181 +++++++++--------- .../resonantinduction/core/Settings.java | 2 + 2 files changed, 92 insertions(+), 91 deletions(-) diff --git a/src/main/scala/resonantinduction/core/ResonantInduction.java b/src/main/scala/resonantinduction/core/ResonantInduction.java index 8d017ebcd..0e15f3de8 100644 --- a/src/main/scala/resonantinduction/core/ResonantInduction.java +++ b/src/main/scala/resonantinduction/core/ResonantInduction.java @@ -40,119 +40,118 @@ import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.registry.GameRegistry; -/** - * The core module of Resonant Induction +/** The core module of Resonant Induction * - * @author Calclavia - */ + * @author Calclavia */ @Mod(modid = ResonantInduction.ID, name = ResonantInduction.NAME, version = Reference.VERSION, dependencies = "required-after:ForgeMultipart@[1.0.0.244,);required-after:CalclaviaCore;before:ThermalExpansion;before:Mekanism") @NetworkMod(channels = Reference.CHANNEL, clientSideRequired = true, serverSideRequired = false, packetHandler = PacketHandler.class) @ModstatInfo(prefix = "resonantin") public class ResonantInduction { - /** Mod Information */ - public static final String ID = "ResonantInduction|Core"; - public static final String NAME = Reference.NAME; + /** Mod Information */ + public static final String ID = "ResonantInduction|Core"; + public static final String NAME = Reference.NAME; - @Instance(ID) - public static ResonantInduction INSTANCE; + @Instance(ID) + public static ResonantInduction INSTANCE; - @SidedProxy(clientSide = "resonantinduction.core.ClientProxy", serverSide = "resonantinduction.core.CommonProxy") - public static CommonProxy proxy; + @SidedProxy(clientSide = "resonantinduction.core.ClientProxy", serverSide = "resonantinduction.core.CommonProxy") + public static CommonProxy proxy; - @Mod.Metadata(ID) - public static ModMetadata metadata; + @Mod.Metadata(ID) + public static ModMetadata metadata; - public static final Logger LOGGER = Logger.getLogger(Reference.NAME); + public static final Logger LOGGER = Logger.getLogger(Reference.NAME); - /** Packets */ - public static final PacketTile PACKET_TILE = new PacketTile(Reference.CHANNEL); - public static final PacketMultiPart PACKET_MULTIPART = new PacketMultiPart(Reference.CHANNEL); - public static final PacketAnnotation PACKET_ANNOTATION = new PacketAnnotation(Reference.CHANNEL); + /** Packets */ + public static final PacketTile PACKET_TILE = new PacketTile(Reference.CHANNEL); + public static final PacketMultiPart PACKET_MULTIPART = new PacketMultiPart(Reference.CHANNEL); + public static final PacketAnnotation PACKET_ANNOTATION = new PacketAnnotation(Reference.CHANNEL); - /** Blocks and Items */ - public static Block blockOre; - public static ItemOreResource itemRubble, itemDust, itemRefinedDust; - public static ItemOreResourceBucket itemBucketMixture, itemBucketMolten; - public static Block blockDust; - public static final HashMap blockMixtureFluids = new HashMap(); - public static final HashMap blockMoltenFluid = new HashMap(); - public static Block blockMachinePart; + /** Blocks and Items */ + public static Block blockOre; + public static ItemOreResource itemRubble, itemDust, itemRefinedDust; + public static ItemOreResourceBucket itemBucketMixture, itemBucketMolten; + public static Block blockDust; + public static final HashMap blockMixtureFluids = new HashMap(); + public static final HashMap blockMoltenFluid = new HashMap(); + public static Block blockMachinePart; - public static final ContentRegistry contentRegistry = new ContentRegistry(Settings.CONFIGURATION, Settings.idManager, ID).setPrefix(Reference.PREFIX).setTab(TabRI.CORE); + public static final ContentRegistry contentRegistry = new ContentRegistry(Settings.CONFIGURATION, Settings.idManager, ID).setPrefix(Reference.PREFIX).setTab(TabRI.CORE); - /** - * Recipe Types - */ - public static enum RecipeType - { - CRUSHER, GRINDER, MIXER, SMELTER, SAWMILL; - } + /** Recipe Types */ + public static enum RecipeType + { + CRUSHER, + GRINDER, + MIXER, + SMELTER, + SAWMILL; + } - @EventHandler - public void preInit(FMLPreInitializationEvent evt) - { - ResonantInduction.LOGGER.setParent(FMLLog.getLogger()); - NetworkRegistry.instance().registerGuiHandler(this, proxy); - Modstats.instance().getReporter().registerMod(this); - Settings.CONFIGURATION.load(); - // Register Forge Events - MinecraftForge.EVENT_BUS.register(ResourceGenerator.INSTANCE); - MinecraftForge.EVENT_BUS.register(new TextureHookHandler()); + @EventHandler + public void preInit(FMLPreInitializationEvent evt) + { + ResonantInduction.LOGGER.setParent(FMLLog.getLogger()); + NetworkRegistry.instance().registerGuiHandler(this, proxy); + Modstats.instance().getReporter().registerMod(this); + Settings.CONFIGURATION.load(); + // Register Forge Events + MinecraftForge.EVENT_BUS.register(ResourceGenerator.INSTANCE); + MinecraftForge.EVENT_BUS.register(new TextureHookHandler()); - blockMachinePart = contentRegistry.createBlock(BlockMachineMaterial.class, ItemBlockMetadata.class); + blockMachinePart = contentRegistry.createBlock(BlockMachineMaterial.class, ItemBlockMetadata.class); - /** - * Melting dusts - */ - blockDust = contentRegistry.createTile(BlockDust.class, TileMaterial.class).setCreativeTab(null); + /** Melting dusts */ + blockDust = contentRegistry.createTile(BlockDust.class, TileMaterial.class).setCreativeTab(null); - // Items - itemRubble = new ItemOreResource(Settings.getNextItemID("oreRubble"), "oreRubble"); - itemDust = new ItemOreResource(Settings.getNextItemID("oreDust"), "oreDust"); - itemRefinedDust = new ItemOreResource(Settings.getNextItemID("oreRefinedDust"), "oreRefinedDust"); - itemBucketMixture = new ItemOreResourceBucket(Settings.getNextItemID("bucketMixture"), "bucketMixture", false); - itemBucketMolten = new ItemOreResourceBucket(Settings.getNextItemID("bucketMolten"), "bucketMolten", true); + // Items + itemRubble = new ItemOreResource(Settings.getNextItemID("oreRubble"), "oreRubble"); + itemDust = new ItemOreResource(Settings.getNextItemID("oreDust"), "oreDust"); + itemRefinedDust = new ItemOreResource(Settings.getNextItemID("oreRefinedDust"), "oreRefinedDust"); + itemBucketMixture = new ItemOreResourceBucket(Settings.getNextItemID("bucketMixture"), "bucketMixture", false); + itemBucketMolten = new ItemOreResourceBucket(Settings.getNextItemID("bucketMolten"), "bucketMolten", true); - GameRegistry.registerItem(itemRubble, itemRubble.getUnlocalizedName()); - GameRegistry.registerItem(itemDust, itemDust.getUnlocalizedName()); - GameRegistry.registerItem(itemRefinedDust, itemRefinedDust.getUnlocalizedName()); - GameRegistry.registerItem(itemBucketMixture, itemBucketMixture.getUnlocalizedName()); - GameRegistry.registerItem(itemBucketMolten, itemBucketMolten.getUnlocalizedName()); + GameRegistry.registerItem(itemRubble, itemRubble.getUnlocalizedName()); + GameRegistry.registerItem(itemDust, itemDust.getUnlocalizedName()); + GameRegistry.registerItem(itemRefinedDust, itemRefinedDust.getUnlocalizedName()); + GameRegistry.registerItem(itemBucketMixture, itemBucketMixture.getUnlocalizedName()); + GameRegistry.registerItem(itemBucketMolten, itemBucketMolten.getUnlocalizedName()); - // Already registered with ContentRegistry - // GameRegistry.registerTileEntity(TileMaterial.class, "ri_material"); - GameRegistry.registerTileEntity(TileFluidMixture.class, "ri_fluid_mixture"); + // Already registered with ContentRegistry + // GameRegistry.registerTileEntity(TileMaterial.class, "ri_material"); + GameRegistry.registerTileEntity(TileFluidMixture.class, "ri_fluid_mixture"); - proxy.preInit(); - TabRI.ITEMSTACK = new ItemStack(blockMachinePart); - } + proxy.preInit(); + TabRI.ITEMSTACK = new ItemStack(blockMachinePart); + } - @EventHandler - public void init(FMLInitializationEvent evt) - { - // Load Languages - ResonantInduction.LOGGER.fine("Languages Loaded:" + LanguageUtility.loadLanguages(Reference.LANGUAGE_DIRECTORY, Reference.LANGUAGES)); - // Set Mod Metadata - Settings.setModMetadata(metadata, ID, NAME); - proxy.init(); - } + @EventHandler + public void init(FMLInitializationEvent evt) + { + // Load Languages + ResonantInduction.LOGGER.fine("Languages Loaded:" + LanguageUtility.loadLanguages(Reference.LANGUAGE_DIRECTORY, Reference.LANGUAGES)); + // Set Mod Metadata + Settings.setModMetadata(metadata, ID, NAME); + proxy.init(); + } - @EventHandler - public void postInit(FMLPostInitializationEvent evt) - { - try - { - ConfigHandler.configure(Settings.CONFIGURATION, "resonantinduction"); - } - catch (Exception e) - { - e.printStackTrace(); - } + @EventHandler + public void postInit(FMLPostInitializationEvent evt) + { + try + { + ConfigHandler.configure(Settings.CONFIGURATION, "resonantinduction"); + } + catch (Exception e) + { + e.printStackTrace(); + } - Settings.CONFIGURATION.save(); - // Generate Resources - ResourceGenerator.generateOreResources(); - proxy.postInit(); - } + Settings.CONFIGURATION.save(); + // Generate Resources + if (Settings.RESOURCE_GENERATOR) + ResourceGenerator.generateOreResources(); + proxy.postInit(); + } } diff --git a/src/main/scala/resonantinduction/core/Settings.java b/src/main/scala/resonantinduction/core/Settings.java index 9221db918..cdfbdd4e7 100644 --- a/src/main/scala/resonantinduction/core/Settings.java +++ b/src/main/scala/resonantinduction/core/Settings.java @@ -65,6 +65,8 @@ public class Settings public static double LEVITATOR_MAX_SPEED = .2; @Config(category = Configuration.CATEGORY_GENERAL, key = "Levitator Acceleration") public static double LEVITATOR_ACCELERATION = .02; + @Config(category = Configuration.CATEGORY_GENERAL, key = "Enabled Resource Generator") + public static boolean RESOURCE_GENERATOR = true; public static void setModMetadata(ModMetadata metadata, String id, String name) { From 6c93020deaa55eaca100701b25ab5838522b5e2b Mon Sep 17 00:00:00 2001 From: Robert S Date: Tue, 25 Mar 2014 08:03:40 -0400 Subject: [PATCH 2/4] Implemented a few more configs for resource generator --- .../core/ResonantInduction.java | 2 +- .../resonantinduction/core/Settings.java | 140 ++-- .../core/resource/ResourceGenerator.java | 793 +++++++++--------- 3 files changed, 471 insertions(+), 464 deletions(-) diff --git a/src/main/scala/resonantinduction/core/ResonantInduction.java b/src/main/scala/resonantinduction/core/ResonantInduction.java index 0e15f3de8..4e7766d01 100644 --- a/src/main/scala/resonantinduction/core/ResonantInduction.java +++ b/src/main/scala/resonantinduction/core/ResonantInduction.java @@ -150,7 +150,7 @@ public class ResonantInduction Settings.CONFIGURATION.save(); // Generate Resources - if (Settings.RESOURCE_GENERATOR) + if (ResourceGenerator.ENABLED) ResourceGenerator.generateOreResources(); proxy.postInit(); } diff --git a/src/main/scala/resonantinduction/core/Settings.java b/src/main/scala/resonantinduction/core/Settings.java index cdfbdd4e7..73146c652 100644 --- a/src/main/scala/resonantinduction/core/Settings.java +++ b/src/main/scala/resonantinduction/core/Settings.java @@ -15,87 +15,85 @@ import cpw.mods.fml.common.ModMetadata; /** @author Calclavia */ public class Settings { - public static final Configuration CONFIGURATION = new Configuration(new File(Loader.instance().getConfigDir(), Reference.NAME + ".cfg")); + public static final Configuration CONFIGURATION = new Configuration(new File(Loader.instance().getConfigDir(), Reference.NAME + ".cfg")); - /** IDs suggested by Jyzarc and Horfius */ - public static final IDManager idManager; + /** IDs suggested by Jyzarc and Horfius */ + public static final IDManager idManager; - static - { - CONFIGURATION.load(); - idManager = new IDManager(CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "BlockIDPrefix", 1200).getInt(1200), CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "ItemIDPrefix", 20150).getInt(20150)); - CONFIGURATION.save(); - } + static + { + CONFIGURATION.load(); + idManager = new IDManager(CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "BlockIDPrefix", 1200).getInt(1200), CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "ItemIDPrefix", 20150).getInt(20150)); + CONFIGURATION.save(); + } - public static int getNextBlockID() - { - return idManager.getNextBlockID(); - } + public static int getNextBlockID() + { + return idManager.getNextBlockID(); + } - public static int getNextBlockID(String key) - { - int id = idManager.getNextBlockID(); - return Settings.CONFIGURATION.get(Configuration.CATEGORY_BLOCK, key, id).getInt(id); - } + public static int getNextBlockID(String key) + { + int id = idManager.getNextBlockID(); + return Settings.CONFIGURATION.get(Configuration.CATEGORY_BLOCK, key, id).getInt(id); + } - public static int getNextItemID() - { - return idManager.getNextItemID(); - } + public static int getNextItemID() + { + return idManager.getNextItemID(); + } - public static int getNextItemID(String key) - { - int id = idManager.getNextItemID(); - return Settings.CONFIGURATION.get(Configuration.CATEGORY_ITEM, key, id).getInt(id); - } + public static int getNextItemID(String key) + { + int id = idManager.getNextItemID(); + return Settings.CONFIGURATION.get(Configuration.CATEGORY_ITEM, key, id).getInt(id); + } - @Config(key = "Engineering Table Autocraft") - public static boolean ALLOW_ENGINEERING_AUTOCRAFT = true; - @Config(key = "Tesla Sound FXs") - public static boolean SOUND_FXS = true; - @Config(key = "Shiny silver Wires") - public static boolean SHINY_SILVER = true; - @Config(key = "Max EM Contractor Path") - public static int MAX_LEVITATOR_DISTANCE = 200; - @Config(category = Configuration.CATEGORY_GENERAL, key = "Levitator Max Reach") - public static int LEVITATOR_MAX_REACH = 40; - @Config(category = Configuration.CATEGORY_GENERAL, key = "Levitator Push Delay") - public static int LEVITATOR_PUSH_DELAY = 5; - @Config(category = Configuration.CATEGORY_GENERAL, key = "Levitator Max Speed") - public static double LEVITATOR_MAX_SPEED = .2; - @Config(category = Configuration.CATEGORY_GENERAL, key = "Levitator Acceleration") - public static double LEVITATOR_ACCELERATION = .02; - @Config(category = Configuration.CATEGORY_GENERAL, key = "Enabled Resource Generator") - public static boolean RESOURCE_GENERATOR = true; + @Config(key = "Engineering Table Autocraft") + public static boolean ALLOW_ENGINEERING_AUTOCRAFT = true; + @Config(key = "Tesla Sound FXs") + public static boolean SOUND_FXS = true; + @Config(key = "Shiny silver Wires") + public static boolean SHINY_SILVER = true; + @Config(key = "Max EM Contractor Path") + public static int MAX_LEVITATOR_DISTANCE = 200; + @Config(category = Configuration.CATEGORY_GENERAL, key = "Levitator Max Reach") + public static int LEVITATOR_MAX_REACH = 40; + @Config(category = Configuration.CATEGORY_GENERAL, key = "Levitator Push Delay") + public static int LEVITATOR_PUSH_DELAY = 5; + @Config(category = Configuration.CATEGORY_GENERAL, key = "Levitator Max Speed") + public static double LEVITATOR_MAX_SPEED = .2; + @Config(category = Configuration.CATEGORY_GENERAL, key = "Levitator Acceleration") + public static double LEVITATOR_ACCELERATION = .02; - public static void setModMetadata(ModMetadata metadata, String id, String name) - { - setModMetadata(metadata, id, name, ""); - } + public static void setModMetadata(ModMetadata metadata, String id, String name) + { + setModMetadata(metadata, id, name, ""); + } - public static void setModMetadata(ModMetadata metadata, String id, String name, String parent) - { - metadata.modId = id; - metadata.name = name; - metadata.description = LanguageUtility.getLocal("meta.resonantinduction.description"); - metadata.url = "http://calclavia.com/resonant-induction"; - metadata.logoFile = "ri_logo.png"; - metadata.version = Reference.VERSION + "." + Reference.BUILD_VERSION; - metadata.authorList = Arrays.asList(new String[] { "Calclavia", "DarkCow" }); - metadata.credits = LanguageUtility.getLocal("meta.resonantinduction.credits"); - metadata.parent = parent; - metadata.autogenerated = false; - } + public static void setModMetadata(ModMetadata metadata, String id, String name, String parent) + { + metadata.modId = id; + metadata.name = name; + metadata.description = LanguageUtility.getLocal("meta.resonantinduction.description"); + metadata.url = "http://calclavia.com/resonant-induction"; + metadata.logoFile = "ri_logo.png"; + metadata.version = Reference.VERSION + "." + Reference.BUILD_VERSION; + metadata.authorList = Arrays.asList(new String[] { "Calclavia", "DarkCow" }); + metadata.credits = LanguageUtility.getLocal("meta.resonantinduction.credits"); + metadata.parent = parent; + metadata.autogenerated = false; + } - public static boolean isOp(String username) - { - MinecraftServer theServer = FMLCommonHandler.instance().getMinecraftServerInstance(); + public static boolean isOp(String username) + { + MinecraftServer theServer = FMLCommonHandler.instance().getMinecraftServerInstance(); - if (theServer != null) - { - return theServer.getConfigurationManager().getOps().contains(username.trim().toLowerCase()); - } + if (theServer != null) + { + return theServer.getConfigurationManager().getOps().contains(username.trim().toLowerCase()); + } - return false; - } + return false; + } } diff --git a/src/main/scala/resonantinduction/core/resource/ResourceGenerator.java b/src/main/scala/resonantinduction/core/resource/ResourceGenerator.java index 3b30016c4..7ba2d2631 100644 --- a/src/main/scala/resonantinduction/core/resource/ResourceGenerator.java +++ b/src/main/scala/resonantinduction/core/resource/ResourceGenerator.java @@ -53,396 +53,405 @@ import cpw.mods.fml.relauncher.SideOnly; /** @author Calclavia */ public class ResourceGenerator implements IVirtualObject { - public static final ResourceGenerator INSTANCE = new ResourceGenerator(); - - @Config(comment = "Allow the Resource Generator to make ore dictionary compatible recipes?") - private static boolean allowOreDictCompatibility = 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; - 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); - } - - // 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.CONFIGURATION.load(); - boolean allowMaterial = 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, maxID++); - } - } - } - - 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(" $", ""); - } - - /** 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)); - - ItemStack dust = ResonantInduction.itemDust.getStackFromMaterial(materialName); - ItemStack rubble = ResonantInduction.itemRubble.getStackFromMaterial(materialName); - ItemStack refinedDust = ResonantInduction.itemRefinedDust.getStackFromMaterial(materialName); - - if (allowOreDictCompatibility) - { - OreDictionary.registerOre("dust" + nameCaps, ResonantInduction.itemDust.getStackFromMaterial(materialName)); - OreDictionary.registerOre("rubble" + nameCaps, ResonantInduction.itemRubble.getStackFromMaterial(materialName)); - OreDictionary.registerOre("dustRefined" + nameCaps, ResonantInduction.itemRefinedDust.getStackFromMaterial(materialName)); - - MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER.name(), "rubble" + nameCaps, dust, dust); - MachineRecipes.INSTANCE.addRecipe(RecipeType.MIXER.name(), "dust" + nameCaps, refinedDust); - MachineRecipes.INSTANCE.addRecipe(RecipeType.SMELTER.name(), new FluidStack(fluidMolten, FluidContainerRegistry.BUCKET_VOLUME), "ingot" + nameCaps); - } - else - { - MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER.name(), rubble, dust, dust); - MachineRecipes.INSTANCE.addRecipe(RecipeType.MIXER.name(), dust, refinedDust); - MachineRecipes.INSTANCE.addRecipe(RecipeType.SMELTER.name(), new FluidStack(fluidMolten, FluidContainerRegistry.BUCKET_VOLUME), "ingot" + nameCaps); - } - - 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(); - } - } - - @ForgeSubscribe - @SideOnly(Side.CLIENT) - public void reloadTextures(TextureStitchEvent.Post e) - { - computeColors(); - } - - @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 - { - Icon 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("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; - } - - @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) - { - - } + public static final ResourceGenerator INSTANCE = new ResourceGenerator(); + + @Config(comment = "Allow the Resource Generator to make ore dictionary compatible recipes?") + private static boolean allowOreDictCompatibility = true; + @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; + 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); + } + + // 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.CONFIGURATION.load(); + boolean allowMaterial = 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, maxID++); + } + } + } + + 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("dust" + nameCaps, ResonantInduction.itemDust.getStackFromMaterial(materialName)); + OreDictionary.registerOre("rubble" + nameCaps, ResonantInduction.itemRubble.getStackFromMaterial(materialName)); + OreDictionary.registerOre("dustRefined" + nameCaps, ResonantInduction.itemRefinedDust.getStackFromMaterial(materialName)); + + MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER.name(), "rubble" + nameCaps, dust, dust); + MachineRecipes.INSTANCE.addRecipe(RecipeType.MIXER.name(), "dust" + 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(); + } + } + + @ForgeSubscribe + @SideOnly(Side.CLIENT) + public void reloadTextures(TextureStitchEvent.Post e) + { + computeColors(); + } + + @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 + { + Icon 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("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; + } + + @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) + { + + } } From ea176da493d3be5f7bd90d6e979e3efe5dd6d087 Mon Sep 17 00:00:00 2001 From: Robert S Date: Tue, 25 Mar 2014 08:13:12 -0400 Subject: [PATCH 3/4] Fixed NPE if fluid blockID is null when using a fluid bucket --- .../resource/fluid/ItemOreResourceBucket.java | 438 +++++++++--------- 1 file changed, 219 insertions(+), 219 deletions(-) diff --git a/src/main/scala/resonantinduction/core/resource/fluid/ItemOreResourceBucket.java b/src/main/scala/resonantinduction/core/resource/fluid/ItemOreResourceBucket.java index 3469f5cde..198e98cd7 100644 --- a/src/main/scala/resonantinduction/core/resource/fluid/ItemOreResourceBucket.java +++ b/src/main/scala/resonantinduction/core/resource/fluid/ItemOreResourceBucket.java @@ -13,6 +13,7 @@ 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 resonantinduction.core.Reference; import resonantinduction.core.TabRI; @@ -22,269 +23,268 @@ import calclavia.lib.utility.LanguageUtility; 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 +/** Modified version of the MC bucket to meet the needs of a dynamic fluid registry system * - * @author Darkguardsman - */ + * @author Darkguardsman */ public class ItemOreResourceBucket extends Item { - final boolean isMolten; + 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(TabRI.CORE); - setHasSubtypes(true); - setMaxDamage(0); - } + public ItemOreResourceBucket(int id, String name, boolean isMolten) + { + super(id); + this.isMolten = isMolten; + setMaxStackSize(1); + setUnlocalizedName(Reference.PREFIX + name); + setTextureName(Reference.PREFIX + name); + setCreativeTab(TabRI.CORE); + setHasSubtypes(true); + setMaxDamage(0); + } - @Override - public String getItemDisplayName(ItemStack is) - { - String material = getMaterialFromStack(is); + @Override + public String getItemDisplayName(ItemStack is) + { + String material = getMaterialFromStack(is); - if (material != null) - { - String fluidID = isMolten ? ResourceGenerator.materialNameToMolten(material) : ResourceGenerator.materialNameToMixture(material); + 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(" ", " "); - } + 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 material; + } - return null; - } + 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()); - int fluidID = isMolten ? ResourceGenerator.getMolten(materialName).blockID : ResourceGenerator.getMixture(materialName).blockID; + /** 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; - MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(world, entityPlayer, false); + 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 (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 (event.getResult() == Event.Result.ALLOW) + { + if (entityPlayer.capabilities.isCreativeMode) + { + return itemStack; + } - if (--itemStack.stackSize <= 0) - { - return event.result; - } + if (--itemStack.stackSize <= 0) + { + return event.result; + } - if (!entityPlayer.inventory.addItemStackToInventory(event.result)) - { - entityPlayer.dropPlayerItem(event.result); - } + if (!entityPlayer.inventory.addItemStackToInventory(event.result)) + { + entityPlayer.dropPlayerItem(event.result); + } - return itemStack; - } + return itemStack; + } - if (movingobjectposition.typeOfHit == EnumMovingObjectType.TILE) - { - int i = movingobjectposition.blockX; - int j = movingobjectposition.blockY; - int k = movingobjectposition.blockZ; + 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 (!world.canMineBlock(entityPlayer, i, j, k)) + { + return itemStack; + } - if (fluidID == 0) - { - if (!entityPlayer.canPlayerEdit(i, j, k, movingobjectposition.sideHit, itemStack)) - { - 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 (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 (entityPlayer.capabilities.isCreativeMode) + { + return itemStack; + } - if (--itemStack.stackSize <= 0) - { - return new ItemStack(Item.bucketWater); - } + 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)); - } + if (!entityPlayer.inventory.addItemStackToInventory(new ItemStack(Item.bucketWater))) + { + entityPlayer.dropPlayerItem(new ItemStack(Item.bucketWater.itemID, 1, 0)); + } - return itemStack; - } + return itemStack; + } - if (world.getBlockMaterial(i, j, k) == Material.lava && world.getBlockMetadata(i, j, k) == 0) - { - world.setBlockToAir(i, j, k); + 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 (entityPlayer.capabilities.isCreativeMode) + { + return itemStack; + } - if (--itemStack.stackSize <= 0) - { - return new ItemStack(Item.bucketLava); - } + 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)); - } + 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); - } + return itemStack; + } + } + else + { + if (fluidID < 0) + { + return new ItemStack(Item.bucketEmpty); + } - if (movingobjectposition.sideHit == 0) - { - --j; - } + if (movingobjectposition.sideHit == 0) + { + --j; + } - if (movingobjectposition.sideHit == 1) - { - ++j; - } + if (movingobjectposition.sideHit == 1) + { + ++j; + } - if (movingobjectposition.sideHit == 2) - { - --k; - } + if (movingobjectposition.sideHit == 2) + { + --k; + } - if (movingobjectposition.sideHit == 3) - { - ++k; - } + if (movingobjectposition.sideHit == 3) + { + ++k; + } - if (movingobjectposition.sideHit == 4) - { - --i; - } + if (movingobjectposition.sideHit == 4) + { + --i; + } - if (movingobjectposition.sideHit == 5) - { - ++i; - } + if (movingobjectposition.sideHit == 5) + { + ++i; + } - if (!entityPlayer.canPlayerEdit(i, j, k, movingobjectposition.sideHit, itemStack)) - { - return itemStack; - } + 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); - } - } - } + if (this.tryPlaceContainedLiquid(world, i, j, k, fluidID) && !entityPlayer.capabilities.isCreativeMode) + { + return new ItemStack(Item.bucketEmpty); + } + } + } + } + } + } + return itemStack; + } - 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(); - /** - * 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.isAirBlock(x, y, z) && !flag) - { - return false; - } - else - { + if (!world.isRemote && flag && !material.isLiquid()) + { + world.destroyBlock(x, y, z, true); + } - if (!world.isRemote && flag && !material.isLiquid()) - { - world.destroyBlock(x, y, z, true); - } + world.setBlock(x, y, z, fluidID, 8, 3); - world.setBlock(x, y, z, fluidID, 8, 3); + return true; + } + } + } - return true; - } - } - } + public ItemStack getStackFromMaterial(String name) + { + ItemStack itemStack = new ItemStack(this); + itemStack.setItemDamage(ResourceGenerator.getID(name)); + return itemStack; + } - 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()); + } - 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 - 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); - } + @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); + } } From e7e2768d1975e6bdce10029af66744b7036825cf Mon Sep 17 00:00:00 2001 From: Robert S Date: Tue, 25 Mar 2014 08:31:51 -0400 Subject: [PATCH 4/4] Fixed block IDs for fluids not showing up in configs --- src/main/scala/resonantinduction/core/ResonantInduction.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/scala/resonantinduction/core/ResonantInduction.java b/src/main/scala/resonantinduction/core/ResonantInduction.java index 4e7766d01..192a502b6 100644 --- a/src/main/scala/resonantinduction/core/ResonantInduction.java +++ b/src/main/scala/resonantinduction/core/ResonantInduction.java @@ -148,10 +148,11 @@ public class ResonantInduction e.printStackTrace(); } - Settings.CONFIGURATION.save(); + // Generate Resources if (ResourceGenerator.ENABLED) ResourceGenerator.generateOreResources(); - proxy.postInit(); + proxy.postInit(); + Settings.CONFIGURATION.save(); } }