diff options
author | Raven Szewczyk <git@eigenraven.me> | 2024-05-24 19:50:35 +0100 |
---|---|---|
committer | Raven Szewczyk <git@eigenraven.me> | 2024-05-24 19:50:35 +0100 |
commit | 6d1b2216464d4dad449ac6fcfec476832224a55e (patch) | |
tree | 526a0c15f7056313c80e6c0386e025e9b3f61781 /src/main/java/gtPlusPlus/core/item | |
parent | b5d35f40afa606ed1b07061dad82e0521a59c186 (diff) | |
download | GT5-Unofficial-6d1b2216464d4dad449ac6fcfec476832224a55e.tar.gz GT5-Unofficial-6d1b2216464d4dad449ac6fcfec476832224a55e.tar.bz2 GT5-Unofficial-6d1b2216464d4dad449ac6fcfec476832224a55e.zip |
Merge addon sources
Diffstat (limited to 'src/main/java/gtPlusPlus/core/item')
88 files changed, 14659 insertions, 0 deletions
diff --git a/src/main/java/gtPlusPlus/core/item/ModItems.java b/src/main/java/gtPlusPlus/core/item/ModItems.java new file mode 100644 index 0000000000..0fabf375a2 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/ModItems.java @@ -0,0 +1,988 @@ +package gtPlusPlus.core.item; + +import static gregtech.api.enums.Mods.Forestry; +import static gregtech.api.enums.Mods.GTPlusPlus; +import static gregtech.api.enums.Mods.GregTech; +import static gregtech.api.enums.Mods.Thaumcraft; +import static gregtech.api.recipe.RecipeMaps.fluidExtractionRecipes; +import static gregtech.api.util.GT_RecipeBuilder.TICKS; +import static gtPlusPlus.core.creative.AddToCreativeTab.tabMisc; + +import net.minecraft.item.EnumRarity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; + +import cpw.mods.fml.common.registry.GameRegistry; +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.util.GT_OreDictUnificator; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.block.base.BasicBlock.BlockTypes; +import gtPlusPlus.core.block.base.BlockBaseModular; +import gtPlusPlus.core.common.compat.COMPAT_Baubles; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.item.base.BaseItemComponent.ComponentTypes; +import gtPlusPlus.core.item.base.BaseItemDamageable; +import gtPlusPlus.core.item.base.BaseItemTCShard; +import gtPlusPlus.core.item.base.CoreItem; +import gtPlusPlus.core.item.base.dusts.BaseItemDust; +import gtPlusPlus.core.item.base.foil.BaseItemFoil; +import gtPlusPlus.core.item.base.gears.BaseItemSmallGear; +import gtPlusPlus.core.item.base.ingots.BaseItemIngot; +import gtPlusPlus.core.item.base.ingots.BaseItemIngot_OLD; +import gtPlusPlus.core.item.base.plates.BaseItemPlate; +import gtPlusPlus.core.item.base.plates.BaseItemPlateDouble; +import gtPlusPlus.core.item.bauble.BatteryPackBaseBauble; +import gtPlusPlus.core.item.chemistry.AgriculturalChem; +import gtPlusPlus.core.item.chemistry.CoalTar; +import gtPlusPlus.core.item.chemistry.GenericChem; +import gtPlusPlus.core.item.chemistry.IonParticles; +import gtPlusPlus.core.item.chemistry.MilledOreProcessing; +import gtPlusPlus.core.item.chemistry.NuclearChem; +import gtPlusPlus.core.item.chemistry.RocketFuels; +import gtPlusPlus.core.item.chemistry.StandardBaseParticles; +import gtPlusPlus.core.item.crafting.ItemDummyResearch; +import gtPlusPlus.core.item.food.BaseItemMetaFood; +import gtPlusPlus.core.item.general.BufferCore; +import gtPlusPlus.core.item.general.ItemAirFilter; +import gtPlusPlus.core.item.general.ItemBasicScrubberTurbine; +import gtPlusPlus.core.item.general.ItemBlueprint; +import gtPlusPlus.core.item.general.ItemEmpty; +import gtPlusPlus.core.item.general.ItemGenericToken; +import gtPlusPlus.core.item.general.ItemHalfCompleteCasings; +import gtPlusPlus.core.item.general.ItemLavaFilter; +import gtPlusPlus.core.item.general.ItemMagicFeather; +import gtPlusPlus.core.item.general.books.ItemBaseBook; +import gtPlusPlus.core.item.general.chassis.ItemBoilerChassis; +import gtPlusPlus.core.item.general.chassis.ItemDehydratorCoil; +import gtPlusPlus.core.item.general.chassis.ItemDehydratorCoilWire; +import gtPlusPlus.core.item.general.spawn.ItemCustomSpawnEgg; +import gtPlusPlus.core.item.init.ItemsFoods; +import gtPlusPlus.core.item.materials.DustDecayable; +import gtPlusPlus.core.item.tool.misc.GregtechPump; +import gtPlusPlus.core.item.wearable.WearableLoader; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.material.ALLOY; +import gtPlusPlus.core.material.ELEMENT; +import gtPlusPlus.core.material.MISC_MATERIALS; +import gtPlusPlus.core.material.Material; +import gtPlusPlus.core.material.MaterialGenerator; +import gtPlusPlus.core.material.NONMATERIAL; +import gtPlusPlus.core.material.nuclear.FLUORIDES; +import gtPlusPlus.core.material.nuclear.NUCLIDE; +import gtPlusPlus.core.recipe.common.CI; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.data.StringUtils; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.minecraft.MaterialUtils; +import gtPlusPlus.core.util.reflect.ReflectionUtils; +import gtPlusPlus.everglades.GTplusplus_Everglades; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; +import gtPlusPlus.xmod.gregtech.common.helpers.VolumetricFlaskHelper; +import gtPlusPlus.xmod.gregtech.common.items.MetaGeneratedGregtechItems; + +public final class ModItems { + + public static Item ZZZ_Empty; + public static Item AAA_Broken; + + public static Item itemAlkalusDisk; + public static ItemCustomSpawnEgg itemCustomSpawnEgg; + + public static Item itemIngotBatteryAlloy; + + public static Item itemBedLocator_Base; + public static Item itemBaseItemWithCharge; + + public static Item itemPersonalCloakingDevice; + public static Item itemPersonalHealingDevice; + public static Item itemSupremePizzaGloves; + + public static ItemBlueprint itemBlueprintBase; + + public static Item dustLithiumCarbonate; + public static Item dustLithiumHydroxide; + public static Item dustLithiumPeroxide; + + public static Item dustQuicklime; + public static Item dustCalciumHydroxide; + public static Item dustCalciumCarbonate; + public static Item dustLi2CO3CaOH2; + public static Item dustLi2BeF4; + + public static Item dustTumbagaMix; + + public static Item dustAer; + public static Item dustIgnis; + public static Item dustTerra; + public static Item dustAqua; + + public static Item cellHydrogenChlorideMix; + + public static Item shardAer; + public static Item shardIgnis; + public static Item shardTerra; + public static Item shardAqua; + + // Zirconium + public static Item itemZirconiumChlorideCinterPellet; + public static Item dustZrCl4; + public static Item dustCookedZrCl4; + + public static Item dustCalciumSulfate; + + public static Item dustFertUN18; + public static Item dustFertUN32; + public static Fluid fluidNuclearWaste; + + // Possibly missing base items that GT may be missing. + + public static Item itemSmallWroughtIronGear; + public static Item itemPlateRawMeat; + public static Item itemPlateClay; + public static Item itemPlateLithium; + public static Item itemPlateEuropium; + public static Item itemPlateVanadium; + public static Item itemDoublePlateClay; + public static Item itemDoublePlateEuropium; + public static Item itemFoilUranium235; + public static Item itemDustIndium; + public static BlockBaseModular blockRawMeat; + + public static Item itemBoilerChassis; + public static Item itemDehydratorCoilWire; + public static Item itemDehydratorCoil; + + public static Item itemLavaFilter; + public static Item itemAirFilter; + + public static Item itemCoalCoke; + public static Item itemCactusCharcoal; + public static Item itemSugarCharcoal; + public static Item itemCactusCoke; + public static Item itemSugarCoke; + + public static Item itemCircuitLFTR; + public static Item itemBasicTurbine; + + public static Item itemHalfCompleteCasings; + + public static Item itemCustomBook; + + // Unstable Elements & Related Content + public static Item dustNeptunium238; + public static Item dustDecayedRadium226; + public static Item dustRadium226; + public static Item dustProtactinium233; + + public static GregtechPump toolGregtechPump; + + public static ItemGenericToken itemGenericToken; + + public static ItemStack itemHotTitaniumIngot; + + public static Fluid fluidZrF4; + public static Fluid fluidFertBasic; + public static Fluid fluidFertUN32; + public static Fluid fluidFertUN18; + + public static DustDecayable dustMolybdenum99; + public static DustDecayable dustTechnetium99; + public static DustDecayable dustTechnetium99M; + + public static IonParticles itemIonParticleBase; + public static StandardBaseParticles itemStandarParticleBase; + + public static BatteryPackBaseBauble itemChargePack_Low_1; + public static BatteryPackBaseBauble itemChargePack_Low_2; + public static BatteryPackBaseBauble itemChargePack_Low_3; + public static BatteryPackBaseBauble itemChargePack_Low_4; + public static BatteryPackBaseBauble itemChargePack_Low_5; + public static BatteryPackBaseBauble itemChargePack_High_1; + public static BatteryPackBaseBauble itemChargePack_High_2; + public static BatteryPackBaseBauble itemChargePack_High_3; + public static BatteryPackBaseBauble itemChargePack_High_4; + + public static ItemDummyResearch itemDummyResearch; + + public static BaseItemMetaFood itemMetaFood; + + public static ItemMagicFeather itemMagicFeather; + + static { + Logger.INFO("Items!"); + // Default item used when recipes fail, handy for debugging. Let's make sure they exist when this class is + // called upon. + AAA_Broken = new BaseItemIngot_OLD( + "AAA_Broken", + "Errors - Tell Alkalus", + Utils.rgbtoHexValue(128, 128, 128), + 0); + ZZZ_Empty = new ItemEmpty(); + } + + public static void init() { + + itemMagicFeather = new ItemMagicFeather(); + + itemAlkalusDisk = new BaseItemDamageable( + "itemAlkalusDisk", + AddToCreativeTab.tabMisc, + 1, + 0, + "Unknown Use", + EnumRarity.rare, + EnumChatFormatting.AQUA, + false, + null); + + itemGenericToken = new ItemGenericToken(); + itemDummyResearch = new ItemDummyResearch(); + itemCustomSpawnEgg = new ItemCustomSpawnEgg(); + + // Register meta item, because we need them for everything. + MetaGeneratedGregtechItems.INSTANCE.generateMetaItems(); + + // Register Hydrogen Blobs first, so we can replace old helium blobs. + // Register Old Helium Blob, this will be replaced when held by a player. + + // Load Wearable Items + WearableLoader.run(); + + itemBlueprintBase = new ItemBlueprint("itemBlueprint"); + + itemHalfCompleteCasings = new ItemHalfCompleteCasings( + "itemHalfCompleteCasings", + AddToCreativeTab.tabMisc, + 32, + 0, + "This isn't quite finished yet.", + EnumRarity.common, + EnumChatFormatting.GRAY, + false, + Utils.rgbtoHexValue(255, 255, 255)).setTextureName(GregTech.ID + ":" + "gt.metaitem.01/" + "761"); + + // Start meta Item Generation + ItemsFoods.load(); + + try { + + registerCustomMaterialComponents(); + + // Elements generate first so they can be used in compounds. + // Missing Elements + MaterialGenerator.generate(ELEMENT.getInstance().SELENIUM); // LFTR byproduct + MaterialGenerator.generate(ELEMENT.getInstance().BROMINE); + MaterialGenerator.generate(ELEMENT.getInstance().KRYPTON); // LFTR byproduct + MaterialGenerator.generate(ELEMENT.getInstance().STRONTIUM); + MaterialGenerator.generate(ELEMENT.getInstance().ZIRCONIUM); + MaterialGenerator.generate(ELEMENT.getInstance().RUTHENIUM); + MaterialGenerator.generate(ELEMENT.getInstance().IODINE); // LFTR byproduct + MaterialGenerator.generate(ELEMENT.getInstance().HAFNIUM); + MaterialGenerator.generate(ELEMENT.getInstance().DYSPROSIUM); + MaterialGenerator.generate(ELEMENT.getInstance().ERBIUM); + MaterialGenerator.generate(ELEMENT.getInstance().PRASEODYMIUM); + MaterialGenerator.generate(ELEMENT.getInstance().TELLURIUM); // LFTR byproduct + MaterialGenerator.generate(ELEMENT.getInstance().RHODIUM); + MaterialGenerator.generate(ELEMENT.getInstance().RHENIUM); + MaterialGenerator.generate(ELEMENT.getInstance().THALLIUM); + MaterialGenerator.generate(ELEMENT.getInstance().GERMANIUM); + + // RADIOACTIVE ELEMENTS + MaterialGenerator.generateNuclearMaterial(ELEMENT.getInstance().POLONIUM, false); + // MaterialGenerator.generateNuclearMaterial(ELEMENT.getInstance().RADON, false); + MaterialGenerator.generateNuclearMaterial(ELEMENT.getInstance().RADIUM, false); + MaterialGenerator.generateNuclearMaterial(ELEMENT.getInstance().PROMETHIUM, false); + MaterialGenerator.generateNuclearMaterial(ELEMENT.getInstance().PROTACTINIUM, false); + MaterialGenerator.generateNuclearMaterial(ELEMENT.getInstance().CURIUM, false); + MaterialGenerator.generateNuclearMaterial(ELEMENT.getInstance().CALIFORNIUM, false); + MaterialGenerator.generateNuclearMaterial(ELEMENT.getInstance().NEPTUNIUM, false); + MaterialGenerator.generateNuclearMaterial(ELEMENT.getInstance().FERMIUM, false); + + // Nuclear Isotopes + + // Lithium-7 is used as a part of the molten lithium fluoride in molten salt reactors: liquid-fluoride + // nuclear reactors. + // The large neutron-absorption cross-section of lithium-6 (about 940 barns[5]) as compared with the very + // small + // neutron cross-section of lithium-7 (about 45 millibarns) makes high separation of lithium-7 from natural + // lithium a + // strong requirement for the possible use in lithium fluoride reactors. + MaterialGenerator.generate(ELEMENT.getInstance().LITHIUM7, false); + // Thorium-232 is the most stable isotope of Thorium, purified for nuclear fuel use in this case. + MaterialGenerator.generateNuclearMaterial(ELEMENT.getInstance().THORIUM232); + // Production of 233U (through the neutron irradiation of 232Th) invariably produces small amounts of 232U + // as an impurity + // because of parasitic (n,2n) reactions on uranium-233 itself, or on protactinium-233, or on thorium-232: + MaterialGenerator.generate(ELEMENT.getInstance().URANIUM232); + // Uranium-233 is a fissile isotope of uranium that is bred from thorium-232 as part of the thorium fuel + // cycle. + MaterialGenerator.generate(ELEMENT.getInstance().URANIUM233); + // Plutonium-238 is a very powerful alpha emitter. This makes the plutonium-238 isotope suitable for usage + // in radioisotope thermoelectric generators (RTGs) + // and radioisotope heater units - one gram of plutonium-238 generates approximately 0.5 W of thermal power. + MaterialGenerator.generateNuclearMaterial(ELEMENT.getInstance().PLUTONIUM238, false); + + // Custom Materials that will have standalone refinery processes + MaterialGenerator.generate(ELEMENT.STANDALONE.ADVANCED_NITINOL, false); + MaterialGenerator.generate(ELEMENT.STANDALONE.ASTRAL_TITANIUM); + MaterialGenerator.generate(ELEMENT.STANDALONE.CELESTIAL_TUNGSTEN); + MaterialGenerator.generate(ELEMENT.STANDALONE.HYPOGEN); + MaterialGenerator.generate(ELEMENT.STANDALONE.CHRONOMATIC_GLASS); + + // Custom Materials that are from Runescape + MaterialGenerator.generate(ELEMENT.STANDALONE.BLACK_METAL); + MaterialGenerator.generate(ELEMENT.STANDALONE.WHITE_METAL); + MaterialGenerator.generateOreMaterialWithAllExcessComponents(ELEMENT.STANDALONE.GRANITE); + MaterialGenerator.generateOreMaterialWithAllExcessComponents(ELEMENT.STANDALONE.RUNITE); + MaterialGenerator.generate(ELEMENT.STANDALONE.DRAGON_METAL, false); + + MISC_MATERIALS.run(); + + MaterialGenerator.generate(ALLOY.SILICON_CARBIDE); + MaterialGenerator.generate(ALLOY.ZIRCONIUM_CARBIDE); + MaterialGenerator.generate(ALLOY.TANTALUM_CARBIDE); + MaterialGenerator.generate(ALLOY.NIOBIUM_CARBIDE); + MaterialGenerator.generate(ALLOY.TUNGSTEN_TITANIUM_CARBIDE); + + // LFTR Fuel components + MaterialGenerator.generateNuclearDusts(FLUORIDES.AMMONIUM_BIFLUORIDE); // LFTR fuel component + MaterialGenerator.generateNuclearDusts(FLUORIDES.BERYLLIUM_HYDROXIDE); // LFTR fuel component + // MaterialGenerator.generateNuclearDusts(FLUORIDES.AMMONIUM_TETRAFLUOROBERYLLATE); // LFTR fuel component + + // Generate Fluorides + MaterialGenerator.generateNuclearDusts(FLUORIDES.BERYLLIUM_FLUORIDE); + MaterialGenerator.generateNuclearDusts(FLUORIDES.LITHIUM_FLUORIDE); + MaterialGenerator.generateNuclearDusts(FLUORIDES.THORIUM_TETRAFLUORIDE); + MaterialGenerator.generateNuclearDusts(FLUORIDES.THORIUM_HEXAFLUORIDE); + MaterialGenerator.generateNuclearDusts(FLUORIDES.URANIUM_TETRAFLUORIDE, false); + MaterialGenerator.generateNuclearDusts(FLUORIDES.URANIUM_HEXAFLUORIDE, false); + MaterialGenerator.generateNuclearDusts(FLUORIDES.ZIRCONIUM_TETRAFLUORIDE); + // LFTR Fluoride outputs + MaterialGenerator.generateNuclearDusts(FLUORIDES.NEPTUNIUM_HEXAFLUORIDE); + MaterialGenerator.generateNuclearDusts(FLUORIDES.TECHNETIUM_HEXAFLUORIDE); + MaterialGenerator.generateNuclearDusts(FLUORIDES.SELENIUM_HEXAFLUORIDE); + + // Generate Reactor Fuel Salts + MaterialGenerator.generateNuclearDusts(NUCLIDE.LiFBeF2ZrF4U235); + MaterialGenerator.generateNuclearDusts(NUCLIDE.LiFBeF2ZrF4UF4); + MaterialGenerator.generateNuclearDusts(NUCLIDE.LiFBeF2ThF4UF4); + // MaterialGenerator.generateNuclearMaterial(NUCLIDE.Li2BeF4, false); + + // Generate some Alloys + + // Misc Alloys + MaterialGenerator.generate(ALLOY.ENERGYCRYSTAL); + MaterialGenerator.generate(ALLOY.BLOODSTEEL); + + MaterialGenerator.generate(ALLOY.ZERON_100); + // Tumbaga was the name given by Spaniards to a non-specific alloy of gold and copper + MaterialGenerator.generate(ALLOY.TUMBAGA); + // Potin is traditionally an alloy of bronze, tin and lead, with varying quantities of each possible + MaterialGenerator.generate(ALLOY.POTIN); + + // Staballoy & Tantalloy + MaterialGenerator.generate(ALLOY.STABALLOY); + MaterialGenerator.generate(ALLOY.TANTALLOY_60); + MaterialGenerator.generate(ALLOY.TANTALLOY_61); + + // Inconel + MaterialGenerator.generate(ALLOY.INCONEL_625); + MaterialGenerator.generate(ALLOY.INCONEL_690); + MaterialGenerator.generate(ALLOY.INCONEL_792); + + // Steels + MaterialGenerator.generateDusts(ALLOY.EGLIN_STEEL_BASE); + MaterialGenerator.generate(ALLOY.EGLIN_STEEL); + MaterialGenerator.generate(ALLOY.MARAGING250); + MaterialGenerator.generate(ALLOY.MARAGING300); + MaterialGenerator.generate(ALLOY.MARAGING350); + MaterialGenerator.generate(ALLOY.AQUATIC_STEEL); + + MaterialGenerator.generate(ALLOY.NITINOL_60, true); + + // Composite Alloys + MaterialGenerator.generate(ALLOY.STELLITE); + MaterialGenerator.generate(ALLOY.TALONITE); + + // Hastelloy + MaterialGenerator.generate(ALLOY.HASTELLOY_W); + MaterialGenerator.generate(ALLOY.HASTELLOY_X); + MaterialGenerator.generate(ALLOY.HASTELLOY_C276); + MaterialGenerator.generate(ALLOY.HASTELLOY_N); + + // Incoloy + MaterialGenerator.generate(ALLOY.INCOLOY_020); + MaterialGenerator.generate(ALLOY.INCOLOY_DS); + MaterialGenerator.generate(ALLOY.INCOLOY_MA956); + + // Leagrisium + MaterialGenerator.generate(ALLOY.LEAGRISIUM); + + // Super Conductor + MaterialGenerator.generate(ALLOY.HG1223, false, false); + + // Generate Fictional Materials + MaterialGenerator.generate(ALLOY.TRINIUM_TITANIUM); + MaterialGenerator.generate(ALLOY.TRINIUM_NAQUADAH, false); + MaterialGenerator.generate(ALLOY.TRINIUM_NAQUADAH_CARBON); + MaterialGenerator.generate(ALLOY.TRINIUM_REINFORCED_STEEL); + + // Top Tier Alloys + MaterialGenerator.generate(ALLOY.HELICOPTER); + MaterialGenerator.generate(ALLOY.LAFIUM); + MaterialGenerator.generate(ALLOY.CINOBITE); + MaterialGenerator.generate(ALLOY.PIKYONIUM); + MaterialGenerator.generate(ALLOY.ABYSSAL); + MaterialGenerator.generate(ALLOY.LAURENIUM); + + // abs recipe in RECIPES_GREGTECH.java + MaterialGenerator.generate(ALLOY.BOTMIUM, true, false); + + MaterialGenerator.generate(ALLOY.HS188A); + + MaterialGenerator.generate(ALLOY.TITANSTEEL); + MaterialGenerator.generate(ALLOY.ARCANITE); + MaterialGenerator.generate(ALLOY.OCTIRON); + + MaterialGenerator.generate(ALLOY.BABBIT_ALLOY, false); + MaterialGenerator.generate(ALLOY.BLACK_TITANIUM, false); + MaterialGenerator.generate(ALLOY.INDALLOY_140, false, false); + + // High Level Bioplastic + MaterialGenerator.generate(ELEMENT.STANDALONE.RHUGNOR, false, false); + + // Must be the final Alloy to Generate + MaterialGenerator.generate(ALLOY.QUANTUM); + + // Ores + MaterialGenerator.generateOreMaterial(FLUORIDES.FLUORITE); + MaterialGenerator.generateOreMaterial(ALLOY.KOBOLDITE); + GTplusplus_Everglades.GenerateOreMaterials(); + + // formula override + ALLOY.TUNGSTEN_TITANIUM_CARBIDE.vChemicalFormula = StringUtils.subscript("(CW)7Ti3"); + ALLOY.TITANSTEEL.vChemicalFormula = StringUtils.subscript("((CW)7Ti3)3???"); + + // Werkstoff bridge + ELEMENT.getInstance().ZIRCONIUM.setWerkstoffID((short) 3); + ELEMENT.getInstance().THORIUM232.setWerkstoffID((short) 30); + ELEMENT.getInstance().RUTHENIUM.setWerkstoffID((short) 64); + ELEMENT.getInstance().HAFNIUM.setWerkstoffID((short) 11000); + ELEMENT.getInstance().IODINE.setWerkstoffID((short) 11012); + + } catch (final Throwable r) { + Logger.INFO("Failed to Generated a Material. " + r.getMessage()); + r.printStackTrace(); + } + + // Generates four elemental shards when TC is not installed. + if (!Thaumcraft.isModLoaded()) { + shardAer = new BaseItemTCShard("Aer", Utils.rgbtoHexValue(225, 225, 5)); + shardIgnis = new BaseItemTCShard("Ignis", Utils.rgbtoHexValue(255, 5, 5)); + shardTerra = new BaseItemTCShard("Terra", Utils.rgbtoHexValue(5, 255, 5)); + shardAqua = new BaseItemTCShard("Aqua", Utils.rgbtoHexValue(5, 5, 255)); + } else { + shardAer = ItemUtils + .getItemStackWithMeta(Thaumcraft.isModLoaded(), "Thaumcraft:ItemShard", "Air Shard", 0, 1) + .getItem(); + shardIgnis = ItemUtils + .getItemStackWithMeta(Thaumcraft.isModLoaded(), "Thaumcraft:ItemShard", "Fire Shard", 1, 1) + .getItem(); + shardAqua = ItemUtils + .getItemStackWithMeta(Thaumcraft.isModLoaded(), "Thaumcraft:ItemShard", "Warer Shard", 2, 1) + .getItem(); + shardTerra = ItemUtils + .getItemStackWithMeta(Thaumcraft.isModLoaded(), "Thaumcraft:ItemShard", "Earth Shard", 3, 1) + .getItem(); + } + // Generates a set of four special dusts to be used in my recipes. + dustAer = ItemUtils.generateSpecialUseDusts(ELEMENT.getInstance().AER, true)[0]; + dustIgnis = ItemUtils.generateSpecialUseDusts(ELEMENT.getInstance().IGNIS, true)[0]; + dustTerra = ItemUtils.generateSpecialUseDusts(ELEMENT.getInstance().TERRA, true)[0]; + dustAqua = ItemUtils.generateSpecialUseDusts(ELEMENT.getInstance().AQUA, true)[0]; + + ItemUtils.generateSpecialUseDusts(MISC_MATERIALS.WOODS_GLASS, false); + cellHydrogenChlorideMix = MISC_MATERIALS.HYDROGEN_CHLORIDE_MIX.getCell(1) + .getItem(); + + // Nuclear Fuel Dusts + dustLithiumCarbonate = ItemUtils.generateSpecialUseDusts( + "LithiumCarbonate", + "Lithium Carbonate", + "Li2CO3", + Utils.rgbtoHexValue(240, 240, 240))[0]; // https://en.wikipedia.org/wiki/Lithium_carbonate + dustLithiumPeroxide = ItemUtils.generateSpecialUseDusts( + "LithiumPeroxide", + "Lithium Peroxide", + "Li2O2", + Utils.rgbtoHexValue(250, 250, 250))[0]; // https://en.wikipedia.org/wiki/Lithium_peroxide + dustLithiumHydroxide = ItemUtils.generateSpecialUseDusts( + "LithiumHydroxide", + "Lithium Hydroxide", + "LiOH", + Utils.rgbtoHexValue(250, 250, 250))[0]; // https://en.wikipedia.org/wiki/Lithium_hydroxide + + if (!ItemUtils.checkForInvalidItems(ItemUtils.getItemStackOfAmountFromOreDict("dustQuicklime", 1))) { + dustQuicklime = ItemUtils + .generateSpecialUseDusts("Quicklime", "Quicklime", "CaO", Utils.rgbtoHexValue(255, 255, 175))[0]; // https://en.wikipedia.org/wiki/Calcium_oxide + } + dustCalciumHydroxide = ItemUtils.generateSpecialUseDusts( + "CalciumHydroxide", + "Hydrated Lime", + "Ca(OH)2", + Utils.rgbtoHexValue(255, 255, 255))[0]; // https://en.wikipedia.org/wiki/Calcium_hydroxide + dustCalciumCarbonate = ItemUtils.generateSpecialUseDusts( + "CalciumCarbonate", + "Calcium Carbonate", + "CaCO3", + Utils.rgbtoHexValue(255, 255, 255))[0]; // https://en.wikipedia.org/wiki/Calcium_carbonate + if ((ItemUtils.getItemStackOfAmountFromOreDictNoBroken("dustGypsum", 1) == null) + || (ItemUtils.getItemStackOfAmountFromOreDictNoBroken("dustCalciumSulfate", 1) == null)) { + dustCalciumSulfate = ItemUtils.generateSpecialUseDusts( + "Gypsum", + "Calcium Sulfate (Gypsum)", + "CaSO4", + Utils.rgbtoHexValue(255, 255, 255))[0]; // https://en.wikipedia.org/wiki/Calcium_sulfate + GT_OreDictUnificator.registerOre("dustCalciumSulfate", ItemUtils.getSimpleStack(dustCalciumSulfate)); + } else { + GT_OreDictUnificator + .registerOre("dustCalciumSulfate", ItemUtils.getItemStackOfAmountFromOreDictNoBroken("dustGypsum", 1)); + } + dustLi2CO3CaOH2 = ItemUtils.generateSpecialUseDusts( + "Li2CO3CaOH2", + "Li2CO3 + Ca(OH)2 Compound", + "Li2CO3CaOH2", + Utils.rgbtoHexValue(255, 255, 255))[0]; // https://en.wikipedia.org/wiki/Calcium_carbonate + MaterialUtils.generateSpecialDustAndAssignToAMaterial(FLUORIDES.SODIUM_FLUORIDE, false); + // FLiBe Fuel Compounds + dustLi2BeF4 = ItemUtils.generateSpecialUseDusts( + "Li2BeF4", + "Lithium Tetrafluoroberyllate Fuel Compound", + "Li2BeF4", + Utils.rgbtoHexValue(255, 255, 255))[0]; // https://en.wikipedia.org/wiki/FLiBe + Material.registerComponentForMaterial(NUCLIDE.Li2BeF4, OrePrefixes.dust, ItemUtils.getSimpleStack(dustLi2BeF4)); + // fluidFLiBeSalt = ("Li2BeF4", "Li2BeF4", 7430, new short[]{255, 255, 255, 100}, 0); + // fluidFLiBeSalt = FluidUtils.addGTFluidNoPrefix("Li2BeF4", "Lithium Tetrafluoroberyllate", new short[]{255, + // 255, 255, 100}, 0, 743, null, CI.emptyCells(1), 1000, true); + // fluidFLiBeSaltBurnt = FluidUtils.addGTFluidNoPrefix("Li2BeF2UF4", "Li2BeF2UF4", new short[]{50, 255, 50, + // 100}, 0, 743, null, CI.emptyCells(1), 1000, true); + + // LFTR Core Fluid Processing + // fluidLftrCore1 = FluidUtils.addGTFluidNoPrefix("LiBeF2UF4FP", "LiBeF2UF4FP", new short[]{110, 255, 110, 100}, + // 0, 800, null, CI.emptyCells(1), 1000, true); + // fluidLftrCore2 = FluidUtils.addGTFluidNoPrefix("UF6F2FP", "UF6F2FP", new short[]{150, 255, 150, 100}, 0, 800, + // null, CI.emptyCells(1), 1000, true); + // fluidLftrCore3 = FluidUtils.addGTFluidNoPrefix("LiFBeF2", "LiFBeF2", new short[]{100, 255, 50, 100}, 0, 800, + // null, CI.emptyCells(1), 1000, true); + // fluidLftrCore4 = FluidUtils.addGTFluidNoPrefix("LiFBeF2UF4", "LiFBeF2UF4", new short[]{50, 255, 100, 100}, 0, + // 800, null, CI.emptyCells(1), 1000, true); + // LFTR Blanket Fluid Processing + fluidNuclearWaste = FluidUtils.addGTFluidNoPrefix( + "nuclear.waste", + "Nuclear Waste", + new short[] { 10, 250, 10, 100 }, + 0, + 1000, + null, + CI.emptyCells(1), + 1000, + true); + + // LFTR Control Circuit + itemCircuitLFTR = new CoreItem( + "itemCircuitLFTR", + "" + EnumChatFormatting.GREEN + "Control Circuit", + AddToCreativeTab.tabMisc, + 1, + 0, + new String[] { "Keeps Multiblocks Stable" }, + EnumRarity.epic, + EnumChatFormatting.DARK_GREEN, + false, + null); + + if (CORE.ConfigSwitches.enableMachine_Pollution) { + itemBasicTurbine = new ItemBasicScrubberTurbine(); + } + + // Zirconium + // Cinter Pellet. + itemZirconiumChlorideCinterPellet = new CoreItem( + "itemZirconiumPellet", + "Zirconium Pellet [" + StringUtils.subscript("ZrCl4") + "]", + tabMisc).setTextureName(GTPlusPlus.ID + ":itemShard"); + GT_OreDictUnificator.registerOre("pelletZirconium", new ItemStack(itemZirconiumChlorideCinterPellet)); + // Zirconium Chloride + dustZrCl4 = ItemUtils.generateSpecialUseDusts("ZrCl4", "ZrCl4", "ZrCl4", Utils.rgbtoHexValue(180, 180, 180))[0]; // http://www.iaea.org/inis/collection/NCLCollectionStore/_Public/39/036/39036750.pdf + dustCookedZrCl4 = ItemUtils + .generateSpecialUseDusts("CookedZrCl4", "Cooked ZrCl4", "ZrCl4", Utils.rgbtoHexValue(180, 180, 180))[0]; // http://www.iaea.org/inis/collection/NCLCollectionStore/_Public/39/036/39036750.pdf + + // Zirconium Tetrafluoride + /* + * GT_OreDictUnificator.registerOre("cellZrF4", + * ItemUtils.getItemStackOfAmountFromOreDict("cellZirconiumTetrafluoride", 1)); + * GT_OreDictUnificator.registerOre("dustZrF4", + * ItemUtils.getItemStackOfAmountFromOreDict("dustZirconiumTetrafluoride", 1)); + */ + fluidZrF4 = FluidUtils.generateFluidNoPrefix( + "ZirconiumTetrafluoride", + "Zirconium Tetrafluoride", + 500, + new short[] { 170, 170, 140, 100 }); // https://en.wikipedia.org/wiki/Zirconium_tetrafluoride + FLUORIDES.ZIRCONIUM_TETRAFLUORIDE.setFluid(fluidZrF4); + + // Coolant Salt + // NaBF4 - NaF - 621C + // dustNaBF4NaF = ItemUtils.generateSpecialUseDusts("NaBF4NaF", "NaBF4NaF", Utils.rgbtoHexValue(45, 45, 90))[0]; + // //https://en.wikipedia.org/wiki/Zirconium_tetrafluoride + + // Load Tree Farmer + if (CORE.ConfigSwitches.enableMultiblock_TreeFarmer) { // https://en.wikipedia.org/wiki/UAN + dustFertUN18 = ItemUtils + .generateSpecialUseDusts("UN18Fertiliser", "UN-18 Fertiliser", Utils.rgbtoHexValue(60, 155, 60))[0]; + dustFertUN32 = ItemUtils + .generateSpecialUseDusts("UN32Fertiliser", "UN-32 Fertiliser", Utils.rgbtoHexValue(55, 190, 55))[0]; + + ItemStack temp1 = ItemUtils.getCorrectStacktype("IC2:itemFertilizer", 1); + ItemStack temp2 = null; + + if (Forestry.isModLoaded()) { + temp2 = ItemUtils.getCorrectStacktype("Forestry:fertilizerCompound", 1); + } + if (temp1 != null) { + fluidFertBasic = FluidUtils.generateFluidNonMolten( + "Fertiliser", + "Fertiliser", + 32, + new short[] { 45, 170, 45, 100 }, + temp1, + null, + true); + GT_Values.RA.stdBuilder() + .itemInputs(temp2) + .fluidOutputs(new FluidStack(fluidFertBasic, 36)) + .duration(5 * TICKS) + .eut(16) + .addTo(fluidExtractionRecipes); + } + fluidFertUN32 = FluidUtils.generateFluidNonMolten( + "UN32Fertiliser", + "UN-32 Fertiliser", + 24, + new short[] { 55, 190, 55, 100 }, + null, + null, + true); + fluidFertUN18 = FluidUtils.generateFluidNonMolten( + "UN18Fertiliser", + "UN-18 Fertiliser", + 22, + new short[] { 60, 155, 60, 100 }, + null, + null, + true); + + /* + * GT_Values.RA.addMixerRecipe( arg0, //Item In arg1, arg2, arg3, arg4, //Fluid in arg5, //Fluid Out arg6, + * //Item out arg7, //Eu arg8); //Time + */ + + } + + // Juice + FluidUtils.generateFluidNonMolten( + "RaisinJuice", + "Raisin Juice", + 2, + new short[] { 51, 0, 51, 100 }, + ItemUtils.getItemStackOfAmountFromOreDictNoBroken("foodRaisins", 1), + ItemUtils.getItemStackOfAmountFromOreDictNoBroken("fruitRaisins", 1), + 50, + true); + + // Test items + toolGregtechPump = new GregtechPump(); + toolGregtechPump.registerPumpType(0, "Simple Hand Pump", 0, 0); + toolGregtechPump.registerPumpType(1, "Advanced Hand Pump", 32000, 1); + toolGregtechPump.registerPumpType(2, "Super Hand Pump", 128000, 2); + toolGregtechPump.registerPumpType(3, "Ultimate Hand Pump", 512000, 3); + + // Xp Fluids - Dev + if (!FluidRegistry.isFluidRegistered("mobessence")) { + FluidUtils.generateFluidNoPrefix("mobessence", "Mob Essence", 0, new short[] { 125, 175, 125, 100 }); + } + + dustNeptunium238 = new DustDecayable( + "dustNeptunium238", + Utils.rgbtoHexValue(175, 240, 75), + 50640, + new String[] { StringUtils.superscript("238Np"), + "Result: Plutonium 238 (" + StringUtils.superscript("238Pu") + ")" }, + ELEMENT.getInstance().PLUTONIUM238.getDust(1) + .getItem(), + 5); + dustDecayedRadium226 = ItemUtils.generateSpecialUseDusts( + "DecayedRadium226", + "Decayed Radium-226", + "Contains Radon (" + StringUtils.superscript("222Rn") + ")", + ELEMENT.getInstance().RADIUM.getRgbAsHex())[0]; + dustRadium226 = new DustDecayable( + "dustRadium226", + ELEMENT.getInstance().RADIUM.getRgbAsHex(), + 90000, + new String[] { StringUtils.superscript("226Ra"), + "Result: Radon (" + StringUtils.superscript("222Rn") + ")" }, + ItemUtils.getSimpleStack(dustDecayedRadium226) + .getItem(), + 5); + dustProtactinium233 = new DustDecayable( + "dustProtactinium233", + ELEMENT.getInstance().PROTACTINIUM.getRgbAsHex(), + 32000, + new String[] { StringUtils.superscript("233Pa"), + "Result: Uranium 233(" + StringUtils.superscript("233U") + ")" }, + ELEMENT.getInstance().URANIUM233.getDust(1) + .getItem(), + 6); + dustMolybdenum99 = new DustDecayable( + "dustMolybdenum99", + ELEMENT.getInstance().MOLYBDENUM.getRgbAsHex(), + 16450, + new String[] { StringUtils.superscript("99Mo"), + "Result: Technicium 99ᵐ (" + StringUtils.superscript("99ᵐTc") + ")" }, + dustTechnetium99M, + 4); + + itemIonParticleBase = new IonParticles(); + itemStandarParticleBase = new StandardBaseParticles(); + + Item a8kFlask = VolumetricFlaskHelper.generateNewFlask("Volumetric_Flask_8k", "Large Volumetric Flask", 8000); + Item a64kFlask = VolumetricFlaskHelper + .generateNewFlask("Volumetric_Flask_32k", "Gigantic Volumetric Flask", 32000); + GregtechItemList.VOLUMETRIC_FLASK_8k.set(a8kFlask); + GregtechItemList.VOLUMETRIC_FLASK_32k.set(a64kFlask); + + itemBoilerChassis = new ItemBoilerChassis(); + itemDehydratorCoilWire = new ItemDehydratorCoilWire(); + itemDehydratorCoil = new ItemDehydratorCoil(); + + itemAirFilter = new ItemAirFilter(); + itemLavaFilter = new ItemLavaFilter(); + + // Chemistry + new CoalTar(); + new RocketFuels(); + + // Nuclear Processing + new NuclearChem(); + + // Farm Animal Fun + new AgriculturalChem(); + + // General Chemistry + new GenericChem(); + + // Milled Ore Processing + new MilledOreProcessing(); + + // IC2 Exp + Logger.INFO("IndustrialCraft2 Found - Loading Resources."); + + // Baubles Mod Test + try { + final Class<?> baublesTest = ReflectionUtils.getClass("baubles.api.IBauble"); + if (baublesTest != null) { + COMPAT_Baubles.run(); + } else { + Logger.INFO("Baubles Not Found - Skipping Resources."); + } + } catch (final Throwable T) { + Logger.INFO("Baubles Not Found - Skipping Resources."); + } + + // Buffer Cores! + Item itemBufferCore; + for (int i = 1; i <= 10; i++) { + itemBufferCore = new BufferCore("itemBufferCore", i).setCreativeTab(AddToCreativeTab.tabMachines); + GameRegistry.registerItem(itemBufferCore, itemBufferCore.getUnlocalizedName()); + } + + itemCustomBook = new ItemBaseBook(); + registerCustomTokens(); + } + + public static void registerCustomTokens() { + itemGenericToken.register(0, "BitCoin", 16, "Can be used on the dark web"); + itemGenericToken.register(1, "Hand Pump Trade Token I", 1, "Craft into a Tier I Hand pump"); + itemGenericToken.register(2, "Hand Pump Trade Token II", 1, "Craft into a Tier II Hand pump"); + itemGenericToken.register(3, "Hand Pump Trade Token III", 1, "Craft into a Tier III Hand pump"); + itemGenericToken.register(4, "Hand Pump Trade Token IV", 1, "Craft into a Tier IV Hand pump"); + } + + public static void registerCustomMaterialComponents() { + // Custom GT++ Crafting Components + + /* + * Try to generate dusts for missing rare earth materials if they don't exist + */ + if (!ItemUtils.checkForInvalidItems(ItemUtils.getItemStackOfAmountFromOreDictNoBroken("dustGadolinium", 1))) { + ItemUtils.generateSpecialUseDusts( + "Gadolinium", + "Gadolinium", + Materials.Gadolinium.mElement.name(), + Utils.rgbtoHexValue(226, 172, 9)); + } + if (!ItemUtils.checkForInvalidItems(ItemUtils.getItemStackOfAmountFromOreDictNoBroken("dustYtterbium", 1))) { + ItemUtils.generateSpecialUseDusts( + "Ytterbium", + "Ytterbium", + Materials.Ytterbium.mElement.name(), + Utils.rgbtoHexValue( + Materials.Yttrium.mRGBa[0] - 60, + Materials.Yttrium.mRGBa[1] - 60, + Materials.Yttrium.mRGBa[2] - 60)); + } + if (!ItemUtils.checkForInvalidItems(ItemUtils.getItemStackOfAmountFromOreDictNoBroken("dustSamarium", 1))) { + ItemUtils.generateSpecialUseDusts( + "Samarium", + "Samarium", + Materials.Samarium.mElement.name(), + Utils.rgbtoHexValue(161, 168, 114)); + } + if (!ItemUtils.checkForInvalidItems(ItemUtils.getItemStackOfAmountFromOreDictNoBroken("dustLanthanum", 1))) { + ItemUtils.generateSpecialUseDusts( + "Lanthanum", + "Lanthanum", + Materials.Lanthanum.mElement.name(), + Utils.rgbtoHexValue(106, 127, 163)); + } + + // Just an unusual plate needed for some black magic. + if (ItemUtils.getItemStackOfAmountFromOreDictNoBroken("plateClay", 1) == null) { + itemPlateClay = new BaseItemPlate(NONMATERIAL.CLAY); + } + if (ItemUtils.getItemStackOfAmountFromOreDictNoBroken("plateDoubleClay", 1) == null) { + itemDoublePlateClay = new BaseItemPlateDouble(NONMATERIAL.CLAY); + } + + // Need this for Mutagenic Frames + if (ItemUtils.getItemStackOfAmountFromOreDictNoBroken("foilUranium235", 1) == null) { + itemFoilUranium235 = new BaseItemFoil(ELEMENT.getInstance().URANIUM235); + } + + // A small gear needed for wizardry. + if (ItemUtils.getItemStackOfAmountFromOreDictNoBroken("gearGtSmallWroughtIron", 1) == null) { + itemSmallWroughtIronGear = new BaseItemSmallGear(NONMATERIAL.WROUGHT_IRON); + } + // Krypton Processing + if (ItemUtils.getItemStackOfAmountFromOreDictNoBroken("ingotHotTitanium", 1) == null) { + itemHotTitaniumIngot = ItemUtils + .getSimpleStack(new BaseItemIngot(ELEMENT.getInstance().TITANIUM, ComponentTypes.HOTINGOT)); + } else { + itemHotTitaniumIngot = ItemUtils.getItemStackOfAmountFromOreDictNoBroken("ingotHotTitanium", 1); + } + + // Need this for Laurenium + if (ItemUtils.getItemStackOfAmountFromOreDictNoBroken("dustIndium", 1) == null) { + itemDustIndium = new BaseItemDust(ELEMENT.getInstance().INDIUM); + } + + // Springs + MaterialUtils + .generateComponentAndAssignToAMaterial(ComponentTypes.SPRING, ELEMENT.STANDALONE.CELESTIAL_TUNGSTEN); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.SPRING, ELEMENT.STANDALONE.WHITE_METAL); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.SPRING, ALLOY.NITINOL_60); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.SPRING, ALLOY.AQUATIC_STEEL); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.SPRING, ALLOY.EGLIN_STEEL); + + // Small Springs + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.SMALLSPRING, ALLOY.MARAGING250); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.SMALLSPRING, ALLOY.NICHROME); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.SMALLSPRING, ALLOY.STABALLOY); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.SMALLSPRING, ALLOY.STEEL_BLACK); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.SMALLSPRING, ALLOY.BLACK_TITANIUM); + + // Fine Wire + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.FINEWIRE, ELEMENT.STANDALONE.WHITE_METAL); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.FINEWIRE, ELEMENT.getInstance().PALLADIUM); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.FINEWIRE, ELEMENT.getInstance().ZIRCONIUM); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.FINEWIRE, ALLOY.LEAGRISIUM); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.FINEWIRE, ALLOY.BABBIT_ALLOY); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.FINEWIRE, ALLOY.KOBOLDITE); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.FINEWIRE, ALLOY.HG1223); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.FINEWIRE, ALLOY.QUANTUM); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.FINEWIRE, ELEMENT.STANDALONE.HYPOGEN); + MaterialUtils + .generateComponentAndAssignToAMaterial(ComponentTypes.FINEWIRE, ELEMENT.STANDALONE.CHRONOMATIC_GLASS); + + // Foil + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.FOIL, ALLOY.BLACK_TITANIUM); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.FOIL, ALLOY.BOTMIUM); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.FOIL, ALLOY.TITANSTEEL); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.FOIL, ALLOY.NITINOL_60); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.FOIL, ALLOY.QUANTUM); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.FOIL, ALLOY.LAURENIUM); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.FOIL, ELEMENT.STANDALONE.HYPOGEN); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.FOIL, ELEMENT.STANDALONE.CELESTIAL_TUNGSTEN); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.FOIL, ELEMENT.STANDALONE.ASTRAL_TITANIUM); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.FOIL, ELEMENT.STANDALONE.RHUGNOR); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.FOIL, ELEMENT.STANDALONE.WHITE_METAL); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.FOIL, ELEMENT.STANDALONE.ADVANCED_NITINOL); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.FOIL, ALLOY.PIKYONIUM); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.FOIL, ALLOY.CINOBITE); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.FOIL, ALLOY.LAFIUM); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.FOIL, ALLOY.TRINIUM_REINFORCED_STEEL); + MaterialUtils.generateComponentAndAssignToAMaterial(ComponentTypes.FOIL, ELEMENT.STANDALONE.CHRONOMATIC_GLASS); + + // Special Sillyness + if (true) { + + if (ItemUtils.getItemStackOfAmountFromOreDictNoBroken("plateSodium", 1) == null) { + new BaseItemPlate(ELEMENT.getInstance().SODIUM); + } + + Material meatRaw = NONMATERIAL.MEAT; + // A plate of Meat. + if (ItemUtils.getItemStackOfAmountFromOreDictNoBroken("plateMeatRaw", 1) == null) { + itemPlateRawMeat = new BaseItemPlate(meatRaw); + ItemUtils.registerFuel(ItemUtils.getSimpleStack(itemPlateRawMeat), 100); + } + // A Block of Meat. + if (ItemUtils.getItemStackOfAmountFromOreDictNoBroken("blockMeatRaw", 1) == null) { + blockRawMeat = new BlockBaseModular(meatRaw, BlockTypes.STANDARD); + ItemUtils.registerFuel(ItemUtils.getSimpleStack(blockRawMeat), 900); + } + } + + // A plate of Vanadium. + if (ItemUtils.getItemStackOfAmountFromOreDictNoBroken("plateVanadium", 1) == null) { + itemPlateVanadium = new BaseItemPlate(ELEMENT.getInstance().VANADIUM); + } + + // A plate of Lithium. + if (ItemUtils.getItemStackOfAmountFromOreDictNoBroken("plateLithium", 1) == null) { + itemPlateLithium = new BaseItemPlate(ELEMENT.getInstance().LITHIUM); + } + + // A plate of Europium. + if ((ItemUtils.getItemStackOfAmountFromOreDictNoBroken("plateEuropium", 1) == null) + && CORE.ConfigSwitches.enableCustom_Pipes) { + itemPlateEuropium = new BaseItemPlate(ELEMENT.getInstance().EUROPIUM); + } + if ((ItemUtils.getItemStackOfAmountFromOreDictNoBroken("plateDoubleEuropium", 1) == null) + && CORE.ConfigSwitches.enableCustom_Pipes) { + itemDoublePlateEuropium = new BaseItemPlateDouble(ELEMENT.getInstance().EUROPIUM); + } + + // Tumbaga Mix (For Simple Crafting) + dustTumbagaMix = ItemUtils + .generateSpecialUseDusts("MixTumbaga", "Tumbaga Mix", "Au2Cu", Utils.rgbtoHexValue(255, 150, 80))[0]; + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/BaseItemBurnable.java b/src/main/java/gtPlusPlus/core/item/base/BaseItemBurnable.java new file mode 100644 index 0000000000..8bbc5a3b08 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/BaseItemBurnable.java @@ -0,0 +1,42 @@ +package gtPlusPlus.core.item.base; + +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.ItemStack; + +import gtPlusPlus.api.objects.data.Pair; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.ItemUtils; + +public class BaseItemBurnable extends CoreItem { + + protected final int meta; + + public BaseItemBurnable(String unlocalizedName, String displayName, CreativeTabs creativeTab, int stackSize, + int maxDmg, String description, String oredictName, int burnTime, int meta) { + super(unlocalizedName, creativeTab, stackSize, maxDmg, description); + this.itemName = displayName; + this.meta = meta; + if (oredictName != null && !oredictName.equals("")) { + registerOrdictionary(oredictName); + } + registerFuel(burnTime); + } + + public void registerFuel(int burn) { + CORE.burnables.add(new Pair<>(burn, ItemUtils.getSimpleStack(this, 1))); + } + + public final void registerOrdictionary(String name) { + ItemUtils.addItemToOreDictionary(ItemUtils.getSimpleStack(this), name); + } + + @Override + public int getDamage(ItemStack stack) { + return this.meta; + } + + @Override + public boolean showDurabilityBar(ItemStack stack) { + return false; + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/BaseItemColourable.java b/src/main/java/gtPlusPlus/core/item/base/BaseItemColourable.java new file mode 100644 index 0000000000..d391207a56 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/BaseItemColourable.java @@ -0,0 +1,100 @@ +package gtPlusPlus.core.item.base; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.List; + +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; + +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.util.GT_LanguageManager; + +public class BaseItemColourable extends Item { + + private final EnumRarity rarity; + private final EnumChatFormatting descColour; + private final boolean hasEffect; + public final int componentColour; + + @Override + public int getColorFromItemStack(final ItemStack stack, final int HEX_OxFFFFFF) { + return this.componentColour; + } + + // 5 + /* + * Name, Tab, Stack, Dmg, Description, Rarity, Text Colour, Effect + */ + public BaseItemColourable(final String unlocalizedName, final CreativeTabs creativeTab, final int stackSize, + final int maxDmg, final String description, final EnumRarity regRarity, final EnumChatFormatting colour, + final boolean Effect, int rgb) { + this.setUnlocalizedName(unlocalizedName); + this.setTextureName(GTPlusPlus.ID + ":" + unlocalizedName); + this.setCreativeTab(creativeTab); + this.setMaxStackSize(stackSize); + this.setMaxDamage(maxDmg); + this.setHasSubtypes(true); + this.rarity = regRarity; + GT_LanguageManager.addStringLocalization("gtplusplus." + this.getUnlocalizedName() + ".tooltip", description); + this.descColour = colour; + this.hasEffect = Effect; + this.componentColour = rgb; + GameRegistry.registerItem(this, unlocalizedName); + } + + // 6 + /* + * Name, Tab, Stack, Dmg, Description, Rarity, Text Colour, Effect + */ + public BaseItemColourable(final String unlocalizedName, final String displayName, final CreativeTabs creativeTab, + final int stackSize, final int maxDmg, final String description, final EnumRarity regRarity, + final EnumChatFormatting colour, final boolean Effect, int rgb) { + this.setUnlocalizedName(unlocalizedName); + GT_LanguageManager.addStringLocalization("gtplusplus." + this.getUnlocalizedName() + ".name", displayName); + this.setTextureName(GTPlusPlus.ID + ":" + unlocalizedName); + this.setCreativeTab(creativeTab); + this.setMaxStackSize(stackSize); + this.setMaxDamage(maxDmg); + this.rarity = regRarity; + GT_LanguageManager.addStringLocalization("gtplusplus." + this.getUnlocalizedName() + ".tooltip", description); + this.descColour = colour; + this.hasEffect = Effect; + this.componentColour = rgb; + GameRegistry.registerItem(this, unlocalizedName); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public void addInformation(final ItemStack stack, final EntityPlayer aPlayer, final List list, final boolean bool) { + list.add( + this.descColour + + GT_LanguageManager.getTranslation("gtplusplus." + this.getUnlocalizedName() + ".tooltip")); + // super.addInformation(stack, aPlayer, list, bool); + } + + @Override + @SideOnly(Side.CLIENT) + public EnumRarity getRarity(final ItemStack par1ItemStack) { + return this.rarity; + } + + @Override + public boolean hasEffect(final ItemStack par1ItemStack, final int pass) { + return this.hasEffect; + } + + @Override + public String getItemStackDisplayName(final ItemStack tItem) { + if (!("gtplusplus." + this.getUnlocalizedName() + ".name") + .equals(GT_LanguageManager.getTranslation("gtplusplus." + this.getUnlocalizedName() + ".name"))) { + return GT_LanguageManager.getTranslation("gtplusplus." + this.getUnlocalizedName() + ".name"); + } else return super.getItemStackDisplayName(tItem); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/BaseItemComponent.java b/src/main/java/gtPlusPlus/core/item/base/BaseItemComponent.java new file mode 100644 index 0000000000..6846f8febb --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/BaseItemComponent.java @@ -0,0 +1,459 @@ +package gtPlusPlus.core.item.base; + +import static gregtech.api.enums.Mods.GTPlusPlus; +import static gregtech.api.enums.Mods.GregTech; + +import java.awt.Color; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; + +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.GregTech_API; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.TextureSet; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_LanguageManager; +import gregtech.api.util.GT_OreDictUnificator; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.material.Material; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.data.StringUtils; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.EntityUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.sys.KeyboardUtils; + +public class BaseItemComponent extends Item { + + private static final Class<TextureSet> mTextureSetPreload; + + static { + mTextureSetPreload = TextureSet.class; + } + + public final Material componentMaterial; + public final String materialName; + public final String unlocalName; + public final String translatedMaterialName; + public final ComponentTypes componentType; + public final int componentColour; + public Object extraData; + + protected IIcon base; + protected IIcon overlay; + + public BaseItemComponent(final Material material, final ComponentTypes componentType) { + this.componentMaterial = material; + this.unlocalName = "item" + componentType.COMPONENT_NAME + material.getUnlocalizedName(); + this.materialName = material.getLocalizedName(); + this.translatedMaterialName = material.getTranslatedName(); + this.componentType = componentType; + this.setCreativeTab(AddToCreativeTab.tabMisc); + this.setUnlocalizedName(this.unlocalName); + this.setMaxStackSize(64); + // this.setTextureName(this.getCorrectTextures()); + this.componentColour = material.getRgbAsHex(); + GameRegistry.registerItem(this, this.unlocalName); + + // if (componentType != ComponentTypes.DUST) + + GT_OreDictUnificator.registerOre( + componentType.getOreDictName() + material.getUnlocalizedName(), + ItemUtils.getSimpleStack(this)); + if (componentType == ComponentTypes.GEAR) { + GT_OreDictUnificator.registerOre("gear" + material.getUnlocalizedName(), ItemUtils.getSimpleStack(this)); + } + registerComponent(); + + GT_LanguageManager.addStringLocalization("gtplusplus.item." + unlocalName + ".name", getFormattedLangName()); + } + + // For Cell Generation + public BaseItemComponent(final String unlocalName, final String localName, final short[] RGBA) { + + // Handles .'s from fluid internal names. + String aFormattedNameForFluids; + if (unlocalName.contains(".")) { + aFormattedNameForFluids = StringUtils.splitAndUppercase(unlocalName, "."); + } else { + aFormattedNameForFluids = unlocalName; + } + Material aTempMaterial = Material.mMaterialCache.get(localName.toLowerCase()); + Logger.INFO("Attempted to get " + localName + " cell material from cache. Valid? " + (aTempMaterial != null)); + this.componentMaterial = aTempMaterial; + this.unlocalName = "itemCell" + aFormattedNameForFluids; + this.materialName = localName; + this.translatedMaterialName = getFluidName( + "fluid." + this.materialName.toLowerCase() + .replace(" ", "")); + this.componentType = ComponentTypes.CELL; + this.setCreativeTab(AddToCreativeTab.tabMisc); + this.setUnlocalizedName(aFormattedNameForFluids); + this.setMaxStackSize(64); + this.componentColour = MathUtils.getRgbAsHex(RGBA); + this.extraData = RGBA; + + this.setTextureName(GTPlusPlus.ID + ":" + "item" + ComponentTypes.CELL.COMPONENT_NAME); + GameRegistry.registerItem(this, aFormattedNameForFluids); + GT_OreDictUnificator.registerOre( + ComponentTypes.CELL.getOreDictName() + Utils.sanitizeStringKeepBrackets(localName), + ItemUtils.getSimpleStack(this)); + registerComponent(); + + GT_LanguageManager + .addStringLocalization("gtplusplus.item." + this.unlocalName + ".name", getFormattedLangName()); + } + + private String getFormattedLangName() { + return componentType.getName() + .replace("@", "%material"); + } + + public boolean registerComponent() { + if (this.componentMaterial == null) { + return false; + } + // Register Component + Map<String, ItemStack> aMap = Material.mComponentMap.get(componentMaterial.getUnlocalizedName()); + if (aMap == null) { + aMap = new HashMap<>(); + } + String aKey = componentType.getGtOrePrefix() + .name(); + ItemStack x = aMap.get(aKey); + if (x == null) { + aMap.put(aKey, ItemUtils.getSimpleStack(this)); + Logger.MATERIALS( + "Registering a material component. Item: [" + componentMaterial.getUnlocalizedName() + + "] Map: [" + + aKey + + "]"); + Material.mComponentMap.put(componentMaterial.getUnlocalizedName(), aMap); + if (componentType == ComponentTypes.PLATE) { + GregTech_API.registerCover( + componentMaterial.getPlate(1), + new GT_RenderedTexture( + componentMaterial.getTextureSet().mTextures[71], + componentMaterial.getRGBA(), + false), + null); + } else if (componentType == ComponentTypes.PLATEDOUBLE) { + GregTech_API.registerCover( + componentMaterial.getPlateDouble(1), + new GT_RenderedTexture( + componentMaterial.getTextureSet().mTextures[72], + componentMaterial.getRGBA(), + false), + null); + } + return true; + } else { + // Bad + Logger.MATERIALS("Tried to double register a material component. "); + return false; + } + } + + public String getCorrectTextures() { + if (!CORE.ConfigSwitches.useGregtechTextures) { + return GTPlusPlus.ID + ":" + "item" + this.componentType.COMPONENT_NAME; + } + String metType = "9j4852jyo3rjmh3owlhw9oe"; + if (this.componentMaterial != null) { + TextureSet u = this.componentMaterial.getTextureSet(); + if (u != null) { + metType = u.mSetName; + } + } + metType = (metType.equals("9j4852jyo3rjmh3owlhw9oe") ? "METALLIC" : metType); + return GregTech.ID + ":" + "materialicons/" + metType + "/" + this.componentType.getOreDictName(); + + // return GregTech.ID + ":" + "materialicons/"+metType+"/" + this.componentType.COMPONENT_NAME.toLowerCase(); + } + + /* + * @Override public String getItemStackDisplayName(final ItemStack p_77653_1_) { if (this.componentType == + * ComponentTypes.SMALLGEAR){ return "Small " + this.materialName+" Gear"; } if (this.componentMaterial != null) { + * return (this.componentMaterial.getLocalizedName()+this.componentType.DISPLAY_NAME); } return + * this.materialName+" Cell"; } + */ + + public final String getMaterialName() { + return this.materialName; + } + + public String getFluidName(String aKey) { + String trans; + trans = GT_LanguageManager.getTranslation(aKey); + if (!trans.equals(aKey)) return trans; + aKey = "fluid." + aKey; + trans = GT_LanguageManager.getTranslation(aKey); + if (!trans.equals(aKey)) return trans; + return GT_LanguageManager.addStringLocalization( + "gtplusplus.fluid." + this.materialName.toLowerCase() + .replace(" ", ""), + this.materialName); + } + + @Override + public String getItemStackDisplayName(ItemStack stack) { + return GT_LanguageManager.getTranslation("gtplusplus.item." + unlocalName + ".name") + .replace("%s", "%temp") + .replace("%material", translatedMaterialName) + .replace("%temp", "%s"); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public final void addInformation(final ItemStack stack, final EntityPlayer aPlayer, final List list, + final boolean bool) { + + try { + + if (this.componentMaterial == null) { + if (this.materialName != null) { + // list.add(Utils.sanitizeStringKeepBrackets(materialName)); + } + } + + if ((this.materialName != null) && (this.materialName != "") + && !this.materialName.equals("") + && (this.componentMaterial != null)) { + + if (this.componentMaterial != null) { + if (!this.componentMaterial.vChemicalFormula.contains("?")) { + list.add(Utils.sanitizeStringKeepBrackets(this.componentMaterial.vChemicalFormula)); + } else if (this.componentMaterial.vChemicalFormula.contains("?")) { + String temp = componentMaterial.vChemicalFormula; + temp = temp.replace(" ", ""); + temp = temp.replace("-", ""); + temp = temp.replace("_", ""); + temp = temp.replace("!", ""); + temp = temp.replace("@", ""); + temp = temp.replace("#", ""); + temp = temp.replace(" ", ""); + list.add(temp); + } + + if (this.componentMaterial.isRadioactive) { + list.add(CORE.GT_Tooltip_Radioactive.get()); + } + + if (this.componentType == ComponentTypes.INGOT || this.componentType == ComponentTypes.HOTINGOT) { + if ((this.materialName != null) && (this.materialName != "") + && !this.materialName.equals("") + && this.unlocalName.toLowerCase() + .contains("hot")) { + list.add( + EnumChatFormatting.GRAY + "Warning: " + + EnumChatFormatting.RED + + "Very hot! " + + EnumChatFormatting.GRAY + + " Avoid direct handling.."); + } + } + } else { + String aChemicalFormula = Material.sChemicalFormula.get(materialName.toLowerCase()); + if (aChemicalFormula != null && aChemicalFormula.length() > 0) { + list.add(Utils.sanitizeStringKeepBrackets(aChemicalFormula)); + } + } + + // Hidden Tooltip + if (KeyboardUtils.isCtrlKeyDown()) { + if (this.componentMaterial != null) { + String type = this.componentMaterial.getTextureSet().mSetName; + String output = type.substring(0, 1) + .toUpperCase() + type.substring(1); + list.add(EnumChatFormatting.GRAY + "Material Type: " + output + "."); + list.add( + EnumChatFormatting.GRAY + "Material State: " + + this.componentMaterial.getState() + .name() + + "."); + list.add( + EnumChatFormatting.GRAY + "Radioactivity Level: " + + this.componentMaterial.vRadiationLevel + + "."); + } + } else { + list.add(EnumChatFormatting.DARK_GRAY + "Hold Ctrl to show additional info."); + } + } + } catch (Throwable t) {} + + super.addInformation(stack, aPlayer, list, bool); + } + + @SuppressWarnings("unchecked") + @Override + public void onUpdate(final ItemStack iStack, final World world, final Entity entityHolding, final int p_77663_4_, + final boolean p_77663_5_) { + if (this.componentMaterial != null) { + if (entityHolding instanceof EntityPlayer) { + if (!((EntityPlayer) entityHolding).capabilities.isCreativeMode) { + EntityUtils.applyRadiationDamageToEntity( + iStack.stackSize, + this.componentMaterial.vRadiationLevel, + world, + entityHolding); + } + } + } + } + + /** + * + * Handle Custom Rendering + * + */ + @Override + @SideOnly(Side.CLIENT) + public boolean requiresMultipleRenderPasses() { + return (CORE.ConfigSwitches.useGregtechTextures ? true : false); + } + + @SuppressWarnings("unchecked") + @Override + public int getColorFromItemStack(final ItemStack stack, final int renderPass) { + + if (this.componentType == ComponentTypes.CELL || this.componentType == ComponentTypes.PLASMACELL) { + if (renderPass == 0 && !CORE.ConfigSwitches.useGregtechTextures) { + return Utils.rgbtoHexValue(255, 255, 255); + } + if (renderPass == 1 && CORE.ConfigSwitches.useGregtechTextures) { + return Utils.rgbtoHexValue(255, 255, 255); + } + } + + try { + if (this.componentMaterial == null) { + if (extraData != null) { + if (short.class.isInstance(extraData)) { + short[] abc = (short[]) extraData; + return Utils.rgbtoHexValue(abc[0], abc[1], abc[2]); + } + } + return this.componentColour; + } + + if (this.componentMaterial.getRGBA()[3] <= 1) { + return this.componentColour; + } else { + // Mild Glow Effect + if (this.componentMaterial.getRGBA()[3] == 2) { + // 4 sec cycle, 200 control point. 20ms interval. + int currentFrame = (int) ((System.nanoTime() % 4_000_000_000L) / 20_000_000L); + int value = currentFrame < 50 ? currentFrame + 1 + : currentFrame < 100 ? 50 : currentFrame < 150 ? 149 - currentFrame : 0; + return Utils.rgbtoHexValue( + Math.min(255, Math.max(componentMaterial.getRGBA()[0] + value, 0)), + Math.min(255, Math.max(componentMaterial.getRGBA()[1] + value, 0)), + Math.min(255, Math.max(componentMaterial.getRGBA()[2] + value, 0))); + } + + // Rainbow Hue Cycle + else if (this.componentMaterial.getRGBA()[3] == 3) { + return Color.HSBtoRGB((float) (System.nanoTime() % 8_000_000_000L) / 8_000_000_000f, 1, 1); + } + } + + } catch (Throwable t) { + + } + return this.componentColour; + } + + @Override + public IIcon getIconFromDamageForRenderPass(final int damage, final int pass) { + if (CORE.ConfigSwitches.useGregtechTextures) { + if (pass == 0) { + return this.base; + } + return this.overlay; + } + return this.base; + } + + @Override + public void registerIcons(final IIconRegister i) { + + if (CORE.ConfigSwitches.useGregtechTextures) { + this.base = i.registerIcon(getCorrectTextures()); + this.overlay = i.registerIcon(getCorrectTextures() + "_OVERLAY"); + } else { + this.base = i.registerIcon(getCorrectTextures()); + // this.overlay = i.registerIcon(getCorrectTextures() + "_OVERLAY"); + } + } + + public static enum ComponentTypes { + + DUST("Dust", "@ Dust", "dust", OrePrefixes.dust), + DUSTSMALL("DustSmall", "Small Pile of @ Dust", "dustSmall", OrePrefixes.dustSmall), + DUSTTINY("DustTiny", "Tiny Pile of @ Dust", "dustTiny", OrePrefixes.dustTiny), + INGOT("Ingot", "@ Ingot", "ingot", OrePrefixes.ingot), + HOTINGOT("HotIngot", "Hot @ Ingot", "ingotHot", OrePrefixes.ingotHot), + PLATE("Plate", "@ Plate", "plate", OrePrefixes.plate), + PLATEDOUBLE("PlateDouble", "Double @ Plate", "plateDouble", OrePrefixes.plateDouble), + ROD("Rod", "@ Rod", "stick", OrePrefixes.stick), + RODLONG("RodLong", "Long @ Rod", "stickLong", OrePrefixes.stickLong), + GEAR("Gear", "@ Gear", "gearGt", OrePrefixes.gearGt), + SMALLGEAR("SmallGear", "Small @ Gear", "gearGtSmall", OrePrefixes.gearGtSmall), // TODO + SCREW("Screw", "@ Screw", "screw", OrePrefixes.screw), + BOLT("Bolt", "@ Bolt", "bolt", OrePrefixes.bolt), + ROTOR("Rotor", "@ Rotor", "rotor", OrePrefixes.rotor), + RING("Ring", "@ Ring", "ring", OrePrefixes.ring), + FOIL("Foil", "@ Foil", "foil", OrePrefixes.foil), + PLASMACELL("CellPlasma", "@ Plasma Cell", "cellPlasma", OrePrefixes.cellPlasma), + CELL("Cell", "@ Cell", "cell", OrePrefixes.cell), + NUGGET("Nugget", "@ Nugget", "nugget", OrePrefixes.nugget), + SPRING("Spring", "@ Spring", "spring", OrePrefixes.spring), + SMALLSPRING("SmallSpring", "Small @ Spring", "springSmall", OrePrefixes.springSmall), + FINEWIRE("FineWire", "Fine @ Wire", "wireFine", OrePrefixes.wireFine), + PLATEDENSE("PlateDense", "Dense @ Plate", "plateDense", OrePrefixes.plateDense),; + + private final String COMPONENT_NAME; + private final String DISPLAY_NAME; + private final String OREDICT_NAME; + private final OrePrefixes a_GT_EQUAL; + + private ComponentTypes(final String LocalName, final String DisplayName, final String OreDictName, + final OrePrefixes aPrefix) { + this.COMPONENT_NAME = LocalName; + this.DISPLAY_NAME = DisplayName; + this.OREDICT_NAME = OreDictName; + this.a_GT_EQUAL = aPrefix; + } + + public String getComponent() { + return this.COMPONENT_NAME; + } + + public String getName() { + return this.DISPLAY_NAME; + } + + public String getOreDictName() { + return this.OREDICT_NAME; + } + + public OrePrefixes getGtOrePrefix() { + return this.a_GT_EQUAL; + } + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/BaseItemDamageable.java b/src/main/java/gtPlusPlus/core/item/base/BaseItemDamageable.java new file mode 100644 index 0000000000..9a4109a1de --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/BaseItemDamageable.java @@ -0,0 +1,194 @@ +package gtPlusPlus.core.item.base; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.List; + +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; + +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.api.objects.Logger; + +public class BaseItemDamageable extends Item { + + private final EnumRarity rarity; + private final String itemDescription; + protected String itemName; + private final boolean hasEffect; + + public BaseItemDamageable(final String unlocalizedName, final CreativeTabs creativeTab, final int stackSize, + final int maxDmg, final String description, final EnumRarity regRarity, final EnumChatFormatting colour, + final boolean Effect, final ItemStack OverrideItem) { + this.setUnlocalizedName(unlocalizedName); + this.setTextureName(GTPlusPlus.ID + ":" + unlocalizedName); + this.setCreativeTab(creativeTab); + this.setMaxStackSize(1); + this.setMaxDamage(251); + this.setNoRepair(); + this.rarity = regRarity; + this.itemDescription = description; + this.hasEffect = Effect; + GameRegistry.registerItem(this, unlocalizedName); + } + + public String getItemDescription() { + return this.itemDescription; + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public void addInformation(final ItemStack stack, final EntityPlayer aPlayer, final List list, final boolean bool) { + int dmg = (int) getItemDamage(stack); + if (dmg <= 3) { + list.add(EnumChatFormatting.GRAY + this.itemDescription); + } + if (dmg > 3 && dmg <= 25) { + list.add( + EnumChatFormatting.GRAY + + "You have discovered that smashing this against valuable stones has some function.."); + } else if (dmg > 0) { + int maxDamage = 250; + list.add( + EnumChatFormatting.GRAY + "" + + (maxDamage - getItemDamage(stack)) + + "/" + + maxDamage + + " gems remaining."); + } + } + + @Override + @SideOnly(Side.CLIENT) + public EnumRarity getRarity(final ItemStack par1ItemStack) { + int dmg = (int) getItemDamage(par1ItemStack); + if (dmg > 200) { + return EnumRarity.epic; + } + return this.rarity; + } + + @Override + public boolean hasEffect(final ItemStack par1ItemStack, final int pass) { + int dmg = (int) getItemDamage(par1ItemStack); + if (dmg > 200) { + return true; + } + return this.hasEffect; + } + + @Override + public String getItemStackDisplayName(final ItemStack tItem) { + if ((this.itemName == null) || this.itemName.equals("")) { + return super.getItemStackDisplayName(tItem); + } + return this.itemName; + } + + private static boolean createNBT(ItemStack rStack) { + final NBTTagCompound tagMain = new NBTTagCompound(); + final NBTTagCompound tagNBT = new NBTTagCompound(); + tagNBT.setLong("Value", 0); + tagMain.setTag("Damage", tagNBT); + rStack.setTagCompound(tagMain); + return true; + } + + public static final long getItemDamage(final ItemStack aStack) { + NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag("Damage"); + if (aNBT != null) { + return aNBT.getLong("Value"); + } + } else { + createNBT(aStack); + } + return 0L; + } + + public static final boolean setItemDamage(final ItemStack aStack, final long aDamage) { + NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag("Damage"); + if (aNBT != null) { + aNBT.setLong("Value", aDamage); + return true; + } + } else { + createNBT(aStack); + } + return false; + } + + @Override + public double getDurabilityForDisplay(ItemStack stack) { + if (stack.getTagCompound() == null) { + createNBT(stack); + } + double currentDamage = getItemDamage(stack); + double durabilitypercent = currentDamage / 100; + double inverse = (100 - durabilitypercent); + return durabilitypercent; + } + + @Override + public boolean showDurabilityBar(ItemStack stack) { + int dmg = (int) getItemDamage(stack); + if (dmg <= 20) { + return false; + } else { + return true; + } + } + + public static ItemStack damageItem(ItemStack item) { + if (item != null) { + long currentUse = BaseItemDamageable.getItemDamage(item); + if (currentUse >= 0 && currentUse <= 250) { + BaseItemDamageable.setItemDamage(item, currentUse + 1); + return item; + } else { + return item; + } + } + return null; + } + + @Override + public boolean doesContainerItemLeaveCraftingGrid(ItemStack stack) { + Logger.INFO("Does Leave Table? " + stack.getDisplayName()); + return true; + } + + @Override + public boolean getShareTag() { + return true; + } + + @Override + public boolean hasContainerItem(ItemStack stack) { + return true; + } + + @Override + public ItemStack getContainerItem(ItemStack itemStack) { + ItemStack stack = itemStack.copy(); + // stack.setItemDamage(stack.getItemDamage() + 1); + damageItem(stack); + stack.stackSize = 1; + return stack; + } + + @Override + public int getDamage(ItemStack stack) { + return (int) getItemDamage(stack); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/BaseItemTCShard.java b/src/main/java/gtPlusPlus/core/item/base/BaseItemTCShard.java new file mode 100644 index 0000000000..3ecb6960d6 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/BaseItemTCShard.java @@ -0,0 +1,69 @@ +package gtPlusPlus.core.item.base; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.List; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +import cpw.mods.fml.common.registry.GameRegistry; +import gregtech.api.util.GT_LanguageManager; +import gregtech.api.util.GT_OreDictUnificator; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.ItemUtils; + +public class BaseItemTCShard extends Item { + + public final String unlocalName; + public final String displayName; + public final int itemColour; + + public BaseItemTCShard(final String DisplayName, final int colour) { + this(DisplayName, colour, null); + } + + public BaseItemTCShard(final String DisplayName, final int colour, final String[] Description) { + this.unlocalName = "item" + Utils.sanitizeString(DisplayName); + this.displayName = DisplayName; + this.itemColour = colour; + this.setCreativeTab(AddToCreativeTab.tabMisc); + this.setUnlocalizedName(this.unlocalName); + if (Description != null) { + for (int i = 0; i < Description.length; i++) { + GT_LanguageManager + .addStringLocalization("gtplusplus." + getUnlocalizedName() + ".tooltip." + i, Description[i]); + } + } + this.setMaxStackSize(64); + this.setTextureName(GTPlusPlus.ID + ":" + "itemShard"); + GameRegistry.registerItem(this, this.unlocalName); + GT_OreDictUnificator.registerOre("shard" + DisplayName, ItemUtils.getSimpleStack(this)); + GT_OreDictUnificator.registerOre("gemInfused" + DisplayName, ItemUtils.getSimpleStack(this)); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public void addInformation(final ItemStack stack, final EntityPlayer aPlayer, final List list, final boolean bool) { + for (int i = 0;; i++) { + String tooltip = GT_LanguageManager + .getTranslation("gtplusplus." + this.getUnlocalizedName() + ".tooltip" + "." + i); + if (!("gtplusplus." + this.getUnlocalizedName() + ".tooltip" + "." + i).equals(tooltip)) { + list.add(tooltip); + } else break; + } + } + + @Override + public int getColorFromItemStack(final ItemStack stack, final int HEX_OxFFFFFF) { + return this.itemColour; + } + + @Override + public void onUpdate(final ItemStack iStack, final World world, final Entity entityHolding, final int p_77663_4_, + final boolean p_77663_5_) {} +} diff --git a/src/main/java/gtPlusPlus/core/item/base/BaseItemTickable.java b/src/main/java/gtPlusPlus/core/item/base/BaseItemTickable.java new file mode 100644 index 0000000000..8417eba3d1 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/BaseItemTickable.java @@ -0,0 +1,332 @@ +package gtPlusPlus.core.item.base; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.List; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.util.Utils; + +public class BaseItemTickable extends CoreItem { + + public final String[] descriptionString; + public final int itemColour; + public final int maxTicks; + public final boolean twoRenderPasses; + public final boolean ticksInContainers; + + public IIcon[] mIcon = new IIcon[2]; + + public BaseItemTickable(boolean twoPass, final String unlocalName, final int colour, final int maxTicks) { + this(false, twoPass, unlocalName, colour, maxTicks, new String[] {}); + } + + public BaseItemTickable(boolean containerTick, boolean twoPass, final String unlocalName, final int colour, + final int maxTicks) { + this(containerTick, twoPass, unlocalName, colour, maxTicks, new String[] {}); + } + + public BaseItemTickable(boolean containerTick, boolean twoPass, final String unlocalName, final int colour, + final int maxTicks, final String[] Description) { + super( + unlocalName, + AddToCreativeTab.tabMisc, + 1, + 999999999, + Description, + EnumRarity.epic, + EnumChatFormatting.DARK_RED, + true, + null); + this.itemColour = colour; + this.descriptionString = Description; + this.maxTicks = maxTicks; + this.twoRenderPasses = twoPass; + this.ticksInContainers = containerTick; + this.maxStackSize = 1; + // setGregtechItemList(); + } + + @Override + public void onUpdate(final ItemStack iStack, final World world, final Entity entityHolding, final int p_77663_4_, + final boolean p_77663_5_) { + if (world == null || iStack == null) { + return; + } + if (world.isRemote) { + return; + } + + boolean active = isTicking(world, iStack); + if (active) { + tickItemTag(world, iStack); + } + } + + /* + * private final boolean setGregtechItemList() { ItemList.Component_LavaFilter.set(this); return + * ItemList.Component_LavaFilter.get(1) != null ? true : false; } + */ + + /** + * + * Handle Custom Rendering + * + */ + @Override + @SideOnly(Side.CLIENT) + public boolean requiresMultipleRenderPasses() { + return this.twoRenderPasses; + } + + @Override + public int getColorFromItemStack(final ItemStack stack, final int renderPass) { + if (renderPass == 1 && this.twoRenderPasses) { + return Utils.rgbtoHexValue(255, 255, 255); + } + return this.itemColour; + } + + @Override + public IIcon getIconFromDamageForRenderPass(final int damage, final int pass) { + if (this.twoRenderPasses) { + if (pass == 0) { + return this.mIcon[0]; + } + return this.mIcon[1]; + } + return this.mIcon[0]; + } + + @Override + public void registerIcons(final IIconRegister i) { + + if (this.twoRenderPasses) { + this.mIcon[0] = i.registerIcon(GTPlusPlus.ID + ":" + this.getUnlocalizedName()); + this.mIcon[1] = i.registerIcon(GTPlusPlus.ID + ":" + this.getUnlocalizedName() + "_OVERLAY"); + } else { + this.mIcon[0] = i.registerIcon(GTPlusPlus.ID + ":" + this.getUnlocalizedName()); + // this.overlay = i.registerIcon(getCorrectTextures() + "_OVERLAY"); + } + } + + protected int getMaxTicks(ItemStack aStack) { + return maxTicks; + } + + protected boolean createNBT(World world, ItemStack rStack) { + final NBTTagCompound tagMain = new NBTTagCompound(); + final NBTTagCompound tagNBT = new NBTTagCompound(); + tagNBT.setLong("Tick", 0); + tagNBT.setLong("maxTick", getMaxTicks(rStack)); + tagNBT.setBoolean("isActive", true); + + // Try set world time + if (world != null) { + // tagNBT.setLong("CreationDate", world.getTotalWorldTime()); + } + + tagMain.setTag("TickableItem", tagNBT); + rStack.setTagCompound(tagMain); + Logger.INFO("Created Tickable NBT data."); + return true; + } + + public final long getTicks(World world, final ItemStack aStack) { + NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag("TickableItem"); + if (aNBT != null) { + return aNBT.getLong("Tick"); + } + } else { + createNBT(world, aStack); + } + return 0L; + } + + public final boolean setTicks(World world, final ItemStack aStack, final long aDamage) { + NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag("TickableItem"); + if (aNBT != null) { + aNBT.setLong("Tick", aDamage); + return true; + } + } else { + createNBT(world, aStack); + } + return false; + } + + public final boolean isTicking(World world, final ItemStack aStack) { + NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag("TickableItem"); + if (aNBT != null) { + return aNBT.getBoolean("isActive"); + } + } else { + return createNBT(world, aStack); + } + return true; + } + + public final boolean setTicking(World world, final ItemStack aStack, final boolean active) { + NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag("TickableItem"); + if (aNBT != null) { + aNBT.setBoolean("isActive", active); + return true; + } + } else { + createNBT(world, aStack); + } + return false; + } + + public final boolean getTicksInContainer(World world, final ItemStack aStack) { + NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag("TickableItem"); + if (aNBT != null) { + return aNBT.getBoolean("ticksInContainer"); + } + } else { + createNBT(world, aStack); + } + return false; + } + + public final boolean setTicksInContainer(World world, final ItemStack aStack, final boolean active) { + NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag("TickableItem"); + if (aNBT != null) { + aNBT.setBoolean("ticksInContainer", active); + return true; + } + } else { + createNBT(world, aStack); + } + return false; + } + + public final long getDifferenceInWorldTimeToCreationTime(World world, final ItemStack aStack) { + NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag("TickableItem"); + if (aNBT != null) { + return (world.getTotalWorldTime() - aNBT.getLong("CreationDate")); + } + } else { + createNBT(world, aStack); + } + return 0L; + } + + public final boolean setItemStackCreationTime(final ItemStack aStack, World world) { + NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag("TickableItem"); + if (aNBT != null) { + aNBT.setLong("CreationDate", world.getTotalWorldTime()); + return true; + } + } else { + createNBT(world, aStack); + } + return false; + } + + public final boolean tickItemTag(World world, ItemStack aStack) { + NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT != null) { + if (aNBT.hasKey("TickableItem")) { + aNBT = aNBT.getCompoundTag("TickableItem"); + // Done Ticking + if (getMaxTicks(aStack) - getTicks(world, aStack) <= 0) { + setTicking(world, aStack, false); + return false; + } + if (isTicking(world, aStack)) { + if (aNBT != null) { + aNBT.setLong("Tick", getTicks(world, aStack) + 1); + return true; + } else { + return false; + } + } else { + return false; + } + } + } + return createNBT(world, aStack); + } + + @Override + public double getDurabilityForDisplay(ItemStack stack) { + if (stack.getTagCompound() == null) { + // createNBT(null, stack); + return 0; + } + double currentDamage = getTicks(null, stack); + double durabilitypercent = currentDamage / getMaxTicks(stack); + return durabilitypercent; + } + + @SuppressWarnings("unchecked") + @Override + public void addInformation(ItemStack stack, EntityPlayer player, @SuppressWarnings("rawtypes") List list, + boolean bool) { + World world = player.getEntityWorld(); + if (this.descriptionString.length > 0) { + list.add(EnumChatFormatting.GRAY + this.descriptionString[0]); + } + long maxTicks = getMaxTicks(stack); + long ticks = 0; + if (stack.hasTagCompound()) { + ticks = getTicks(world, stack); + } + EnumChatFormatting durability = EnumChatFormatting.GRAY; + if (maxTicks - ticks > (maxTicks * 0.8)) { + durability = EnumChatFormatting.GRAY; + } else if (maxTicks - ticks > (maxTicks * 0.6)) { + durability = EnumChatFormatting.GREEN; + } else if (maxTicks - ticks > (maxTicks * 0.4)) { + durability = EnumChatFormatting.YELLOW; + } else if (maxTicks - ticks > (maxTicks * 0.2)) { + durability = EnumChatFormatting.GOLD; + } else if (maxTicks - ticks > 0) { + durability = EnumChatFormatting.RED; + } + list.add(durability + "" + ((maxTicks - ticks) / 20) + EnumChatFormatting.GRAY + " seconds until decay"); + + if (this.descriptionString.length > 1) { + for (int h = 1; h < this.descriptionString.length; h++) { + list.add(EnumChatFormatting.GRAY + this.descriptionString[h]); + } + } + + // super.addInformation(stack, player, list, bool); + } + + @Override + public boolean showDurabilityBar(ItemStack stack) { + return false; + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/BaseItemWithDamageValue.java b/src/main/java/gtPlusPlus/core/item/base/BaseItemWithDamageValue.java new file mode 100644 index 0000000000..0e1b0ab0f2 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/BaseItemWithDamageValue.java @@ -0,0 +1,30 @@ +package gtPlusPlus.core.item.base; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +public class BaseItemWithDamageValue extends Item { + + public BaseItemWithDamageValue(final String unlocalizedName) { + this.setUnlocalizedName(unlocalizedName); + this.setTextureName(GTPlusPlus.ID + ":" + unlocalizedName); + this.setMaxStackSize(1); + this.setMaxDamage(100); + } + + @Override + public void setDamage(final ItemStack stack, final int damage) { + super.setDamage(stack, damage); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public void addInformation(final ItemStack stack, final EntityPlayer aPlayer, final List list, final boolean bool) { + super.addInformation(stack, aPlayer, list, bool); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/BasicSpawnEgg.java b/src/main/java/gtPlusPlus/core/item/base/BasicSpawnEgg.java new file mode 100644 index 0000000000..b564d60424 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/BasicSpawnEgg.java @@ -0,0 +1,238 @@ +package gtPlusPlus.core.item.base; + +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockLiquid; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityList; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.IEntityLivingData; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemMonsterPlacer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Facing; +import net.minecraft.util.IIcon; +import net.minecraft.util.MathHelper; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.creative.AddToCreativeTab; + +public class BasicSpawnEgg extends ItemMonsterPlacer { + + @SideOnly(Side.CLIENT) + private IIcon theIcon; + + protected int colorBase = 0x000000; + protected int colorSpots = 0xFFFFFF; + protected String entityMODID = ""; + protected String entityToSpawnName = ""; + protected String entityToSpawnNameFull = ""; + protected EntityLiving entityToSpawn = null; + + public BasicSpawnEgg() { + super(); + } + + public BasicSpawnEgg(final String MODID, final String parEntityToSpawnName, final int parPrimaryColor, + final int parSecondaryColor) { + this.setHasSubtypes(false); + this.maxStackSize = 64; + this.setCreativeTab(AddToCreativeTab.tabOther); + this.setEntityToSpawnName(parEntityToSpawnName); + this.colorBase = parPrimaryColor; + this.colorSpots = parSecondaryColor; + this.entityMODID = MODID; + + // DEBUG + Logger.WARNING("Spawn egg constructor for " + this.entityToSpawnName); + } + + /** + * Callback for item usage. If the item does something special on right clicking, + * + * he will have one of those. Return True if something happen and false if it don't. This is for ITEMS, not BLOCKS + */ + @Override + public boolean onItemUse(final ItemStack par1ItemStack, final EntityPlayer par2EntityPlayer, final World par3World, + int par4, int par5, int par6, final int par7, final float par8, final float par9, final float par10) { + if (par3World.isRemote) { + return true; + } + final Block block = par3World.getBlock(par4, par5, par6); + par4 += Facing.offsetsXForSide[par7]; + par5 += Facing.offsetsYForSide[par7]; + par6 += Facing.offsetsZForSide[par7]; + double d0 = 0.0D; + + if ((par7 == 1) && (block.getRenderType() == 11)) { + d0 = 0.5D; + } + + final Entity entity = this.spawnEntity(par3World, par4 + 0.5D, par5 + d0, par6 + 0.5D); + + if (entity != null) { + if ((entity instanceof EntityLivingBase) && par1ItemStack.hasDisplayName()) { + ((EntityLiving) entity).setCustomNameTag(par1ItemStack.getDisplayName()); + } + + if (!par2EntityPlayer.capabilities.isCreativeMode) { + --par1ItemStack.stackSize; + } + } + + return true; + } + + /** + * Called whenever this item is equipped and the right mouse button is pressed. + * + * Args: itemStack, world, entityPlayer + */ + @Override + public ItemStack onItemRightClick(final ItemStack par1ItemStack, final World par2World, + final EntityPlayer par3EntityPlayer) { + if (par2World.isRemote) { + return par1ItemStack; + } + final MovingObjectPosition movingobjectposition = this + .getMovingObjectPositionFromPlayer(par2World, par3EntityPlayer, true); + + if (movingobjectposition == null) { + return par1ItemStack; + } + if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { + + final int i = movingobjectposition.blockX; + final int j = movingobjectposition.blockY; + final int k = movingobjectposition.blockZ; + + if (!par2World.canMineBlock(par3EntityPlayer, i, j, k)) { + return par1ItemStack; + } + + if (!par3EntityPlayer.canPlayerEdit(i, j, k, movingobjectposition.sideHit, par1ItemStack)) { + return par1ItemStack; + } + + if (par2World.getBlock(i, j, k) instanceof BlockLiquid) { + final Entity entity = this.spawnEntity(par2World, i, j, k); + + if (entity != null) { + if ((entity instanceof EntityLivingBase) && par1ItemStack.hasDisplayName()) { + ((EntityLiving) entity).setCustomNameTag(par1ItemStack.getDisplayName()); + } + + if (!par3EntityPlayer.capabilities.isCreativeMode) { + --par1ItemStack.stackSize; + } + } + } + } + + return par1ItemStack; + } + + /** + * Spawns the creature specified by the egg's type in the location specified by + * + * the last three parameters. Parameters: world, entityID, x, y, z. + */ + public Entity spawnEntity(final World parWorld, final double parX, final double parY, final double parZ) { + + if (!parWorld.isRemote) // never spawn entity on client side + { + this.entityToSpawnNameFull = this.entityMODID + "." + this.entityToSpawnName; + if (EntityList.stringToClassMapping.containsKey(this.entityToSpawnNameFull)) { + this.entityToSpawn = (EntityLiving) EntityList.createEntityByName(this.entityToSpawnNameFull, parWorld); + + this.entityToSpawn.setLocationAndAngles( + parX, + parY, + parZ, + MathHelper.wrapAngleTo180_float(parWorld.rand.nextFloat() * 360.0F), + 0.0F); + + parWorld.spawnEntityInWorld(this.entityToSpawn); + this.entityToSpawn.onSpawnWithEgg((IEntityLivingData) null); + this.entityToSpawn.playLivingSound(); + } else { + // DEBUG + Logger.WARNING("Entity not found " + this.entityToSpawnName); + } + } + + return this.entityToSpawn; + } + + /** + * returns a list of items with the same ID, but different meta (eg: dye returns 16 items) + */ + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + @SideOnly(Side.CLIENT) + public void getSubItems(final Item parItem, final CreativeTabs parTab, final List parList) { + parList.add(new ItemStack(parItem, 1, 0)); + } + + @Override + @SideOnly(Side.CLIENT) + public int getColorFromItemStack(final ItemStack par1ItemStack, final int parColorType) { + return (parColorType == 0) ? this.colorBase : this.colorSpots; + } + + @Override + @SideOnly(Side.CLIENT) + public boolean requiresMultipleRenderPasses() { + return true; + } + + @Override + // Doing this override means that there is no localization for language + // unless you specifically check for localization here and convert + public String getItemStackDisplayName(final ItemStack par1ItemStack) { + return "Spawn " + this.entityToSpawnName; + } + + @Override + @SideOnly(Side.CLIENT) + public void registerIcons(final IIconRegister par1IconRegister) { + super.registerIcons(par1IconRegister); + this.theIcon = par1IconRegister.registerIcon(this.getIconString() + "_overlay"); + } + + /** + * Gets an icon index based on an item's damage value and the given render pass + */ + @Override + @SideOnly(Side.CLIENT) + public IIcon getIconFromDamageForRenderPass(final int parDamageVal, final int parRenderPass) { + return parRenderPass > 0 ? this.theIcon : super.getIconFromDamageForRenderPass(parDamageVal, parRenderPass); + } + + public void setColors(final int parColorBase, final int parColorSpots) { + this.colorBase = parColorBase; + this.colorSpots = parColorSpots; + } + + public int getColorBase() { + return this.colorBase; + } + + public int getColorSpots() { + return this.colorSpots; + } + + public final void setEntityToSpawnName(final String parEntityToSpawnName) { + this.entityToSpawnName = parEntityToSpawnName; + this.entityToSpawnNameFull = this.entityMODID + "." + this.entityToSpawnName; + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/CoreItem.java b/src/main/java/gtPlusPlus/core/item/base/CoreItem.java new file mode 100644 index 0000000000..4745fda281 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/CoreItem.java @@ -0,0 +1,286 @@ +package gtPlusPlus.core.item.base; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.List; + +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; + +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.util.GT_LanguageManager; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.util.minecraft.ItemUtils; + +public class CoreItem extends Item { + + private final EnumRarity rarity; + private final EnumChatFormatting descColour; + protected String itemName; + private final boolean hasEffect; + + // Replace Item - What does this item turn into when held. + private final ItemStack turnsInto; + + // 0 + /* + * Name, Tab - 64 Stack, 0 Dmg + */ + public CoreItem(final String unlocalizedName, final CreativeTabs creativeTab) { + this(unlocalizedName, creativeTab, 64, 0); // Calls 3 + } + + // 0 + /* + * Name, Tab - 64 Stack, 0 Dmg + */ + public CoreItem(final String unlocalizedName, final String displayName, final CreativeTabs creativeTab) { + this(unlocalizedName, creativeTab, 64, 0); // Calls 3 + this.itemName = displayName; + } + + // 0.1 + /* + * Name, Tab - 64 Stack, 0 Dmg + */ + public CoreItem(final String unlocalizedName, final CreativeTabs creativeTab, final ItemStack OverrideItem) { + this( + unlocalizedName, + creativeTab, + 64, + 0, + new String[] { + "This item will be replaced by another when held by a player, it is old and should not be used in recipes." }, + EnumRarity.uncommon, + EnumChatFormatting.UNDERLINE, + false, + OverrideItem); // Calls 5 + } + + // 0.1 + /* + * Name, Tab - 64 Stack, 0 Dmg + */ + public CoreItem(final String unlocalizedName, final String displayName, final CreativeTabs creativeTab, + final ItemStack OverrideItem) { + this( + unlocalizedName, + creativeTab, + 64, + 0, + new String[] { + "This item will be replaced by another when held by a player, it is old and should not be used in recipes." }, + EnumRarity.uncommon, + EnumChatFormatting.UNDERLINE, + false, + OverrideItem); // Calls 5 + this.itemName = displayName; + } + + // 1 + /* + * Name, Tab, Stack - 0 Dmg + */ + public CoreItem(final String unlocalizedName, final CreativeTabs creativeTab, final int stackSize) { + this(unlocalizedName, creativeTab, stackSize, 0); // Calls 3 + } + + // 2 + /* + * Name, Tab, Stack, Description - 0 Dmg + */ + public CoreItem(final String unlocalizedName, final CreativeTabs creativeTab, final int stackSize, + final String[] description) { + this(unlocalizedName, creativeTab, stackSize, 0, description); // Calls 4 + } + + // 3 + /* + * Name, Tab, Stack, Dmg - Description + */ + public CoreItem(String unlocalizedName, CreativeTabs creativeTab, int stackSize, String string) { + this(unlocalizedName, creativeTab, stackSize, new String[] { string }); + } + + public CoreItem(final String unlocalizedName, final CreativeTabs creativeTab, final int stackSize, + final int maxDmg) { + this(unlocalizedName, creativeTab, stackSize, maxDmg, new String[] {}); // Calls 4 + } + + // 4 //Not Rare + basic tooltip + /* + * Name, Tab, Stack, Dmg, Description + */ + public CoreItem(String unlocalizedName, CreativeTabs creativeTab, int stackSize, int maxDmg, String string) { + this(unlocalizedName, creativeTab, stackSize, maxDmg, new String[] { string }); + } + + public CoreItem(final String unlocalizedName, final CreativeTabs creativeTab, final int stackSize, final int maxDmg, + final String[] description) { + this( + unlocalizedName, + creativeTab, + stackSize, + maxDmg, + description, + EnumRarity.common, + EnumChatFormatting.GRAY, + false, + null); // Calls 4.5 + } + + // 4.5 + /* + * Name, Tab, Stack, Dmg, Description, Text Colour - Common + */ + public CoreItem(final String unlocalizedName, final CreativeTabs creativeTab, final int stackSize, final int maxDmg, + final String[] description, final EnumChatFormatting colour) { + this(unlocalizedName, creativeTab, stackSize, maxDmg, description, EnumRarity.common, colour, false, null); // Calls + // 5 + } + + // 4.75 + /* + * Name, Tab, Stack, Dmg, Description, Rarity - Gray text + */ + public CoreItem(String unlocalizedName, CreativeTabs creativeTab, int stackSize, int maxDmg, String string, + EnumRarity uncommon) { + this(unlocalizedName, creativeTab, stackSize, maxDmg, new String[] { string }, uncommon); + } + + public CoreItem(final String unlocalizedName, final CreativeTabs creativeTab, final int stackSize, final int maxDmg, + final String[] description, final EnumRarity rarity) { + this( + unlocalizedName, + creativeTab, + stackSize, + maxDmg, + description, + rarity, + EnumChatFormatting.GRAY, + false, + null); // Calls 5 + } + + // 5 + /* + * Name, Tab, Stack, Dmg, Description, Rarity, Text Colour, Effect + */ + public CoreItem(final String unlocalizedName, final CreativeTabs creativeTab, final int stackSize, final int maxDmg, + final String[] description, final EnumRarity regRarity, final EnumChatFormatting colour, final boolean Effect, + final ItemStack OverrideItem) { + this.setUnlocalizedName(unlocalizedName); + this.setTextureName(GTPlusPlus.ID + ":" + unlocalizedName); + this.setCreativeTab(creativeTab); + this.setMaxStackSize(stackSize); + this.setMaxDamage(maxDmg); + this.rarity = regRarity; + this.setItemDescription(description); + this.descColour = colour != null ? colour : EnumChatFormatting.RESET; + this.hasEffect = Effect; + this.turnsInto = OverrideItem; + GameRegistry.registerItem(this, unlocalizedName); + } + + // 6 + /* + * Name, Tab, Stack, Dmg, Description, Rarity, Text Colour, Effect + */ + public CoreItem(final String unlocalizedName, final String displayName, final CreativeTabs creativeTab, + final int stackSize, final int maxDmg, final String[] description, final EnumRarity regRarity, + final EnumChatFormatting colour, final boolean Effect, final ItemStack OverrideItem) { + this.setUnlocalizedName(unlocalizedName); + this.itemName = displayName; + this.setTextureName(GTPlusPlus.ID + ":" + unlocalizedName); + this.setCreativeTab(creativeTab); + this.setMaxStackSize(stackSize); + this.setMaxDamage(maxDmg); + this.rarity = regRarity; + this.setItemDescription(description); + this.descColour = colour != null ? colour : EnumChatFormatting.RESET; + this.hasEffect = Effect; + this.turnsInto = OverrideItem; + GameRegistry.registerItem(this, unlocalizedName); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public void addInformation(final ItemStack stack, final EntityPlayer aPlayer, final List list, final boolean bool) { + for (int i = 0;; i++) { + String tooltip = GT_LanguageManager + .getTranslation("gtplusplus." + this.getUnlocalizedName() + ".tooltip" + "." + i); + if (!("gtplusplus." + this.getUnlocalizedName() + ".tooltip" + "." + i).equals(tooltip)) { + list.add(tooltip); + } else break; + } + } + + @Override + @SideOnly(Side.CLIENT) + public EnumRarity getRarity(final ItemStack par1ItemStack) { + return this.rarity; + } + + @Override + public boolean hasEffect(final ItemStack par1ItemStack, final int pass) { + return this.hasEffect; + } + + @Override + public void onUpdate(final ItemStack iStack, final World world, final Entity entityHolding, final int p_77663_4_, + final boolean p_77663_5_) { + if (this.turnsInto != null) { + if (entityHolding instanceof EntityPlayer) { + + Logger.INFO("Replacing " + iStack.getDisplayName() + " with " + this.turnsInto.getDisplayName() + "."); + final ItemStack tempTransform = this.turnsInto; + if (iStack.stackSize == 64) { + tempTransform.stackSize = 64; + ((EntityPlayer) entityHolding).inventory.addItemStackToInventory((tempTransform)); + for (int l = 0; l < 64; l++) { + ((EntityPlayer) entityHolding).inventory.consumeInventoryItem(this); + } + + } else { + tempTransform.stackSize = 1; + ((EntityPlayer) entityHolding).inventory.addItemStackToInventory((tempTransform)); + ((EntityPlayer) entityHolding).inventory.consumeInventoryItem(this); + } + } + } + } + + @Override + public boolean isDamageable() { + return false; + } + + @Override + public boolean isRepairable() { + return false; + } + + public ItemStack getStack() { + return ItemUtils.getSimpleStack(this); + } + + public void setItemDescription(String[] description) { + for (int i = 0; i < description.length; i++) { + GT_LanguageManager.addStringLocalization( + "gtplusplus." + this.getUnlocalizedName() + ".tooltip" + "." + i, + description[i]); + } + } + /* + * @Override public String getItemStackDisplayName(final ItemStack tItem) { if ((this.itemName == null) || + * this.itemName.equals("")) { return super.getItemStackDisplayName(tItem); } return this.itemName; } + */ +} diff --git a/src/main/java/gtPlusPlus/core/item/base/bolts/BaseItemBolt.java b/src/main/java/gtPlusPlus/core/item/base/bolts/BaseItemBolt.java new file mode 100644 index 0000000000..74ff99a7fe --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/bolts/BaseItemBolt.java @@ -0,0 +1,11 @@ +package gtPlusPlus.core.item.base.bolts; + +import gtPlusPlus.core.item.base.BaseItemComponent; +import gtPlusPlus.core.material.Material; + +public class BaseItemBolt extends BaseItemComponent { + + public BaseItemBolt(final Material material) { + super(material, BaseItemComponent.ComponentTypes.BOLT); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/cell/BaseItemCell.java b/src/main/java/gtPlusPlus/core/item/base/cell/BaseItemCell.java new file mode 100644 index 0000000000..1140390375 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/cell/BaseItemCell.java @@ -0,0 +1,73 @@ +package gtPlusPlus.core.item.base.cell; + +import static gregtech.api.enums.Mods.GTPlusPlus; +import static gregtech.api.enums.Mods.GregTech; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidContainerRegistry; +import net.minecraftforge.fluids.FluidStack; + +import gtPlusPlus.core.item.base.BaseItemComponent; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.material.Material; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import ic2.core.Ic2Items; + +public class BaseItemCell extends BaseItemComponent { + + ComponentTypes Cell = ComponentTypes.CELL; + + public BaseItemCell(final Material material) { + super(material, BaseItemComponent.ComponentTypes.CELL); + this.fluidColour = (short[]) material.getRGBA(); + } + + public BaseItemCell(final String unlocalName, final String localName, final short[] RGBa) { + super(unlocalName, localName, RGBa); + this.fluidColour = RGBa; + FluidStack aFluid = FluidUtils.getFluidStack(unlocalName.toLowerCase(), 1000); + if (aFluid != null) { + FluidContainerRegistry.registerFluidContainer(aFluid, ItemUtils.getSimpleStack(this), Ic2Items.cell.copy()); + } + } + + public BaseItemCell(final String unlocalName, final String localName, final short[] RGBa, final Fluid cellFluid) { + super(unlocalName, localName, RGBa); + this.fluidColour = RGBa; + FluidContainerRegistry.registerFluidContainer( + FluidUtils.getFluidStack(cellFluid, 1000), + ItemUtils.getSimpleStack(this), + Ic2Items.cell.copy()); + } + + @Override + public void registerIcons(final IIconRegister i) { + + if (CORE.ConfigSwitches.useGregtechTextures) { + this.base = i.registerIcon(GregTech.ID + ":" + "materialicons/METALLIC/" + "cell"); + this.overlay = i.registerIcon(GregTech.ID + ":" + "materialicons/METALLIC/" + "cell_OVERLAY"); + } else { + this.base = i.registerIcon(GTPlusPlus.ID + ":" + "item" + this.Cell.getComponent()); + this.overlay = i.registerIcon(GTPlusPlus.ID + ":" + "item" + this.Cell.getComponent() + "_Overlay"); + } + // this.overlay = cellMaterial.getFluid(1000).getFluid().get + } + + private final short[] fluidColour; + boolean upwards = true; + + @Override + public int getColorFromItemStack(final ItemStack stack, final int renderPass) { + if (renderPass == 0 && !CORE.ConfigSwitches.useGregtechTextures) { + return Utils.rgbtoHexValue(230, 230, 230); + } + if (renderPass == 1 && CORE.ConfigSwitches.useGregtechTextures) { + return Utils.rgbtoHexValue(230, 230, 230); + } + return this.componentColour; + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/cell/BaseItemPlasmaCell.java b/src/main/java/gtPlusPlus/core/item/base/cell/BaseItemPlasmaCell.java new file mode 100644 index 0000000000..151f3f3860 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/cell/BaseItemPlasmaCell.java @@ -0,0 +1,76 @@ +package gtPlusPlus.core.item.base.cell; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.Entity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.DamageSource; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.core.item.base.BaseItemComponent; +import gtPlusPlus.core.material.Material; +import gtPlusPlus.core.util.Utils; + +public class BaseItemPlasmaCell extends BaseItemComponent { + + private IIcon base; + private IIcon overlay; + ComponentTypes PlasmaCell = ComponentTypes.PLASMACELL; + private int tickCounter = 0; + private final int tickCounterMax = 200; + private final short[] fluidColour; + + public BaseItemPlasmaCell(final Material material) { + super(material, ComponentTypes.PLASMACELL); + this.fluidColour = (short[]) material.getRGBA(); + } + + @Override + @SideOnly(Side.CLIENT) + public boolean requiresMultipleRenderPasses() { + return true; + } + + @Override + public void registerIcons(final IIconRegister i) { + this.base = i.registerIcon(GTPlusPlus.ID + ":" + "item" + this.PlasmaCell.getComponent()); + this.overlay = i.registerIcon(GTPlusPlus.ID + ":" + "item" + this.PlasmaCell.getComponent() + "_Overlay"); + // this.overlay = cellMaterial.getFluid(1000).getFluid().get + } + + @Override + public int getColorFromItemStack(final ItemStack stack, final int renderPass) { + if (renderPass == 0) { + return Utils.rgbtoHexValue(230, 230, 230); + } + return this.componentColour; + } + + @Override + public IIcon getIconFromDamageForRenderPass(final int damage, final int pass) { + if (pass == 0) { + return this.base; + } + return this.overlay; + } + + @Override + public void onUpdate(final ItemStack iStack, final World world, final Entity entityHolding, final int p_77663_4_, + final boolean p_77663_5_) { + if (this.componentMaterial != null) { + if (!world.isRemote) { + if (this.tickCounter < this.tickCounterMax) { + this.tickCounter++; + } else if (this.tickCounter >= this.tickCounterMax) { + entityHolding.attackEntityFrom(DamageSource.onFire, 2); + this.tickCounter = 0; + } + } + } + super.onUpdate(iStack, world, entityHolding, p_77663_4_, p_77663_5_); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/dusts/BaseItemDust.java b/src/main/java/gtPlusPlus/core/item/base/dusts/BaseItemDust.java new file mode 100644 index 0000000000..fd52fe78c4 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/dusts/BaseItemDust.java @@ -0,0 +1,135 @@ +package gtPlusPlus.core.item.base.dusts; + +import gtPlusPlus.core.item.base.BaseItemComponent; +import gtPlusPlus.core.material.Material; + +public class BaseItemDust extends BaseItemComponent { + + private BaseItemComponent[] mSizedDusts = new BaseItemComponent[2]; + + public BaseItemDust(Material aMat) { + this(aMat, true); + } + + public BaseItemDust(Material aMat, boolean generateSmallDusts) { + super(aMat, ComponentTypes.DUST); + if (generateSmallDusts) { + mSizedDusts[0] = new BaseItemComponent(aMat, ComponentTypes.DUSTSMALL); + mSizedDusts[1] = new BaseItemComponent(aMat, ComponentTypes.DUSTTINY); + } + } + + public BaseItemDust(DustState aState, Material aMat) { + super(aMat, ComponentTypes.DUST); + if (aState.generatesSmallDust()) { + mSizedDusts[0] = new BaseItemComponent(aMat, ComponentTypes.DUSTSMALL); + } + if (aState.generatesTinyDust()) { + mSizedDusts[1] = new BaseItemComponent(aMat, ComponentTypes.DUSTTINY); + } + } + + private BaseItemDust(String unlocalizedName, String materialName, Material matInfo, int colour, String pileSize, + int tier, boolean addRecipes) { + super(matInfo, ComponentTypes.DUST); + } + + public static class DustState { + + static final int NORMAL = (1); + static final int SMALL = (10); + static final int TINY = (100); + final int MIXTURE; + final boolean[] doesThings = new boolean[3]; + + public DustState(boolean genDust, boolean genSmallDust, boolean genDustTiny) { + int aTotal = 0; + if (genDust) { + aTotal += NORMAL; + doesThings[0] = true; + } else { + doesThings[0] = false; + } + if (genSmallDust) { + aTotal += SMALL; + doesThings[1] = true; + } else { + doesThings[1] = false; + } + if (genDustTiny) { + aTotal += TINY; + doesThings[2] = true; + } else { + doesThings[2] = false; + } + MIXTURE = aTotal; + } + + public boolean generatesDust() { + return doesThings[0]; + } + + public boolean generatesSmallDust() { + return doesThings[1]; + } + + public boolean generatesTinyDust() { + return doesThings[2]; + } + + private DustState(int amount) { + + if (amount == 1) { + doesThings[0] = true; + doesThings[1] = false; + doesThings[2] = false; + + } else if (amount == 10) { + doesThings[0] = false; + doesThings[1] = true; + doesThings[2] = false; + } else if (amount == 100) { + doesThings[0] = false; + doesThings[1] = false; + doesThings[2] = true; + + } else if (amount == 11) { + doesThings[0] = true; + doesThings[1] = true; + doesThings[2] = false; + + } else if (amount == 101) { + doesThings[0] = true; + doesThings[1] = false; + doesThings[2] = true; + + } else if (amount == 110) { + doesThings[0] = false; + doesThings[1] = true; + doesThings[2] = true; + + } else if (amount == 111) { + doesThings[0] = true; + doesThings[1] = true; + doesThings[2] = true; + } else { + doesThings[0] = false; + doesThings[1] = false; + doesThings[2] = false; + } + MIXTURE = amount; + } + + public DustState get(int a) { + if (a == 1) { + return new DustState(NORMAL); + } else if (a == 10) { + return new DustState(SMALL); + } else if (a == 100) { + return new DustState(TINY); + } else { + return new DustState(MIXTURE); + } + } + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/dusts/BaseItemDustUnique.java b/src/main/java/gtPlusPlus/core/item/base/dusts/BaseItemDustUnique.java new file mode 100644 index 0000000000..2592fe3cf7 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/dusts/BaseItemDustUnique.java @@ -0,0 +1,164 @@ +package gtPlusPlus.core.item.base.dusts; + +import static gregtech.api.enums.Mods.GTPlusPlus; +import static gregtech.api.enums.Mods.GregTech; +import static gtPlusPlus.core.creative.AddToCreativeTab.tabMisc; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +import cpw.mods.fml.common.registry.GameRegistry; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.util.GT_LanguageManager; +import gregtech.api.util.GT_OreDictUnificator; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.material.Material; +import gtPlusPlus.core.util.data.StringUtils; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; + +public class BaseItemDustUnique extends Item { + + protected final int colour; + protected final int sRadiation; + protected final String materialName; + protected final String chemicalNotation; + + public BaseItemDustUnique(final String unlocalizedName, final String materialName, final int colour, + final String pileSize) { + this(unlocalizedName, materialName, "NullFormula", colour, pileSize); + } + + public BaseItemDustUnique(final String unlocalizedName, final String materialName, final String mChemicalFormula, + final int colour, final String pileSize) { + this.setUnlocalizedName(unlocalizedName); + this.setMaxStackSize(64); + this.setTextureName(this.getCorrectTexture(pileSize)); + this.setCreativeTab(tabMisc); + this.colour = colour; + this.materialName = materialName; + if (mChemicalFormula == null || mChemicalFormula.equals("") || mChemicalFormula.equals("NullFormula")) { + this.chemicalNotation = StringUtils.subscript(materialName); + } else { + this.chemicalNotation = StringUtils.subscript(mChemicalFormula); + } + this.sRadiation = ItemUtils.getRadioactivityLevel(materialName); + GameRegistry.registerItem(this, unlocalizedName); + + String type; + if (this.getUnlocalizedName() + .contains("DustTiny")) { + type = "Tiny Pile of %material Dust"; + } else if (this.getUnlocalizedName() + .contains("DustSmall")) { + type = "Small Pile of %material Dust"; + } else { + type = "%material Dust"; + } + GT_LanguageManager.addStringLocalization("gtplusplus." + this.getUnlocalizedName() + ".name", type); + + String temp = ""; + Logger.WARNING("Unlocalized name for OreDict nameGen: " + this.getUnlocalizedName()); + if (this.getUnlocalizedName() + .contains("item.")) { + temp = this.getUnlocalizedName() + .replace("item.", ""); + Logger.WARNING("Generating OreDict Name: " + temp); + } else { + temp = this.getUnlocalizedName(); + } + if (temp.contains("DustTiny")) { + temp = temp.replace("itemD", "d"); + Logger.WARNING("Generating OreDict Name: " + temp); + } else if (temp.contains("DustSmall")) { + temp = temp.replace("itemD", "d"); + Logger.WARNING("Generating OreDict Name: " + temp); + } else { + temp = temp.replace("itemD", "d"); + Logger.WARNING("Generating OreDict Name: " + temp); + } + if ((temp != null) && !temp.equals("")) { + GT_OreDictUnificator.registerOre(temp, ItemUtils.getSimpleStack(this)); + } + registerComponent(); + } + + public boolean registerComponent() { + if (this.materialName == null) { + return false; + } + String aName = materialName; + // Register Component + Map<String, ItemStack> aMap = Material.mComponentMap.get(aName); + if (aMap == null) { + aMap = new HashMap<>(); + } + String aKey = OrePrefixes.dust.name(); + ItemStack x = aMap.get(aKey); + if (x == null) { + aMap.put(aKey, ItemUtils.getSimpleStack(this)); + Logger.MATERIALS("Registering a material component. Item: [" + aName + "] Map: [" + aKey + "]"); + Material.mComponentMap.put(aName, aMap); + return true; + } else { + // Bad + Logger.MATERIALS("Tried to double register a material component. "); + return false; + } + } + + @Override + public String getItemStackDisplayName(final ItemStack iStack) { + return GT_LanguageManager.getTranslation("gtplusplus." + getUnlocalizedName() + ".name") + .replace("%material", GT_LanguageManager.getTranslation("gtplusplus.material." + materialName)); + } + + private String getCorrectTexture(final String pileSize) { + if (!CORE.ConfigSwitches.useGregtechTextures) { + if ((pileSize.equals("dust")) || (pileSize.equals("Dust"))) { + this.setTextureName(GTPlusPlus.ID + ":" + "dust"); + } else { + this.setTextureName(GTPlusPlus.ID + ":" + "dust" + pileSize); + } + } + if (pileSize.toLowerCase() + .contains("small")) { + return GregTech.ID + ":" + "materialicons/SHINY/dustSmall"; + } else if (pileSize.toLowerCase() + .contains("tiny")) { + return GregTech.ID + ":" + "materialicons/SHINY/dustTiny"; + } + return GregTech.ID + ":" + "materialicons/SHINY/dust"; + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public void addInformation(final ItemStack stack, final EntityPlayer aPlayer, final List list, final boolean bool) { + if (this.sRadiation > 0) { + list.add(CORE.GT_Tooltip_Radioactive.get()); + } + if (this.chemicalNotation.length() > 0 && !chemicalNotation.equals("") + && !chemicalNotation.equals("NullFormula")) { + list.add(this.chemicalNotation); + } + super.addInformation(stack, aPlayer, list, bool); + } + + public final String getMaterialName() { + return StringUtils.subscript(this.materialName); + } + + @Override + public int getColorFromItemStack(final ItemStack stack, final int HEX_OxFFFFFF) { + if (this.colour == 0) { + return MathUtils.generateSingularRandomHexValue(); + } + return this.colour; + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/foil/BaseItemFoil.java b/src/main/java/gtPlusPlus/core/item/base/foil/BaseItemFoil.java new file mode 100644 index 0000000000..9b55461cfd --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/foil/BaseItemFoil.java @@ -0,0 +1,11 @@ +package gtPlusPlus.core.item.base.foil; + +import gtPlusPlus.core.item.base.BaseItemComponent; +import gtPlusPlus.core.material.Material; + +public class BaseItemFoil extends BaseItemComponent { + + public BaseItemFoil(final Material material) { + super(material, BaseItemComponent.ComponentTypes.FOIL); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/gears/BaseItemGear.java b/src/main/java/gtPlusPlus/core/item/base/gears/BaseItemGear.java new file mode 100644 index 0000000000..d759c7f116 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/gears/BaseItemGear.java @@ -0,0 +1,11 @@ +package gtPlusPlus.core.item.base.gears; + +import gtPlusPlus.core.item.base.BaseItemComponent; +import gtPlusPlus.core.material.Material; + +public class BaseItemGear extends BaseItemComponent { + + public BaseItemGear(final Material material) { + super(material, BaseItemComponent.ComponentTypes.GEAR); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/gears/BaseItemSmallGear.java b/src/main/java/gtPlusPlus/core/item/base/gears/BaseItemSmallGear.java new file mode 100644 index 0000000000..ddfdbd7534 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/gears/BaseItemSmallGear.java @@ -0,0 +1,11 @@ +package gtPlusPlus.core.item.base.gears; + +import gtPlusPlus.core.item.base.BaseItemComponent; +import gtPlusPlus.core.material.Material; + +public class BaseItemSmallGear extends BaseItemComponent { + + public BaseItemSmallGear(final Material material) { + super(material, BaseItemComponent.ComponentTypes.SMALLGEAR); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/ingots/BaseItemIngot.java b/src/main/java/gtPlusPlus/core/item/base/ingots/BaseItemIngot.java new file mode 100644 index 0000000000..fc2748ec23 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/ingots/BaseItemIngot.java @@ -0,0 +1,20 @@ +package gtPlusPlus.core.item.base.ingots; + +import gtPlusPlus.core.item.base.BaseItemComponent; +import gtPlusPlus.core.material.Material; + +public class BaseItemIngot extends BaseItemComponent { + + protected final String materialName; + protected final String unlocalName; + + public BaseItemIngot(final Material material) { + this(material, ComponentTypes.INGOT); + } + + public BaseItemIngot(final Material material, final ComponentTypes type) { + super(material, type); + this.materialName = material.getLocalizedName(); + this.unlocalName = material.getUnlocalizedName(); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/ingots/BaseItemIngotHot.java b/src/main/java/gtPlusPlus/core/item/base/ingots/BaseItemIngotHot.java new file mode 100644 index 0000000000..9d22c0faf8 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/ingots/BaseItemIngotHot.java @@ -0,0 +1,111 @@ +package gtPlusPlus.core.item.base.ingots; + +import static gregtech.api.enums.Mods.GTPlusPlus; +import static gregtech.api.enums.Mods.GregTech; +import static gregtech.api.recipe.RecipeMaps.vacuumFreezerRecipes; +import static gregtech.api.util.GT_RecipeBuilder.TICKS; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.enums.GT_Values; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.item.base.BaseItemComponent; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.material.Material; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.EntityUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; + +public class BaseItemIngotHot extends BaseItemIngot { + + private final ItemStack outputIngot; + private int tickCounter = 0; + private final int tickCounterMax = 200; + private final int mTier; + + private IIcon base; + private IIcon overlay; + + public BaseItemIngotHot(final Material material) { + super(material, ComponentTypes.HOTINGOT); + this.setTextureName(GTPlusPlus.ID + ":" + "itemIngotHot"); + this.outputIngot = material.getIngot(1); + this.mTier = material.vTier; + this.generateRecipe(); + } + + @Override + public String getItemStackDisplayName(final ItemStack p_77653_1_) { + return super.getItemStackDisplayName(p_77653_1_); + // return ("Hot "+this.materialName+ " Ingot"); + } + + @Override + public int getColorFromItemStack(final ItemStack stack, final int HEX_OxFFFFFF) { + return Utils.rgbtoHexValue(225, 225, 225); + } + + private void generateRecipe() { + Logger.WARNING("Adding Vacuum Freezer recipe for a Hot Ingot of " + this.materialName + "."); + GT_Values.RA.stdBuilder() + .itemInputs(ItemUtils.getSimpleStack(this)) + .itemOutputs(this.outputIngot.copy()) + .duration(Math.max(this.componentMaterial.getMass() * 3L, 1L) * TICKS) + .eut(this.componentMaterial.vVoltageMultiplier) + .addTo(vacuumFreezerRecipes); + } + + @Override + public void onUpdate(final ItemStack iStack, final World world, final Entity entityHolding, final int p_77663_4_, + final boolean p_77663_5_) { + if (this.componentMaterial != null) { + if (entityHolding != null && entityHolding instanceof EntityPlayer) { + if (!((EntityPlayer) entityHolding).capabilities.isCreativeMode) { + EntityUtils.applyHeatDamageToEntity(1, world, entityHolding); + } + } + } + super.onUpdate(iStack, world, entityHolding, p_77663_4_, p_77663_5_); + } + + @Override + @SideOnly(Side.CLIENT) + public boolean requiresMultipleRenderPasses() { + if (CORE.ConfigSwitches.useGregtechTextures) { + return true; + } else { + return false; + } + } + + @Override + public void registerIcons(final IIconRegister i) { + + if (CORE.ConfigSwitches.useGregtechTextures) { + this.base = i.registerIcon(GregTech.ID + ":" + "materialicons/METALLIC/" + "ingotHot"); + this.overlay = i.registerIcon(GregTech.ID + ":" + "materialicons/METALLIC/" + "ingotHot_OVERLAY"); + } else { + this.base = i + .registerIcon(GTPlusPlus.ID + ":" + "item" + BaseItemComponent.ComponentTypes.HOTINGOT.getComponent()); + } + // this.overlay = cellMaterial.getFluid(1000).getFluid().get + } + + @Override + public IIcon getIconFromDamageForRenderPass(final int damage, final int pass) { + if (pass == 0 && CORE.ConfigSwitches.useGregtechTextures) { + return this.base; + } else if (pass == 1 && CORE.ConfigSwitches.useGregtechTextures) { + return this.overlay; + } else { + return this.overlay; + } + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/ingots/BaseItemIngot_OLD.java b/src/main/java/gtPlusPlus/core/item/base/ingots/BaseItemIngot_OLD.java new file mode 100644 index 0000000000..6335820c9a --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/ingots/BaseItemIngot_OLD.java @@ -0,0 +1,106 @@ +package gtPlusPlus.core.item.base.ingots; + +import static gregtech.api.enums.Mods.GTPlusPlus; +import static gregtech.api.recipe.RecipeMaps.compressorRecipes; +import static gregtech.api.util.GT_RecipeBuilder.SECONDS; + +import net.minecraft.entity.Entity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +import cpw.mods.fml.common.registry.GameRegistry; +import gregtech.api.enums.GT_Values; +import gregtech.api.util.GT_OreDictUnificator; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.EntityUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; + +public class BaseItemIngot_OLD extends Item { + + protected int colour; + protected String materialName; + protected String unlocalName; + + public BaseItemIngot_OLD(final String unlocalizedName, final String materialName, final int colour, + final int sRadioactivity) { + this.setUnlocalizedName(unlocalizedName); + this.setCreativeTab(AddToCreativeTab.tabMisc); + this.unlocalName = unlocalizedName; + this.setMaxStackSize(64); + this.setTextureName(GTPlusPlus.ID + ":" + "itemIngot"); + this.colour = colour; + this.materialName = materialName; + this.sRadiation = sRadioactivity; + GameRegistry.registerItem(this, unlocalizedName); + String temp = ""; + if (this.unlocalName.contains("itemIngot")) { + temp = this.unlocalName.replace("itemI", "i"); + } else if (this.unlocalName.contains("itemHotIngot")) { + temp = this.unlocalName.replace("itemHotIngot", "ingotHot"); + } + if ((temp != null) && !temp.equals("")) { + GT_OreDictUnificator.registerOre(temp, ItemUtils.getSimpleStack(this)); + } + // this.generateCompressorRecipe(); + } + + @Override + public String getItemStackDisplayName(final ItemStack p_77653_1_) { + + return (this.materialName + " Ingot"); + } + + public final String getMaterialName() { + return this.materialName; + } + + @Override + public int getColorFromItemStack(final ItemStack stack, final int HEX_OxFFFFFF) { + if (this.colour == 0) { + return MathUtils.generateSingularRandomHexValue(); + } + return this.colour; + } + + private void generateCompressorRecipe() { + if (this.unlocalName.contains("itemIngot")) { + final ItemStack tempStack = ItemUtils.getSimpleStack(this, 9); + ItemStack tempOutput = null; + String temp = this.getUnlocalizedName() + .replace("item.itemIngot", "block"); + Logger.WARNING("Unlocalized name for OreDict nameGen: " + this.getUnlocalizedName()); + if (this.getUnlocalizedName() + .contains("item.")) { + temp = this.getUnlocalizedName() + .replace("item.", ""); + Logger.WARNING("Generating OreDict Name: " + temp); + } + temp = temp.replace("itemIngot", "block"); + Logger.WARNING("Generating OreDict Name: " + temp); + if ((temp != null) && !temp.equals("")) { + tempOutput = ItemUtils.getItemStackOfAmountFromOreDict(temp, 1); + if (tempOutput != null) { + GT_Values.RA.stdBuilder() + .itemInputs(tempStack) + .itemOutputs(tempOutput) + .duration(15 * SECONDS) + .eut(2) + .addTo(compressorRecipes); + } + } + } else if (this.unlocalName.contains("itemHotIngot")) { + return; + } + } + + protected final int sRadiation; + + @Override + public void onUpdate(final ItemStack iStack, final World world, final Entity entityHolding, final int p_77663_4_, + final boolean p_77663_5_) { + EntityUtils.applyRadiationDamageToEntity(iStack.stackSize, this.sRadiation, world, entityHolding); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/itemblock/ItemBlockBasicTile.java b/src/main/java/gtPlusPlus/core/item/base/itemblock/ItemBlockBasicTile.java new file mode 100644 index 0000000000..cf50da52a3 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/itemblock/ItemBlockBasicTile.java @@ -0,0 +1,51 @@ +package gtPlusPlus.core.item.base.itemblock; + +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; + +import gtPlusPlus.api.interfaces.ITileTooltip; + +public class ItemBlockBasicTile extends ItemBlock { + + private final int mID; + + public ItemBlockBasicTile(final Block block) { + super(block); + this.mID = ((ITileTooltip) block).getTooltipID(); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public void addInformation(final ItemStack stack, final EntityPlayer aPlayer, final List list, final boolean bool) { + if (this.mID == 0) { // Fish trap + list.add("This trap catches fish faster if surrounded by more water blocks"); + list.add("Can also be placed beside upto 4 other fish traps"); + list.add("Requires at least two faces touching water"); + list.add("1/1000 chance to produce triple loot."); + } else if (this.mID == 4) { // Circuit Table + list.add("Easy Circuit Configuration"); + list.add("Change default setting with a Screwdriver"); + list.add("Default is used to select slot for auto-insertion"); + } else if (this.mID == 5) { // Decayables Chest + list.add("Chest which holds radioactive materials"); + list.add("Items which decay will tick while inside"); + list.add("Place with right click"); + } else if (this.mID == 6) { // Butterfly Killer + list.add("Kills Forestry Butterflies, Bats and other pests"); + list.add("Use either Formaldehyde or Hydrogen cyanide"); + list.add("Be weary of your neighbours"); + } else if (this.mID == 8) { // Volumetric Flask Setter + list.add("Easy Flask Configuration"); + list.add("Configure default input slot with a screwdriver"); + } else if (this.mID == 9) { + + } else { + list.add("Bad Tooltip ID - " + mID); + } + super.addInformation(stack, aPlayer, list, bool); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/itemblock/ItemBlockGtBlock.java b/src/main/java/gtPlusPlus/core/item/base/itemblock/ItemBlockGtBlock.java new file mode 100644 index 0000000000..98c652a1ba --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/itemblock/ItemBlockGtBlock.java @@ -0,0 +1,184 @@ +package gtPlusPlus.core.item.base.itemblock; + +import java.util.HashMap; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; + +import gtPlusPlus.core.block.base.BasicBlock.BlockTypes; +import gtPlusPlus.core.block.base.BlockBaseModular; +import gtPlusPlus.core.block.base.BlockBaseOre; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.material.Material; +import gtPlusPlus.core.material.MaterialStack; +import gtPlusPlus.core.util.minecraft.EntityUtils; +import gtPlusPlus.core.util.sys.KeyboardUtils; + +public class ItemBlockGtBlock extends ItemBlock { + + public static HashMap<String, String> sNameCache = new HashMap<>(); + + protected final int blockColour; + private int sRadiation; + + private Material mMaterial; + protected BlockTypes thisBlockType; + + private final Block thisBlock; + private boolean isOre = false; + private boolean isModular = false; + + public ItemBlockGtBlock(final Block block) { + super(block); + this.thisBlock = block; + if (block instanceof BlockBaseOre) { + this.isOre = true; + } else if (block instanceof BlockBaseModular) { + this.isModular = true; + } + final BlockBaseModular baseBlock = (BlockBaseModular) block; + if (isModular) { + this.blockColour = baseBlock.getRenderColor(0); + } else if (isOre) { + this.blockColour = block.getBlockColor(); + } else { + this.blockColour = block.getBlockColor(); + } + + if (block instanceof BlockBaseModular g) { + this.mMaterial = g.getMaterialEx(); + this.thisBlockType = g.thisBlock; + } else { + this.mMaterial = null; + this.thisBlockType = BlockTypes.STANDARD; + } + } + + public int getBlockTypeMeta() { + if (this.thisBlockType.equals(BlockTypes.STANDARD)) { + return 0; + } else if (this.thisBlockType.equals(BlockTypes.FRAME)) { + return 1; + } else if (this.thisBlockType.equals(BlockTypes.ORE)) { + return 2; + } + return 0; + } + + public String getUnlocalizedBlockName() { + return "block." + mMaterial.getUnlocalizedName() + + "." + + this.thisBlockType.name() + .toLowerCase(); + } + + public String GetProperName() { + String tempIngot = sNameCache.get(getUnlocalizedBlockName()); + if (tempIngot == null) { + tempIngot = "BAD.UNLOCAL.NAME"; + } + return tempIngot; + } + + @Override + public String getItemStackDisplayName(ItemStack stack) { + return this.thisBlock.getLocalizedName(); + } + + public int getRenderColor(final int aMeta) { + return this.blockColour; + } + + @Override + public void addInformation(final ItemStack stack, final EntityPlayer aPlayer, final List list, final boolean bool) { + + if (this.mMaterial != null) { + list.add(this.mMaterial.vChemicalFormula); + } else { + + try { + BlockBaseModular g = (BlockBaseModular) thisBlock; + this.mMaterial = g.getMaterialEx(); + } catch (Throwable t) { + + } + + // list.add("Material is Null."); + } + + if (this.isOre) { + if (KeyboardUtils.isCtrlKeyDown()) { + Block b = Block.getBlockFromItem(stack.getItem()); + if (b != null) { + + String aTool = b.getHarvestTool(stack.getItemDamage()); + int aMiningLevel1 = b.getHarvestLevel(stack.getItemDamage()); + + if (this.mMaterial != null) { + list.add("Mining Level: " + Math.min(Math.max(aMiningLevel1, 0), 5)); + list.add("Contains: "); + if (mMaterial.getComposites() + .isEmpty()) { + list.add("- " + mMaterial.getLocalizedName()); + } else { + for (MaterialStack m : mMaterial.getComposites()) { + list.add( + "- " + m.getStackMaterial() + .getLocalizedName() + " x" + m.getPartsPerOneHundred()); + } + } + } + } + } else { + list.add(EnumChatFormatting.DARK_GRAY + "Hold Ctrl to show additional info."); + } + } else { + Block b = Block.getBlockFromItem(stack.getItem()); + if (b != null) { + String aTool = b.getHarvestTool(stack.getItemDamage()); + int aMiningLevel1 = b.getHarvestLevel(stack.getItemDamage()); + list.add("Mining Level: " + Math.min(Math.max(aMiningLevel1, 0), 5)); + } + } + + if (this.mMaterial != null) { + if (this.mMaterial.vRadiationLevel > 0) { + list.add(CORE.GT_Tooltip_Radioactive.get()); + } + } + + super.addInformation(stack, aPlayer, list, bool); + } + + @Override + public void onUpdate(final ItemStack iStack, final World world, final Entity entityHolding, final int p_77663_4_, + final boolean p_77663_5_) { + + if (!isModular && !isOre) { + mMaterial = null; + } else { + if (this.mMaterial == null) { + Block b = Block.getBlockFromItem(iStack.getItem()); + if (isOre) { + mMaterial = ((BlockBaseOre) b).getMaterialEx(); + } else { + mMaterial = ((BlockBaseModular) b).getMaterialEx(); + } + if (mMaterial != null) { + this.sRadiation = mMaterial.vRadiationLevel; + } else { + this.sRadiation = 0; + } + } + if (this.sRadiation > 0) { + EntityUtils.applyRadiationDamageToEntity(iStack.stackSize, this.sRadiation, world, entityHolding); + } + } + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/itemblock/ItemBlockMeta.java b/src/main/java/gtPlusPlus/core/item/base/itemblock/ItemBlockMeta.java new file mode 100644 index 0000000000..54cfefbac2 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/itemblock/ItemBlockMeta.java @@ -0,0 +1,106 @@ +package gtPlusPlus.core.item.base.itemblock; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemBlockWithMetadata; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.api.interfaces.ITileTooltip; +import gtPlusPlus.api.objects.data.AutoMap; + +public class ItemBlockMeta extends ItemBlockWithMetadata { + + private final Block mBlock; + private HashMap<Integer, AutoMap<String>> aTooltips = new LinkedHashMap<>(); + + public ItemBlockMeta(final Block aBlock) { + super(aBlock, aBlock); + this.mBlock = aBlock; + this.setMaxDamage(0); + this.setHasSubtypes(true); + if (aBlock instanceof ITileTooltip aTooltip) { + // aTooltips.put(aTooltip.getTooltipID(), aTooltip.getTooltipMap()); + } + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public void addInformation(final ItemStack stack, final EntityPlayer aPlayer, final List list, final boolean bool) { + Block aThis = Block.getBlockFromItem(stack.getItem()); + if (aThis != null) { + if (!aTooltips.isEmpty()) { + AutoMap<String> h = aTooltips.get(stack.getItemDamage()); + if (h != null && !h.isEmpty()) { + for (String s : h) { + list.add(s); + } + } + } + } + super.addInformation(stack, aPlayer, list, bool); + } + + /** + * Gets an icon index based on an item's damage value + */ + @Override + @SideOnly(Side.CLIENT) + public IIcon getIconFromDamage(final int p_77617_1_) { + return this.mBlock.getIcon(2, p_77617_1_); + } + + /** + * Returns the metadata of the block which this Item (ItemBlock) can place + */ + @Override + public int getMetadata(final int p_77647_1_) { + return p_77647_1_; + } + + @Override + public String getUnlocalizedName(final ItemStack stack) { + return this.getUnlocalizedName() + "." + stack.getItemDamage(); + } + + @Override + public boolean isDamageable() { + return false; + } + + @Override + public int getItemEnchantability() { + return 0; + } + + @Override + public boolean getIsRepairable(ItemStack p_82789_1_, ItemStack p_82789_2_) { + return false; + } + + @Override + public boolean isBookEnchantable(ItemStack stack, ItemStack book) { + return false; + } + + @Override + public boolean showDurabilityBar(ItemStack stack) { + return false; + } + + @Override + public double getDurabilityForDisplay(ItemStack stack) { + return 0; + } + + @Override + public int getItemEnchantability(ItemStack stack) { + return 0; + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/itemblock/ItemBlockOre.java b/src/main/java/gtPlusPlus/core/item/base/itemblock/ItemBlockOre.java new file mode 100644 index 0000000000..0cee16b3f6 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/itemblock/ItemBlockOre.java @@ -0,0 +1,148 @@ +package gtPlusPlus.core.item.base.itemblock; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; + +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.core.block.base.BlockBaseOre; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.material.Material; +import gtPlusPlus.core.material.MaterialStack; +import gtPlusPlus.core.util.minecraft.EntityUtils; +import gtPlusPlus.core.util.sys.KeyboardUtils; +import gtPlusPlus.everglades.gen.gt.WorldGen_GT_Ore_Layer; + +public class ItemBlockOre extends ItemBlock { + + private final BlockBaseOre mThisOre; + private final Material mThisMaterial; + private final int mThisRadiation; + + public ItemBlockOre(final Block block) { + super(block); + if (block instanceof BlockBaseOre) { + this.mThisOre = (BlockBaseOre) block; + this.mThisMaterial = this.mThisOre.getMaterialEx(); + this.mThisRadiation = this.mThisMaterial.vRadiationLevel; + } else { + this.mThisOre = null; + this.mThisMaterial = null; + this.mThisRadiation = 0; + } + } + + private static Map<String, AutoMap<String>> mMapOreBlockItemToDimName = new LinkedHashMap<>(); + private static boolean mInitOres_Everglades = false; + private AutoMap<String> mDimsForThisOre = new AutoMap<>(); + + @Override + public void addInformation(final ItemStack stack, final EntityPlayer aPlayer, final List list, final boolean bool) { + + if (!mInitOres_Everglades) { + for (WorldGen_GT_Ore_Layer f : gtPlusPlus.everglades.gen.gt.WorldGen_Ores.validOreveins.values()) { + Material[] m2 = new Material[] { f.mPrimary, f.mSecondary, f.mBetween, f.mSporadic }; + for (Material m1 : m2) { + AutoMap<String> aMap = mMapOreBlockItemToDimName.get( + m1.getUnlocalizedName() + .toLowerCase()); + if (aMap == null) { + aMap = new AutoMap<>(); + } + String aDimName = "Everglades"; + if (!aMap.containsValue(aDimName)) { + aMap.put(aDimName); + } + mMapOreBlockItemToDimName.put( + m1.getUnlocalizedName() + .toLowerCase(), + aMap); + } + } + mInitOres_Everglades = true; + } + + if (this.mThisMaterial != null) { + list.add(this.mThisMaterial.vChemicalFormula); + } + + // Radioactive? + if (this.mThisRadiation > 0) { + list.add(CORE.GT_Tooltip_Radioactive.get()); + } + + if (this.mThisMaterial != null) { + list.add("Ore contains: "); + if (mThisMaterial.getComposites() + .isEmpty()) { + list.add("- " + mThisMaterial.getLocalizedName()); + } else { + for (MaterialStack m : mThisMaterial.getComposites()) { + list.add( + "- " + m.getStackMaterial() + .getLocalizedName() + " x" + m.getPartsPerOneHundred()); + } + } + } + + if (KeyboardUtils.isCtrlKeyDown()) { + + Block b = Block.getBlockFromItem(stack.getItem()); + if (b != null) { + int aMiningLevel1 = b.getHarvestLevel(stack.getItemDamage()); + if (aMiningLevel1 != 0) { + list.add("Mining Level: " + Math.min(Math.max(aMiningLevel1, 0), 5)); + } + } + + if (mDimsForThisOre.isEmpty()) { + AutoMap<String> A = mMapOreBlockItemToDimName.get( + this.mThisMaterial.getUnlocalizedName() + .toLowerCase()); + if (A != null) { + mDimsForThisOre = A; + } + } + + list.add("Found: "); + if (!mDimsForThisOre.isEmpty()) { + for (String m : mDimsForThisOre) { + list.add("- " + m); + } + } else { + list.add("- Unknown"); + } + + } else { + list.add(EnumChatFormatting.DARK_GRAY + "Hold Ctrl to show additional info."); + } + + super.addInformation(stack, aPlayer, list, bool); + } + + @Override + public void onUpdate(final ItemStack iStack, final World world, final Entity entityHolding, final int p_77663_4_, + final boolean p_77663_5_) { + if (this.mThisMaterial != null) { + if (this.mThisRadiation > 0) { + if (entityHolding instanceof EntityPlayer) { + if (!((EntityPlayer) entityHolding).capabilities.isCreativeMode) { + EntityUtils.applyRadiationDamageToEntity( + iStack.stackSize, + this.mThisMaterial.vRadiationLevel, + world, + entityHolding); + } + } + } + } + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/misc/BaseItemMisc.java b/src/main/java/gtPlusPlus/core/item/base/misc/BaseItemMisc.java new file mode 100644 index 0000000000..020becc687 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/misc/BaseItemMisc.java @@ -0,0 +1,154 @@ +package gtPlusPlus.core.item.base.misc; + +import static gregtech.api.enums.Mods.Forestry; +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.List; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; + +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.util.GT_LanguageManager; +import gregtech.api.util.GT_OreDictUnificator; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.ItemUtils; + +public class BaseItemMisc extends Item { + + public final String displayName; + public final String unlocalName; + public final MiscTypes miscType; + public final Object componentColour; + + public BaseItemMisc(final String displayName, final short[] RGB, final int maxStackSize, final MiscTypes miscType, + String[] description) { + + // Set-up the Misc Generic Item + this.displayName = displayName; + String unlocalName = Utils.sanitizeString(displayName); + this.unlocalName = "item" + miscType.TYPE + unlocalName; + this.miscType = miscType; + this.setCreativeTab(AddToCreativeTab.tabMisc); + this.setUnlocalizedName(this.unlocalName); + this.setMaxStackSize(maxStackSize); + // this.setTextureName(this.getCorrectTextures()); + if (RGB != null) { + this.componentColour = Utils.rgbtoHexValue(RGB[0], RGB[1], RGB[2]); + } else { + this.componentColour = null; + } + if (description != null) { + for (int i = 0; i < description.length; i++) { + GT_LanguageManager + .addStringLocalization("gtplusplus." + this.getUnlocalizedName() + ".tooltip." + i, description[i]); + } + } + GameRegistry.registerItem(this, this.unlocalName); + GT_OreDictUnificator.registerOre(miscType.getOreDictPrefix() + unlocalName, ItemUtils.getSimpleStack(this)); + } + + private String getCorrectTextures() { + return GTPlusPlus.ID + ":" + "item" + this.miscType.TYPE; + } + + @Override + @SideOnly(Side.CLIENT) + public boolean requiresMultipleRenderPasses() { + return this.miscType == MiscTypes.DROP; + } + + @Override + public int getRenderPasses(int meta) { + return (this.miscType == MiscTypes.DROP) ? 2 : 1; + } + + @SideOnly(Side.CLIENT) + private IIcon secondIcon; + + @Override + @SideOnly(Side.CLIENT) + public void registerIcons(IIconRegister par1IconRegister) { + if (this.miscType == MiscTypes.DROP && Forestry.isModLoaded()) { + this.itemIcon = par1IconRegister.registerIcon("forestry:honeyDrop.0"); + this.secondIcon = par1IconRegister.registerIcon("forestry:honeyDrop.1"); + } else { + this.itemIcon = par1IconRegister.registerIcon(getCorrectTextures()); + } + } + + @Override + public IIcon getIcon(ItemStack stack, int pass) { + return (pass == 0) ? itemIcon : secondIcon; + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public final void addInformation(final ItemStack stack, final EntityPlayer aPlayer, final List list, + final boolean bool) { + for (int i = 0;; i++) { + String tooltip = GT_LanguageManager + .getTranslation("gtplusplus." + this.getUnlocalizedName() + ".tooltip" + "." + i); + if (!("gtplusplus." + this.getUnlocalizedName() + ".tooltip" + "." + i).equals(tooltip)) { + list.add(tooltip); + } else break; + } + } + + @Override + public int getColorFromItemStack(final ItemStack stack, final int HEX_OxFFFFFF) { + // Returns default colour if a custom one is not set. + if (this.componentColour == null) { + return 16777215; + } else { + return (int) this.componentColour; + } + } + + @Override + public void onUpdate(final ItemStack iStack, final World world, final Entity entityHolding, final int p_77663_4_, + final boolean p_77663_5_) { + // Nothing Fancy here yet. + } + + public static enum MiscTypes { + + POTION("Potion", " Potion", "potion"), + KEY("Key", " Key", "key"), + BIGKEY("KeyBig", " Big Key", "bosskey"), + BOTTLE("Bottle", " Bottle", "bottle"), + GEM("Gem", " Gemstone", "gem"), + DROP("Droplet", " Droplet", "droplet"), + MUSHROOM("Mushroom", " Mushroom", "mushroom"); + + private final String TYPE; + private final String DISPLAY_NAME_SUFFIX; + private final String OREDICT_PREFIX; + + private MiscTypes(final String LocalName, final String DisplayNameSuffix, final String OreDictPrefix) { + this.TYPE = LocalName; + this.DISPLAY_NAME_SUFFIX = DisplayNameSuffix; + this.OREDICT_PREFIX = OreDictPrefix; + } + + public String getType() { + return this.TYPE; + } + + public String getName() { + return this.DISPLAY_NAME_SUFFIX; + } + + public String getOreDictPrefix() { + return this.OREDICT_PREFIX; + } + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/misc/BaseItemParticle.java b/src/main/java/gtPlusPlus/core/item/base/misc/BaseItemParticle.java new file mode 100644 index 0000000000..b6292c695e --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/misc/BaseItemParticle.java @@ -0,0 +1,66 @@ +package gtPlusPlus.core.item.base.misc; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; + +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.item.base.CoreItem; + +public abstract class BaseItemParticle extends CoreItem { + + protected static final Map<Integer, Integer> aColourMap = new LinkedHashMap<>(); + private final int aMaxCount; + + public BaseItemParticle(String aType, int aCount, EnumRarity aRarity) { + super( + "particle" + aType, + aType, + AddToCreativeTab.tabOther, + 64, + 0, + new String[] {}, + aRarity, + EnumChatFormatting.DARK_AQUA, + false, + null); + this.setTextureName(GTPlusPlus.ID + ":" + "science/Atom"); + aMaxCount = aCount; + this.setHasSubtypes(true); + } + + @Override + public int getColorFromItemStack(final ItemStack stack, final int HEX_OxFFFFFF) { + return aColourMap.get(stack.getItemDamage()); + } + + public int getColorFromParentClass(ItemStack stack, int aaa) { + return super.getColorFromItemStack(stack, aaa); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public void getSubItems(Item item, CreativeTabs tab, List list) { + for (int i = 0; i < aMaxCount; i++) { + list.add(new ItemStack(item, 1, i)); + } + } + + @Override + public final String getItemStackDisplayName(final ItemStack tItem) { + String aReturnValue = super.getItemStackDisplayName(tItem); + String[] a2 = getAffixes(); + aReturnValue = (a2[0] + aReturnValue + a2[1]); + return aReturnValue; + } + + public abstract String[] getAffixes(); +} diff --git a/src/main/java/gtPlusPlus/core/item/base/nugget/BaseItemNugget.java b/src/main/java/gtPlusPlus/core/item/base/nugget/BaseItemNugget.java new file mode 100644 index 0000000000..b0537f022f --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/nugget/BaseItemNugget.java @@ -0,0 +1,11 @@ +package gtPlusPlus.core.item.base.nugget; + +import gtPlusPlus.core.item.base.BaseItemComponent; +import gtPlusPlus.core.material.Material; + +public class BaseItemNugget extends BaseItemComponent { + + public BaseItemNugget(final Material material) { + super(material, BaseItemComponent.ComponentTypes.NUGGET); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/ore/BaseItemCentrifugedCrushedOre.java b/src/main/java/gtPlusPlus/core/item/base/ore/BaseItemCentrifugedCrushedOre.java new file mode 100644 index 0000000000..9a72f62040 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/ore/BaseItemCentrifugedCrushedOre.java @@ -0,0 +1,10 @@ +package gtPlusPlus.core.item.base.ore; + +import gtPlusPlus.core.material.Material; + +public class BaseItemCentrifugedCrushedOre extends BaseOreComponent { + + public BaseItemCentrifugedCrushedOre(final Material material) { + super(material, BaseOreComponent.ComponentTypes.CRUSHEDCENTRIFUGED); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/ore/BaseItemCrushedOre.java b/src/main/java/gtPlusPlus/core/item/base/ore/BaseItemCrushedOre.java new file mode 100644 index 0000000000..e9588f9f96 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/ore/BaseItemCrushedOre.java @@ -0,0 +1,10 @@ +package gtPlusPlus.core.item.base.ore; + +import gtPlusPlus.core.material.Material; + +public class BaseItemCrushedOre extends BaseOreComponent { + + public BaseItemCrushedOre(final Material material) { + super(material, BaseOreComponent.ComponentTypes.CRUSHED); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/ore/BaseItemImpureDust.java b/src/main/java/gtPlusPlus/core/item/base/ore/BaseItemImpureDust.java new file mode 100644 index 0000000000..f80e392703 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/ore/BaseItemImpureDust.java @@ -0,0 +1,10 @@ +package gtPlusPlus.core.item.base.ore; + +import gtPlusPlus.core.material.Material; + +public class BaseItemImpureDust extends BaseOreComponent { + + public BaseItemImpureDust(final Material material) { + super(material, BaseOreComponent.ComponentTypes.DUSTIMPURE); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/ore/BaseItemMilledOre.java b/src/main/java/gtPlusPlus/core/item/base/ore/BaseItemMilledOre.java new file mode 100644 index 0000000000..90235a18b3 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/ore/BaseItemMilledOre.java @@ -0,0 +1,24 @@ +package gtPlusPlus.core.item.base.ore; + +import net.minecraft.item.Item; + +import gregtech.api.enums.Materials; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.material.Material; +import gtPlusPlus.core.util.minecraft.MaterialUtils; + +public class BaseItemMilledOre extends BaseOreComponent { + + public BaseItemMilledOre(final Material material, int aMaterialEU) { + super(material, BaseOreComponent.ComponentTypes.MILLED); + CORE.RA.addMillingRecipe(material, aMaterialEU); + } + + public static Item generate(Materials aMat, int aMaterialEU) { + return generate(MaterialUtils.generateMaterialFromGtENUM(aMat), aMaterialEU); + } + + public static Item generate(Material aMat, int aMaterialEU) { + return new BaseItemMilledOre(aMat, aMaterialEU); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/ore/BaseItemPurifiedCrushedOre.java b/src/main/java/gtPlusPlus/core/item/base/ore/BaseItemPurifiedCrushedOre.java new file mode 100644 index 0000000000..744b204d43 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/ore/BaseItemPurifiedCrushedOre.java @@ -0,0 +1,10 @@ +package gtPlusPlus.core.item.base.ore; + +import gtPlusPlus.core.material.Material; + +public class BaseItemPurifiedCrushedOre extends BaseOreComponent { + + public BaseItemPurifiedCrushedOre(final Material material) { + super(material, BaseOreComponent.ComponentTypes.CRUSHEDPURIFIED); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/ore/BaseItemPurifiedDust.java b/src/main/java/gtPlusPlus/core/item/base/ore/BaseItemPurifiedDust.java new file mode 100644 index 0000000000..4b94b98e64 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/ore/BaseItemPurifiedDust.java @@ -0,0 +1,10 @@ +package gtPlusPlus.core.item.base.ore; + +import gtPlusPlus.core.material.Material; + +public class BaseItemPurifiedDust extends BaseOreComponent { + + public BaseItemPurifiedDust(final Material material) { + super(material, BaseOreComponent.ComponentTypes.DUSTPURE); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/ore/BaseItemRawOre.java b/src/main/java/gtPlusPlus/core/item/base/ore/BaseItemRawOre.java new file mode 100644 index 0000000000..bca44d0045 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/ore/BaseItemRawOre.java @@ -0,0 +1,10 @@ +package gtPlusPlus.core.item.base.ore; + +import gtPlusPlus.core.material.Material; + +public class BaseItemRawOre extends BaseOreComponent { + + public BaseItemRawOre(final Material material) { + super(material, BaseOreComponent.ComponentTypes.RAWORE); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/ore/BaseOreComponent.java b/src/main/java/gtPlusPlus/core/item/base/ore/BaseOreComponent.java new file mode 100644 index 0000000000..2074bb2ede --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/ore/BaseOreComponent.java @@ -0,0 +1,272 @@ +package gtPlusPlus.core.item.base.ore; + +import static gregtech.api.enums.Mods.GTPlusPlus; +import static gregtech.api.enums.Mods.GregTech; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; + +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.util.GT_OreDictUnificator; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.material.Material; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.EntityUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; + +public class BaseOreComponent extends Item { + + @SideOnly(Side.CLIENT) + private IIcon base; + + @SideOnly(Side.CLIENT) + private IIcon overlay; + + public final Material componentMaterial; + public final String materialName; + public final String unlocalName; + public final ComponentTypes componentType; + public final int componentColour; + public Object extraData; + + public BaseOreComponent(final Material material, final ComponentTypes componentType) { + this.componentMaterial = material; + this.unlocalName = componentType.COMPONENT_NAME + material.getUnlocalizedName(); + this.materialName = material.getLocalizedName(); + this.componentType = componentType; + this.setCreativeTab(AddToCreativeTab.tabMisc); + this.setUnlocalizedName(this.unlocalName); + this.setMaxStackSize(64); + this.componentColour = material.getRgbAsHex(); + GameRegistry.registerItem(this, this.unlocalName); + registerComponent(); + GT_OreDictUnificator + .registerOre(componentType.getComponent() + material.getUnlocalizedName(), ItemUtils.getSimpleStack(this)); + } + + public boolean registerComponent() { + Logger.MATERIALS("Attempting to register " + this.getUnlocalizedName() + "."); + if (this.componentMaterial == null) { + Logger.MATERIALS("Tried to register " + this.getUnlocalizedName() + " but the material was null."); + return false; + } + // Register Component + Map<String, ItemStack> aMap = Material.mComponentMap.get(componentMaterial.getUnlocalizedName()); + if (aMap == null) { + aMap = new HashMap<>(); + } + String aKey = "Invalid"; + switch (componentType) { + case CRUSHED -> aKey = OrePrefixes.crushed.name(); + case CRUSHEDCENTRIFUGED -> aKey = OrePrefixes.crushedCentrifuged.name(); + case CRUSHEDPURIFIED -> aKey = OrePrefixes.crushedPurified.name(); + case DUST -> aKey = OrePrefixes.dust.name(); + case DUSTIMPURE -> aKey = OrePrefixes.dustImpure.name(); + case DUSTPURE -> aKey = OrePrefixes.dustPure.name(); + case MILLED -> aKey = OrePrefixes.milled.name(); + case RAWORE -> aKey = OrePrefixes.rawOre.name(); + } + + ItemStack x = aMap.get(aKey); + if (x == null) { + aMap.put(aKey, ItemUtils.getSimpleStack(this)); + Logger.MATERIALS( + "Registering a material component. Item: [" + componentMaterial.getUnlocalizedName() + + "] Map: [" + + aKey + + "]"); + Material.mComponentMap.put(componentMaterial.getUnlocalizedName(), aMap); + return true; + } else { + // Bad + Logger.MATERIALS("Tried to double register a material component. "); + return false; + } + } + + /* + * @Override public String getItemStackDisplayName(final ItemStack p_77653_1_) { return + * (this.componentType.getPrefix()+this.componentMaterial.getLocalizedName()+this.componentType.DISPLAY_NAME); } + */ + + public final String getMaterialName() { + return this.materialName; + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public final void addInformation(final ItemStack stack, final EntityPlayer aPlayer, final List list, + final boolean bool) { + if (this.materialName != null && !this.materialName.equals("")) { + if (this.componentMaterial != null) { + if (!this.componentMaterial.vChemicalFormula.contains("?")) { + list.add(Utils.sanitizeStringKeepBrackets(this.componentMaterial.vChemicalFormula)); + } else if (this.componentMaterial.vChemicalFormula.contains("?")) { + String temp = componentMaterial.vChemicalFormula; + temp = temp.replace(" ", ""); + temp = temp.replace("-", ""); + temp = temp.replace("_", ""); + temp = temp.replace("!", ""); + temp = temp.replace("@", ""); + temp = temp.replace("#", ""); + temp = temp.replace(" ", ""); + list.add(temp); + } + if (this.componentMaterial.isRadioactive) { + list.add(CORE.GT_Tooltip_Radioactive.get() + " | Level: " + this.componentMaterial.vRadiationLevel); + } + } else { + String aChemicalFormula = Material.sChemicalFormula.get(materialName.toLowerCase()); + if (aChemicalFormula != null && aChemicalFormula.length() > 0) { + list.add(Utils.sanitizeStringKeepBrackets(aChemicalFormula)); + } + } + } + super.addInformation(stack, aPlayer, list, bool); + } + + @Override + public void onUpdate(final ItemStack iStack, final World world, final Entity entityHolding, final int p_77663_4_, + final boolean p_77663_5_) { + if (this.componentMaterial != null) { + if (entityHolding instanceof EntityPlayer) { + if (!((EntityPlayer) entityHolding).capabilities.isCreativeMode) { + EntityUtils.applyRadiationDamageToEntity( + iStack.stackSize, + this.componentMaterial.vRadiationLevel, + world, + entityHolding); + } + } + } + } + + /** + * Rendering Related + * + * @author Alkalus + * + */ + @Override + @SideOnly(Side.CLIENT) + public boolean requiresMultipleRenderPasses() { + if (this.componentType.hasOverlay()) { + return true; + } + return false; + } + + @Override + @SideOnly(Side.CLIENT) + public void registerIcons(final IIconRegister par1IconRegister) { + if (this.componentType == ComponentTypes.MILLED) { + this.base = par1IconRegister.registerIcon(GTPlusPlus.ID + ":" + "processing/MilledOre/milled"); + if (this.componentType.hasOverlay()) { + this.overlay = par1IconRegister + .registerIcon(GTPlusPlus.ID + ":" + "processing/MilledOre/milled_OVERLAY"); + } + } else if (CORE.ConfigSwitches.useGregtechTextures) { + // Logger.MATERIALS(this.componentType.getPrefix()+this.componentMaterial.getLocalizedName()+this.componentType.DISPLAY_NAME+" + // is using `"+GregTech.ID + ":" + "materialicons/METALLIC/" + this.componentType.COMPONENT_NAME+"' as the + // layer 0 texture path."); + this.base = par1IconRegister + .registerIcon(GregTech.ID + ":" + "materialicons/METALLIC/" + this.componentType.COMPONENT_NAME); + if (this.componentType.hasOverlay()) { + // Logger.MATERIALS(this.componentType.getPrefix()+this.componentMaterial.getLocalizedName()+this.componentType.DISPLAY_NAME+" + // is using `"+GregTech.ID + ":" + "materialicons/METALLIC/" + + // this.componentType.COMPONENT_NAME+"_OVERLAY"+"' as the layer 1 texture path."); + this.overlay = par1IconRegister.registerIcon( + GregTech.ID + ":" + "materialicons/METALLIC/" + this.componentType.COMPONENT_NAME + "_OVERLAY"); + } + } else { + this.base = par1IconRegister.registerIcon(GTPlusPlus.ID + ":" + "item" + this.componentType.getComponent()); + if (this.componentType.hasOverlay()) { + this.overlay = par1IconRegister + .registerIcon(GTPlusPlus.ID + ":" + "item" + this.componentType.getComponent() + "_Overlay"); + } + } + } + + @Override + public int getColorFromItemStack(final ItemStack stack, final int renderPass) { + if (this.componentType == ComponentTypes.MILLED) { + if (renderPass == 1) { + return Utils.rgbtoHexValue(230, 230, 230); + } + return this.componentColour; + } else { + if (renderPass == 0 && !CORE.ConfigSwitches.useGregtechTextures) { + return this.componentColour; + } + if (renderPass == 1 && CORE.ConfigSwitches.useGregtechTextures) { + return Utils.rgbtoHexValue(230, 230, 230); + } + return this.componentColour; + } + } + + @Override + public IIcon getIconFromDamageForRenderPass(final int damage, final int pass) { + if (pass == 0) { + return this.base; + } + return this.overlay; + } + + public static enum ComponentTypes { + + DUST("dust", "", " Dust", true), + DUSTIMPURE("dustImpure", "Impure ", " Dust", true), + DUSTPURE("dustPure", "Purified ", " Dust", true), + CRUSHED("crushed", "Crushed ", " Ore", true), + CRUSHEDCENTRIFUGED("crushedCentrifuged", "Centrifuged Crushed ", " Ore", true), + CRUSHEDPURIFIED("crushedPurified", "Purified Crushed ", " Ore", true), + RAWORE("oreRaw", "Raw ", " Ore", true), + MILLED("milled", "Milled ", " Ore", true); + + private final String COMPONENT_NAME; + private final String PREFIX; + private final String DISPLAY_NAME; + private final boolean HAS_OVERLAY; + + private ComponentTypes(final String LocalName, final String prefix, final String DisplayName, + final boolean overlay) { + this.COMPONENT_NAME = LocalName; + this.PREFIX = prefix; + this.DISPLAY_NAME = DisplayName; + this.HAS_OVERLAY = overlay; + // dust + Dirty, Impure, Pure, Refined + // crushed + centrifuged, purified + } + + public String getComponent() { + return this.COMPONENT_NAME; + } + + public String getName() { + return this.DISPLAY_NAME; + } + + public boolean hasOverlay() { + return this.HAS_OVERLAY; + } + + public String getPrefix() { + return this.PREFIX; + } + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/plates/BaseItemPlate.java b/src/main/java/gtPlusPlus/core/item/base/plates/BaseItemPlate.java new file mode 100644 index 0000000000..0fad7a8258 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/plates/BaseItemPlate.java @@ -0,0 +1,23 @@ +package gtPlusPlus.core.item.base.plates; + +import gtPlusPlus.core.item.base.BaseItemComponent; +import gtPlusPlus.core.material.Material; +import gtPlusPlus.core.material.state.MaterialState; +import gtPlusPlus.core.util.minecraft.MaterialUtils; + +public class BaseItemPlate extends BaseItemComponent { + + public BaseItemPlate(final Material material) { + super(material, BaseItemComponent.ComponentTypes.PLATE); + } + + public BaseItemPlate(final String unlocalizedName, final String materialName, final MaterialState state, + final short[] colour, final int tier, final int sRadioactivity) { + this( + MaterialUtils.generateQuickMaterial( + materialName, + state, + new short[] { colour[0], colour[1], colour[2], 0 }, + sRadioactivity)); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/plates/BaseItemPlateDense.java b/src/main/java/gtPlusPlus/core/item/base/plates/BaseItemPlateDense.java new file mode 100644 index 0000000000..580e028c00 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/plates/BaseItemPlateDense.java @@ -0,0 +1,11 @@ +package gtPlusPlus.core.item.base.plates; + +import gtPlusPlus.core.item.base.BaseItemComponent; +import gtPlusPlus.core.material.Material; + +public class BaseItemPlateDense extends BaseItemComponent { + + public BaseItemPlateDense(Material material) { + super(material, ComponentTypes.PLATEDENSE); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/plates/BaseItemPlateDouble.java b/src/main/java/gtPlusPlus/core/item/base/plates/BaseItemPlateDouble.java new file mode 100644 index 0000000000..4f5bc12829 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/plates/BaseItemPlateDouble.java @@ -0,0 +1,12 @@ +package gtPlusPlus.core.item.base.plates; + +import gtPlusPlus.core.item.base.BaseItemComponent; +import gtPlusPlus.core.material.Material; + +public class BaseItemPlateDouble extends BaseItemComponent { + + public BaseItemPlateDouble(final Material material) { + super(material, BaseItemComponent.ComponentTypes.PLATEDOUBLE); + this.setMaxStackSize(32); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/plates/BaseItemPlate_OLD.java b/src/main/java/gtPlusPlus/core/item/base/plates/BaseItemPlate_OLD.java new file mode 100644 index 0000000000..168d5236c6 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/plates/BaseItemPlate_OLD.java @@ -0,0 +1,91 @@ +package gtPlusPlus.core.item.base.plates; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.List; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +import cpw.mods.fml.common.registry.GameRegistry; +import gregtech.api.util.GT_OreDictUnificator; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.data.StringUtils; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.EntityUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; + +public class BaseItemPlate_OLD extends Item { + + protected final int colour; + protected final int sRadiation; + protected final String materialName; + protected final String unlocalName; + protected final String chemicalNotation; + + public BaseItemPlate_OLD(final String unlocalizedName, final String materialName, final int colour, + final int sRadioactivity) { + this(unlocalizedName, materialName, "NullFormula", colour, sRadioactivity); + } + + public BaseItemPlate_OLD(final String unlocalizedName, final String materialName, final String mChemicalFormula, + final int colour, final int sRadioactivity) { + this.setUnlocalizedName("itemPlate" + unlocalizedName); + this.setCreativeTab(AddToCreativeTab.tabMisc); + this.unlocalName = "itemPlate" + unlocalizedName; + this.setMaxStackSize(64); + this.setTextureName(GTPlusPlus.ID + ":" + "itemPlate"); + this.setMaxStackSize(64); + this.colour = colour; + this.materialName = materialName; + if (mChemicalFormula.equals("") || mChemicalFormula.equals("NullFormula")) { + this.chemicalNotation = StringUtils.subscript(materialName); + } else { + this.chemicalNotation = StringUtils.subscript(mChemicalFormula); + } + this.sRadiation = sRadioactivity; + GameRegistry.registerItem(this, "itemPlate" + unlocalizedName); + String temp; + if (this.unlocalName.toLowerCase() + .contains("itemplate")) { + temp = this.unlocalName.replace("itemP", "p"); + if ((temp != null) && !temp.equals("")) { + GT_OreDictUnificator.registerOre(temp, ItemUtils.getSimpleStack(this)); + } + } + } + + public final String getMaterialName() { + return this.materialName; + } + + @Override + public int getColorFromItemStack(final ItemStack stack, final int HEX_OxFFFFFF) { + if (this.colour == 0) { + return MathUtils.generateSingularRandomHexValue(); + } + return this.colour; + } + + @Override + public void onUpdate(final ItemStack iStack, final World world, final Entity entityHolding, final int p_77663_4_, + final boolean p_77663_5_) { + EntityUtils.applyRadiationDamageToEntity(iStack.stackSize, this.sRadiation, world, entityHolding); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public void addInformation(final ItemStack stack, final EntityPlayer aPlayer, final List list, final boolean bool) { + if (this.sRadiation > 0) { + list.add(CORE.GT_Tooltip_Radioactive.get()); + } + if (StringUtils.containsSuperOrSubScript(this.chemicalNotation)) { + list.add(this.chemicalNotation); + } + super.addInformation(stack, aPlayer, list, bool); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/rings/BaseItemRing.java b/src/main/java/gtPlusPlus/core/item/base/rings/BaseItemRing.java new file mode 100644 index 0000000000..d25ea02d52 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/rings/BaseItemRing.java @@ -0,0 +1,11 @@ +package gtPlusPlus.core.item.base.rings; + +import gtPlusPlus.core.item.base.BaseItemComponent; +import gtPlusPlus.core.material.Material; + +public class BaseItemRing extends BaseItemComponent { + + public BaseItemRing(final Material material) { + super(material, BaseItemComponent.ComponentTypes.RING); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/rods/BaseItemRod.java b/src/main/java/gtPlusPlus/core/item/base/rods/BaseItemRod.java new file mode 100644 index 0000000000..9a9998d63a --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/rods/BaseItemRod.java @@ -0,0 +1,11 @@ +package gtPlusPlus.core.item.base.rods; + +import gtPlusPlus.core.item.base.BaseItemComponent; +import gtPlusPlus.core.material.Material; + +public class BaseItemRod extends BaseItemComponent { + + public BaseItemRod(final Material material) { + super(material, BaseItemComponent.ComponentTypes.ROD); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/rods/BaseItemRodLong.java b/src/main/java/gtPlusPlus/core/item/base/rods/BaseItemRodLong.java new file mode 100644 index 0000000000..bf7dd3bccc --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/rods/BaseItemRodLong.java @@ -0,0 +1,11 @@ +package gtPlusPlus.core.item.base.rods; + +import gtPlusPlus.core.item.base.BaseItemComponent; +import gtPlusPlus.core.material.Material; + +public class BaseItemRodLong extends BaseItemComponent { + + public BaseItemRodLong(final Material material) { + super(material, BaseItemComponent.ComponentTypes.RODLONG); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/rotors/BaseItemRotor.java b/src/main/java/gtPlusPlus/core/item/base/rotors/BaseItemRotor.java new file mode 100644 index 0000000000..c2fae0fc8b --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/rotors/BaseItemRotor.java @@ -0,0 +1,11 @@ +package gtPlusPlus.core.item.base.rotors; + +import gtPlusPlus.core.item.base.BaseItemComponent; +import gtPlusPlus.core.material.Material; + +public class BaseItemRotor extends BaseItemComponent { + + public BaseItemRotor(final Material material) { + super(material, BaseItemComponent.ComponentTypes.ROTOR); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/screws/BaseItemScrew.java b/src/main/java/gtPlusPlus/core/item/base/screws/BaseItemScrew.java new file mode 100644 index 0000000000..7f0ba8c504 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/screws/BaseItemScrew.java @@ -0,0 +1,11 @@ +package gtPlusPlus.core.item.base.screws; + +import gtPlusPlus.core.item.base.BaseItemComponent; +import gtPlusPlus.core.material.Material; + +public class BaseItemScrew extends BaseItemComponent { + + public BaseItemScrew(final Material material) { + super(material, BaseItemComponent.ComponentTypes.SCREW); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/base/wire/BaseItemFineWire.java b/src/main/java/gtPlusPlus/core/item/base/wire/BaseItemFineWire.java new file mode 100644 index 0000000000..3e2cee49a9 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/base/wire/BaseItemFineWire.java @@ -0,0 +1,11 @@ +package gtPlusPlus.core.item.base.wire; + +import gtPlusPlus.core.item.base.BaseItemComponent; +import gtPlusPlus.core.material.Material; + +public class BaseItemFineWire extends BaseItemComponent { + + public BaseItemFineWire(final Material material) { + super(material, BaseItemComponent.ComponentTypes.FINEWIRE); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/bauble/BaseBauble.java b/src/main/java/gtPlusPlus/core/item/bauble/BaseBauble.java new file mode 100644 index 0000000000..92468aa6d8 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/bauble/BaseBauble.java @@ -0,0 +1,133 @@ +package gtPlusPlus.core.item.bauble; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.ai.attributes.AttributeModifier; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.event.entity.living.LivingAttackEvent; + +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Multimap; + +import baubles.api.BaubleType; +import baubles.api.IBauble; +import baubles.common.container.InventoryBaubles; +import baubles.common.lib.PlayerHandler; +import cpw.mods.fml.common.Optional; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import gregtech.api.enums.Mods; +import gregtech.api.util.GT_LanguageManager; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.NBTUtils; + +@Optional.InterfaceList( + value = { @Optional.Interface(iface = "baubles.api.IBauble", modid = Mods.Names.BAUBLES), + @Optional.Interface(iface = "baubles.api.BaubleType", modid = Mods.Names.BAUBLES) }) +public class BaseBauble extends Item implements IBauble { + + /** + * Implementation suggestions taken from Botania. + */ + private BaubleType mThisBauble; + + private List<String> damageNegations = new ArrayList<>(); + Multimap<String, AttributeModifier> attributes = HashMultimap.create(); + + public BaseBauble(BaubleType type) { + this.mThisBauble = type; + Utils.registerEvent(this); + this.setMaxStackSize(1); + this.setCreativeTab(AddToCreativeTab.tabMisc); + } + + @Override + public String getItemStackDisplayName(final ItemStack tItem) { + String key = "gtplusplus." + getUnlocalizedName() + ".name"; + if (key.equals(GT_LanguageManager.getTranslation(key))) { + return super.getItemStackDisplayName(tItem).replaceAll(".name", ""); + } + return GT_LanguageManager.getTranslation(key); + } + + @SubscribeEvent + public void onPlayerAttacked(LivingAttackEvent event) { + if (event.entityLiving instanceof EntityPlayer player) { + if (getCorrectBauble(player) != null && damageNegations.contains(event.source.damageType)) + event.setCanceled(true); + } + } + + @Override + public boolean canEquip(ItemStack arg0, EntityLivingBase arg1) { + return arg1 instanceof EntityPlayer; + } + + @Override + public boolean canUnequip(ItemStack arg0, EntityLivingBase arg1) { + return arg1 instanceof EntityPlayer; + } + + @Override + public BaubleType getBaubleType(ItemStack arg0) { + return mThisBauble; + } + + @Override + public void onEquipped(ItemStack stack, EntityLivingBase entity) { + if (entity instanceof EntityPlayer) { + onEquippedOrLoadedIntoWorld(entity); + setPlayerHashcode(stack, entity.hashCode()); + } + } + + @Override + public void onWornTick(ItemStack stack, EntityLivingBase player) { + if (getPlayerHashcode(stack) != player.hashCode()) { + onEquippedOrLoadedIntoWorld(player); + setPlayerHashcode(stack, player.hashCode()); + } + } + + public void onEquippedOrLoadedIntoWorld(EntityLivingBase player) { + attributes.clear(); + player.getAttributeMap() + .applyAttributeModifiers(attributes); + } + + @Override + public void onUnequipped(ItemStack stack, EntityLivingBase player) { + attributes.clear(); + player.getAttributeMap() + .removeAttributeModifiers(attributes); + } + + public ItemStack getCorrectBauble(EntityPlayer player) { + InventoryBaubles baubles = PlayerHandler.getPlayerBaubles(player); + ItemStack stack1 = baubles.getStackInSlot(1); + ItemStack stack2 = baubles.getStackInSlot(2); + return isCorrectBauble(stack1) ? stack1 : isCorrectBauble(stack2) ? stack2 : null; + } + + private boolean isCorrectBauble(ItemStack stack) { + return stack != null && (stack.getItem() == this); + } + + @Override + public int getEntityLifespan(ItemStack itemStack, World world) { + return Integer.MAX_VALUE; + } + + public static int getPlayerHashcode(ItemStack stack) { + return NBTUtils.getInteger(stack, "mPlayerHashcode"); + } + + public static void setPlayerHashcode(ItemStack stack, int hash) { + NBTUtils.setInteger(stack, "mPlayerHashcode", hash); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/bauble/BatteryPackBaseBauble.java b/src/main/java/gtPlusPlus/core/item/bauble/BatteryPackBaseBauble.java new file mode 100644 index 0000000000..881146b15d --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/bauble/BatteryPackBaseBauble.java @@ -0,0 +1,261 @@ +package gtPlusPlus.core.item.bauble; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.List; + +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.StatCollector; +import net.minecraft.world.World; + +import baubles.api.BaubleType; +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.enums.GT_Values; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.xmod.gregtech.common.helpers.ChargingHelper; +import ic2.api.item.ElectricItem; +import ic2.api.item.IElectricItem; + +public class BatteryPackBaseBauble extends ElectricBaseBauble { + + public BatteryPackBaseBauble(int tier) { + super(BaubleType.BELT, tier, GT_Values.V[tier] * 20 * 300, "GTPP.BattPack.0" + tier + ".name"); + String aUnlocalName = "GTPP.BattPack.0" + tier + ".name"; + this.setCreativeTab(AddToCreativeTab.tabMachines); + if (GameRegistry.findItem(GTPlusPlus.ID, aUnlocalName) == null) { + GameRegistry.registerItem(this, aUnlocalName); + } + } + + @SideOnly(Side.CLIENT) + @Override + public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) { + ItemStack itemStack = new ItemStack(this, 1); + ItemStack charged; + if (this.getEmptyItem(itemStack) == this) { + charged = new ItemStack(this, 1); + ElectricItem.manager.charge(charged, 0.0D, Integer.MAX_VALUE, true, false); + itemList.add(charged); + } + if (this.getChargedItem(itemStack) == this) { + charged = new ItemStack(this, 1); + ElectricItem.manager.charge(charged, Double.POSITIVE_INFINITY, Integer.MAX_VALUE, true, false); + itemList.add(charged); + } + } + + @Override + public void onUpdate(final ItemStack itemStack, final World worldObj, final Entity player, final int p_77663_4_, + final boolean p_77663_5_) { + super.onUpdate(itemStack, worldObj, player, p_77663_4_, p_77663_5_); + } + + @Override + public boolean canProvideEnergy(final ItemStack itemStack) { + double aItemCharge = ElectricItem.manager.getCharge(itemStack); + return aItemCharge > 0; + } + + @Override + public String getItemStackDisplayName(final ItemStack p_77653_1_) { + return (EnumChatFormatting.BLUE + super.getItemStackDisplayName(p_77653_1_) + EnumChatFormatting.GRAY); + } + + @Override + public boolean showDurabilityBar(final ItemStack stack) { + return true; + } + + public int secondsLeft(final ItemStack stack) { + double r = 0; + r = this.getCharge(stack) / (10000 * 20); + return (int) MathUtils.decimalRounding(r); + } + + @SuppressWarnings("unchecked") + @Override + public void addInformation(final ItemStack stack, final EntityPlayer aPlayer, final List list, final boolean bool) { + list.add(""); + String aString1 = StatCollector.translateToLocal("GTPP.battpack.tooltip.1"); + String aString2 = StatCollector.translateToLocal("GTPP.battpack.tooltip.2"); + String aString3 = StatCollector.translateToLocal("GTPP.battpack.tooltip.3"); + String aString4 = StatCollector.translateToLocal("GTPP.battpack.tooltip.4"); + + String aEU = StatCollector.translateToLocal("GTPP.info.eu"); + String aEUT = aEU + "/t"; + + list.add(EnumChatFormatting.GREEN + aString1 + EnumChatFormatting.GRAY); + list.add( + EnumChatFormatting.GREEN + aString2 + + " " + + (int) getTransferLimit(stack) + + aEUT + + " " + + aString3 + + EnumChatFormatting.GRAY); + list.add(EnumChatFormatting.GREEN + aString4 + EnumChatFormatting.GRAY); + super.addInformation(stack, aPlayer, list, bool); + } + + @Override + public String getToolTip(final ItemStack stack) { + return ElectricItem.manager.getToolTip(stack); + } + + @Override + public boolean canEquip(final ItemStack arg0, final EntityLivingBase arg1) { + return true; + } + + @Override + public boolean canUnequip(final ItemStack arg0, final EntityLivingBase arg1) { + return true; + } + + @Override // TODO + public void onEquipped(final ItemStack arg0, final EntityLivingBase arg1) {} + + @Override // TODO + public void onUnequipped(final ItemStack arg0, final EntityLivingBase arg1) {} + + @Override // TODO + public void onWornTick(final ItemStack aBaubleStack, final EntityLivingBase aPlayer) { + if (!aPlayer.worldObj.isRemote) { + + try { + + if (this.getCharge(aBaubleStack) >= getTransferLimit(aBaubleStack)) { + // Try Iterate Armour Slots of Player + if (aPlayer instanceof EntityPlayer) { + + // amour + for (final ItemStack aInvStack : ((EntityPlayer) aPlayer).inventory.armorInventory) { + if (aInvStack != null) { + if (aInvStack == aBaubleStack) { + continue; + } + if (ChargingHelper.isItemValid(aInvStack)) { + double aTransferRate = 0; + final IElectricItem electricItem = (IElectricItem) aInvStack.getItem(); + if (electricItem != null) { + aTransferRate = electricItem.getTransferLimit(aInvStack); + double aItemCharge = ElectricItem.manager.getCharge(aInvStack); + if (aItemCharge >= 0 && aItemCharge != electricItem.getMaxCharge(aInvStack)) { + if (aItemCharge <= (electricItem.getMaxCharge(aInvStack) - aTransferRate)) { + if (ElectricItem.manager.getCharge(aBaubleStack) >= aTransferRate) { + if (ElectricItem.manager.getCharge(aInvStack) + <= (electricItem.getMaxCharge(aInvStack) - aTransferRate)) { + double d = ElectricItem.manager + .charge(aInvStack, aTransferRate * 16, mTier, false, true); + if (d > 0) { + d = ElectricItem.manager.charge( + aInvStack, + aTransferRate * 16, + mTier, + false, + false); + ElectricItem.manager + .discharge(aBaubleStack, d, mTier, false, true, false); + // Logger.INFO("Charging " + aInvStack.getDisplayName() + " + // | " + d + " | "+electricItem.getMaxCharge(aInvStack)); + } + } else { + // Logger.INFO("5"); + } + } else { + // Logger.INFO("4"); + } + } else { + // Logger.INFO("3"); + } + + } else { + // Logger.INFO("1"); + } + } + } + } + if (this.getCharge(aBaubleStack) > 0) { + continue; + } else { + break; + } + } + + // Hotbar Slots + int aSlotCounter = 0; + for (final ItemStack aInvStack : ((EntityPlayer) aPlayer).inventory.mainInventory) { + if (aSlotCounter > (InventoryPlayer.getHotbarSize() - 1)) { + break; + } + aSlotCounter++; + if (aInvStack != null) { + if (aInvStack == aBaubleStack) { + continue; + } + if (ChargingHelper.isItemValid(aInvStack)) { + double aTransferRate = 0; + final IElectricItem electricItem = (IElectricItem) aInvStack.getItem(); + if (electricItem != null) { + aTransferRate = electricItem.getTransferLimit(aInvStack); + double aItemCharge = ElectricItem.manager.getCharge(aInvStack); + if (aItemCharge >= 0 && aItemCharge != electricItem.getMaxCharge(aInvStack)) { + if (aItemCharge <= (electricItem.getMaxCharge(aInvStack) - aTransferRate)) { + if (ElectricItem.manager.getCharge(aBaubleStack) >= aTransferRate) { + if (ElectricItem.manager.getCharge(aInvStack) + <= (electricItem.getMaxCharge(aInvStack) - aTransferRate)) { + double d = ElectricItem.manager + .charge(aInvStack, aTransferRate, mTier, false, true); + if (d > 0) { + d = ElectricItem.manager + .charge(aInvStack, aTransferRate, mTier, false, false); + ElectricItem.manager + .discharge(aBaubleStack, d, mTier, false, true, false); + // Logger.INFO("Charging " + aInvStack.getDisplayName() + " + // | " + d + " | "+electricItem.getMaxCharge(aInvStack)); + } + } else { + // Logger.INFO("5"); + } + } else { + // Logger.INFO("4"); + } + } else { + // Logger.INFO("3"); + } + + } else { + // Logger.INFO("1"); + } + } + } + } + if (this.getCharge(aBaubleStack) > 0) { + continue; + } else { + break; + } + } + } + } + } catch (Throwable t) { + + } + } + } + + @Override + public String getTextureNameForBauble() { + return "chargepack/" + mTier; + } +} diff --git a/src/main/java/gtPlusPlus/core/item/bauble/ElectricBaseBauble.java b/src/main/java/gtPlusPlus/core/item/bauble/ElectricBaseBauble.java new file mode 100644 index 0000000000..ab17e91232 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/bauble/ElectricBaseBauble.java @@ -0,0 +1,220 @@ +package gtPlusPlus.core.item.bauble; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.List; + +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.StatCollector; +import net.minecraft.world.World; + +import baubles.api.BaubleType; +import baubles.api.IBauble; +import cpw.mods.fml.common.Optional; +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.Mods; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.util.math.MathUtils; +import ic2.api.item.ElectricItem; +import ic2.api.item.IElectricItem; +import ic2.api.item.IElectricItemManager; + +@Optional.InterfaceList( + value = { @Optional.Interface(iface = "baubles.api.IBauble", modid = Mods.Names.BAUBLES), + @Optional.Interface(iface = "baubles.api.BaubleType", modid = Mods.Names.BAUBLES) }) +public abstract class ElectricBaseBauble extends BaseBauble implements IElectricItem, IElectricItemManager, IBauble { + + public final int mTier; + private final double maxValueEU; + private final BaubleType mType; + + public ElectricBaseBauble(BaubleType aType, int aTier, double aMaxEU, String aUnlocalName) { + super(aType); + mType = aType; + mTier = aTier; + maxValueEU = aMaxEU; + this.setUnlocalizedName(aUnlocalName); + this.setTextureName(GTPlusPlus.ID + ":" + getTextureNameForBauble()); + this.setMaxDamage(27); + this.setMaxStackSize(1); + this.setNoRepair(); + this.setCreativeTab(AddToCreativeTab.tabMachines); + if (GameRegistry.findItem(GTPlusPlus.ID, aUnlocalName) == null) { + GameRegistry.registerItem(this, aUnlocalName); + } + } + + public abstract String getTextureNameForBauble(); + + @SuppressWarnings("unchecked") + @SideOnly(Side.CLIENT) + @Override + public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) { + ItemStack itemStack = new ItemStack(this, 1); + ItemStack charged; + if (this.getEmptyItem(itemStack) == this) { + charged = new ItemStack(this, 1); + ElectricItem.manager.charge(charged, 0.0D, Integer.MAX_VALUE, true, false); + itemList.add(charged); + } + if (this.getChargedItem(itemStack) == this) { + charged = new ItemStack(this, 1); + ElectricItem.manager.charge(charged, Double.POSITIVE_INFINITY, Integer.MAX_VALUE, true, false); + itemList.add(charged); + } + } + + @Override + public void onUpdate(final ItemStack itemStack, final World worldObj, final Entity player, final int p_77663_4_, + final boolean p_77663_5_) { + super.onUpdate(itemStack, worldObj, player, p_77663_4_, p_77663_5_); + } + + @Override + public boolean canProvideEnergy(final ItemStack itemStack) { + double aItemCharge = ElectricItem.manager.getCharge(itemStack); + return aItemCharge > 0; + } + + @Override + public final Item getChargedItem(final ItemStack itemStack) { + final ItemStack x = itemStack.copy(); + x.setItemDamage(27); + return x.getItem(); + } + + @Override + public final Item getEmptyItem(final ItemStack itemStack) { + final ItemStack x = itemStack.copy(); + x.setItemDamage(0); + return x.getItem(); + } + + @Override + public final double getMaxCharge(final ItemStack itemStack) { + return maxValueEU; + } + + @Override + public final int getTier(final ItemStack itemStack) { + return mTier; + } + + @Override + public final double getTransferLimit(final ItemStack itemStack) { + return GT_Values.V[mTier]; + } + + @Override + public final double getDurabilityForDisplay(final ItemStack stack) { + return 1.0D - (this.getCharge(stack) / this.getMaxCharge(stack)); + } + + @Override + public boolean showDurabilityBar(final ItemStack stack) { + return true; + } + + @SuppressWarnings("unchecked") + @Override + public void addInformation(final ItemStack stack, final EntityPlayer aPlayer, final List list, final boolean bool) { + list.add(""); + String aEuInfo = StatCollector.translateToLocal("GTPP.info.euInfo"); + String aTier = StatCollector.translateToLocal("GTPP.machines.tier"); + String aInputLimit = StatCollector.translateToLocal("GTPP.info.inputLimit"); + String aCurrentPower = StatCollector.translateToLocal("GTPP.info.currentPower"); + String aEU = StatCollector.translateToLocal("GTPP.info.eu"); + String aEUT = aEU + "/t"; + + list.add(EnumChatFormatting.GOLD + aEuInfo + EnumChatFormatting.GRAY); + list.add( + EnumChatFormatting.GRAY + aTier + + ": [" + + EnumChatFormatting.YELLOW + + GT_Utility.formatNumbers(this.getTier(stack)) + + EnumChatFormatting.GRAY + + "] " + + aInputLimit + + ": [" + + EnumChatFormatting.YELLOW + + GT_Utility.formatNumbers(this.getTransferLimit(stack)) + + EnumChatFormatting.GRAY + + aEUT + + "]"); + list.add( + EnumChatFormatting.GRAY + aCurrentPower + + ": [" + + EnumChatFormatting.YELLOW + + GT_Utility.formatNumbers(this.getCharge(stack)) + + EnumChatFormatting.GRAY + + aEU + + "] [" + + EnumChatFormatting.YELLOW + + GT_Utility.formatNumbers(MathUtils.findPercentage(this.getCharge(stack), this.getMaxCharge(stack))) + + EnumChatFormatting.GRAY + + "%]"); + super.addInformation(stack, aPlayer, list, bool); + } + + @Override + public final double charge(final ItemStack stack, final double amount, final int tier, + final boolean ignoreTransferLimit, final boolean simulate) { + /* + * if (!simulate) { ElectricItem.manager.charge(stack, amount, tier, true, simulate); } + */ + + return ElectricItem.manager.charge(stack, amount, tier, true, simulate); + } + + @Override + public final double discharge(final ItemStack stack, final double amount, final int tier, + final boolean ignoreTransferLimit, final boolean externally, final boolean simulate) { + /* + * if (!simulate) { ElectricItem.manager.discharge(stack, amount, tier, ignoreTransferLimit, externally, + * simulate); } + */ + + return ElectricItem.manager.discharge(stack, amount, tier, ignoreTransferLimit, externally, simulate); + } + + @Override + public final double getCharge(final ItemStack stack) { + return ElectricItem.manager.getCharge(stack); + } + + @Override + public final boolean canUse(final ItemStack stack, final double amount) { + return ElectricItem.manager.canUse(stack, amount); + } + + @Override + public final boolean use(final ItemStack stack, final double amount, final EntityLivingBase entity) { + return ElectricItem.manager.use(stack, amount, entity); + } + + @Override + public final void chargeFromArmor(final ItemStack stack, final EntityLivingBase entity) { + ElectricItem.manager.chargeFromArmor(stack, entity); + } + + @Override + public String getToolTip(final ItemStack stack) { + // return ElectricItem.manager.getToolTip(stack); + return null; + } + + @Override + public final BaubleType getBaubleType(final ItemStack arg0) { + return mType; + } +} diff --git a/src/main/java/gtPlusPlus/core/item/bauble/FireProtectionBauble.java b/src/main/java/gtPlusPlus/core/item/bauble/FireProtectionBauble.java new file mode 100644 index 0000000000..c3c371ae35 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/bauble/FireProtectionBauble.java @@ -0,0 +1,120 @@ +package gtPlusPlus.core.item.bauble; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.lang.reflect.Field; +import java.util.List; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; + +import baubles.api.BaubleType; +import cpw.mods.fml.common.registry.GameRegistry; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.util.reflect.ReflectionUtils; +import gtPlusPlus.preloader.CORE_Preloader; + +public class FireProtectionBauble extends BaseBauble { + + private static Field isImmuneToFire; + + static { + isImmuneToFire = ReflectionUtils + .getField(Entity.class, !CORE_Preloader.DEV_ENVIRONMENT ? "func_70045_F" : "isImmuneToFire"); + } + + public static boolean fireImmune(Entity aEntity) { + return aEntity.isImmuneToFire(); + } + + public static boolean setEntityImmuneToFire(Entity aEntity, boolean aImmune) { + try { + return ReflectionUtils.setField(aEntity, isImmuneToFire, aImmune); + } catch (Throwable t) {} + return false; + } + + public FireProtectionBauble() { + super(BaubleType.RING); + String aUnlocalName = "GTPP.bauble.fireprotection.0" + ".name"; + this.setUnlocalizedName(aUnlocalName); + this.setTextureName(GTPlusPlus.ID + ":" + getTextureNameForBauble()); + this.setMaxDamage(100); + this.setMaxStackSize(1); + this.setNoRepair(); + this.setCreativeTab(AddToCreativeTab.tabMachines); + if (GameRegistry.findItem(GTPlusPlus.ID, aUnlocalName) == null) { + GameRegistry.registerItem(this, aUnlocalName); + } + } + + @Override + public void onUpdate(final ItemStack itemStack, final World worldObj, final Entity player, final int p_77663_4_, + final boolean p_77663_5_) { + super.onUpdate(itemStack, worldObj, player, p_77663_4_, p_77663_5_); + } + + @Override + public String getItemStackDisplayName(final ItemStack p_77653_1_) { + return (EnumChatFormatting.DARK_RED + super.getItemStackDisplayName(p_77653_1_) + EnumChatFormatting.GRAY); + } + + @Override + public boolean showDurabilityBar(final ItemStack stack) { + return false; + } + + @Override + public void addInformation(final ItemStack stack, final EntityPlayer aPlayer, final List list, final boolean bool) { + super.addInformation(stack, aPlayer, list, bool); + } + + @Override + public boolean canEquip(final ItemStack arg0, final EntityLivingBase arg1) { + return true; + } + + @Override + public boolean canUnequip(final ItemStack arg0, final EntityLivingBase arg1) { + return true; + } + + @Override + public void onEquipped(final ItemStack arg0, final EntityLivingBase aPlayer) {} + + @Override + public void onUnequipped(final ItemStack arg0, final EntityLivingBase aPlayer) { + if (!aPlayer.worldObj.isRemote) { + if (aPlayer instanceof EntityPlayer bPlayer) { + if (bPlayer.isPotionActive(Potion.fireResistance)) { + bPlayer.removePotionEffect(Potion.fireResistance.id); + } + setEntityImmuneToFire(bPlayer, false); + } + } + } + + @Override + public void onWornTick(final ItemStack aBaubleStack, final EntityLivingBase aPlayer) { + if (!aPlayer.worldObj.isRemote) { + if (aPlayer instanceof EntityPlayer bPlayer) { + if (!fireImmune(bPlayer)) { + setEntityImmuneToFire(bPlayer, true); + } + if (!bPlayer.isPotionActive(Potion.fireResistance)) { + bPlayer.addPotionEffect(new PotionEffect(Potion.fireResistance.id, 100, 4)); + } + } + } + } + + public String getTextureNameForBauble() { + return "baubles/itemFireProtectGlovesBetter"; + } +} diff --git a/src/main/java/gtPlusPlus/core/item/chemistry/AgriculturalChem.java b/src/main/java/gtPlusPlus/core/item/chemistry/AgriculturalChem.java new file mode 100644 index 0000000000..e14d9f7f08 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/chemistry/AgriculturalChem.java @@ -0,0 +1,667 @@ +package gtPlusPlus.core.item.chemistry; + +import static gregtech.api.enums.Mods.BiomesOPlenty; +import static gregtech.api.enums.Mods.Forestry; +import static gregtech.api.enums.Mods.TinkerConstruct; +import static gregtech.api.recipe.RecipeMaps.centrifugeRecipes; +import static gregtech.api.recipe.RecipeMaps.compressorRecipes; +import static gregtech.api.recipe.RecipeMaps.mixerRecipes; +import static gregtech.api.util.GT_RecipeBuilder.SECONDS; +import static gregtech.api.util.GT_RecipeConstants.UniversalChemical; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.init.Blocks; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.oredict.OreDictionary; + +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.TierEU; +import gregtech.api.util.GT_OreDictUnificator; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.api.objects.minecraft.ItemPackage; +import gtPlusPlus.core.item.circuit.GTPP_IntegratedCircuit_Item; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.recipe.common.CI; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.reflect.ReflectionUtils; +import gtPlusPlus.plugin.agrichem.BioRecipes; +import gtPlusPlus.plugin.agrichem.item.algae.ItemAgrichemBase; +import gtPlusPlus.plugin.agrichem.item.algae.ItemAlgaeBase; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; + +public class AgriculturalChem extends ItemPackage { + + private static boolean aBOP; + private static boolean aTiCon; + + private static AutoMap<FluidStack> mBloodFluids = new AutoMap<>(); + + /** + * Fluids + */ + + // Poop Juice + public static Fluid PoopJuice; + // Manure Slurry + public static Fluid ManureSlurry; + // Fertile Manure Slurry + public static Fluid FertileManureSlurry; + // Blood + public static Fluid CustomBlood; + // Red Mud + public static Fluid RedMud; + /** + * Items + */ + + // Manure Byproducts + public static Item dustManureByproducts; + // Organic Fertilizer + public static Item dustOrganicFertilizer; + // Dirt + public static Item dustDirt; + + // Poop Juice + // vv - Centrifuge + // Manure Slurry && Manure Byproducts -> (Elements) Centrifuge to several tiny + // piles + // vv - Chem Reactor - Add Peat, Meat + // Organic Fertilizer + // vv - Dehydrate + // Fertilizer + + // Poop Juice + // vv - Mixer - Add Blood, Bone, Meat (1000L Poo, 200L Blood, x2 Bone, x3 Meat) + // Fertile Manure Slurry + // vv - Chem Reactor - Add Peat x1.5 + // Organic Fertilizer x3 + // vv - Dehydrate + // Fertilizer + + public static Item mAlgae; + public static Item mBioCircuit; + public static Item mAgrichemItem1; + + /* + * 0 - Algae Biomass 1 - Green Algae Biomass 2 - Brown Algae Biomass 3 - Golden-Brown Algae Biomass 4 - Red Algae + * Biomass 5 - Cellulose Fiber 6 - Golden-Brown Cellulose Fiber 7 - Red Cellulose Fiber 8 - Compost 9 - Wood Pellet + * 10 - Wood Brick 11 - Cellulose Pulp 12 - Raw Bio Resin 13 - Catalyst Carrier 14 - Green Metal Catalyst 15 - + * Alginic Acid 16 - Alumina 17 - Aluminium Pellet 18 - Sodium Aluminate 19 - Sodium Hydroxide // Exists in Newer GT + * 20 - Sodium Carbonate 21 - Lithium Chloride 22 - Pellet Mold 23 - Clean Aluminium Mix 24 - Pinecone + */ + + public static ItemStack mAlgaeBiosmass; + public static ItemStack mGreenAlgaeBiosmass; + public static ItemStack mBrownAlgaeBiosmass; + public static ItemStack mGoldenBrownAlgaeBiosmass; + public static ItemStack mRedAlgaeBiosmass; + public static ItemStack mCelluloseFiber; + public static ItemStack mGoldenBrownCelluloseFiber; + public static ItemStack mRedCelluloseFiber; + public static ItemStack mCompost; + public static ItemStack mWoodPellet; + public static ItemStack mWoodBrick; + public static ItemStack mCellulosePulp; + public static ItemStack mRawBioResin; + public static ItemStack mCatalystCarrier; + public static ItemStack mGreenCatalyst; + public static ItemStack mAlginicAcid; + public static ItemStack mAlumina; + public static ItemStack mAluminiumPellet; + public static ItemStack mSodiumAluminate; + public static ItemStack mSodiumHydroxide; + public static ItemStack mSodiumCarbonate; + public static ItemStack mLithiumChloride; + public static ItemStack mPelletMold; + public static ItemStack mCleanAluminiumMix; + public static ItemStack mPinecone; + public static ItemStack mCrushedPine; + + @Override + public void items() { + // Nitrogen, Ammonium Nitrate, Phosphates, Calcium, Copper, Carbon + dustManureByproducts = ItemUtils.generateSpecialUseDusts( + "ManureByproducts", + "Manure Byproduct", + "(N2H4O3)N2P2Ca3CuC8", + Utils.rgbtoHexValue(110, 75, 25))[0]; + + // Basically Guano + dustOrganicFertilizer = ItemUtils.generateSpecialUseDusts( + "OrganicFertilizer", + "Organic Fertilizer", + "Ca5(PO4)3(OH)", + Utils.rgbtoHexValue(240, 240, 240))[0]; + + // Dirt Dust :) + dustDirt = ItemUtils.generateSpecialUseDusts("Dirt", "Dried Earth", Utils.rgbtoHexValue(65, 50, 15))[0]; + + mAlgae = new ItemAlgaeBase(); + mAgrichemItem1 = new ItemAgrichemBase(); + mBioCircuit = new GTPP_IntegratedCircuit_Item("BioRecipeSelector", "bioscience/BioCircuit"); + GregtechItemList.Circuit_BioRecipeSelector.set(mBioCircuit); + + mAlgaeBiosmass = ItemUtils.simpleMetaStack(mAgrichemItem1, 0, 1); + mGreenAlgaeBiosmass = ItemUtils.simpleMetaStack(mAgrichemItem1, 1, 1); + mBrownAlgaeBiosmass = ItemUtils.simpleMetaStack(mAgrichemItem1, 2, 1); + mGoldenBrownAlgaeBiosmass = ItemUtils.simpleMetaStack(mAgrichemItem1, 3, 1); + mRedAlgaeBiosmass = ItemUtils.simpleMetaStack(mAgrichemItem1, 4, 1); + mCelluloseFiber = ItemUtils.simpleMetaStack(mAgrichemItem1, 5, 1); + mGoldenBrownCelluloseFiber = ItemUtils.simpleMetaStack(mAgrichemItem1, 6, 1); + mRedCelluloseFiber = ItemUtils.simpleMetaStack(mAgrichemItem1, 7, 1); + mCompost = ItemUtils.simpleMetaStack(mAgrichemItem1, 8, 1); + mWoodPellet = ItemUtils.simpleMetaStack(mAgrichemItem1, 9, 1); + mWoodBrick = ItemUtils.simpleMetaStack(mAgrichemItem1, 10, 1); + mCellulosePulp = ItemUtils.simpleMetaStack(mAgrichemItem1, 11, 1); + mRawBioResin = ItemUtils.simpleMetaStack(mAgrichemItem1, 12, 1); + mCatalystCarrier = ItemUtils.simpleMetaStack(mAgrichemItem1, 13, 1); + mGreenCatalyst = ItemUtils.simpleMetaStack(mAgrichemItem1, 14, 1); + mAlginicAcid = ItemUtils.simpleMetaStack(mAgrichemItem1, 15, 1); + mAlumina = ItemUtils.simpleMetaStack(mAgrichemItem1, 16, 1); + mAluminiumPellet = ItemUtils.simpleMetaStack(mAgrichemItem1, 17, 1); + mSodiumAluminate = ItemUtils.simpleMetaStack(mAgrichemItem1, 18, 1); + + /* + * If It exists, don't add a new one. + */ + if (OreDictionary.doesOreNameExist("dustSodiumHydroxide_GT5U") + || OreDictionary.doesOreNameExist("dustSodiumHydroxide")) { + List<ItemStack> aTest = OreDictionary.getOres("dustSodiumHydroxide", false); + ItemStack aTestStack; + if (aTest.isEmpty()) { + aTest = OreDictionary.getOres("dustSodiumHydroxide_GT5U", false); + if (aTest.isEmpty()) { + aTestStack = ItemUtils.simpleMetaStack(mAgrichemItem1, 19, 1); + } else { + aTestStack = aTest.get(0); + } + } else { + aTestStack = aTest.get(0); + } + mSodiumHydroxide = aTestStack; + } else { + mSodiumHydroxide = ItemUtils.simpleMetaStack(mAgrichemItem1, 19, 1); + } + mSodiumCarbonate = ItemUtils.simpleMetaStack(mAgrichemItem1, 20, 1); + mLithiumChloride = ItemUtils.simpleMetaStack(mAgrichemItem1, 21, 1); + mPelletMold = ItemUtils.simpleMetaStack(mAgrichemItem1, 22, 1); + mCleanAluminiumMix = ItemUtils.simpleMetaStack(mAgrichemItem1, 23, 1); + mPinecone = ItemUtils.simpleMetaStack(mAgrichemItem1, 24, 1); + mCrushedPine = ItemUtils.simpleMetaStack(mAgrichemItem1, 25, 1); + + ItemUtils.addItemToOreDictionary(mGreenAlgaeBiosmass, "biomassGreenAlgae"); + ItemUtils.addItemToOreDictionary(mBrownAlgaeBiosmass, "biomassBrownAlgae"); + ItemUtils.addItemToOreDictionary(mGoldenBrownAlgaeBiosmass, "biomassGoldenBrownAlgae"); + ItemUtils.addItemToOreDictionary(mRedAlgaeBiosmass, "biomassRedAlgae"); + + ItemUtils.addItemToOreDictionary(mCelluloseFiber, "fiberCellulose"); + ItemUtils.addItemToOreDictionary(mGoldenBrownCelluloseFiber, "fiberCellulose"); + ItemUtils.addItemToOreDictionary(mGoldenBrownCelluloseFiber, "fiberGoldenBrownCellulose"); + ItemUtils.addItemToOreDictionary(mRedCelluloseFiber, "fiberCellulose"); + ItemUtils.addItemToOreDictionary(mRedCelluloseFiber, "fiberRedCellulose"); + + ItemUtils.addItemToOreDictionary(mWoodPellet, "pelletWood"); + ItemUtils.addItemToOreDictionary(mWoodBrick, "brickWood"); + ItemUtils.addItemToOreDictionary(mCellulosePulp, "pulpCellulose"); + + ItemUtils.addItemToOreDictionary(mCatalystCarrier, "catalystEmpty"); + ItemUtils.addItemToOreDictionary(mGreenCatalyst, "catalystAluminiumSilver"); + ItemUtils.addItemToOreDictionary(mAlginicAcid, "dustAlginicAcid"); + ItemUtils.addItemToOreDictionary(mAlumina, "dustAlumina"); + ItemUtils.addItemToOreDictionary(mAluminiumPellet, "pelletAluminium"); + + ItemUtils.addItemToOreDictionary(mSodiumAluminate, "dustSodiumAluminate"); + ItemUtils.addItemToOreDictionary(mSodiumHydroxide, "dustSodiumHydroxide"); + ItemUtils.addItemToOreDictionary(mSodiumCarbonate, "dustSodiumCarbonate"); + ItemUtils.addItemToOreDictionary(mLithiumChloride, "dustLithiumChloride"); + ItemUtils.addItemToOreDictionary(mPinecone, "pinecone"); + ItemUtils.addItemToOreDictionary(mCrushedPine, "crushedPineMaterial"); + + // Handle GT NaOH dusts + List<ItemStack> NaOHSmall = OreDictionary.getOres("dustSmallSodiumHydroxide_GT5U", false); + if (!NaOHSmall.isEmpty()) { + ItemUtils.addItemToOreDictionary(NaOHSmall.get(0), "dustSmallSodiumHydroxide"); + } + List<ItemStack> NaOHTiny = OreDictionary.getOres("dustTinySodiumHydroxide_GT5U", false); + if (!NaOHTiny.isEmpty()) { + ItemUtils.addItemToOreDictionary(NaOHTiny.get(0), "dustTinySodiumHydroxide"); + } + } + + @Override + public void blocks() { + // None yet + } + + @Override + public void fluids() { + // Sewage + PoopJuice = FluidUtils.generateFluidNonMolten( + "raw.waste", + "Raw Animal Waste", + 32 + 175, + new short[] { 100, 70, 30, 100 }, + null, + null, + 0, + true); + + // Sewage + ManureSlurry = FluidUtils.generateFluidNonMolten( + "manure.slurry", + "Manure Slurry", + 39 + 175, + new short[] { 75, 45, 15, 100 }, + null, + null, + 0, + true); + + // Sewage + FertileManureSlurry = FluidUtils.generateFluidNonMolten( + "fertile.manure.slurry", + "Fertile Manure Slurry", + 45 + 175, + new short[] { 65, 50, 15, 100 }, + null, + null, + 0, + true); + + RedMud = FluidUtils.generateFluidNoPrefix( + "mud.red.slurry", + "Red Mud Slurry", + 32 + 175, + new short[] { 180, 35, 25, 100 }, + true); + } + + public AgriculturalChem() { + super(); + + aBOP = BiomesOPlenty.isModLoaded(); + aTiCon = TinkerConstruct.isModLoaded(); + + Logger.INFO("Adding Agrochemical content"); + + FluidStack aBlood; + if (aBOP) { + aBlood = FluidUtils.getFluidStack("hell_blood", 100); + if (aBlood != null) { + Logger.INFO("Found Biome's o Plenty, enabled Blood support."); + CustomBlood = aBlood.getFluid(); + mBloodFluids.put(aBlood); + } + } + + if (aTiCon) { + aBlood = FluidUtils.getFluidStack("blood", 100); + if (aBlood != null) { + Logger.INFO("Found Tinker's Construct, enabled Blood support."); + CustomBlood = aBlood.getFluid(); + mBloodFluids.put(FluidUtils.getFluidStack("blood", 100)); + } + } + + // Handle Blood Internally, Create if required. + if (mBloodFluids.isEmpty() || CustomBlood == null) { + Logger.INFO( + "Did not find any existing Blood fluids. Trying to wildcard search the fluid registry, then generate our own if that fails."); + FluidStack aTempBlood = FluidUtils.getWildcardFluidStack("blood", 100); + if (aTempBlood != null) { + CustomBlood = aTempBlood.getFluid(); + } else { + aTempBlood = FluidUtils.getWildcardFluidStack("hell_blood", 100); + if (aTempBlood == null) { + CustomBlood = FluidUtils + .generateFluidNoPrefix("blood", "Blood", 32 + 175, new short[] { 175, 25, 25, 100 }, true); + } else { + CustomBlood = aTempBlood.getFluid(); + } + } + Logger.INFO("Using " + CustomBlood.getName()); + mBloodFluids.put(FluidUtils.getFluidStack(CustomBlood, 100)); + } + } + + private static final AutoMap<ItemStack> mMeats = new AutoMap<>(); + private static final AutoMap<ItemStack> mFish = new AutoMap<>(); + private static final AutoMap<ItemStack> mFruits = new AutoMap<>(); + private static final AutoMap<ItemStack> mVege = new AutoMap<>(); + private static final AutoMap<ItemStack> mNuts = new AutoMap<>(); + private static final AutoMap<ItemStack> mSeeds = new AutoMap<>(); + private static final AutoMap<ItemStack> mPeat = new AutoMap<>(); + private static final AutoMap<ItemStack> mBones = new AutoMap<>(); + private static final AutoMap<ItemStack> mBoneMeal = new AutoMap<>(); + + private static final AutoMap<ItemStack> mList_Master_Meats = new AutoMap<>(); + private static final AutoMap<ItemStack> mList_Master_FruitVege = new AutoMap<>(); + private static final AutoMap<ItemStack> mList_Master_Seeds = new AutoMap<>(); + private static final AutoMap<ItemStack> mList_Master_Bones = new AutoMap<>(); + + private static void processAllOreDict() { + processOreDict("listAllmeatraw", mMeats); + processOreDict("listAllfishraw", mFish); + processOreDict("listAllfruit", mFruits); + processOreDict("listAllVeggie", mVege); + processOreDict("listAllnut", mNuts); + processOreDict("listAllSeed", mSeeds); + processOreDict("brickPeat", mPeat); + processOreDict("bone", mBones); + processOreDict("dustBone", mBoneMeal); + // Just make a mega list, makes life easier. + if (!mMeats.isEmpty()) { + for (ItemStack g : mMeats) { + mList_Master_Meats.put(g); + } + } + if (!mFish.isEmpty()) { + for (ItemStack g : mFish) { + mList_Master_Meats.put(g); + } + } + if (!mFruits.isEmpty()) { + for (ItemStack g : mFruits) { + mList_Master_FruitVege.put(g); + } + } + if (!mVege.isEmpty()) { + for (ItemStack g : mVege) { + mList_Master_FruitVege.put(g); + } + } + if (!mNuts.isEmpty()) { + for (ItemStack g : mNuts) { + mList_Master_FruitVege.put(g); + } + } + if (!mSeeds.isEmpty()) { + for (ItemStack g : mSeeds) { + mList_Master_Seeds.put(g); + } + } + if (!mBoneMeal.isEmpty()) { + for (ItemStack g : mBoneMeal) { + mList_Master_Bones.put(g); + } + } + if (!mBones.isEmpty()) { + for (ItemStack g : mBones) { + mList_Master_Bones.put(g); + } + } + } + + private static void processOreDict(String aOreName, AutoMap<ItemStack> aMap) { + ArrayList<ItemStack> aTemp = OreDictionary.getOres(aOreName); + if (!aTemp.isEmpty()) { + for (ItemStack stack : aTemp) { + aMap.put(stack); + } + } + } + + private static void addBasicSlurryRecipes() { + + ItemStack aManureByprod1 = ItemUtils.getItemStackOfAmountFromOreDict("dustTinyManureByproducts", 1); + ItemStack aManureByprod2 = ItemUtils.getItemStackOfAmountFromOreDict("dustSmallManureByproducts", 1); + ItemStack aDirtDust = ItemUtils.getSimpleStack(dustDirt, 1); + + // Poop Juice to Basic Slurry + GT_Values.RA.stdBuilder() + .itemInputs(GT_Utility.getIntegratedCircuit(10)) + .itemOutputs(aDirtDust, aDirtDust, aManureByprod1, aManureByprod1, aManureByprod1, aManureByprod1) + .outputChances(2000, 2000, 500, 500, 250, 250) + .fluidInputs(FluidUtils.getFluidStack(PoopJuice, 1000)) + .fluidOutputs(FluidUtils.getFluidStack(ManureSlurry, 250)) + .duration(10 * SECONDS) + .eut(TierEU.RECIPE_LV) + .addTo(centrifugeRecipes); + + // More Efficient way to get byproducts, less Slurry + GT_Values.RA.stdBuilder() + .itemInputs(GT_Utility.getIntegratedCircuit(20)) + .itemOutputs(aDirtDust, aDirtDust, aManureByprod1, aManureByprod1, aManureByprod2, aManureByprod2) + .outputChances(4000, 3000, 1250, 1250, 675, 675) + .fluidInputs(FluidUtils.getFluidStack(PoopJuice, 1000)) + .fluidOutputs(FluidUtils.getFluidStack(ManureSlurry, 50)) + .duration(20 * SECONDS) + .eut(TierEU.RECIPE_MV / 2) + .addTo(centrifugeRecipes); + } + + private static void addAdvancedSlurryRecipes() { + + ItemStack aCircuit = GT_Utility.getIntegratedCircuit(10); + ItemStack aBone; + ItemStack aMeat; + ItemStack aEmptyCells = Materials.Empty.getCells(2); + ItemStack aInputCells = ItemUtils.getItemStackOfAmountFromOreDict("cellRawAnimalWaste", 2); + FluidStack aOutput = FluidUtils.getFluidStack(FertileManureSlurry, 1000); + + for (FluidStack aBloodStack : mBloodFluids) { + for (ItemStack aBoneStack : mList_Master_Bones) { + aBone = ItemUtils.getSimpleStack(aBoneStack, 2); + for (ItemStack aMeatStack : mList_Master_Meats) { + aMeat = ItemUtils.getSimpleStack(aMeatStack, 5); + // Poop Juice to Fertile Slurry + GT_Values.RA.stdBuilder() + .itemInputs(aCircuit, aBone, aMeat, aInputCells) + .itemOutputs(aEmptyCells) + .fluidInputs(aBloodStack) + .fluidOutputs(aOutput) + .duration(8 * SECONDS) + .eut(TierEU.RECIPE_MV / 2) + .addTo(mixerRecipes); + } + } + } + } + + private static void addBasicOrganiseFertRecipes() { + FluidStack aInputFluid = FluidUtils.getFluidStack(ManureSlurry, 1000); + ItemStack aOutputDust = ItemUtils.getSimpleStack(dustOrganicFertilizer, 3); + ItemStack aPeat; + ItemStack aMeat; + for (ItemStack aPeatStack : mPeat) { + aPeat = ItemUtils.getSimpleStack(aPeatStack, 3); + for (ItemStack aMeatStack : mList_Master_Meats) { + aMeat = ItemUtils.getSimpleStack(aMeatStack, 5); + GT_Values.RA.stdBuilder() + .itemInputs(aPeat, aMeat) + .itemOutputs(aOutputDust) + .fluidInputs(aInputFluid) + .duration(20 * SECONDS) + .eut(TierEU.RECIPE_MV) + .addTo(UniversalChemical); + } + aPeat = ItemUtils.getSimpleStack(aPeatStack, 2); + for (ItemStack aMeatStack : mList_Master_FruitVege) { + aMeat = ItemUtils.getSimpleStack(aMeatStack, 9); + GT_Values.RA.stdBuilder() + .itemInputs(aPeat, aMeat) + .itemOutputs(aOutputDust) + .fluidInputs(aInputFluid) + .duration(10 * SECONDS) + .eut(TierEU.RECIPE_MV) + .addTo(UniversalChemical); + } + } + } + + private static void addAdvancedOrganiseFertRecipes() { + FluidStack aInputFluid = FluidUtils.getFluidStack(FertileManureSlurry, 1000); + ItemStack aOutputDust = ItemUtils.getSimpleStack(dustOrganicFertilizer, 7); + ItemStack aPeat; + ItemStack aMeat; + for (ItemStack aPeatStack : mPeat) { + aPeat = ItemUtils.getSimpleStack(aPeatStack, 5); + for (ItemStack aMeatStack : mList_Master_Meats) { + aMeat = ItemUtils.getSimpleStack(aMeatStack, 7); + GT_Values.RA.stdBuilder() + .itemInputs(aPeat, aMeat) + .itemOutputs(aOutputDust) + .fluidInputs(aInputFluid) + .duration(10 * SECONDS) + .eut(140) + .addTo(UniversalChemical); + } + aPeat = ItemUtils.getSimpleStack(aPeatStack, 3); + for (ItemStack aMeatStack : mList_Master_FruitVege) { + aMeat = ItemUtils.getSimpleStack(aMeatStack, 12); + GT_Values.RA.stdBuilder() + .itemInputs(aPeat, aMeat) + .itemOutputs(aOutputDust) + .fluidInputs(aInputFluid) + .duration(5 * SECONDS) + .eut(140) + .addTo(UniversalChemical); + } + } + } + + public static ItemStack aFertForestry; + public static ItemStack aFertIC2; + + private static void addMiscRecipes() { + + ItemStack aDustOrganicFert = ItemUtils.getSimpleStack(dustOrganicFertilizer, 1); + ItemStack aManureByprod = ItemUtils.getSimpleStack(dustManureByproducts, 1); + + // Dehydrate Organise Fert to Normal Fert. + + /* + * Forestry Support + */ + if (Forestry.isModLoaded()) { + Field aItemField = ReflectionUtils + .getField(ReflectionUtils.getClass("forestry.plugins.PluginCore"), "items"); + try { + Object aItemRegInstance = aItemField != null ? aItemField.get(aItemField) : null; + if (aItemRegInstance != null) { + Field aFertField = ReflectionUtils.getField(aItemRegInstance.getClass(), "fertilizerCompound"); + Object aItemInstance = aFertField.get(aItemRegInstance); + if (aItemInstance instanceof Item aForestryFert) { + aFertForestry = ItemUtils.getSimpleStack((Item) aItemInstance); + CORE.RA.addDehydratorRecipe( + new ItemStack[] { CI.getNumberedCircuit(11), + ItemUtils.getSimpleStack(aDustOrganicFert, 4) }, + null, + null, + new ItemStack[] { ItemUtils.getSimpleStack(aForestryFert, 3), aManureByprod, + aManureByprod }, + new int[] { 10000, 2000, 2000 }, + 20 * 20, + 240); + } + } + } catch (IllegalArgumentException | IllegalAccessException e) { + + } + } + + /* + * IC2 Support + */ + aFertIC2 = ItemUtils.getItemStackFromFQRN("IC2:itemFertilizer", 1); + CORE.RA.addDehydratorRecipe( + new ItemStack[] { CI.getNumberedCircuit(12), ItemUtils.getSimpleStack(aDustOrganicFert, 4) }, + null, + null, + new ItemStack[] { ItemUtils.getItemStackFromFQRN("IC2:itemFertilizer", 3), aManureByprod, aManureByprod }, + new int[] { 10000, 2000, 2000 }, + 20 * 20, + 240); + + // Dirt Production + GT_Values.RA.stdBuilder() + .itemInputs(ItemUtils.getSimpleStack(dustDirt, 9)) + .itemOutputs(ItemUtils.getSimpleStack(Blocks.dirt)) + .duration(2 * SECONDS) + .eut(8) + .addTo(compressorRecipes); + + // Centrifuge Byproducts + + // Ammonium Nitrate, Phosphates, Calcium, Copper, Carbon + GT_Values.RA.stdBuilder() + .itemInputs(ItemUtils.getSimpleStack(aManureByprod, 4), GT_Utility.getIntegratedCircuit(20)) + .itemOutputs( + GT_OreDictUnificator.get(OrePrefixes.dustSmall, Materials.Phosphorus, 2L), + GT_OreDictUnificator.get(OrePrefixes.dustSmall, Materials.Calcium, 2L), + GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.Copper, 1L), + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Carbon, 1L), + ItemUtils.getSimpleStack(dustDirt, 1), + ItemUtils.getItemStackOfAmountFromOreDict("dustTinyAmmoniumNitrate", 1)) + .outputChances(2500, 2500, 750, 1000, 5000, 250) + .fluidInputs(Materials.SulfuricAcid.getFluid(250)) + .fluidOutputs(FluidUtils.getFluidStack("sulfuricapatite", 50)) + .duration(20 * SECONDS) + .eut(TierEU.RECIPE_MV / 2) + .addTo(centrifugeRecipes); + + // Add Fuel Usages + CORE.RA.addSemifluidFuel(FluidUtils.getFluidStack(PoopJuice, 1000), 12); + CORE.RA.addSemifluidFuel(FluidUtils.getFluidStack(ManureSlurry, 1000), 24); + CORE.RA.addSemifluidFuel(FluidUtils.getFluidStack(FertileManureSlurry, 1000), 32); + + // Red Slurry / Tailings Processing + GT_Values.RA.stdBuilder() + .itemInputs(CI.getNumberedBioCircuit(10)) + .itemOutputs( + GT_OreDictUnificator.get(OrePrefixes.dustSmall, Materials.Iron, 1L), + GT_OreDictUnificator.get(OrePrefixes.dustSmall, Materials.Copper, 1L), + GT_OreDictUnificator.get(OrePrefixes.dustSmall, Materials.Tin, 1L), + GT_OreDictUnificator.get(OrePrefixes.dustSmall, Materials.Sulfur, 1L), + GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.Nickel, 1L), + GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.Lead, 1L)) + .outputChances(3000, 3000, 2000, 2000, 1000, 1000) + .fluidInputs(FluidUtils.getFluidStack(AgriculturalChem.RedMud, 1000)) + .fluidOutputs(Materials.Water.getFluid(500)) + .duration(30 * SECONDS) + .eut(TierEU.RECIPE_LV) + .addTo(centrifugeRecipes); + } + + @Override + public String errorMessage() { + return "Failed to generate recipes for AgroChem."; + } + + @Override + public boolean generateRecipes() { + if (mBloodFluids.isEmpty()) { + Logger.INFO("Could not find, nor create Blood fluid. Unable to add recipes."); + return false; + } + + // Organise OreDict + processAllOreDict(); + + // Slurry Production + addBasicSlurryRecipes(); + addAdvancedSlurryRecipes(); + + // Organic Fert. Production + addBasicOrganiseFertRecipes(); + addAdvancedOrganiseFertRecipes(); + + addMiscRecipes(); + + BioRecipes.init(); + + return true; + } +} diff --git a/src/main/java/gtPlusPlus/core/item/chemistry/CoalTar.java b/src/main/java/gtPlusPlus/core/item/chemistry/CoalTar.java new file mode 100644 index 0000000000..1fafbb5088 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/chemistry/CoalTar.java @@ -0,0 +1,319 @@ +package gtPlusPlus.core.item.chemistry; + +import static gregtech.api.recipe.RecipeMaps.distillationTowerRecipes; +import static gregtech.api.recipe.RecipeMaps.distilleryRecipes; +import static gregtech.api.util.GT_RecipeBuilder.SECONDS; +import static gregtech.api.util.GT_RecipeConstants.UniversalChemical; +import static gtPlusPlus.api.recipe.GTPPRecipeMaps.chemicalDehydratorRecipes; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; + +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.util.GT_OreDictUnificator; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.minecraft.ItemPackage; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.recipe.common.CI; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.reflect.AddGregtechRecipe; + +public class CoalTar extends ItemPackage { + + public static Fluid Coal_Gas; + public static Fluid Coal_Oil; + public static Fluid Ethylene; + public static Fluid Ethylbenzene; + public static Fluid Anthracene; + public static Fluid Toluene; + public static Fluid Coal_Tar; + public static Fluid Coal_Tar_Oil; + public static Fluid Sulfuric_Coal_Tar_Oil; + public static Fluid Naphthalene; + + public static void recipeCreateEthylene() { + + FluidStack bioEth1 = FluidUtils.getFluidStack("fluid.bioethanol", 1000); + FluidStack bioEth2 = FluidUtils.getFluidStack("bioethanol", 1000); + + // C2H6O = C2H4 + H2O + if (bioEth1 != null) { + CORE.RA.addDehydratorRecipe( + new ItemStack[] { CI.getNumberedBioCircuit(17), + ItemUtils.getItemStackOfAmountFromOreDict("cellEmpty", 1) }, + bioEth1, + FluidUtils.getWater(1000), + new ItemStack[] { ItemUtils.getItemStackOfAmountFromOreDict("cellEthylene", 1) }, + new int[] { 10000 }, + 120 * 20, + 80); + } + + if (bioEth2 != null) { + CORE.RA.addDehydratorRecipe( + new ItemStack[] { CI.getNumberedBioCircuit(18), + ItemUtils.getItemStackOfAmountFromOreDict("cellEmpty", 1) }, + bioEth2, + FluidUtils.getWater(1000), + new ItemStack[] { ItemUtils.getItemStackOfAmountFromOreDict("cellEthylene", 1) }, + new int[] { 10000 }, + 120 * 20, + 80); + } + } + + public static void recipeCreateBenzene() { + // C7H8 + 2H = CH4 + C6H6 + GT_Values.RA.stdBuilder() + .itemInputs(Materials.Toluene.getCells(1)) + .itemOutputs(Materials.Benzene.getCells(1)) + .fluidInputs(Materials.Hydrogen.getGas(2000)) + .fluidOutputs(Materials.Methane.getGas(1000)) + .duration(10 * SECONDS) + .eut(90) + .noOptimize() + .addTo(chemicalDehydratorRecipes); + } + + public static void recipeCreateEthylbenzene() { + // C2H4 + C6H6 = C8H10 + GT_Values.RA.addChemicalRecipe( + ItemUtils.getItemStackOfAmountFromOreDict("cellEthylene", 2), + ItemUtils.getGregtechCircuit(1), + FluidUtils.getFluidStack("benzene", 2000), + FluidUtils.getFluidStack("fluid.ethylbenzene", 2000), + ItemUtils.getItemStackOfAmountFromOreDict("cellEmpty", 2), + 300); + + GT_Values.RA.addChemicalRecipe( + ItemUtils.getItemStackOfAmountFromOreDict("cellBenzene", 2), + ItemUtils.getGregtechCircuit(1), + FluidUtils.getFluidStack("ethylene", 2000), + FluidUtils.getFluidStack("fluid.ethylbenzene", 2000), + ItemUtils.getItemStackOfAmountFromOreDict("cellEmpty", 2), + 300); + } + + public static void recipeCoalToCoalTar() { + // Charcoal + AddGregtechRecipe.addCokeAndPyrolyseRecipes( + GT_OreDictUnificator.get(OrePrefixes.gem, Materials.Charcoal, 32L), + 8, + GT_Values.NF, + ItemUtils.getItemStackOfAmountFromOreDict("dustSmallDirt", 2), + FluidUtils.getFluidStack("fluid.coaltar", 800), + 15, + 120); + // Lignite + AddGregtechRecipe.addCokeAndPyrolyseRecipes( + GT_OreDictUnificator.get(OrePrefixes.gem, Materials.Lignite, 16L), + 8, + GT_Values.NF, + ItemUtils.getItemStackOfAmountFromOreDict("dustSmallDarkAsh", 2), + FluidUtils.getFluidStack("fluid.coaltar", 800), + 45, + 60); + + // Coal + AddGregtechRecipe.addCokeAndPyrolyseRecipes( + GT_OreDictUnificator.get(OrePrefixes.gem, Materials.Coal, 12L), + 8, + GT_Values.NF, + ItemUtils.getItemStackOfAmountFromOreDict("dustSmallDarkAsh", 2), + FluidUtils.getFluidStack("fluid.coaltar", 2200), + 30, + 120); + + // Coke + AddGregtechRecipe.addCokeAndPyrolyseRecipes( + ItemUtils.getItemStackOfAmountFromOreDict("fuelCoke", 8), + 8, + GT_Values.NF, + ItemUtils.getItemStackOfAmountFromOreDict("dustSmallAsh", 3), + FluidUtils.getFluidStack("fluid.coaltar", 3400), + 15, + 240); + } + + private static void recipeCoalTarToCoalTarOil() { + // v - Distill (60% Tar oil/15% Naphtha/20% Ethylbenzene/5% Anthracene) +60% Kerosene + // Create Coal Tar Oil + + FluidStack[] distOutputs = new FluidStack[] { FluidUtils.getFluidStack("fluid.coaltaroil", 600), + FluidUtils.getFluidStack("liquid_naphtha", 150), FluidUtils.getFluidStack("fluid.ethylbenzene", 200), + FluidUtils.getFluidStack("fluid.anthracene", 50), FluidUtils.getFluidStack("fluid.kerosene", 600) }; + for (int i = 0; i < distOutputs.length; i++) { + GT_Values.RA.stdBuilder() + .itemInputs(GT_Utility.getIntegratedCircuit(i + 1)) + .fluidInputs(FluidUtils.getFluidStack("fluid.coaltar", 1000)) + .fluidOutputs(distOutputs[i]) + .duration(30 * SECONDS) + .eut(64) + .addTo(distilleryRecipes); + } + GT_Values.RA.stdBuilder() + .fluidInputs(FluidUtils.getFluidStack("fluid.coaltar", 1000)) + .fluidOutputs(distOutputs) + .duration(15 * SECONDS) + .eut(256) + .addTo(distillationTowerRecipes); + } + + private static void recipeCoalTarOilToSulfuricOilToNaphthalene() { + // SulfuricCoalTarOil + GT_Values.RA.addChemicalRecipe( + ItemUtils.getItemStackOfAmountFromOreDict("cellCoalTarOil", 8), + ItemUtils.getItemStackOfAmountFromOreDict("cellSulfuricAcid", 8), + null, + null, + ItemUtils.getItemStackOfAmountFromOreDict("cellSulfuricCoalTarOil", 16), + 20 * 16); + GT_Values.RA.addDistilleryRecipe( + CI.getNumberedCircuit(6), // Circuit + FluidUtils.getFluidStack("fluid.sulfuriccoaltaroil", 1000), // aInput + FluidUtils.getFluidStack("fluid.naphthalene", 1000), // aOutput + 1200, // aDuration + 30, // aEUt + false // Hidden? + ); + } + + private static void recipeNaphthaleneToPhthalicAcid() { + // SulfuricCoalTarOil + GT_Values.RA.stdBuilder() + .itemInputs(Materials.Lithium.getDust(5)) + .fluidInputs(FluidUtils.getFluidStack(Naphthalene, 2000)) + .fluidOutputs(Materials.PhthalicAcid.getFluid(2500)) + .eut(30) + .duration(16 * SECONDS) + .noOptimize() + .addTo(UniversalChemical); + } + + private static void recipePhthalicAcidToPhthalicAnhydride() { + CORE.RA.addDehydratorRecipe( + new ItemStack[] { CI.getNumberedBioCircuit(15) }, + Materials.PhthalicAcid.getFluid(1000), + null, + new ItemStack[] { ItemUtils.getItemStackOfAmountFromOreDict("dustPhthalicAnhydride", 15) }, + new int[] { 10000 }, + 60 * 20, + 120); + } + + @Override + public String errorMessage() { + return "Bad Coal Science!"; + } + + @Override + public boolean generateRecipes() { + recipeCreateEthylene(); + recipeCreateBenzene(); + recipeCreateEthylbenzene(); + + recipeCoalToCoalTar(); + recipeCoalTarToCoalTarOil(); + recipeCoalTarOilToSulfuricOilToNaphthalene(); + recipeNaphthaleneToPhthalicAcid(); + recipePhthalicAcidToPhthalicAnhydride(); + + // Burn the coal gas! + GT_Values.RA.addFuel(ItemUtils.getItemStackOfAmountFromOreDict("cellCoalGas", 1), null, 96, 1); + CORE.RA.addSemifluidFuel(ItemUtils.getItemStackOfAmountFromOreDict("cellSulfuricCoalTarOil", 1), 64); + CORE.RA.addSemifluidFuel(ItemUtils.getItemStackOfAmountFromOreDict("cellCoalTarOil", 1), 32); + CORE.RA.addSemifluidFuel(ItemUtils.getItemStackOfAmountFromOreDict("cellCoalTar", 1), 16); + + return true; + } + + @Override + public void items() { + // v - Dehydrate at 180C+ + // Create Phthalic Anhydride + ItemUtils.generateSpecialUseDusts( + "PhthalicAnhydride", + "Phthalic Anhydride", + "C6H4(CO)2O", + Utils.rgbtoHexValue(175, 175, 175)); + + // Lithium Hydroperoxide - LiOH + H2O2 → LiOOH + 2 H2O + ItemUtils.generateSpecialUseDusts( + "LithiumHydroperoxide", + "Lithium Hydroperoxide", + "HLiO2", + Utils.rgbtoHexValue(125, 125, 125)); + // v - Dehydrate + // Lithium Peroxide - 2 LiOOH → Li2O2 + H2O2 + 2 H2O + } + + @Override + public void blocks() {} + + @Override + public void fluids() { + + // Create Coal Gas + Coal_Gas = FluidUtils + .generateFluidNonMolten("CoalGas", "Coal Gas", 500, new short[] { 48, 48, 48, 100 }, null, null); + // Ethanol + // v - Dehydrate cells to remove water + + // Create Ethylene + if (!FluidUtils.doesFluidExist("ethylene")) { + Ethylene = FluidUtils + .generateFluidNonMolten("ethylene", "Ethylene", -103, new short[] { 255, 255, 255, 100 }, null, null); + } else { + Ethylene = FluidUtils.getWildcardFluidStack("ethylene", 1) + .getFluid(); + } + + // Create Ethylbenzene - Ethylbenzene is produced in on a large scale by combining benzene and ethylene in an + // acid-catalyzed chemical reaction + // Use Chemical Reactor + Ethylbenzene = FluidUtils.generateFluidNonMolten( + "Ethylbenzene", + "Ethylbenzene", + 136, + new short[] { 255, 255, 255, 100 }, + null, + null); + // Create Anthracene + Anthracene = FluidUtils + .generateFluidNonMolten("Anthracene", "Anthracene", 340, new short[] { 255, 255, 255, 100 }, null, null); + // Toluene + if (!FluidUtils.doesFluidExist("liquid_toluene")) { + Toluene = FluidUtils + .generateFluidNonMolten("liquid_toluene", "Toluene", -95, new short[] { 140, 70, 20, 100 }, null, null); + } else { + Toluene = FluidUtils.getWildcardFluidStack("liquid_toluene", 1) + .getFluid(); + } + + // Create Coal Tar + Coal_Tar = FluidUtils + .generateFluidNonMolten("CoalTar", "Coal Tar", 450, new short[] { 32, 32, 32, 100 }, null, null); + // v - Distill (60% Tar oil/15% Naphtha/20% Ethylbenzene/5% Anthracene) + // Create Coal Tar Oil + Coal_Tar_Oil = FluidUtils + .generateFluidNonMolten("CoalTarOil", "Coal Tar Oil", 240, new short[] { 240, 240, 150, 100 }, null, null); + // v - Wash With Sulfuric Acid + // Create Sulfuric Coal Tar Oil + Sulfuric_Coal_Tar_Oil = FluidUtils.generateFluidNonMolten( + "SulfuricCoalTarOil", + "Sulfuric Coal Tar Oil", + 240, + new short[] { 250, 170, 12, 100 }, + null, + null); + // v - Distill (No loss, just time consuming) + // Create Naphthalene + Naphthalene = FluidUtils + .generateFluidNonMolten("Naphthalene", "Naphthalene", 115, new short[] { 210, 185, 135, 100 }, null, null); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/chemistry/GenericChem.java b/src/main/java/gtPlusPlus/core/item/chemistry/GenericChem.java new file mode 100644 index 0000000000..31ea030c64 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/chemistry/GenericChem.java @@ -0,0 +1,961 @@ +package gtPlusPlus.core.item.chemistry; + +import static gregtech.api.recipe.RecipeMaps.assemblerRecipes; +import static gregtech.api.recipe.RecipeMaps.blastFurnaceRecipes; +import static gregtech.api.util.GT_RecipeBuilder.MINUTES; +import static gregtech.api.util.GT_RecipeBuilder.SECONDS; +import static gregtech.api.util.GT_RecipeConstants.COIL_HEAT; +import static gregtech.api.util.GT_RecipeConstants.FUEL_TYPE; +import static gregtech.api.util.GT_RecipeConstants.FUEL_VALUE; +import static gtPlusPlus.api.recipe.GTPPRecipeMaps.chemicalDehydratorRecipes; + +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; + +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.ItemList; +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.TextureSet; +import gregtech.api.enums.TierEU; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_OreDictUnificator; +import gregtech.api.util.GT_RecipeConstants; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.minecraft.ItemPackage; +import gtPlusPlus.core.item.chemistry.general.ItemGenericChemBase; +import gtPlusPlus.core.item.circuit.GTPP_IntegratedCircuit_Item; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.material.ELEMENT; +import gtPlusPlus.core.material.MISC_MATERIALS; +import gtPlusPlus.core.material.Material; +import gtPlusPlus.core.material.MaterialGenerator; +import gtPlusPlus.core.material.MaterialStack; +import gtPlusPlus.core.material.NONMATERIAL; +import gtPlusPlus.core.material.state.MaterialState; +import gtPlusPlus.core.recipe.common.CI; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.plugin.agrichem.BioRecipes; +import gtPlusPlus.plugin.agrichem.block.AgrichemFluids; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; + +public class GenericChem extends ItemPackage { + + /** + * Materials + */ + + // Refined PTFE + public static final Material TEFLON = new Material( + "Teflon", + MaterialState.SOLID, + TextureSet.SET_SHINY, + new short[] { 75, 45, 75 }, + 330, + 640, + -1, + -1, + false, + null, + 0, + new MaterialStack(NONMATERIAL.PTFE, 75), + new MaterialStack(NONMATERIAL.PLASTIC, 15), + new MaterialStack(ELEMENT.getInstance().CARBON, 5), + new MaterialStack(ELEMENT.getInstance().SODIUM, 5)); + + /** + * Fluids + */ + public static Fluid Benzene; + + public static Fluid NitroBenzene; + public static Fluid Aniline; + public static Fluid Polyurethane; + public static Fluid Phenol; // https://en.wikipedia.org/wiki/Phenol#Uses + public static Fluid Cyclohexane; // https://en.wikipedia.org/wiki/Cyclohexane + public static Fluid Cyclohexanone; // https://en.wikipedia.org/wiki/Cyclohexanone + public static Fluid Cadaverine; // https://en.wikipedia.org/wiki/Cadaverine + public static Fluid Putrescine; // https://en.wikipedia.org/wiki/Putrescine + public static Fluid BoricAcid; + public static Fluid HydrochloricAcid; + + public static Fluid Ethylanthraquinone2; + public static Fluid Ethylanthrahydroquinone2; + public static Fluid Hydrogen_Peroxide; + public static Fluid Lithium_Peroxide; + public static Fluid Carbon_Disulfide; + + /** + * Items + */ + + // Phenol Byproducts + + public static ItemGenericChemBase mGenericChemItem1; + public static Item mAdvancedCircuit; + + private ItemStack mCatalystCarrier; + + public static ItemStack mRedCatalyst; + public static ItemStack mYellowCatalyst; + public static ItemStack mBlueCatalyst; + public static ItemStack mOrangeCatalyst; + public static ItemStack mPurpleCatalyst; + public static ItemStack mBrownCatalyst; + public static ItemStack mPinkCatalyst; + public static ItemStack mFormaldehydeCatalyst; + public static ItemStack mSolidAcidCatalyst; + public static ItemStack mInfiniteMutationCatalyst; + + // QFT Catalysts + public static ItemStack mPlatinumGroupCatalyst; + public static ItemStack mPlasticPolymerCatalyst; + public static ItemStack mRubberPolymerCatalyst; + public static ItemStack mAdhesionPromoterCatalyst; + public static ItemStack mTitaTungstenIndiumCatalyst; + public static ItemStack mRadioactivityCatalyst; + public static ItemStack mRareEarthGroupCatalyst; + public static ItemStack mLimpidWaterCatalyst; + public static ItemStack mSimpleNaquadahCatalyst; + public static ItemStack mAdvancedNaquadahCatalyst; + public static ItemStack mRawIntelligenceCatalyst; + public static ItemStack mParticleAccelerationCatalyst; + public static ItemStack mUltimatePlasticCatalyst; + public static ItemStack mBiologicalIntelligenceCatalyst; + public static ItemStack mFlawlessWaterCatalyst; + public static ItemStack TemporalHarmonyCatalyst; + public static ItemStack mSynchrotronCapableCatalyst; + public static ItemStack mAlgagenicGrowthPromoterCatalyst; + + public static ItemStack mMillingBallAlumina; + public static ItemStack mMillingBallSoapstone; + + public static ItemStack mSodiumEthoxide; + public static ItemStack mSodiumEthylXanthate; + public static ItemStack mPotassiumEthylXanthate; + public static ItemStack mPotassiumHydroxide; + + @Override + public void items() { + + MaterialGenerator.generate(TEFLON, false); + + mGenericChemItem1 = new ItemGenericChemBase(); + mAdvancedCircuit = new GTPP_IntegratedCircuit_Item("T3RecipeSelector", "science/general/AdvancedCircuit"); + GregtechItemList.Circuit_T3RecipeSelector.set(mAdvancedCircuit); + + registerItemStacks(); + registerOreDict(); + + GregtechItemList.Milling_Ball_Alumina.set(mMillingBallAlumina); + GregtechItemList.Milling_Ball_Soapstone.set(mMillingBallSoapstone); + } + + public void registerItemStacks() { + + mCatalystCarrier = ItemUtils.simpleMetaStack(AgriculturalChem.mAgrichemItem1, 13, 1); + + mRedCatalyst = ItemUtils.simpleMetaStack(mGenericChemItem1, 0, 1); + mYellowCatalyst = ItemUtils.simpleMetaStack(mGenericChemItem1, 1, 1); + mBlueCatalyst = ItemUtils.simpleMetaStack(mGenericChemItem1, 2, 1); + mOrangeCatalyst = ItemUtils.simpleMetaStack(mGenericChemItem1, 3, 1); + mPurpleCatalyst = ItemUtils.simpleMetaStack(mGenericChemItem1, 4, 1); + mBrownCatalyst = ItemUtils.simpleMetaStack(mGenericChemItem1, 5, 1); + mPinkCatalyst = ItemUtils.simpleMetaStack(mGenericChemItem1, 6, 1); + mMillingBallAlumina = ItemUtils.simpleMetaStack(mGenericChemItem1, 7, 1); + mMillingBallSoapstone = ItemUtils.simpleMetaStack(mGenericChemItem1, 8, 1); + mSodiumEthoxide = ItemUtils.simpleMetaStack(mGenericChemItem1, 9, 1); + mSodiumEthylXanthate = ItemUtils.simpleMetaStack(mGenericChemItem1, 10, 1); + mPotassiumEthylXanthate = ItemUtils.simpleMetaStack(mGenericChemItem1, 11, 1); + mPotassiumHydroxide = ItemUtils.simpleMetaStack(mGenericChemItem1, 12, 1); + mFormaldehydeCatalyst = ItemUtils.simpleMetaStack(mGenericChemItem1, 13, 1); + mSolidAcidCatalyst = ItemUtils.simpleMetaStack(mGenericChemItem1, 14, 1); + mInfiniteMutationCatalyst = ItemUtils.simpleMetaStack(mGenericChemItem1, 15, 1); + + // QFT Catalysts + mPlatinumGroupCatalyst = ItemUtils.simpleMetaStack(mGenericChemItem1, 16, 1); + mPlasticPolymerCatalyst = ItemUtils.simpleMetaStack(mGenericChemItem1, 17, 1); + mRubberPolymerCatalyst = ItemUtils.simpleMetaStack(mGenericChemItem1, 18, 1); + mAdhesionPromoterCatalyst = ItemUtils.simpleMetaStack(mGenericChemItem1, 19, 1); + mTitaTungstenIndiumCatalyst = ItemUtils.simpleMetaStack(mGenericChemItem1, 20, 1); + mRadioactivityCatalyst = ItemUtils.simpleMetaStack(mGenericChemItem1, 21, 1); + mRareEarthGroupCatalyst = ItemUtils.simpleMetaStack(mGenericChemItem1, 22, 1); + mSimpleNaquadahCatalyst = ItemUtils.simpleMetaStack(mGenericChemItem1, 23, 1); + mAdvancedNaquadahCatalyst = ItemUtils.simpleMetaStack(mGenericChemItem1, 24, 1); + mRawIntelligenceCatalyst = ItemUtils.simpleMetaStack(mGenericChemItem1, 25, 1); + mUltimatePlasticCatalyst = ItemUtils.simpleMetaStack(mGenericChemItem1, 26, 1); + mBiologicalIntelligenceCatalyst = ItemUtils.simpleMetaStack(mGenericChemItem1, 27, 1); + TemporalHarmonyCatalyst = ItemUtils.simpleMetaStack(mGenericChemItem1, 28, 1); + mLimpidWaterCatalyst = ItemUtils.simpleMetaStack(mGenericChemItem1, 29, 1); + mFlawlessWaterCatalyst = ItemUtils.simpleMetaStack(mGenericChemItem1, 30, 1); + mParticleAccelerationCatalyst = ItemUtils.simpleMetaStack(mGenericChemItem1, 31, 1); + mSynchrotronCapableCatalyst = ItemUtils.simpleMetaStack(mGenericChemItem1, 32, 1); + mAlgagenicGrowthPromoterCatalyst = ItemUtils.simpleMetaStack(mGenericChemItem1, 33, 1); + } + + public void registerOreDict() { + + ItemUtils.addItemToOreDictionary(mRedCatalyst, "catalystIronCopper"); + ItemUtils.addItemToOreDictionary(mYellowCatalyst, "catalystTungstenNickel"); + ItemUtils.addItemToOreDictionary(mBlueCatalyst, "catalystCobaltTitanium"); + ItemUtils.addItemToOreDictionary(mOrangeCatalyst, "catalystVanadiumPalladium"); + ItemUtils.addItemToOreDictionary(mPurpleCatalyst, "catalystIridiumRuthenium"); + ItemUtils.addItemToOreDictionary(mBrownCatalyst, "catalystNickelAluminium"); + ItemUtils.addItemToOreDictionary(mPinkCatalyst, "catalystPlatinumRhodium"); + ItemUtils.addItemToOreDictionary(mMillingBallAlumina, "millingballAlumina"); + ItemUtils.addItemToOreDictionary(mMillingBallSoapstone, "millingballSoapstone"); + ItemUtils.addItemToOreDictionary(mSodiumEthoxide, "dustSodiumEthoxide"); + ItemUtils.addItemToOreDictionary(mSodiumEthylXanthate, "dustSodiumEthylXanthate"); + ItemUtils.addItemToOreDictionary(mPotassiumEthylXanthate, "dustPotassiumEthylXanthate"); + ItemUtils.addItemToOreDictionary(mPotassiumHydroxide, "dustPotassiumHydroxide"); + ItemUtils.addItemToOreDictionary(mFormaldehydeCatalyst, "catalystFormaldehyde"); + ItemUtils.addItemToOreDictionary(mSolidAcidCatalyst, "catalystSolidAcid"); + ItemUtils.addItemToOreDictionary(mInfiniteMutationCatalyst, "catalystInfiniteMutation"); + ItemUtils.addItemToOreDictionary(mPlatinumGroupCatalyst, "catalystPlatinumGroup"); + ItemUtils.addItemToOreDictionary(mPlasticPolymerCatalyst, "catalystPlasticPolymer"); + ItemUtils.addItemToOreDictionary(mRubberPolymerCatalyst, "catalystRubberPolymer"); + ItemUtils.addItemToOreDictionary(mAdhesionPromoterCatalyst, "catalystAdhesionPromoter"); + ItemUtils.addItemToOreDictionary(mTitaTungstenIndiumCatalyst, "catalystTitaTungstenIndium"); + ItemUtils.addItemToOreDictionary(mRadioactivityCatalyst, "catalystRadioactivity"); + ItemUtils.addItemToOreDictionary(mRareEarthGroupCatalyst, "catalystRareEarthGroup"); + ItemUtils.addItemToOreDictionary(mSimpleNaquadahCatalyst, "catalystSimpleNaquadah"); + ItemUtils.addItemToOreDictionary(mAdvancedNaquadahCatalyst, "catalystAdvancedNaquadah"); + ItemUtils.addItemToOreDictionary(mRawIntelligenceCatalyst, "catalystRawIntelligence"); + ItemUtils.addItemToOreDictionary(mUltimatePlasticCatalyst, "catalystUltimatePlastic"); + ItemUtils.addItemToOreDictionary(mBiologicalIntelligenceCatalyst, "catalystBiologicalIntelligence"); + ItemUtils.addItemToOreDictionary(TemporalHarmonyCatalyst, "catalystTemporalHarmony"); + ItemUtils.addItemToOreDictionary(mLimpidWaterCatalyst, "catalystLimpidWater"); + ItemUtils.addItemToOreDictionary(mFlawlessWaterCatalyst, "catalystFlawlessWater"); + ItemUtils.addItemToOreDictionary(mParticleAccelerationCatalyst, "catalystParticleAcceleration"); + ItemUtils.addItemToOreDictionary(mSynchrotronCapableCatalyst, "catalystSynchrotronCapable"); + ItemUtils.addItemToOreDictionary(mAlgagenicGrowthPromoterCatalyst, "catalystAlgagenicGrowthPromoter"); + } + + @Override + public void blocks() {} + + @Override + public void fluids() { + + if (!FluidRegistry.isFluidRegistered("benzene")) { + Benzene = FluidUtils + .generateFluidNoPrefix("benzene", "Benzene", 278, new short[] { 100, 70, 30, 100 }, true); + } else { + Benzene = FluidRegistry.getFluid("benzene"); + } + + NitroBenzene = FluidUtils + .generateFluidNoPrefix("nitrobenzene", "Nitrobenzene", 278, new short[] { 70, 50, 40, 100 }, true); + + Aniline = FluidUtils.generateFluidNoPrefix("aniline", "Aniline", 266, new short[] { 100, 100, 30, 100 }, true); + + BoricAcid = FluidUtils + .generateFluidNoPrefix("boricacid", "Boric Acid", 278, new short[] { 90, 30, 120, 100 }, true); + + Polyurethane = FluidUtils + .generateFluidNoPrefix("polyurethane", "Polyurethane", 350, new short[] { 100, 70, 100, 100 }, true); + + if (!FluidRegistry.isFluidRegistered("phenol")) { + Phenol = FluidUtils.generateFluidNoPrefix("phenol", "Phenol", 313, new short[] { 100, 70, 30, 100 }, true); + } else { + Phenol = FluidRegistry.getFluid("phenol"); + } + + // Use GT's if it exists, else make our own. + if (FluidRegistry.isFluidRegistered("hydrochloricacid_gt5u")) { + HydrochloricAcid = FluidRegistry.getFluid("hydrochloricacid_gt5u"); + } else { + HydrochloricAcid = FluidUtils.generateFluidNoPrefix( + "hydrochloricacid", + "Hydrochloric Acid", + 285, + new short[] { 183, 200, 196, 100 }, + true); + } + + Cyclohexane = FluidUtils + .generateFluidNoPrefix("cyclohexane", "Cyclohexane", 32 + 175, new short[] { 100, 70, 30, 100 }, true); + Cyclohexanone = FluidUtils + .generateFluidNoPrefix("cyclohexanone", "Cyclohexanone", 32 + 175, new short[] { 100, 70, 30, 100 }, true); + + Cadaverine = FluidUtils + .generateFluidNoPrefix("cadaverine", "Cadaverine", 32 + 175, new short[] { 100, 70, 30, 100 }, true); + Putrescine = FluidUtils + .generateFluidNoPrefix("putrescine", "Putrescine", 32 + 175, new short[] { 100, 70, 30, 100 }, true); + + // Create 2-Ethylanthraquinone + // 2-Ethylanthraquinone is prepared from the reaction of phthalic anhydride and ethylbenzene + Ethylanthraquinone2 = FluidUtils.generateFluidNonMolten( + "2Ethylanthraquinone", + "2-Ethylanthraquinone", + 415, + new short[] { 227, 255, 159, 100 }, + null, + null); + // Create 2-Ethylanthrahydroquinone + // Palladium plate + Hydrogen(250) + 2-Ethylanthraquinone(500) = 600 Ethylanthrahydroquinone + Ethylanthrahydroquinone2 = FluidUtils.generateFluidNonMolten( + "2Ethylanthrahydroquinone", + "2-Ethylanthrahydroquinone", + 415, + new short[] { 207, 225, 129, 100 }, + null, + null); + // Create Hydrogen Peroxide + // Compressed Air(1500) + Ethylanthrahydroquinone(500) + Anthracene(5) = 450 Ethylanthraquinone && 200 Peroxide + Hydrogen_Peroxide = FluidUtils.generateFluidNonMolten( + "HydrogenPeroxide", + "Hydrogen Peroxide", + 150, + new short[] { 210, 255, 255, 100 }, + null, + null); + + // Lithium Hydroperoxide - LiOH + H2O2 → LiOOH + 2 H2O + // ItemUtils.generateSpecialUseDusts("LithiumHydroperoxide", "Lithium Hydroperoxide", "HLiO2", + // Utils.rgbtoHexValue(125, 125, 125)); + // v - Dehydrate + // Lithium Peroxide - 2 LiOOH → Li2O2 + H2O2 + 2 H2O + Lithium_Peroxide = FluidUtils.generateFluidNonMolten( + "LithiumPeroxide", + "Lithium Peroxide", + 446, + new short[] { 135, 135, 135, 100 }, + null, + null); + + Carbon_Disulfide = FluidUtils + .generateFluidNoPrefix("CarbonDisulfide", "Carbon Disulfide", 350, new short[] { 175, 175, 175, 100 }); + } + + @Override + public String errorMessage() { + return "Failed to generate recipes for GenericChem."; + } + + @Override + public boolean generateRecipes() { + + recipeAdvancedChip(); + recipeCatalystRed(); + recipeCatalystYellow(); + recipeCatalystBlue(); + recipeCatalystOrange(); + recipeCatalystPurple(); + recipeCatalystBrown(); + recipeCatalystPink(); + recipeCatalystFormaldehyde(); + recipeCatalystSolidAcid(); + recipeCatalystInfiniteMutation(); + + recipeGrindingBallAlumina(); + recipeGrindingBallSoapstone(); + + recipeNitroBenzene(); + recipeAniline(); + recipeCadaverineAndPutrescine(); + recipeCyclohexane(); + recipeCyclohexanone(); + + recipe2Ethylanthraquinone(); + recipe2Ethylanthrahydroquinone(); + recipeHydrogenPeroxide(); + recipeLithiumHydroperoxide(); + recipeLithiumPeroxide(); + + recipeSodiumEthoxide(); + recipeCarbonDisulfide(); + recipeEthylXanthates(); + recipePotassiumHydroxide(); + + recipeMutatedLivingSolder(); + + registerFuels(); + + return true; + } + + private void recipeSodiumEthoxide() { + // C2H5OH + Na → C2H5ONa + H + CORE.RA.addChemicalPlantRecipe( + new ItemStack[] { CI.getNumberedCircuit(16), ELEMENT.getInstance().SODIUM.getDust(1) }, + new FluidStack[] { Materials.Ethanol.getFluid(1000) }, + new ItemStack[] { ItemUtils.getSimpleStack(mSodiumEthoxide, 9) }, + new FluidStack[] { ELEMENT.getInstance().HYDROGEN.getFluidStack(1000) }, + 20 * 20, + 120, + 2); + } + + private void recipePotassiumHydroxide() { + // Ca(OH)2 + K2O + CO2 → CaCO3 + 2 KOH + CORE.RA.addChemicalPlantRecipe( + new ItemStack[] { CI.getNumberedCircuit(18), Materials.Potash.getDust(3), + ItemUtils.getItemStackOfAmountFromOreDict("dustCalciumHydroxide", 5), }, + new FluidStack[] { Materials.CarbonDioxide.getGas(1000) }, + new ItemStack[] { ItemUtils.getItemStackOfAmountFromOreDict("dustCalciumCarbonate", 5), + ItemUtils.getSimpleStack(mPotassiumHydroxide, 6) }, + new FluidStack[] {}, + 20 * 30, + 120, + 2); + } + + private void recipeEthylXanthates() { + + // Potassium ethyl xanthate - CH3CH2OH + CS2 + KOH → C3H5KOS2 + H2O + CORE.RA.addChemicalPlantRecipe( + new ItemStack[] { CI.getNumberedCircuit(17), ItemUtils.getSimpleStack(mPotassiumHydroxide, 3), }, + new FluidStack[] { Materials.Ethanol.getFluid(1000), FluidUtils.getFluidStack(Carbon_Disulfide, 1000), }, + new ItemStack[] { ItemUtils.getSimpleStack(mPotassiumEthylXanthate, 12) }, + new FluidStack[] { FluidUtils.getWater(1000) }, + 20 * 60, + 120, + 4); + + // Sodium ethyl xanthate - CH3CH2ONa + CS2 → CH3CH2OCS2Na + CORE.RA.addChemicalPlantRecipe( + new ItemStack[] { CI.getNumberedCircuit(17), ItemUtils.getSimpleStack(mSodiumEthoxide, 9) }, + new FluidStack[] { FluidUtils.getFluidStack(Carbon_Disulfide, 1000), }, + new ItemStack[] { ItemUtils.getSimpleStack(mSodiumEthylXanthate, 12) }, + new FluidStack[] {}, + 20 * 60, + 120, + 4); + } + + private void recipeCarbonDisulfide() { + + GT_Values.RA.stdBuilder() + .itemInputs( + ItemUtils.getItemStackOfAmountFromOreDict("fuelCoke", 8), + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Sulfur, 16L)) + .itemOutputs(GT_OreDictUnificator.get(OrePrefixes.dust, Materials.DarkAsh, 1L)) + .fluidOutputs(FluidUtils.getFluidStack(Carbon_Disulfide, 4000)) + .duration(10 * MINUTES) + .eut(TierEU.RECIPE_LV) + .metadata(COIL_HEAT, 1500) + .addTo(blastFurnaceRecipes); + + CORE.RA.addChemicalPlantRecipe( + new ItemStack[] { CI.getNumberedCircuit(20), ItemUtils.getSimpleStack(mBrownCatalyst, 0), + ItemUtils.getItemStackOfAmountFromOreDict("dustSulfur", 4) }, + new FluidStack[] { FluidUtils.getFluidStack(CoalTar.Coal_Gas, 1000), }, + new ItemStack[] {}, + new FluidStack[] { FluidUtils.getFluidStack(Carbon_Disulfide, 2000) }, + 20 * 60 * 5, + 30, + 2); + } + + private void recipeMutatedLivingSolder() { + + // Endgame soldering alloy meant for the bioware circuit line and beyond. + CORE.RA.addChemicalPlantRecipe( + new ItemStack[] { ItemUtils.getSimpleStack(GenericChem.mInfiniteMutationCatalyst, 0), + ItemList.Circuit_Chip_Biocell.get(64), ItemList.Gravistar.get(8), + Materials.InfinityCatalyst.getDust(2) }, + new FluidStack[] { FluidUtils.getFluidStack("plasma.tin", 18000), + FluidUtils.getFluidStack("plasma.bismuth", 18000), FluidUtils.getFluidStack("cryotheum", 4000) }, + new ItemStack[] {}, + new FluidStack[] { MISC_MATERIALS.MUTATED_LIVING_SOLDER.getFluidStack(144 * 280) }, + 20 * 800, + 3842160, + 7); + } + + private static void registerFuels() { + + // Burnables + + // Gas Fuels + GT_Values.RA.stdBuilder() + .itemInputs(ItemUtils.getItemStackOfAmountFromOreDict("cellNitrobenzene", 1)) + .metadata(FUEL_VALUE, 1600) + .metadata(FUEL_TYPE, 1) + .duration(0) + .eut(0) + .addTo(GT_RecipeConstants.Fuel); + } + + private void recipeGrindingBallAlumina() { + GT_Values.RA.stdBuilder() + .itemInputs(ItemUtils.getSimpleStack(AgriculturalChem.mAlumina, 64), GT_Utility.getIntegratedCircuit(10)) + .itemOutputs(ItemUtils.getSimpleStack(mMillingBallAlumina, 8)) + .fluidInputs(FluidUtils.getFluidStack(GenericChem.Aniline, 4000)) + .duration(3 * MINUTES) + .eut(TierEU.RECIPE_HV) + .addTo(assemblerRecipes); + } + + private void recipeGrindingBallSoapstone() { + GT_Values.RA.stdBuilder() + .itemInputs( + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Soapstone, 32L), + GT_Utility.getIntegratedCircuit(10)) + .itemOutputs(ItemUtils.getSimpleStack(mMillingBallSoapstone, 8)) + .fluidInputs(FluidUtils.getFluidStack(AgrichemFluids.mLiquidResin, 2500)) + .duration(2 * MINUTES) + .eut(TierEU.RECIPE_HV) + .addTo(assemblerRecipes); + } + + private void recipeCyclohexane() { + + // C6H6 + 6H = C6H12 + CORE.RA.addChemicalPlantRecipe( + new ItemStack[] { getTierTwoChip(), ItemUtils.getSimpleStack(mBrownCatalyst, 0) }, + new FluidStack[] { FluidUtils.getFluidStack(Benzene, 1000), FluidUtils.getFluidStack("hydrogen", 6000) }, + new ItemStack[] {}, + new FluidStack[] { FluidUtils.getFluidStack(Cyclohexane, 1000), }, + 20 * 120, + 120, + 2); + } + + private void recipeCyclohexanone() { + + // C6H12 + 2O(Air) = C6H10O + H2O + CORE.RA.addChemicalPlantRecipe( + new ItemStack[] { getTierTwoChip(), ItemUtils.getSimpleStack(mBlueCatalyst, 0) }, + new FluidStack[] { FluidUtils.getFluidStack(Cyclohexane, 1000), FluidUtils.getFluidStack("air", 4000) }, + new ItemStack[] {}, + new FluidStack[] { FluidUtils.getFluidStack(Cyclohexanone, 1000), }, + 20 * 120, + 120, + 2); + + CORE.RA.addChemicalPlantRecipe( + new ItemStack[] { getTierTwoChip(), }, + new FluidStack[] { FluidUtils.getFluidStack(Cyclohexane, 1000), FluidUtils.getFluidStack("oxygen", 2000) }, + new ItemStack[] {}, + new FluidStack[] { FluidUtils.getFluidStack(Cyclohexanone, 1000), }, + 20 * 120, + 120, + 2); + } + + private void recipeCatalystRed() { + // Assembler Recipe + GT_Values.RA.stdBuilder() + .itemInputs( + getTierOneChip(), + CI.getEmptyCatalyst(10), + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Iron, 2L), + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Copper, 2L)) + .itemOutputs(ItemUtils.getSimpleStack(mRedCatalyst, 10)) + .duration(20 * SECONDS) + .eut(TierEU.RECIPE_LV) + .addTo(assemblerRecipes); + } + + private void recipeCatalystYellow() { + // Assembler Recipe + GT_Values.RA.stdBuilder() + .itemInputs( + getTierThreeChip(), + CI.getEmptyCatalyst(10), + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Tungsten, 4L), + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Nickel, 4L)) + .itemOutputs(ItemUtils.getSimpleStack(mYellowCatalyst, 10)) + .duration(1 * MINUTES) + .eut(TierEU.RECIPE_EV) + .addTo(assemblerRecipes); + } + + private void recipeCatalystBlue() { + // Assembler Recipe + GT_Values.RA.stdBuilder() + .itemInputs( + getTierTwoChip(), + CI.getEmptyCatalyst(10), + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Cobalt, 3L), + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Titanium, 3L)) + .itemOutputs(ItemUtils.getSimpleStack(mBlueCatalyst, 10)) + .duration(40 * SECONDS) + .eut(TierEU.RECIPE_HV) + .addTo(assemblerRecipes); + } + + private void recipeCatalystOrange() { + // Assembler Recipe + GT_Values.RA.stdBuilder() + .itemInputs( + getTierTwoChip(), + CI.getEmptyCatalyst(10), + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Vanadium, 5L), + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Palladium, 5L)) + .itemOutputs(ItemUtils.getSimpleStack(mOrangeCatalyst, 10)) + .duration(40 * SECONDS) + .eut(TierEU.RECIPE_HV) + .addTo(assemblerRecipes); + } + + private void recipeCatalystPurple() { + // Assembler Recipe + GT_Values.RA.stdBuilder() + .itemInputs( + getTierFourChip(), + CI.getEmptyCatalyst(10), + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Iridium, 6L), + ELEMENT.getInstance().RUTHENIUM.getDust(6)) + .itemOutputs(ItemUtils.getSimpleStack(mPurpleCatalyst, 10)) + .duration(2 * MINUTES) + .eut(TierEU.RECIPE_IV) + .addTo(assemblerRecipes); + } + + private void recipeCatalystBrown() { + // Assembler Recipe + GT_Values.RA.stdBuilder() + .itemInputs( + getTierOneChip(), + CI.getEmptyCatalyst(10), + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Nickel, 4L), + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Aluminium, 4L)) + .itemOutputs(ItemUtils.getSimpleStack(mBrownCatalyst, 10)) + .duration(15 * SECONDS) + .eut(TierEU.RECIPE_LV) + .addTo(assemblerRecipes); + } + + private void recipeCatalystPink() { + // Assembler Recipe + GT_Values.RA.stdBuilder() + .itemInputs( + getTierThreeChip(), + CI.getEmptyCatalyst(10), + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Platinum, 4L), + ELEMENT.getInstance().RHODIUM.getDust(4)) + .itemOutputs(ItemUtils.getSimpleStack(mPinkCatalyst, 10)) + .duration(30 * SECONDS) + .eut(TierEU.RECIPE_EV) + .addTo(assemblerRecipes); + } + + private void recipeCatalystFormaldehyde() { + // Assembler Recipe + GT_Values.RA.stdBuilder() + .itemInputs( + getTierThreeChip(), + CI.getEmptyCatalyst(4), + ItemUtils.getSimpleStack(RocketFuels.Formaldehyde_Catalyst_Dust, 8)) + .itemOutputs(ItemUtils.getSimpleStack(mFormaldehydeCatalyst, 4)) + .duration(30 * SECONDS) + .eut(TierEU.RECIPE_HV / 2) + .addTo(assemblerRecipes); + } + + private void recipeCatalystSolidAcid() { + // Assembler Recipe + GT_Values.RA.stdBuilder() + .itemInputs( + getTierThreeChip(), + CI.getEmptyCatalyst(5), + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Lapis, 2L)) + .itemOutputs(ItemUtils.getSimpleStack(GenericChem.mSolidAcidCatalyst, 5)) + .fluidInputs(MISC_MATERIALS.SOLID_ACID_MIXTURE.getFluidStack(1000)) + .duration(30 * SECONDS) + .eut(TierEU.RECIPE_EV) + .addTo(assemblerRecipes); + } + + private void recipeCatalystInfiniteMutation() { + // Assembler Recipe + GT_Values.RA.stdBuilder() + .itemInputs( + getTierThreeChip(), + CI.getEmptyCatalyst(5), + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Infinity, 1L), + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Naquadria, 10L)) + .itemOutputs(ItemUtils.getSimpleStack(GenericChem.mInfiniteMutationCatalyst, 5)) + .duration(5 * SECONDS) + .eut(TierEU.RECIPE_UHV) + .addTo(assemblerRecipes); + } + + private void recipeCadaverineAndPutrescine() { + + // Basic Recipe + CORE.RA.addChemicalPlantRecipe( + new ItemStack[] { getTierOneChip(), ItemUtils.getSimpleStack(Items.rotten_flesh, 64) }, + new FluidStack[] { FluidUtils.getHotWater(2000) }, + new ItemStack[] {}, + new FluidStack[] { FluidUtils.getFluidStack(Cadaverine, 250), FluidUtils.getFluidStack(Putrescine, 250), }, + 20 * 120, + 120, + 1); + + // Advanced Recipe + CORE.RA.addChemicalPlantRecipe( + new ItemStack[] { getTierTwoChip(), ItemUtils.getSimpleStack(Items.rotten_flesh, 128), + ItemUtils.simpleMetaStack(AgriculturalChem.mAgrichemItem1, 8, 32) }, + new FluidStack[] { FluidUtils.getHotWater(3000) }, + new ItemStack[] {}, + new FluidStack[] { FluidUtils.getFluidStack(Cadaverine, 750), FluidUtils.getFluidStack(Putrescine, 750), }, + 20 * 120, + 240, + 2); + } + + private void recipeAniline() { + + // C6H5NO2 + 6H = C6H7N + 2H2O + CORE.RA.addChemicalPlantRecipe( + new ItemStack[] { getTierThreeChip(), ItemUtils.getSimpleStack(mBlueCatalyst, 0) }, + new FluidStack[] { FluidUtils.getFluidStack(NitroBenzene, 1000), + FluidUtils.getFluidStack("hydrogen", 6000) }, + new ItemStack[] {}, + new FluidStack[] { FluidUtils.getFluidStack(Aniline, 1000), }, + 20 * 30, + 500, + 3); + } + + private void recipeNitroBenzene() { + + // C6H6 + HNO3 =H2SO4= C6H5NO2 +H2O + CORE.RA.addChemicalPlantRecipe( + new ItemStack[] { getTierThreeChip(), }, + new FluidStack[] { FluidUtils.getFluidStack(Benzene, 5000), FluidUtils.getFluidStack("sulfuricacid", 1000), + FluidUtils.getFluidStack("nitricacid", 5000), FluidUtils.getDistilledWater(10000) }, + new ItemStack[] {}, + new FluidStack[] { FluidUtils.getFluidStack(NitroBenzene, 5000), }, + 20 * 30, + 500, + 4); + } + + private void recipe2Ethylanthraquinone() { + + // C6H4(CO)2O + C6H5CH2CH3 = C6H4(CO)2C6H3CH2CH3 + H2O + CORE.RA.addChemicalPlantRecipe( + new ItemStack[] { CI.getNumberedCircuit(4), + ItemUtils.getItemStackOfAmountFromOreDict("dustPhthalicAnhydride", 15), }, + new FluidStack[] { FluidUtils.getFluidStack(CoalTar.Ethylbenzene, 1000), }, + new ItemStack[] {}, + new FluidStack[] { FluidUtils.getFluidStack(Ethylanthraquinone2, 1000), }, + 20 * 15, + 120, + 2); + } + + private void recipe2Ethylanthrahydroquinone() { + + // C6H4(CO)2C6H3CH2CH3 + 2H = C6H4(COH)2C6H3CH2CH3 + CORE.RA.addChemicalPlantRecipe( + new ItemStack[] { CI.getNumberedCircuit(4), ItemUtils.getSimpleStack(mOrangeCatalyst, 0), }, + new FluidStack[] { FluidUtils.getFluidStack(Ethylanthraquinone2, 1000), + FluidUtils.getFluidStack("hydrogen", 2000), }, + new ItemStack[] {}, + new FluidStack[] { FluidUtils.getFluidStack(Ethylanthrahydroquinone2, 1000), }, + 20 * 40, + 120, + 2); + } + + private void recipeLithiumPeroxide() { + // 2HLiO2 = Li2O2 + H2O2 + GT_Values.RA.stdBuilder() + .itemInputs(ItemUtils.getItemStackOfAmountFromOreDict("dustLithiumHydroperoxide", 8)) + .fluidOutputs(FluidUtils.getFluidStack("fluid.hydrogenperoxide", 1000)) + .itemOutputs(ItemUtils.getItemStackOfAmountFromOreDict("dustLithiumPeroxide", 4)) + .duration(100 * SECONDS) + .eut(120) + .noOptimize() + .addTo(chemicalDehydratorRecipes); + } + + private void recipeLithiumHydroperoxide() { + + // LiOH + H2O2 = HLiO2 + H2O + CORE.RA.addChemicalPlantRecipe( + new ItemStack[] { CI.getNumberedCircuit(4), + ItemUtils.getItemStackOfAmountFromOreDict("dustLithiumHydroxide", 3), }, + new FluidStack[] { FluidUtils.getFluidStack("fluid.hydrogenperoxide", 1000), }, + new ItemStack[] { ItemUtils.getItemStackOfAmountFromOreDict("dustLithiumHydroperoxide", 4), }, + new FluidStack[] {}, + 20 * 30, + 240, + 1); + + } + + private void recipeHydrogenPeroxide() { + + // C6H4(COH)2C6H3CH2CH3 + 2O =(C6H4CH)2= H2O2 + C6H4(CO)2C6H3CH2CH3 + CORE.RA.addChemicalPlantRecipe( + new ItemStack[] { CI.getNumberedCircuit(4), }, + new FluidStack[] { FluidUtils.getFluidStack("air", 20000), + FluidUtils.getFluidStack(Ethylanthrahydroquinone2, 5000), + FluidUtils.getFluidStack("fluid.anthracene", 50), }, + new ItemStack[] {}, + new FluidStack[] { FluidUtils.getFluidStack(Ethylanthraquinone2, 5000), + FluidUtils.getFluidStack("fluid.hydrogenperoxide", 5000), }, + 20 * 30, + 240, + 1); + + CORE.RA.addChemicalPlantRecipe( + new ItemStack[] { CI.getNumberedCircuit(4), }, + new FluidStack[] { Materials.Oxygen.getGas(10000), FluidUtils.getFluidStack(Ethylanthrahydroquinone2, 5000), + FluidUtils.getFluidStack("fluid.anthracene", 50), }, + new ItemStack[] {}, + new FluidStack[] { FluidUtils.getFluidStack(Ethylanthraquinone2, 5000), + FluidUtils.getFluidStack("fluid.hydrogenperoxide", 5000), }, + 20 * 5, + 240, + 1); + + } + + private static ItemStack getTierOneChip() { + return CI.getNumberedAdvancedCircuit(4); + } + + private static ItemStack getTierTwoChip() { + return CI.getNumberedAdvancedCircuit(8); + } + + private static ItemStack getTierThreeChip() { + return CI.getNumberedAdvancedCircuit(12); + } + + private static ItemStack getTierFourChip() { + return CI.getNumberedAdvancedCircuit(16); + } + + private static void recipeAdvancedChip() { + GT_ModHandler.addShapelessCraftingRecipe( + GregtechItemList.Circuit_T3RecipeSelector.getWithDamage(1L, 0L), + 0, + new Object[] { OrePrefixes.circuit.get(Materials.Advanced) }); + + long bits = 0; + BioRecipes.addCraftingRecipe( + GregtechItemList.Circuit_T3RecipeSelector.getWithDamage(1L, 1L, new Object[0]), + bits, + new Object[] { "d ", " P ", " ", 'P', + GregtechItemList.Circuit_T3RecipeSelector.getWildcard(1L, new Object[0]) }); + BioRecipes.addCraftingRecipe( + GregtechItemList.Circuit_T3RecipeSelector.getWithDamage(1L, 2L, new Object[0]), + bits, + new Object[] { " d ", " P ", " ", 'P', + GregtechItemList.Circuit_T3RecipeSelector.getWildcard(1L, new Object[0]) }); + BioRecipes.addCraftingRecipe( + GregtechItemList.Circuit_T3RecipeSelector.getWithDamage(1L, 3L, new Object[0]), + bits, + new Object[] { " d", " P ", " ", 'P', + GregtechItemList.Circuit_T3RecipeSelector.getWildcard(1L, new Object[0]) }); + BioRecipes.addCraftingRecipe( + GregtechItemList.Circuit_T3RecipeSelector.getWithDamage(1L, 4L, new Object[0]), + bits, + new Object[] { " ", " Pd", " ", 'P', + GregtechItemList.Circuit_T3RecipeSelector.getWildcard(1L, new Object[0]) }); + BioRecipes.addCraftingRecipe( + GregtechItemList.Circuit_T3RecipeSelector.getWithDamage(1L, 5L, new Object[0]), + bits, + new Object[] { " ", " P ", " d", 'P', + GregtechItemList.Circuit_T3RecipeSelector.getWildcard(1L, new Object[0]) }); + BioRecipes.addCraftingRecipe( + GregtechItemList.Circuit_T3RecipeSelector.getWithDamage(1L, 6L, new Object[0]), + bits, + new Object[] { " ", " P ", " d ", 'P', + GregtechItemList.Circuit_T3RecipeSelector.getWildcard(1L, new Object[0]) }); + BioRecipes.addCraftingRecipe( + GregtechItemList.Circuit_T3RecipeSelector.getWithDamage(1L, 7L, new Object[0]), + bits, + new Object[] { " ", " P ", "d ", 'P', + GregtechItemList.Circuit_T3RecipeSelector.getWildcard(1L, new Object[0]) }); + BioRecipes.addCraftingRecipe( + GregtechItemList.Circuit_T3RecipeSelector.getWithDamage(1L, 8L, new Object[0]), + bits, + new Object[] { " ", "dP ", " ", 'P', + GregtechItemList.Circuit_T3RecipeSelector.getWildcard(1L, new Object[0]) }); + BioRecipes.addCraftingRecipe( + GregtechItemList.Circuit_T3RecipeSelector.getWithDamage(1L, 9L, new Object[0]), + bits, + new Object[] { "P d", " ", " ", 'P', + GregtechItemList.Circuit_T3RecipeSelector.getWildcard(1L, new Object[0]) }); + BioRecipes.addCraftingRecipe( + GregtechItemList.Circuit_T3RecipeSelector.getWithDamage(1L, 10L, new Object[0]), + bits, + new Object[] { "P ", " d", " ", 'P', + GregtechItemList.Circuit_T3RecipeSelector.getWildcard(1L, new Object[0]) }); + BioRecipes.addCraftingRecipe( + GregtechItemList.Circuit_T3RecipeSelector.getWithDamage(1L, 11L, new Object[0]), + bits, + new Object[] { "P ", " ", " d", 'P', + GregtechItemList.Circuit_T3RecipeSelector.getWildcard(1L, new Object[0]) }); + BioRecipes.addCraftingRecipe( + GregtechItemList.Circuit_T3RecipeSelector.getWithDamage(1L, 12L, new Object[0]), + bits, + new Object[] { "P ", " ", " d ", 'P', + GregtechItemList.Circuit_T3RecipeSelector.getWildcard(1L, new Object[0]) }); + BioRecipes.addCraftingRecipe( + GregtechItemList.Circuit_T3RecipeSelector.getWithDamage(1L, 13L, new Object[0]), + bits, + new Object[] { " P", " ", " d", 'P', + GregtechItemList.Circuit_T3RecipeSelector.getWildcard(1L, new Object[0]) }); + BioRecipes.addCraftingRecipe( + GregtechItemList.Circuit_T3RecipeSelector.getWithDamage(1L, 14L, new Object[0]), + bits, + new Object[] { " P", " ", " d ", 'P', + GregtechItemList.Circuit_T3RecipeSelector.getWildcard(1L, new Object[0]) }); + BioRecipes.addCraftingRecipe( + GregtechItemList.Circuit_T3RecipeSelector.getWithDamage(1L, 15L, new Object[0]), + bits, + new Object[] { " P", " ", "d ", 'P', + GregtechItemList.Circuit_T3RecipeSelector.getWildcard(1L, new Object[0]) }); + BioRecipes.addCraftingRecipe( + GregtechItemList.Circuit_T3RecipeSelector.getWithDamage(1L, 16L, new Object[0]), + bits, + new Object[] { " P", "d ", " ", 'P', + GregtechItemList.Circuit_T3RecipeSelector.getWildcard(1L, new Object[0]) }); + BioRecipes.addCraftingRecipe( + GregtechItemList.Circuit_T3RecipeSelector.getWithDamage(1L, 17L, new Object[0]), + bits, + new Object[] { " ", " ", "d P", 'P', + GregtechItemList.Circuit_T3RecipeSelector.getWildcard(1L, new Object[0]) }); + BioRecipes.addCraftingRecipe( + GregtechItemList.Circuit_T3RecipeSelector.getWithDamage(1L, 18L, new Object[0]), + bits, + new Object[] { " ", "d ", " P", 'P', + GregtechItemList.Circuit_T3RecipeSelector.getWildcard(1L, new Object[0]) }); + BioRecipes.addCraftingRecipe( + GregtechItemList.Circuit_T3RecipeSelector.getWithDamage(1L, 19L, new Object[0]), + bits, + new Object[] { "d ", " ", " P", 'P', + GregtechItemList.Circuit_T3RecipeSelector.getWildcard(1L, new Object[0]) }); + BioRecipes.addCraftingRecipe( + GregtechItemList.Circuit_T3RecipeSelector.getWithDamage(1L, 20L, new Object[0]), + bits, + new Object[] { " d ", " ", " P", 'P', + GregtechItemList.Circuit_T3RecipeSelector.getWildcard(1L, new Object[0]) }); + BioRecipes.addCraftingRecipe( + GregtechItemList.Circuit_T3RecipeSelector.getWithDamage(1L, 21L, new Object[0]), + bits, + new Object[] { "d ", " ", "P ", 'P', + GregtechItemList.Circuit_T3RecipeSelector.getWildcard(1L, new Object[0]) }); + BioRecipes.addCraftingRecipe( + GregtechItemList.Circuit_T3RecipeSelector.getWithDamage(1L, 22L, new Object[0]), + bits, + new Object[] { " d ", " ", "P ", 'P', + GregtechItemList.Circuit_T3RecipeSelector.getWildcard(1L, new Object[0]) }); + BioRecipes.addCraftingRecipe( + GregtechItemList.Circuit_T3RecipeSelector.getWithDamage(1L, 23L, new Object[0]), + bits, + new Object[] { " d", " ", "P ", 'P', + GregtechItemList.Circuit_T3RecipeSelector.getWildcard(1L, new Object[0]) }); + BioRecipes.addCraftingRecipe( + GregtechItemList.Circuit_T3RecipeSelector.getWithDamage(1L, 24L, new Object[0]), + bits, + new Object[] { " ", " d", "P ", 'P', + GregtechItemList.Circuit_T3RecipeSelector.getWildcard(1L, new Object[0]) }); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/chemistry/IonParticles.java b/src/main/java/gtPlusPlus/core/item/chemistry/IonParticles.java new file mode 100644 index 0000000000..d4f5e832f6 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/chemistry/IonParticles.java @@ -0,0 +1,171 @@ +package gtPlusPlus.core.item.chemistry; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.HashMap; +import java.util.List; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IIcon; + +import gregtech.api.enums.Materials; +import gtPlusPlus.core.item.base.misc.BaseItemParticle; +import gtPlusPlus.core.material.ELEMENT; +import gtPlusPlus.core.util.Utils; + +public class IonParticles extends BaseItemParticle { + + public static HashMap<String, Integer> NameToMetaMap = new HashMap<>(); + public static HashMap<Integer, String> MetaToNameMap = new HashMap<>(); + + public IonParticles() { + super("Ion", ELEMENT.NAMES.length, EnumRarity.rare); + } + + public static IIcon[] overlays = new IIcon[ELEMENT.NAMES.length]; + public static IIcon baseTexture; + + static { + // Generate Ions + int key = 0; + for (String s : ELEMENT.NAMES) { + // Map names to Meta + NameToMetaMap.put(Utils.sanitizeString(s.toLowerCase()), key); + MetaToNameMap.put(key, Utils.sanitizeString(s.toLowerCase())); + Materials m = Materials.get(s); + int aColour = 0; + if (m == null) { + aColour = Utils.rgbtoHexValue(128, 128, 128); + } else { + aColour = Utils.rgbtoHexValue(m.mRGBa[0], m.mRGBa[1], m.mRGBa[2]); + } + aColourMap.put(key++, aColour); + } + } + + @Override + public String[] getAffixes() { + return new String[] { "", "" }; + } + + @Override + public String getUnlocalizedName() { + return ""; + } + + @Override + public String getUnlocalizedName(final ItemStack itemStack) { + return "item.particle.ion" + "." + ELEMENT.NAMES[itemStack.getItemDamage()]; + } + + private static boolean createNBT(ItemStack rStack) { + final NBTTagCompound tagMain = new NBTTagCompound(); + final NBTTagCompound tagNBT = new NBTTagCompound(); + tagNBT.setLong("Charge", 0); + tagMain.setTag("Ion", tagNBT); + rStack.setTagCompound(tagMain); + return true; + } + + public static final long getChargeState(final ItemStack aStack) { + NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag("Ion"); + if (aNBT != null) { + return aNBT.getLong("Charge"); + } + } else { + createNBT(aStack); + } + return 0L; + } + + public static final boolean setChargeState(final ItemStack aStack, final long aCharge) { + NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag("Ion"); + if (aNBT != null) { + aNBT.setLong("Charge", aCharge); + return true; + } + } + return false; + } + + @Override + public double getDurabilityForDisplay(ItemStack stack) { + if (stack.getTagCompound() == null) { + createNBT(stack); + } + double chargeState = getChargeState(stack); + return chargeState; + } + + @Override + public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool) { + long aCharge = getChargeState(stack); + String aState = EnumChatFormatting.YELLOW + "Unknown" + EnumChatFormatting.GRAY; + // State not set + if (aCharge == 0) { + list.add( + EnumChatFormatting.GRAY + "A " + + MetaToNameMap.get(stack.getItemDamage()) + + " Ion with an " + + aState + + " charge state"); + } else { + if (aCharge > 0) { + aState = EnumChatFormatting.GREEN + "Positive" + EnumChatFormatting.GRAY; + } else { + aState = EnumChatFormatting.RED + "Negative" + EnumChatFormatting.GRAY; + } + + list.add( + EnumChatFormatting.GRAY + "A " + + MetaToNameMap.get(stack.getItemDamage()) + + " Ion with a " + + aState + + " charge state of " + + aCharge + + ""); + } + super.addInformation(stack, player, list, bool); + } + + @Override + public void registerIcons(IIconRegister reg) { + for (int i = 0; i < IonParticles.overlays.length; i++) { + IonParticles.overlays[i] = reg.registerIcon(GTPlusPlus.ID + ":" + "ion/" + i); + } + IonParticles.baseTexture = reg.registerIcon(GTPlusPlus.ID + ":" + "ion/IonBase"); + } + + @Override + public IIcon getIconFromDamage(int meta) { + return IonParticles.overlays[meta]; + } + + @Override + public boolean requiresMultipleRenderPasses() { + return true; + } + + @Override + public IIcon getIconFromDamageForRenderPass(int aMeta, int aPass) { + if (aPass == 0) { + return IonParticles.baseTexture; + } else { + return IonParticles.overlays[aMeta]; + } + } + + @Override + public int getRenderPasses(int metadata) { + return 2; + } +} diff --git a/src/main/java/gtPlusPlus/core/item/chemistry/MilledOreProcessing.java b/src/main/java/gtPlusPlus/core/item/chemistry/MilledOreProcessing.java new file mode 100644 index 0000000000..5a848d2616 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/chemistry/MilledOreProcessing.java @@ -0,0 +1,752 @@ +package gtPlusPlus.core.item.chemistry; + +import static gregtech.api.enums.Mods.BiomesOPlenty; +import static gregtech.api.enums.Mods.Forestry; + +import java.util.HashMap; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; + +import gregtech.api.enums.Materials; +import gregtech.api.util.GT_OreDictUnificator; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.api.objects.data.Pair; +import gtPlusPlus.api.objects.data.Quad; +import gtPlusPlus.api.objects.minecraft.ItemPackage; +import gtPlusPlus.core.item.base.ore.BaseItemMilledOre; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.material.ELEMENT; +import gtPlusPlus.core.material.Material; +import gtPlusPlus.core.material.NONMATERIAL; +import gtPlusPlus.core.recipe.common.CI; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.minecraft.MaterialUtils; +import gtPlusPlus.core.util.minecraft.NBTUtils; +import gtPlusPlus.xmod.bop.HANDLER_BiomesOPlenty; +import gtPlusPlus.xmod.bop.blocks.BOP_Block_Registrator; + +public class MilledOreProcessing extends ItemPackage { + + /** + * Fluids + */ + public static Fluid SphaleriteFlotationFroth; + + public static Fluid ChalcopyriteFlotationFroth; + public static Fluid NickelFlotationFroth; + public static Fluid PlatinumFlotationFroth; + public static Fluid PentlanditeFlotationFroth; + + public static Fluid RedstoneFlotationFroth; + public static Fluid SpessartineFlotationFroth; + public static Fluid GrossularFlotationFroth; + public static Fluid AlmandineFlotationFroth; + public static Fluid PyropeFlotationFroth; + public static Fluid MonaziteFlotationFroth; + + public static Fluid PineOil; + + /** + * Items + */ + + // Zinc, Iron, Indium, Germanium + public static Item milledSphalerite; + + // Copper, Iron, Cadmium, Indium + public static Item milledChalcopyrite; + + // Nickel, Cobalt, Rhodium, Ruthenium + public static Item milledNickel; + + // Platinum, Rhodium, Selenium, Tellurium + public static Item milledPlatinum; + + // Iron, Nickel, Promethium, Hafnium + public static Item milledPentlandite; + + // Redstone, Chrome, Firestone, Dysprosium + public static Item milledRedstone; + + // Manganese, Aluminium, Osmium, Strontium + public static Item milledSpessartine; + + // Calcium, Aluminium, Tungsten, Thallium + public static Item milledGrossular; + + // Aluminium, Magnesium, Yttrium, Ytterbium + public static Item milledAlmandine; + + // Magnesium, Manganese, Borax, Rhenium + public static Item milledPyrope; + + // Erbium, Lanthanum, Praseodymium, Europium + public static Item milledMonazite; + + @Override + public void items() { + + milledSphalerite = BaseItemMilledOre.generate(Materials.Sphalerite, MaterialUtils.getVoltageForTier(6)); + milledChalcopyrite = BaseItemMilledOre.generate(Materials.Chalcopyrite, MaterialUtils.getVoltageForTier(5)); + milledNickel = BaseItemMilledOre.generate(Materials.Nickel, MaterialUtils.getVoltageForTier(5)); + milledPlatinum = BaseItemMilledOre.generate(Materials.Platinum, MaterialUtils.getVoltageForTier(6)); + milledPentlandite = BaseItemMilledOre.generate(Materials.Pentlandite, MaterialUtils.getVoltageForTier(6)); + + milledRedstone = BaseItemMilledOre.generate(Materials.Redstone, MaterialUtils.getVoltageForTier(5)); + milledSpessartine = BaseItemMilledOre.generate(Materials.Spessartine, MaterialUtils.getVoltageForTier(6)); + milledGrossular = BaseItemMilledOre.generate(Materials.Grossular, MaterialUtils.getVoltageForTier(6)); + milledAlmandine = BaseItemMilledOre.generate(Materials.Almandine, MaterialUtils.getVoltageForTier(6)); + milledPyrope = BaseItemMilledOre.generate(Materials.Pyrope, MaterialUtils.getVoltageForTier(4)); + milledMonazite = BaseItemMilledOre.generate(Materials.Monazite, MaterialUtils.getVoltageForTier(7)); + } + + @Override + public void blocks() { + // None yet + } + + @Override + public void fluids() { + + short[] aZincFrothRGB = Materials.Sphalerite.mRGBa; + SphaleriteFlotationFroth = FluidUtils.generateFluidNoPrefix( + "froth.zincflotation", + "Sphalerite Froth", + 32 + 175, + new short[] { aZincFrothRGB[0], aZincFrothRGB[1], aZincFrothRGB[2], 100 }, + true); + short[] aCopperFrothRGB = Materials.Chalcopyrite.mRGBa; + ChalcopyriteFlotationFroth = FluidUtils.generateFluidNoPrefix( + "froth.copperflotation", + "Chalcopyrite Froth", + 32 + 175, + new short[] { aCopperFrothRGB[0], aCopperFrothRGB[1], aCopperFrothRGB[2], 100 }, + true); + short[] aNickelFrothRGB = Materials.Nickel.mRGBa; + NickelFlotationFroth = FluidUtils.generateFluidNoPrefix( + "froth.nickelflotation", + "Nickel Froth", + 32 + 175, + new short[] { aNickelFrothRGB[0], aNickelFrothRGB[1], aNickelFrothRGB[2], 100 }, + true); + short[] aPlatinumFrothRGB = Materials.Platinum.mRGBa; + PlatinumFlotationFroth = FluidUtils.generateFluidNoPrefix( + "froth.platinumflotation", + "Platinum Froth", + 32 + 175, + new short[] { aPlatinumFrothRGB[0], aPlatinumFrothRGB[1], aPlatinumFrothRGB[2], 100 }, + true); + short[] aPentlanditeFrothRGB = Materials.Pentlandite.mRGBa; + PentlanditeFlotationFroth = FluidUtils.generateFluidNoPrefix( + "froth.pentlanditeflotation", + "Pentlandite Froth", + 32 + 175, + new short[] { aPentlanditeFrothRGB[0], aPentlanditeFrothRGB[1], aPentlanditeFrothRGB[2], 100 }, + true); + + short[] aRedstoneFrothRGB = Materials.Redstone.mRGBa; + RedstoneFlotationFroth = FluidUtils.generateFluidNoPrefix( + "froth.redstoneflotation", + "Redstone Froth", + 32 + 175, + new short[] { aRedstoneFrothRGB[0], aRedstoneFrothRGB[1], aRedstoneFrothRGB[2], 100 }, + true); + short[] aSpessartineFrothRGB = Materials.Spessartine.mRGBa; + SpessartineFlotationFroth = FluidUtils.generateFluidNoPrefix( + "froth.spessartineflotation", + "Spessartine Froth", + 32 + 175, + new short[] { aSpessartineFrothRGB[0], aSpessartineFrothRGB[1], aSpessartineFrothRGB[2], 100 }, + true); + short[] aGrossularFrothRGB = Materials.Grossular.mRGBa; + GrossularFlotationFroth = FluidUtils.generateFluidNoPrefix( + "froth.grossularflotation", + "Grossular Froth", + 32 + 175, + new short[] { aGrossularFrothRGB[0], aGrossularFrothRGB[1], aGrossularFrothRGB[2], 100 }, + true); + short[] aAlmandineFrothRGB = Materials.Almandine.mRGBa; + AlmandineFlotationFroth = FluidUtils.generateFluidNoPrefix( + "froth.almandineflotation", + "Almandine Froth", + 32 + 175, + new short[] { aAlmandineFrothRGB[0], aAlmandineFrothRGB[1], aAlmandineFrothRGB[2], 100 }, + true); + short[] aPyropeFrothRGB = Materials.Pyrope.mRGBa; + PyropeFlotationFroth = FluidUtils.generateFluidNoPrefix( + "froth.pyropeflotation", + "Pyrope Froth", + 32 + 175, + new short[] { aPyropeFrothRGB[0], aPyropeFrothRGB[1], aPyropeFrothRGB[2], 100 }, + true); + short[] aMonaziteFrothRGB = Materials.Monazite.mRGBa; + MonaziteFlotationFroth = FluidUtils.generateFluidNoPrefix( + "froth.Monaziteflotation", + "Monazite Froth", + 32 + 175, + new short[] { aMonaziteFrothRGB[0], aMonaziteFrothRGB[1], aMonaziteFrothRGB[2], 100 }, + true); + + PineOil = FluidUtils + .generateFluidNoPrefix("pineoil", "Pine Oil", 32 + 175, new short[] { 250, 200, 60, 100 }, true); + } + + public MilledOreProcessing() { + super(); + Logger.INFO("Adding Ore Milling content"); + } + + private static void addMiscRecipes() { + + /* + * First 5 + */ + + // milledSphalerite + registerOreDataForMilledType( + SphaleriteFlotationFroth, + ELEMENT.getInstance().ZINC, + 180, + ELEMENT.getInstance().IRON, + 120, + ELEMENT.getInstance().INDIUM, + 64, + ELEMENT.getInstance().GERMANIUM, + 15); + // milledChalcopyrite + registerOreDataForMilledType( + ChalcopyriteFlotationFroth, + ELEMENT.getInstance().COPPER, + 180, + ELEMENT.getInstance().IRON, + 120, + ELEMENT.getInstance().CADMIUM, + 50, + ELEMENT.getInstance().INDIUM, + 10); + // milledNickel + registerOreDataForMilledType( + NickelFlotationFroth, + ELEMENT.getInstance().NICKEL, + 150, + ELEMENT.getInstance().COBALT, + 120, + ELEMENT.getInstance().RHODIUM, + 32, + ELEMENT.getInstance().RUTHENIUM, + 16); + // milledPlatinum + registerOreDataForMilledType( + PlatinumFlotationFroth, + ELEMENT.getInstance().PLATINUM, + 120, + ELEMENT.getInstance().RHODIUM, + 60, + ELEMENT.getInstance().SELENIUM, + 40, + ELEMENT.getInstance().TELLURIUM, + 10); + // milledPentlandite + registerOreDataForMilledType( + PentlanditeFlotationFroth, + ELEMENT.getInstance().IRON, + 150, + ELEMENT.getInstance().NICKEL, + 100, + ELEMENT.getInstance().PROMETHIUM, + 20, + ELEMENT.getInstance().HAFNIUM, + 10); + + /* + * Second 5 + */ + // milledRedstone + registerOreDataForMilledType( + RedstoneFlotationFroth, + NONMATERIAL.REDSTONE, + 300, + ELEMENT.getInstance().CHROMIUM, + 60, + MaterialUtils.generateMaterialFromGtENUM(Materials.Firestone), + 45, + ELEMENT.getInstance().DYSPROSIUM, + 16); + // milledSpessartine + registerOreDataForMilledType( + SpessartineFlotationFroth, + ELEMENT.getInstance().MANGANESE, + 150, + ELEMENT.getInstance().ALUMINIUM, + 90, + ELEMENT.getInstance().OSMIUM, + 30, + ELEMENT.getInstance().STRONTIUM, + 20); + // milledGrossular + registerOreDataForMilledType( + GrossularFlotationFroth, + ELEMENT.getInstance().CALCIUM, + 180, + ELEMENT.getInstance().ALUMINIUM, + 110, + ELEMENT.getInstance().TUNGSTEN, + 60, + ELEMENT.getInstance().THALLIUM, + 15); + // milledAlmandine + registerOreDataForMilledType( + AlmandineFlotationFroth, + ELEMENT.getInstance().ALUMINIUM, + 150, + ELEMENT.getInstance().MAGNESIUM, + 75, + ELEMENT.getInstance().YTTRIUM, + 25, + ELEMENT.getInstance().YTTERBIUM, + 15); + // milledPyrope + registerOreDataForMilledType( + PyropeFlotationFroth, + ELEMENT.getInstance().MAGNESIUM, + 110, + ELEMENT.getInstance().MANGANESE, + 70, + MaterialUtils.generateMaterialFromGtENUM(Materials.Borax), + 60, + ELEMENT.getInstance().RHENIUM, + 20); + // milledMonazite TODO + registerOreDataForMilledType( + MonaziteFlotationFroth, + ELEMENT.getInstance().ERBIUM, + 64, + ELEMENT.getInstance().LANTHANUM, + 32, + ELEMENT.getInstance().LUTETIUM, + 16, + ELEMENT.getInstance().EUROPIUM, + 8); + } + + @Override + public String errorMessage() { + return "Failed to generate recipes for OreMillingProc."; + } + + @Override + public boolean generateRecipes() { + addMiscRecipes(); + addPineOilExtraction(); + addFlotationRecipes1(); + addFlotationRecipes2(); + addVacuumFurnaceRecipes(); + return true; + } + + private void addVacuumFurnaceRecipes() { + int aCircuitID = 1; + + CORE.RA.addVacuumFurnaceRecipe( + new ItemStack[] { CI.getNumberedCircuit(aCircuitID++) }, + new FluidStack[] { FluidUtils.getFluidStack(SphaleriteFlotationFroth, 4000) }, + getOutputsFromMap(SphaleriteFlotationFroth), + new FluidStack[] { FluidUtils.getFluidStack(AgriculturalChem.RedMud, 2000), FluidUtils.getWater(2000) }, + 20 * 120, + MaterialUtils.getVoltageForTier(6), + 5500); + CORE.RA.addVacuumFurnaceRecipe( + new ItemStack[] { CI.getNumberedCircuit(aCircuitID++) }, + new FluidStack[] { FluidUtils.getFluidStack(ChalcopyriteFlotationFroth, 4000) }, + getOutputsFromMap(ChalcopyriteFlotationFroth), + new FluidStack[] { FluidUtils.getFluidStack(AgriculturalChem.RedMud, 2000), FluidUtils.getWater(2000) }, + 20 * 120, + MaterialUtils.getVoltageForTier(5), + 4500); + + CORE.RA.addVacuumFurnaceRecipe( + new ItemStack[] { CI.getNumberedCircuit(aCircuitID++) }, + new FluidStack[] { FluidUtils.getFluidStack(NickelFlotationFroth, 4000) }, + getOutputsFromMap(NickelFlotationFroth), + new FluidStack[] { FluidUtils.getFluidStack(AgriculturalChem.RedMud, 2000), FluidUtils.getWater(2000) }, + 20 * 120, + MaterialUtils.getVoltageForTier(5), + 4500); + CORE.RA.addVacuumFurnaceRecipe( + new ItemStack[] { CI.getNumberedCircuit(aCircuitID++) }, + new FluidStack[] { FluidUtils.getFluidStack(PlatinumFlotationFroth, 4000) }, + getOutputsFromMap(PlatinumFlotationFroth), + new FluidStack[] { FluidUtils.getFluidStack(AgriculturalChem.RedMud, 2000), FluidUtils.getWater(2000) }, + 20 * 120, + MaterialUtils.getVoltageForTier(6), + 5500); + CORE.RA.addVacuumFurnaceRecipe( + new ItemStack[] { CI.getNumberedCircuit(aCircuitID++) }, + new FluidStack[] { FluidUtils.getFluidStack(PentlanditeFlotationFroth, 4000) }, + getOutputsFromMap(PentlanditeFlotationFroth), + new FluidStack[] { FluidUtils.getFluidStack(AgriculturalChem.RedMud, 2000), FluidUtils.getWater(2000) }, + 20 * 120, + MaterialUtils.getVoltageForTier(6), + 5500); + + CORE.RA.addVacuumFurnaceRecipe( + new ItemStack[] { CI.getNumberedCircuit(aCircuitID++) }, + new FluidStack[] { FluidUtils.getFluidStack(RedstoneFlotationFroth, 4000) }, + getOutputsFromMap(RedstoneFlotationFroth), + new FluidStack[] { FluidUtils.getFluidStack(AgriculturalChem.RedMud, 2000), FluidUtils.getWater(2000) }, + 20 * 120, + MaterialUtils.getVoltageForTier(5), + 4500); + CORE.RA.addVacuumFurnaceRecipe( + new ItemStack[] { CI.getNumberedCircuit(aCircuitID++) }, + new FluidStack[] { FluidUtils.getFluidStack(SpessartineFlotationFroth, 4000) }, + getOutputsFromMap(SpessartineFlotationFroth), + new FluidStack[] { FluidUtils.getFluidStack(AgriculturalChem.RedMud, 2000), FluidUtils.getWater(2000) }, + 20 * 120, + MaterialUtils.getVoltageForTier(6), + 5500); + CORE.RA.addVacuumFurnaceRecipe( + new ItemStack[] { CI.getNumberedCircuit(aCircuitID++) }, + new FluidStack[] { FluidUtils.getFluidStack(GrossularFlotationFroth, 4000) }, + getOutputsFromMap(GrossularFlotationFroth), + new FluidStack[] { FluidUtils.getFluidStack(AgriculturalChem.RedMud, 2000), FluidUtils.getWater(2000) }, + 20 * 120, + MaterialUtils.getVoltageForTier(6), + 5500); + CORE.RA.addVacuumFurnaceRecipe( + new ItemStack[] { CI.getNumberedCircuit(aCircuitID++) }, + new FluidStack[] { FluidUtils.getFluidStack(AlmandineFlotationFroth, 4000) }, + getOutputsFromMap(AlmandineFlotationFroth), + new FluidStack[] { FluidUtils.getFluidStack(AgriculturalChem.RedMud, 2000), FluidUtils.getWater(2000) }, + 20 * 120, + MaterialUtils.getVoltageForTier(6), + 5500); + CORE.RA.addVacuumFurnaceRecipe( + new ItemStack[] { CI.getNumberedCircuit(aCircuitID++) }, + new FluidStack[] { FluidUtils.getFluidStack(PyropeFlotationFroth, 4000) }, + getOutputsFromMap(PyropeFlotationFroth), + new FluidStack[] { FluidUtils.getFluidStack(AgriculturalChem.RedMud, 2000), FluidUtils.getWater(2000) }, + 20 * 120, + MaterialUtils.getVoltageForTier(4), + 3500); + CORE.RA.addVacuumFurnaceRecipe( + new ItemStack[] { CI.getNumberedCircuit(aCircuitID++) }, + new FluidStack[] { FluidUtils.getFluidStack(MonaziteFlotationFroth, 4000) }, + getOutputsFromMap(MonaziteFlotationFroth), + new FluidStack[] { FluidUtils.getFluidStack(AgriculturalChem.RedMud, 2000), FluidUtils.getWater(2000) }, + 20 * 120, + MaterialUtils.getVoltageForTier(7), + 7500); + } + + private void addFlotationRecipes1() { + + // Sphalerite + CORE.RA.addFlotationRecipe( + Materials.Sphalerite, + ItemUtils.getSimpleStack(GenericChem.mSodiumEthylXanthate, 1), + new FluidStack[] { FluidUtils.getFluidStack(PineOil, 14000), }, + new FluidStack[] { FluidUtils.getFluidStack(SphaleriteFlotationFroth, 1000) }, + 20 * 480, + MaterialUtils.getVoltageForTier(6)); + + // Chalcopyrite + CORE.RA.addFlotationRecipe( + Materials.Chalcopyrite, + ItemUtils.getSimpleStack(GenericChem.mSodiumEthylXanthate, 1), + new FluidStack[] { FluidUtils.getFluidStack(PineOil, 12000), }, + new FluidStack[] { FluidUtils.getFluidStack(ChalcopyriteFlotationFroth, 1000) }, + 20 * 480, + MaterialUtils.getVoltageForTier(5)); + + // Nickel + CORE.RA.addFlotationRecipe( + Materials.Nickel, + ItemUtils.getSimpleStack(GenericChem.mPotassiumEthylXanthate, 1), + new FluidStack[] { FluidUtils.getFluidStack(PineOil, 25000), }, + new FluidStack[] { FluidUtils.getFluidStack(NickelFlotationFroth, 1000) }, + 20 * 480, + MaterialUtils.getVoltageForTier(5)); + + // Platinum + CORE.RA.addFlotationRecipe( + Materials.Platinum, + ItemUtils.getSimpleStack(GenericChem.mPotassiumEthylXanthate, 1), + new FluidStack[] { FluidUtils.getFluidStack(PineOil, 35000), }, + new FluidStack[] { FluidUtils.getFluidStack(PlatinumFlotationFroth, 1000) }, + 20 * 480, + MaterialUtils.getVoltageForTier(6)); + + // Pentlandite + CORE.RA.addFlotationRecipe( + Materials.Pentlandite, + ItemUtils.getSimpleStack(GenericChem.mSodiumEthylXanthate, 1), + new FluidStack[] { FluidUtils.getFluidStack(PineOil, 14000), }, + new FluidStack[] { FluidUtils.getFluidStack(PentlanditeFlotationFroth, 1000) }, + 20 * 480, + MaterialUtils.getVoltageForTier(6)); + } + + private void addFlotationRecipes2() { + + // Redstone + CORE.RA.addFlotationRecipe( + Materials.Redstone, + ItemUtils.getSimpleStack(GenericChem.mSodiumEthylXanthate, 1), + new FluidStack[] { FluidUtils.getFluidStack(PineOil, 13000), }, + new FluidStack[] { FluidUtils.getFluidStack(RedstoneFlotationFroth, 1000) }, + 20 * 480, + MaterialUtils.getVoltageForTier(5)); + + // Spessartine + CORE.RA.addFlotationRecipe( + Materials.Spessartine, + ItemUtils.getSimpleStack(GenericChem.mPotassiumEthylXanthate, 1), + new FluidStack[] { FluidUtils.getFluidStack(PineOil, 35000), }, + new FluidStack[] { FluidUtils.getFluidStack(SpessartineFlotationFroth, 1000) }, + 20 * 480, + MaterialUtils.getVoltageForTier(6)); + + // Grossular + CORE.RA.addFlotationRecipe( + Materials.Grossular, + ItemUtils.getSimpleStack(GenericChem.mPotassiumEthylXanthate, 1), + new FluidStack[] { FluidUtils.getFluidStack(PineOil, 28000), }, + new FluidStack[] { FluidUtils.getFluidStack(GrossularFlotationFroth, 1000) }, + 20 * 480, + MaterialUtils.getVoltageForTier(6)); + + // Almandine + CORE.RA.addFlotationRecipe( + Materials.Almandine, + ItemUtils.getSimpleStack(GenericChem.mSodiumEthylXanthate, 1), + new FluidStack[] { FluidUtils.getFluidStack(PineOil, 18000), }, + new FluidStack[] { FluidUtils.getFluidStack(AlmandineFlotationFroth, 1000) }, + 20 * 480, + MaterialUtils.getVoltageForTier(5)); + + // Pyrope + CORE.RA.addFlotationRecipe( + Materials.Pyrope, + ItemUtils.getSimpleStack(GenericChem.mSodiumEthylXanthate, 1), + new FluidStack[] { FluidUtils.getFluidStack(PineOil, 8000), }, + new FluidStack[] { FluidUtils.getFluidStack(PyropeFlotationFroth, 1000) }, + 20 * 480, + MaterialUtils.getVoltageForTier(4)); + + // Monazite + CORE.RA.addFlotationRecipe( + Materials.Monazite, + ItemUtils.getSimpleStack(GenericChem.mPotassiumEthylXanthate, 1), + new FluidStack[] { FluidUtils.getFluidStack(PineOil, 30000), }, + new FluidStack[] { FluidUtils.getFluidStack(MonaziteFlotationFroth, 1000) }, + 20 * 480, + MaterialUtils.getVoltageForTier(6)); + } + + private void addPineOilExtraction() { + AutoMap<ItemStack> aLogs = new AutoMap<>(); + AutoMap<ItemStack> aLeaves = new AutoMap<>(); + AutoMap<ItemStack> aSaplings = new AutoMap<>(); + AutoMap<ItemStack> aPinecones = new AutoMap<>(); + + ItemStack aCrushedPine = ItemUtils.getSimpleStack(AgriculturalChem.mCrushedPine, 1); + + aLogs.add(ItemUtils.getSimpleStack(BOP_Block_Registrator.log_Pine)); + aLeaves.add(ItemUtils.getSimpleStack(BOP_Block_Registrator.leaves_Pine)); + aSaplings.add(ItemUtils.getSimpleStack(BOP_Block_Registrator.sapling_Pine)); + aPinecones.add(ItemUtils.getSimpleStack(AgriculturalChem.mPinecone, 1)); + + if (BiomesOPlenty.isModLoaded()) { + aLogs.add(HANDLER_BiomesOPlenty.getStack(HANDLER_BiomesOPlenty.logs4, 0, 1)); + aLeaves.add(HANDLER_BiomesOPlenty.getStack(HANDLER_BiomesOPlenty.colorizedLeaves2, 1, 1)); + aSaplings.add(HANDLER_BiomesOPlenty.getStack(HANDLER_BiomesOPlenty.colorizedSaplings, 5, 1)); + aPinecones.add(ItemUtils.simpleMetaStack(HANDLER_BiomesOPlenty.mPineCone, 13, 1)); + } + if (Forestry.isModLoaded()) { + ItemStack aForestryLog = ItemUtils.getItemStackFromFQRN("Forestry:logs", 1); + if (aForestryLog != null) { + aForestryLog.setItemDamage(20); // Set to Pine + aLogs.add(aForestryLog); + } + ItemStack aForestryLeaves = ItemUtils.getItemStackFromFQRN("Forestry:leaves", 1); + if (aForestryLeaves != null) { + NBTUtils.setString(aForestryLeaves, "species", "forestry.treePine"); // Set to Pine + aLeaves.add(aForestryLeaves); + } + } + + for (ItemStack aLog : aLogs) { + addRecipe(aLog, ItemUtils.getSimpleStack(aCrushedPine, 16), new int[] { 10000, 7500, 5000, 2500 }, 10, 120); + } + for (ItemStack aLeaf : aLeaves) { + addRecipe(aLeaf, ItemUtils.getSimpleStack(aCrushedPine, 2), new int[] { 5000, 5000, 2500, 2500 }, 10, 30); + } + for (ItemStack aSapling : aSaplings) { + addRecipe( + aSapling, + ItemUtils.getSimpleStack(aCrushedPine, 4), + new int[] { 7500, 7500, 2500, 2500 }, + 10, + 60); + } + for (ItemStack aCone : aPinecones) { + addRecipe(aCone, ItemUtils.getSimpleStack(aCrushedPine, 1), new int[] { 7500, 7500, 5000, 2500 }, 10, 60); + } + + CORE.RA.addChemicalPlantRecipe( + new ItemStack[] { CI.getNumberedAdvancedCircuit(16), ItemUtils.getSimpleStack(aCrushedPine, 64) }, + new FluidStack[] { FluidUtils.getSteam(5000), }, + new ItemStack[] { ItemUtils.getItemStackOfAmountFromOreDict("dustTinyAsh", 5), + ItemUtils.getItemStackOfAmountFromOreDict("dustTinyAsh", 5), + ItemUtils.getItemStackOfAmountFromOreDict("dustTinyDarkAsh", 5), + ItemUtils.getItemStackOfAmountFromOreDict("dustTinyDarkAsh", 5) }, + new FluidStack[] { FluidUtils.getFluidStack(PineOil, 500) }, + new int[] { 2000, 2000, 2000, 2000 }, + 20 * 60, + 120, + 3); + + CORE.RA.addChemicalPlantRecipe( + new ItemStack[] { CI.getNumberedAdvancedCircuit(18), ItemUtils.getSimpleStack(aCrushedPine, 64) }, + new FluidStack[] { FluidUtils.getSuperHeatedSteam(5000), }, + new ItemStack[] { ItemUtils.getItemStackOfAmountFromOreDict("dustTinyAsh", 5), + ItemUtils.getItemStackOfAmountFromOreDict("dustTinyAsh", 5), + ItemUtils.getItemStackOfAmountFromOreDict("dustTinyDarkAsh", 5), + ItemUtils.getItemStackOfAmountFromOreDict("dustTinyDarkAsh", 5) }, + new FluidStack[] { FluidUtils.getFluidStack(PineOil, 1500) }, + new int[] { 3000, 3000, 3000, 3000 }, + 20 * 45, + 120, + 4); + } + + public boolean addRecipe(ItemStack aInput, ItemStack aOutput1, int[] aChances, int aTime, int aEU) { + aOutput1 = GT_OreDictUnificator.get(true, aOutput1); + ItemStack aOutputs[] = new ItemStack[4]; + for (int i = 0; i < aChances.length; i++) { + aOutputs[i] = aOutput1; + } + aOutputs = cleanArray(aOutputs); + if ((GT_Utility.isStackInvalid(aInput)) + || (GT_Utility.isStackInvalid(aOutput1) || (GT_Utility.getContainerItem(aInput, false) != null))) { + return false; + } + + return CORE.RA.addChemicalPlantRecipe( + new ItemStack[] { CI.getNumberedAdvancedCircuit(14), aInput }, + new FluidStack[] {}, + aOutputs, + new FluidStack[] {}, + aChances, + aTime * 20, + aEU, + 3); + } + + public static ItemStack[] cleanArray(ItemStack[] input) { + int aArraySize = input.length; + AutoMap<ItemStack> aCleanedItems = new AutoMap<>(); + for (ItemStack checkStack : input) { + if (ItemUtils.checkForInvalidItems(checkStack)) { + aCleanedItems.put(checkStack); + } + } + ItemStack[] aOutput = new ItemStack[aCleanedItems.size()]; + for (int i = 0; i < aArraySize; i++) { + ItemStack aMappedStack = aCleanedItems.get(i); + if (aMappedStack != null) { + aOutput[i] = aMappedStack; + } + } + return aOutput; + } + + private static final HashMap<String, Quad<Pair<Material, Integer>, Pair<Material, Integer>, Pair<Material, Integer>, Pair<Material, Integer>>> aMilledFluidMap = new HashMap<>(); + + public static void registerOreDataForMilledType(Fluid aMilledFluid, Materials aOutput1, int aPerc1, + Materials aOutput2, int aPerc2, Materials aOutput3, int aPerc3, Materials aOutput4, int aPerc4) { + registerOreDataForMilledType( + aMilledFluid, + MaterialUtils.generateMaterialFromGtENUM(aOutput1), + aPerc1, + MaterialUtils.generateMaterialFromGtENUM(aOutput2), + aPerc2, + MaterialUtils.generateMaterialFromGtENUM(aOutput3), + aPerc3, + MaterialUtils.generateMaterialFromGtENUM(aOutput4), + aPerc4); + } + + public static void registerOreDataForMilledType(Fluid aMilledFluid, Material aOutput1, int aPerc1, + Material aOutput2, int aPerc2, Material aOutput3, int aPerc3, Material aOutput4, int aPerc4) { + + Pair<Material, Integer> aFluidOutput1 = new Pair<>(aOutput1, aPerc1); + Pair<Material, Integer> aFluidOutput2 = new Pair<>(aOutput2, aPerc2); + Pair<Material, Integer> aFluidOutput3 = new Pair<>(aOutput3, aPerc3); + Pair<Material, Integer> aFluidOutput4 = new Pair<>(aOutput4, aPerc4); + Quad<Pair<Material, Integer>, Pair<Material, Integer>, Pair<Material, Integer>, Pair<Material, Integer>> aDataQuad = new Quad<>( + aFluidOutput1, + aFluidOutput2, + aFluidOutput3, + aFluidOutput4); + aMilledFluidMap.put(aMilledFluid.getUnlocalizedName(), aDataQuad); + } + + private static ItemStack[] getOutputsFromMap(Fluid aFluid) { + String aKey = aFluid.getUnlocalizedName(); + return getArrayFromQuad(aMilledFluidMap.get(aKey)); + } + + private static ItemStack[] getArrayFromQuad( + Quad<Pair<Material, Integer>, Pair<Material, Integer>, Pair<Material, Integer>, Pair<Material, Integer>> aData) { + AutoMap<ItemStack> aOutputs = new AutoMap<>(); + for (Object aPair : aData.values()) { + if (aPair != null && Pair.class.isInstance(aPair)) { + Pair aObj = (Pair) aPair; + Material aMat = (Material) aObj.getKey(); + int aCount = (int) aObj.getValue(); + aOutputs.addAll(getItemStackFromPair(aMat, aCount)); + } + } + ItemStack[] aRealOutputArray = new ItemStack[aOutputs.size()]; + int aIndex = 0; + for (ItemStack aStack : aOutputs) { + aRealOutputArray[aIndex++] = aStack; + } + return aRealOutputArray; + } + + private static AutoMap<ItemStack> getItemStackFromPair(Material aMat, Integer aCount) { + AutoMap<ItemStack> aOutputs = new AutoMap<>(); + if (aCount > 64) { + AutoMap<Integer> sizes = getStackSizes(aCount); + for (int aSplitSize : sizes) { + ItemStack aDustStack = aMat.getDust(aSplitSize); + aOutputs.put(aDustStack); + } + } else { + ItemStack aDustStack = aMat.getDust(aCount); + aOutputs.put(aDustStack); + } + return aOutputs; + } + + private static AutoMap<Integer> getStackSizes(int aBigSize) { + AutoMap<Integer> aSizes = new AutoMap<>(); + if (aBigSize <= 64) { + aSizes.add(aBigSize); + } else { + for (int i = aBigSize; i > 0; i -= 64) { + aSizes.add(i); + } + } + return aSizes; + } +} diff --git a/src/main/java/gtPlusPlus/core/item/chemistry/NuclearChem.java b/src/main/java/gtPlusPlus/core/item/chemistry/NuclearChem.java new file mode 100644 index 0000000000..d83b5a7cea --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/chemistry/NuclearChem.java @@ -0,0 +1,105 @@ +package gtPlusPlus.core.item.chemistry; + +import static gregtech.api.util.GT_RecipeBuilder.SECONDS; +import static gregtech.api.util.GT_RecipeConstants.UniversalChemical; + +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; + +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.TierEU; +import gregtech.api.util.GT_OreDictUnificator; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.minecraft.ItemPackage; +import gtPlusPlus.core.util.minecraft.FluidUtils; + +public class NuclearChem extends ItemPackage { + + public static Fluid Burnt_LiFBeF2ThF4UF4; + public static Fluid Burnt_LiFBeF2ZrF4UF4; + public static Fluid Burnt_LiFBeF2ZrF4U235; + + public static Fluid Impure_LiFBeF2; + + public static Fluid GeneticMutagen; + private static boolean generateMutagenRecipe = false; + + @Override + public void items() {} + + @Override + public void blocks() {} + + @Override + public void fluids() { + // Create Used Nuclear Fuels + Burnt_LiFBeF2ThF4UF4 = FluidUtils.generateFluidNonMolten( + "BurntLiFBeF2ThF4UF4", + "Burnt LiFBeF2ThF4UF4 Salt", + 545, + new short[] { 48, 175, 48, 100 }, + null, + null); + Burnt_LiFBeF2ZrF4UF4 = FluidUtils.generateFluidNonMolten( + "BurntLiFBeF2ZrF4UF4", + "Burnt LiFBeF2ZrF4UF4 Salt", + 520, + new short[] { 48, 168, 68, 100 }, + null, + null); + Burnt_LiFBeF2ZrF4U235 = FluidUtils.generateFluidNonMolten( + "BurntLiFBeF2ZrF4U235", + "Burnt LiFBeF2ZrF4U235 Salt", + 533, + new short[] { 68, 185, 48, 100 }, + null, + null); + Impure_LiFBeF2 = FluidUtils.generateFluidNonMolten( + "ImpureLiFBeF2", + "Impure Molten Salt Base", + 533, + new short[] { 110, 75, 186, 100 }, + null, + null); + if (FluidUtils.getFluidStack("fluid.Mutagen", 1) == null) { + GeneticMutagen = FluidUtils.generateFluidNonMolten( + "GeneticMutagen", + "Genetic Mutagen", + 12, + new short[] { 22, 148, 185, 100 }, + null, + null); + generateMutagenRecipe = true; + } else { + GeneticMutagen = FluidUtils.getFluidStack("fluid.Mutagen", 1) + .getFluid(); + } + } + + @Override + public String errorMessage() { + return "Bad Nuclear Chemistry Recipes."; + } + + @Override + public boolean generateRecipes() { + if (generateMutagenRecipe) { + chemReactor_CreateMutagen(); + } + return true; + } + + private static void chemReactor_CreateMutagen() { + GT_Values.RA.stdBuilder() + .itemInputs( + GT_OreDictUnificator.get(OrePrefixes.gem, Materials.NetherStar, 2), + GT_Utility.getIntegratedCircuit(20)) + .fluidInputs(FluidRegistry.getFluidStack("mobessence", 5000)) + .fluidOutputs(FluidUtils.getFluidStack(GeneticMutagen, 8000)) + .duration(30 * SECONDS) + .eut(TierEU.RECIPE_HV) + .addTo(UniversalChemical); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/chemistry/RocketFuels.java b/src/main/java/gtPlusPlus/core/item/chemistry/RocketFuels.java new file mode 100644 index 0000000000..3fc682e7cc --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/chemistry/RocketFuels.java @@ -0,0 +1,562 @@ +package gtPlusPlus.core.item.chemistry; + +import static gregtech.api.recipe.RecipeMaps.distilleryRecipes; +import static gregtech.api.recipe.RecipeMaps.mixerRecipes; +import static gregtech.api.recipe.RecipeMaps.vacuumFreezerRecipes; +import static gregtech.api.util.GT_RecipeBuilder.SECONDS; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; + +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.TierEU; +import gregtech.api.util.GT_OreDictUnificator; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.minecraft.ItemPackage; +import gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.core.item.base.BaseItemComponent; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.recipe.common.CI; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.minecraft.MaterialUtils; + +public class RocketFuels extends ItemPackage { + + public static HashSet<String> mValidRocketFuelNames = new HashSet<>(); + public static HashMap<Integer, Fluid> mValidRocketFuels = new HashMap<>(); + + public static Fluid Oil_Heavy; + public static Fluid Diesel; + public static Fluid Kerosene; + public static Fluid RP1; + public static Fluid Nitrogen_Tetroxide; + public static Fluid Hydrazine; + public static Fluid Monomethylhydrazine; + public static Fluid Unsymmetrical_Dimethylhydrazine; + public static Fluid Nitrous_Oxide; + public static Fluid Hydrated_Ammonium_Nitrate_Slurry; + public static Fluid Liquid_Oxygen; + public static Fluid Liquid_Hydrogen; + public static Fluid Formaldehyde; + + // Rocket Fuel Mixes + public static Fluid Unsymmetrical_Dimethylhydrazine_Plus_Nitrogen_Tetroxide; + public static Fluid RP1_Plus_Liquid_Oxygen; + public static Fluid Dense_Hydrazine_Mix; + public static Fluid Monomethylhydrazine_Plus_Nitric_Acid; + + public static Item Ammonium_Nitrate_Dust; + public static Item Formaldehyde_Catalyst_Dust; + public static ItemStack Formaldehyde_Catalyst_Stack; + + public RocketFuels() { + super(true); + } + + public static void createKerosene() { + + FluidStack fuelA = FluidUtils.getFluidStack("diesel", 3000); + FluidStack fuelB = FluidUtils.getFluidStack("fuel", 3000); + + if (fuelA != null) { + GT_Values.RA.stdBuilder() + .itemInputs(GT_Utility.getIntegratedCircuit(23)) + .fluidInputs(fuelA) + .fluidOutputs(FluidUtils.getFluidStack(Kerosene, 1800)) + .duration(10 * SECONDS) + .eut(TierEU.RECIPE_MV / 2) + .addTo(distilleryRecipes); + } + if (fuelA == null && fuelB != null) { + GT_Values.RA.stdBuilder() + .itemInputs(GT_Utility.getIntegratedCircuit(23)) + .fluidInputs(fuelB) + .fluidOutputs(FluidUtils.getFluidStack(Kerosene, 1800)) + .duration(10 * SECONDS) + .eut(TierEU.RECIPE_MV / 2) + .addTo(distilleryRecipes); + } + } + + public static void createRP1() { + FluidStack fuelA = FluidUtils.getFluidStack(Kerosene, 1000); + if (fuelA != null) { + GT_Values.RA.stdBuilder() + .itemInputs(GT_Utility.getIntegratedCircuit(23)) + .fluidInputs(fuelA) + .fluidOutputs(FluidUtils.getFluidStack(RP1, 750)) + .duration(40 * SECONDS) + .eut(TierEU.RECIPE_MV) + .addTo(distilleryRecipes); + } + } + + public static void createNitrogenTetroxide() { + // 2HNO3 + Cu = N2O4 + H2O + CuO + CORE.RA.addChemicalPlantRecipe( + new ItemStack[] { ItemUtils.getItemStackOfAmountFromOreDict("dustCopper", 1), + ItemUtils.getSimpleStack(GenericChem.mOrangeCatalyst, 0), }, + new FluidStack[] { FluidUtils.getFluidStack("nitricacid", 2000) }, + new ItemStack[] { Materials.CupricOxide.getDust(2), }, + new FluidStack[] { FluidUtils.getFluidStack(Nitrogen_Tetroxide, 1000), }, + new int[] { 100, 100, 50, 50 }, + 20 * 30, + MaterialUtils.getVoltageForTier(3), + 3); + } + + public static void createHydrazine() { + + // H2O2 + 2NH3 = N2H4 + 2H2O + CORE.RA.addChemicalPlantRecipe( + new ItemStack[] { CI.getNumberedCircuit(21) }, + new FluidStack[] { FluidUtils.getFluidStack("fluid.hydrogenperoxide", 1000), + FluidUtils.getFluidStack("ammonia", 2000), }, + new ItemStack[] {}, + new FluidStack[] { FluidUtils.getFluidStack(Hydrazine, 1000), }, + 20 * 30, + MaterialUtils.getVoltageForTier(2), + 1); + } + + public static void createMonomethylhydrazine() { + + // C + 2H + N2H4 = CH6N2 + CORE.RA.addChemicalPlantRecipe( + new ItemStack[] { CI.getNumberedCircuit(21), ItemUtils.getItemStackOfAmountFromOreDict("dustCarbon", 1) }, + new FluidStack[] { FluidUtils.getFluidStack("hydrogen", 2000), FluidUtils.getFluidStack(Hydrazine, 1000), }, + new ItemStack[] {}, + new FluidStack[] { FluidUtils.getFluidStack(Monomethylhydrazine, 1000), }, + 20 * 48, + 240, + 2); + } + + private static void createLOH() { + GT_Values.RA.stdBuilder() + .itemInputs(ItemUtils.getItemStackOfAmountFromOreDict("cellHydrogen", 1)) + .itemOutputs(ItemUtils.getItemStackOfAmountFromOreDict("cellLiquidHydrogen", 1)) + .duration(16 * SECONDS) + .eut(TierEU.RECIPE_MV) + .addTo(vacuumFreezerRecipes); + } + + private static void createHydratedAmmoniumNitrateSlurry() { + + // NH3 + HNO3 = NH4NO3 + CORE.RA.addChemicalPlantRecipe( + new ItemStack[] { CI.getNumberedAdvancedCircuit(21), }, + new FluidStack[] { FluidUtils.getFluidStack("ammonia", 4000), + FluidUtils.getFluidStack("nitricacid", 4000), }, + new ItemStack[] {}, + new FluidStack[] { FluidUtils.getFluidStack(Hydrated_Ammonium_Nitrate_Slurry, 5184), }, + 20 * 60, + 120, + 1); + } + + private static void createAmmoniumNitrateDust() { + CORE.RA.addDehydratorRecipe( + new ItemStack[] { CI.getNumberedCircuit(8) }, + FluidUtils.getFluidStack(Hydrated_Ammonium_Nitrate_Slurry, 8 * 144), + FluidUtils.getWater(2000), + new ItemStack[] { ItemUtils.getSimpleStack(Ammonium_Nitrate_Dust, 8) }, + new int[] { 10000 }, + 90 * 20, + 480); + } + + private static void createFormaldehyde() { + + // O + CH4O = CH2O + H2O + CORE.RA.addChemicalPlantRecipe( + new ItemStack[] { CI.getNumberedAdvancedCircuit(21), + ItemUtils.getSimpleStack(GenericChem.mFormaldehydeCatalyst, 0), }, + new FluidStack[] { FluidUtils.getFluidStack("oxygen", 32000), + FluidUtils.getFluidStack("methanol", 32000), }, + new ItemStack[] {}, + new FluidStack[] { FluidUtils.getFluidStack(Formaldehyde, 32000), }, + 20 * 90, + 120, + 1); + } + + private static void createFormaldehydeCatalyst() { + GT_Values.RA.stdBuilder() + .itemInputs( + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Iron, 16L), + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Vanadium, 1L), + GT_Utility.getIntegratedCircuit(18)) + .itemOutputs(ItemUtils.getSimpleStack(Formaldehyde_Catalyst_Dust, 4)) + .duration(8 * SECONDS) + .eut(TierEU.RECIPE_LV) + .addTo(mixerRecipes); + } + + private static void createUnsymmetricalDimethylhydrazine() { + + CORE.RA.addChemicalPlantRecipe( + new ItemStack[] { CI.getNumberedAdvancedCircuit(21), + ItemUtils.getSimpleStack(GenericChem.mFormaldehydeCatalyst, 0), }, + new FluidStack[] { FluidUtils.getFluidStack("fluid.hydrazine", 2000), + FluidUtils.getFluidStack(Formaldehyde, 2000), FluidUtils.getFluidStack("hydrogen", 4000), }, + new ItemStack[] {}, + new FluidStack[] { FluidUtils.getFluidStack(Unsymmetrical_Dimethylhydrazine, 2000), + FluidUtils.getWater(2000) }, + 20 * 60, + 120, + 3); + } + + private static void addRocketFuelsToMap() { + HashMap<Integer, GT_Recipe> mRocketFuels = new LinkedHashMap<>(); + mRocketFuels.put( + 0, + new GT_Recipe( + true, + new ItemStack[] {}, + new ItemStack[] {}, + null, + new int[] {}, + new FluidStack[] { FluidUtils.getFluidStack(RP1_Plus_Liquid_Oxygen, 1000) }, + new FluidStack[] {}, + 0, + 0, + 512)); // Fuel Value + + mRocketFuels.put( + 1, + new GT_Recipe( + true, + new ItemStack[] {}, + new ItemStack[] {}, + null, + new int[] {}, + new FluidStack[] { FluidUtils.getFluidStack(Dense_Hydrazine_Mix, 1000) }, + new FluidStack[] {}, + 0, + 0, + 1024)); // Fuel Value + + mRocketFuels.put( + 2, + new GT_Recipe( + true, + new ItemStack[] {}, + new ItemStack[] {}, + null, + new int[] {}, + new FluidStack[] { FluidUtils.getFluidStack(Monomethylhydrazine_Plus_Nitric_Acid, 1000) }, + new FluidStack[] {}, + 0, + 0, + 2048)); // Fuel Value + + mRocketFuels.put( + 3, + new GT_Recipe( + true, + new ItemStack[] {}, + new ItemStack[] {}, + null, + new int[] {}, + new FluidStack[] { + FluidUtils.getFluidStack(Unsymmetrical_Dimethylhydrazine_Plus_Nitrogen_Tetroxide, 1000) }, + new FluidStack[] {}, + 0, + 0, + 4196)); // Fuel Value + + // Add in default Diesel for the Buggy + mValidRocketFuels.put(-1, Diesel); + + mValidRocketFuelNames.add(FluidRegistry.getFluidName(Diesel)); + for (int mID : mRocketFuels.keySet()) { + GT_Recipe aFuelRecipe = mRocketFuels.get(mID); + if (aFuelRecipe != null) { + mValidRocketFuelNames.add(FluidRegistry.getFluidName(aFuelRecipe.mFluidInputs[0].getFluid())); + mValidRocketFuels.put(mID, aFuelRecipe.mFluidInputs[0].getFluid()); + GTPPRecipeMaps.rocketFuels.add(aFuelRecipe); + } + } + } + + private static void createRocketFuels() { + + // RP1_Plus_Liquid_Oxygen + CORE.RA.addChemicalPlantRecipe( + new ItemStack[] { CI.getNumberedCircuit(1), }, + new FluidStack[] { FluidUtils.getFluidStack(Liquid_Oxygen, 2000), FluidUtils.getFluidStack(RP1, 500), }, + new ItemStack[] {}, + new FluidStack[] { FluidUtils.getFluidStack(RP1_Plus_Liquid_Oxygen, 1500), }, + 20 * 15, + 240, + 3); + + // Dense_Hydrazine_Mix + CORE.RA.addChemicalPlantRecipe( + new ItemStack[] { CI.getNumberedCircuit(2), }, + new FluidStack[] { FluidUtils.getFluidStack(Hydrazine, 4000), FluidUtils.getFluidStack("methanol", 6000), }, + new ItemStack[] {}, + new FluidStack[] { FluidUtils.getFluidStack(Dense_Hydrazine_Mix, 10000), }, + 20 * 30, + 240, + 4); + + // Monomethylhydrazine_Plus_Nitric_Acid + CORE.RA.addChemicalPlantRecipe( + new ItemStack[] { CI.getNumberedCircuit(3), }, + new FluidStack[] { FluidUtils.getFluidStack(Monomethylhydrazine, 2000), + FluidUtils.getFluidStack("nitricacid", 1000), }, + new ItemStack[] {}, + new FluidStack[] { FluidUtils.getFluidStack(Monomethylhydrazine_Plus_Nitric_Acid, 2000), }, + 20 * 45, + 480, + 5); + + // Unsymmetrical_Dimethylhydrazine_Plus_Nitrogen_Tetroxide + CORE.RA.addChemicalPlantRecipe( + new ItemStack[] { CI.getNumberedCircuit(4), }, + new FluidStack[] { FluidUtils.getFluidStack(Unsymmetrical_Dimethylhydrazine, 2000), + FluidUtils.getFluidStack(Nitrogen_Tetroxide, 2000), }, + new ItemStack[] {}, + new FluidStack[] { + FluidUtils.getFluidStack(Unsymmetrical_Dimethylhydrazine_Plus_Nitrogen_Tetroxide, 5000), }, + 20 * 60, + 480, + 6); + } + + @Override + public String errorMessage() { + return "Bad Rocket Fuel Science!"; + } + + @Override + public boolean generateRecipes() { + createKerosene(); + createRP1(); + createNitrogenTetroxide(); + createHydrazine(); + createMonomethylhydrazine(); + + createLOH(); + + createHydratedAmmoniumNitrateSlurry(); + createAmmoniumNitrateDust(); + createFormaldehyde(); + createFormaldehydeCatalyst(); + createUnsymmetricalDimethylhydrazine(); + + createRocketFuels(); + addRocketFuelsToMap(); + + return true; + } + + @Override + public void items() { + Formaldehyde_Catalyst_Dust = ItemUtils.generateSpecialUseDusts( + "FormaldehydeCatalyst", + "Formaldehyde Catalyst", + "Fe16V1", + Utils.rgbtoHexValue(25, 5, 25))[0]; + Formaldehyde_Catalyst_Stack = ItemUtils.getSimpleStack(Formaldehyde_Catalyst_Dust); + } + + @Override + public void blocks() {} + + @Override + public void fluids() { + + // Register default fluids + Diesel = MaterialUtils.getMaterial("Fuel", "Diesel") + .getFluid(1) + .getFluid(); + + // 5.08 Compat + if (!FluidUtils.doesFluidExist("liquid_heavy_oil")) { + Oil_Heavy = FluidUtils + .generateFluidNoPrefix("liquid_heavy_oil", "Heavy Oil", 200, new short[] { 10, 10, 10, 100 }); + } else { + Oil_Heavy = MaterialUtils.getMaterial("OilHeavy", "Oil") + .getFluid(1) + .getFluid(); + if (ItemUtils.getItemStackOfAmountFromOreDictNoBroken("cellOilHeavy", 1) == null) { + new BaseItemComponent("OilHeavy", "Heavy Oil", new short[] { 10, 10, 10 }); + } + } + + // Create Kerosene + Kerosene = FluidUtils + .generateFluidNonMolten("Kerosene", "Kerosene", 233, new short[] { 150, 40, 150, 100 }, null, null); + CoalTar.Coal_Oil = Kerosene; + + // RP! Focket Fuel + RP1 = FluidUtils.generateFluidNonMolten("RP1Fuel", "RP-1", 500, new short[] { 210, 50, 50, 100 }, null, null); + + // Create Nitrogen Tetroxide + Nitrogen_Tetroxide = FluidUtils.generateFluidNonMolten( + "NitrogenTetroxide", + "Nitrogen Tetroxide", + 261, + new short[] { 170, 170, 0, 100 }, + null, + null); + + // Create Hydrazine + Hydrazine = FluidUtils + .generateFluidNonMolten("Hydrazine", "Hydrazine", 275, new short[] { 250, 250, 250, 100 }, null, null); + + // Create Monomethylhydrazine + Monomethylhydrazine = FluidUtils.generateFluidNonMolten( + "Monomethylhydrazine", + "Monomethylhydrazine", + 221, + new short[] { 125, 125, 125, 100 }, + null, + null); + + // Create Anthracene + Nitrous_Oxide = FluidUtils.generateFluidNonMolten( + "NitrousOxide", + "Nitrous Oxide", + 182, + new short[] { 255, 255, 255, 100 }, + null, + null); + + // Nos + if (!FluidUtils.doesFluidExist("NitrousOxide")) { + Nitrous_Oxide = FluidUtils + .generateFluidNoPrefix("NitrousOxide", "Nitrous Oxide", 182, new short[] { 255, 255, 255, 100 }); + } else { + Nitrous_Oxide = FluidUtils.getWildcardFluidStack("NitrousOxide", 1) + .getFluid(); + if (ItemUtils.getItemStackOfAmountFromOreDictNoBroken("cellNitrousOxide", 1) == null) { + new BaseItemComponent("NitrousOxide", "Nitrous Oxide", new short[] { 10, 10, 175 }); + } + } + + // Unsymmetrical_Dimethylhydrazine + if (FluidUtils.getFluidStack("1,1dimethylhydrazine", 1) == null) { + Unsymmetrical_Dimethylhydrazine = FluidUtils.generateFluidNonMolten( + "UnsymmetricalDimethylhydrazine", + "Unsymmetrical Dimethylhydrazine", + 216, + new short[] { 70, 210, 20, 100 }, + null, + null); + } else { + Unsymmetrical_Dimethylhydrazine = FluidUtils.getFluidStack("1,1dimethylhydrazine", 1000) + .getFluid(); + } + + // Create Hydrated_Ammonium_Nitrate_Slurry + Hydrated_Ammonium_Nitrate_Slurry = FluidUtils.generateFluidNonMolten( + "AmmoniumNitrateSlurry", + "Hydrated Ammonium Nitrate Slurry", + 450, + new short[] { 150, 75, 150, 100 }, + null, + null); + + // Lithium Hydroperoxide - LiOH + H2O2 → LiOOH + 2 H2O + Ammonium_Nitrate_Dust = ItemUtils.generateSpecialUseDusts( + "AmmoniumNitrate", + "Ammonium Nitrate", + "N2H4O3", + Utils.rgbtoHexValue(150, 75, 150))[0]; + + // Create Liquid_Oxygen + if (FluidUtils.getFluidStack("LiquidOxygen", 1) == null + && FluidUtils.getFluidStack("liquidoxygen", 1) == null) { + Liquid_Oxygen = FluidUtils.generateFluidNonMolten( + "LiquidOxygen", + "Liquid Oxygen", + 54, + new short[] { 75, 75, 220, 100 }, + null, + null); + } else { + if (FluidUtils.getFluidStack("LiquidOxygen", 1) != null) { + Liquid_Oxygen = FluidUtils.getFluidStack("LiquidOxygen", 1) + .getFluid(); + } else { + Liquid_Oxygen = FluidUtils.getFluidStack("liquidoxygen", 1) + .getFluid(); + } + if (ItemUtils.getItemStackOfAmountFromOreDictNoBroken("cellLiquidOxygen", 1) == null) { + new BaseItemComponent("LiquidOxygen", "Liquid Oxygen", new short[] { 10, 10, 175 }); + } + } + + // Create Liquid_Hydrogen + if (FluidUtils.getFluidStack("LiquidHydrogen", 1) == null + && FluidUtils.getFluidStack("liquidhydrogen", 1) == null) { + Liquid_Hydrogen = FluidUtils.generateFluidNonMolten( + "LiquidHydrogen", + "Liquid Hydrogen", + 14, + new short[] { 75, 75, 220, 100 }, + null, + null); + } else { + if (FluidUtils.getFluidStack("LiquidHydrogen", 1) != null) { + Liquid_Hydrogen = FluidUtils.getFluidStack("LiquidHydrogen", 1) + .getFluid(); + } else { + Liquid_Hydrogen = FluidUtils.getFluidStack("liquidhydrogen", 1) + .getFluid(); + } + if (ItemUtils.getItemStackOfAmountFromOreDictNoBroken("cellLiquidHydrogen", 1) == null) { + new BaseItemComponent("LiquidHydrogen", "Liquid Hydrogen", new short[] { 10, 10, 175 }); + } + } + + Formaldehyde = FluidUtils + .generateFluidNonMolten("Formaldehyde", "Formaldehyde", 185, new short[] { 150, 75, 150, 100 }, null, null); + + Unsymmetrical_Dimethylhydrazine_Plus_Nitrogen_Tetroxide = FluidUtils.generateFluidNonMolten( + "RocketFuelMixA", + "H8N4C2O4 Rocket Fuel", + 216, + new short[] { 50, 220, 50, 100 }, + null, + null); + RP1_Plus_Liquid_Oxygen = FluidUtils.generateFluidNonMolten( + "RocketFuelMixB", + "Rp-1 Rocket Fuel", + 250, + new short[] { 250, 50, 50, 100 }, + null, + null); + Monomethylhydrazine_Plus_Nitric_Acid = FluidUtils.generateFluidNonMolten( + "RocketFuelMixC", + "CN3H7O3 Rocket Fuel", + 221, + new short[] { 125, 75, 180, 100 }, + null, + null); + Dense_Hydrazine_Mix = FluidUtils.generateFluidNonMolten( + "RocketFuelMixD", + "Dense Hydrazine Fuel Mixture", + 275, + new short[] { 175, 80, 120, 100 }, + null, + null); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/chemistry/StandardBaseParticles.java b/src/main/java/gtPlusPlus/core/item/chemistry/StandardBaseParticles.java new file mode 100644 index 0000000000..1604bcb571 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/chemistry/StandardBaseParticles.java @@ -0,0 +1,156 @@ +package gtPlusPlus.core.item.chemistry; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.HashMap; +import java.util.List; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IIcon; + +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.core.item.base.misc.BaseItemParticle; +import gtPlusPlus.core.material.Particle; +import gtPlusPlus.core.material.Particle.ElementaryGroup; +import gtPlusPlus.core.util.Utils; + +public class StandardBaseParticles extends BaseItemParticle { + + public static HashMap<String, Integer> NameToMetaMap = new HashMap<>(); + public static HashMap<Integer, String> MetaToNameMap = new HashMap<>(); + + public StandardBaseParticles() { + super("Base", aTypes.length, EnumRarity.rare); + } + + private static final String[] aTypes = new String[] { "Graviton", "Up", "Down", "Charm", "Strange", "Top", "Bottom", + "Electron", "Electron Neutrino", "Muon", "Muon Neutrino", "Tau", "Tau Neutrino", "Gluon", "Photon", "Z Boson", + "W Boson", "Higgs Boson", "Proton", "Neutron", "Lambda", "Omega", "Pion", "ETA Meson", "Unknown" }; + + public IIcon[] icons = new IIcon[aTypes.length]; + + static { + // Generate Ions + int key = 0; + + for (String s : aTypes) { + // Map names to Meta + NameToMetaMap.put(Utils.sanitizeString(s.toLowerCase()), key); + MetaToNameMap.put(key, Utils.sanitizeString(s.toLowerCase())); + for (Particle o : Particle.aMap) { + int aColour = 0; + if (o.mParticleName.toLowerCase() + .equals(s.toLowerCase())) { + if (o.mParticleType == ElementaryGroup.BARYON) { + aColour = Utils.rgbtoHexValue(174, 226, 156); + aColourMap.put(key++, aColour); + } else if (o.mParticleType == ElementaryGroup.BOSON) { + if (o == Particle.HIGGS_BOSON) { + aColour = Utils.rgbtoHexValue(226, 196, 104); + aColourMap.put(key++, aColour); + } else { + aColour = Utils.rgbtoHexValue(226, 52, 66); + aColourMap.put(key++, aColour); + } + } else if (o.mParticleType == ElementaryGroup.LEPTON) { + aColour = Utils.rgbtoHexValue(126, 226, 95); + aColourMap.put(key++, aColour); + } else if (o.mParticleType == ElementaryGroup.MESON) { + aColour = Utils.rgbtoHexValue(90, 154, 226); + aColourMap.put(key++, aColour); + } else { + aColour = Utils.rgbtoHexValue(188, 61, 226); + aColourMap.put(key++, aColour); + } + } + } + } + } + + @Override + public String[] getAffixes() { + return new String[] { "", "" }; + } + + @Override + public String getUnlocalizedName() { + return ""; + } + + @Override + public String getUnlocalizedName(final ItemStack itemStack) { + return "item.particle.base" + "." + aTypes[itemStack.getItemDamage()]; + } + + public static Particle getParticle(ItemStack aStack) { + AutoMap<Particle> g = Particle.aMap; + for (Particle p : g) { + String aPartName = Utils.sanitizeString(p.mParticleName.toLowerCase()); + String expectedPart = Utils.sanitizeString(aTypes[aStack.getItemDamage()].toLowerCase()); + if (aPartName.equals(expectedPart)) { + return p; + } + } + return Particle.UNKNOWN; + } + + @Override + public int getColorFromItemStack(final ItemStack stack, final int HEX_OxFFFFFF) { + // return Utils.rgbtoHexValue(200, 200, 200); + return super.getColorFromParentClass(stack, HEX_OxFFFFFF); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool) { + Particle aCharge = getParticle(stack); + EnumChatFormatting aColour = EnumChatFormatting.GRAY; + String aState = aColour + "Unknown" + EnumChatFormatting.RESET; + if (aCharge != null) { + String aGroup = aCharge.mParticleType.name() + .toLowerCase(); + if (aGroup.toLowerCase() + .contains("quark")) { + aColour = EnumChatFormatting.LIGHT_PURPLE; + } else if (aGroup.toLowerCase() + .contains("lepton")) { + aColour = EnumChatFormatting.GREEN; + } else if (aCharge == Particle.HIGGS_BOSON) { + aColour = EnumChatFormatting.YELLOW; + } else if (aGroup.toLowerCase() + .contains("boson")) { + aColour = EnumChatFormatting.RED; + } else if (aGroup.toLowerCase() + .contains("baryon")) { + aColour = EnumChatFormatting.BLUE; + } else if (aGroup.toLowerCase() + .contains("meson")) { + aColour = EnumChatFormatting.WHITE; + } else { + aColour = EnumChatFormatting.GRAY; + } + String aFirstLet = aGroup.substring(0, 1) + .toUpperCase(); + aGroup = aGroup.replaceFirst(aGroup.substring(0, 1), aFirstLet); + aState = aColour + aGroup + EnumChatFormatting.RESET; + list.add(EnumChatFormatting.GRAY + "Type: " + aState); + } + super.addInformation(stack, player, list, bool); + } + + @Override + public void registerIcons(IIconRegister reg) { + for (int i = 0; i < this.icons.length; i++) { + this.icons[i] = reg.registerIcon(GTPlusPlus.ID + ":" + "particle/new/" + i); + } + } + + @Override + public IIcon getIconFromDamage(int meta) { + return this.icons[meta]; + } +} diff --git a/src/main/java/gtPlusPlus/core/item/chemistry/general/ItemGenericChemBase.java b/src/main/java/gtPlusPlus/core/item/chemistry/general/ItemGenericChemBase.java new file mode 100644 index 0000000000..8ef674ac19 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/chemistry/general/ItemGenericChemBase.java @@ -0,0 +1,321 @@ +package gtPlusPlus.core.item.chemistry.general; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.List; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; + +import cpw.mods.fml.common.registry.GameRegistry; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.item.chemistry.GenericChem; +import gtPlusPlus.core.util.minecraft.ItemUtils; + +public class ItemGenericChemBase extends Item { + + protected final IIcon base[]; + + private final int aMetaSize = 34; + + /* + * 0 - Red Metal Catalyst //FeCu 1 - Yellow Metal Catalyst //WNi 2 - Blue Metal Catalyst //CoTi 3 - Orange Metal + * Catalyst //Vanadium Pd 4 - Purple Metal Catalyst //IrIdium Ruthenium 5 - Brown Metal Catalyst //NiAl 6 - Pink + * Metal Catalyst //PtRh 7 - Alumina Grinding Ball 8 - Soapstone Grinding Ball 9 - Sodium Ethoxide // 2 Sodium + 1 + * Ethanol | 2 C2H5OH + 2 Na → 2 C2H5ONa + H2 10 - Sodium Ethyl Xanthate //CH3CH2ONa + CS2 → CH3CH2OCS2Na 11 - + * Potassium Ethyl Xanthate //CH3CH2OH + CS2 + KOH → CH3CH2OCS2K + H2O 12 - Potassium Hydroxide // KOH 13 - + * Formaldehyde Catalyst //Fe16V1 14 - Solid Acid Catalyst //H2SO4 15 - Infinite Mutation Catalyst (for Mutated + * Living Solder) 16 - Platinum Group Catalyst (for platline skip) 17 - Plastic Polymer Catalyst (for early plastics + * skip) 18 - Rubber Polymer Catalyst (for early rubbers skip) 19 - Adhesion Promoter Catalyst (for glue/solder + * skip) 20 - Tita-Tungsten Indium Catalyst (for titanium/tungsten/indium skip) 21 - Radioactivity Catalyst (for + * thorium/uranium/plutonium skip) 22 - Rare-Earth Group Catalyst (for monaline skip) 23 - Simple Naquadah Catalyst + * (for early naqline skip) 24 - Advanced Naquadah Catalyst (for late naqline skip) 25 - Raw Intelligence Catalyst + * (for stem cells skip) 26 - Ultimate Plasticizer Catalyst (for late plastics skip) 27 - Biological Intelligence + * Catalyst (for bio cells skip) 28 - Temporal Harmonizer Catalyst (for Eternity processing) 29 - Limpid Water + * Catalyst (for early waterline skip) 30 - Flawless Water Catalyst (for advanced waterline skip) 33 - Algagenic + * Growth Promoter Catalyst (for seaweed skip) + */ + + public ItemGenericChemBase() { + this.setHasSubtypes(true); + this.setNoRepair(); + this.setMaxStackSize(64); + this.setMaxDamage(0); + base = new IIcon[aMetaSize]; + this.setUnlocalizedName("BasicGenericChemItem"); + GameRegistry.registerItem(this, this.getUnlocalizedName()); + } + + @Override + public int getItemStackLimit(ItemStack stack) { + if (ItemUtils.isMillingBall(stack)) { + return 16; + } + return super.getItemStackLimit(stack); + } + + @Override + public boolean isDamageable() { + return false; + } + + @Override + public boolean shouldRotateAroundWhenRendering() { + return super.shouldRotateAroundWhenRendering(); + } + + @Override + public void onUpdate(ItemStack p_77663_1_, World p_77663_2_, Entity p_77663_3_, int p_77663_4_, + boolean p_77663_5_) { + super.onUpdate(p_77663_1_, p_77663_2_, p_77663_3_, p_77663_4_, p_77663_5_); + } + + @Override + public String getItemStackDisplayName(ItemStack aStack) { + return super.getItemStackDisplayName(aStack); + } + + @Override + public EnumRarity getRarity(ItemStack p_77613_1_) { + return EnumRarity.common; + } + + @Override + public boolean requiresMultipleRenderPasses() { + return false; + } + + @Override + public void getSubItems(Item aItem, CreativeTabs p_150895_2_, List aList) { + for (int i = 0; i < aMetaSize; i++) { + aList.add(ItemUtils.simpleMetaStack(aItem, i, 1)); + } + } + + @Override + public boolean getIsRepairable(ItemStack p_82789_1_, ItemStack p_82789_2_) { + return false; + } + + @Override + public boolean isRepairable() { + return false; + } + + @Override + public boolean isBookEnchantable(ItemStack stack, ItemStack book) { + return false; + } + + @Override + public int getItemEnchantability() { + return 0; + } + + @Override + public int getItemEnchantability(ItemStack stack) { + return 0; + } + + @Override + public void registerIcons(final IIconRegister u) { + for (int i = 0; i < this.aMetaSize; i++) { + String aPath = GTPlusPlus.ID + ":" + "science/general/MetaItem1/" + i; + this.base[i] = u.registerIcon(aPath); + } + } + + @Override + public IIcon getIconFromDamageForRenderPass(final int damage, final int pass) { + return this.base[damage]; + } + + @Override + public IIcon getIconFromDamage(int damage) { + return this.base[damage]; + } + + @Override + public IIcon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining) { + return this.base[stack.getItemDamage()]; + } + + @Override + public IIcon getIcon(ItemStack stack, int pass) { + return this.base[stack.getItemDamage()]; + } + + @Override + public String getUnlocalizedName(ItemStack stack) { + return super.getUnlocalizedName() + "." + stack.getItemDamage(); + } + + @Override + public double getDurabilityForDisplay(ItemStack aStack) { + if (ItemUtils.isMillingBall(aStack)) { + if (aStack.getTagCompound() == null || aStack.getTagCompound() + .hasNoTags()) { + createMillingBallNBT(aStack); + } + double currentDamage = getMillingBallDamage(aStack); + return currentDamage / getMaxBallDurability(aStack); + } else if (ItemUtils.isCatalyst(aStack)) { + if (aStack.getTagCompound() == null || aStack.getTagCompound() + .hasNoTags()) { + createCatalystNBT(aStack); + } + double currentDamage = getCatalystDamage(aStack); + return currentDamage / getCatalystMaxDamage(aStack); + } else { + return 1D; + } + } + + @SuppressWarnings("unchecked") + @Override + public void addInformation(ItemStack aStack, EntityPlayer player, List list, boolean bool) { + boolean aHasSpecialTooltips = false; + int aMaxDamage = 0; + int aDamageSegment = 0; + int aDam = 0; + EnumChatFormatting durability = EnumChatFormatting.GRAY; + if (ItemUtils.isMillingBall(aStack)) { + list.add(EnumChatFormatting.GRAY + "Tumble Tumble Tumble"); + aMaxDamage = getMillingBallMaxDamage(aStack); + aDamageSegment = aMaxDamage / 5; + aDam = aMaxDamage - getMillingBallDamage(aStack); + aHasSpecialTooltips = true; + } + if (ItemUtils.isCatalyst(aStack)) { + list.add(EnumChatFormatting.GRAY + "Active Reaction Agent"); + aMaxDamage = getCatalystMaxDamage(aStack); + aDamageSegment = aMaxDamage / 5; + aDam = aMaxDamage - getCatalystDamage(aStack); + aHasSpecialTooltips = true; + } + if (aHasSpecialTooltips) { + if (aDam > aDamageSegment * 3) { + durability = EnumChatFormatting.GREEN; + } else if (aDam > aDamageSegment * 2) { + durability = EnumChatFormatting.YELLOW; + } else if (aDam > aDamageSegment) { + durability = EnumChatFormatting.GOLD; + } else if (aDam >= 0) { + durability = EnumChatFormatting.RED; + } + list.add(durability + "" + (aDam) + EnumChatFormatting.GRAY + " / " + aMaxDamage); + } + super.addInformation(aStack, player, list, bool); + } + + @Override + public boolean showDurabilityBar(ItemStack aStack) { + if (ItemUtils.isMillingBall(aStack)) { + int aDam = getMillingBallDamage(aStack); + if (aDam > 0) { + return true; + } + } else if (ItemUtils.isCatalyst(aStack)) { + int aDam = getCatalystDamage(aStack); + if (aDam > 0) { + return true; + } + } + return false; + } + + public static boolean createMillingBallNBT(ItemStack rStack) { + final NBTTagCompound tagMain = new NBTTagCompound(); + final NBTTagCompound tagNBT = new NBTTagCompound(); + tagNBT.setLong("Damage", 0); + tagNBT.setLong("MaxDamage", getMaxBallDurability(rStack)); + tagMain.setTag("MillingBall", tagNBT); + rStack.setTagCompound(tagMain); + return true; + } + + public static int getMillingBallDamage(ItemStack aStack) { + if (aStack.getTagCompound() == null || aStack.getTagCompound() + .hasNoTags()) { + createMillingBallNBT(aStack); + } + NBTTagCompound aNBT = aStack.getTagCompound(); + return aNBT.getCompoundTag("MillingBall") + .getInteger("Damage"); + } + + public static int getMillingBallMaxDamage(ItemStack aStack) { + if (aStack.getTagCompound() == null || aStack.getTagCompound() + .hasNoTags()) { + createMillingBallNBT(aStack); + } + NBTTagCompound aNBT = aStack.getTagCompound(); + return aNBT.getCompoundTag("MillingBall") + .getInteger("MaxDamage"); + } + + public static void setMillingBallDamage(ItemStack aStack, int aAmount) { + NBTTagCompound aNBT = aStack.getTagCompound(); + aNBT = aNBT.getCompoundTag("MillingBall"); + aNBT.setInteger("Damage", aAmount); + } + + public static int getMaxBallDurability(ItemStack aStack) { + if (GT_Utility.areStacksEqual(aStack, GenericChem.mMillingBallAlumina, true)) { + return 100; + } + if (GT_Utility.areStacksEqual(aStack, GenericChem.mMillingBallSoapstone, true)) { + return 50; + } + return 0; + } + + public static boolean createCatalystNBT(ItemStack rStack) { + final NBTTagCompound tagMain = new NBTTagCompound(); + final NBTTagCompound tagNBT = new NBTTagCompound(); + tagNBT.setLong("Damage", 0); + tagNBT.setLong("MaxDamage", getMaxCatalystDurability(rStack)); + tagMain.setTag("catalyst", tagNBT); + rStack.setTagCompound(tagMain); + return true; + } + + public static int getCatalystDamage(ItemStack aStack) { + if (aStack.getTagCompound() == null || aStack.getTagCompound() + .hasNoTags()) { + createCatalystNBT(aStack); + } + NBTTagCompound aNBT = aStack.getTagCompound(); + return aNBT.getCompoundTag("catalyst") + .getInteger("Damage"); + } + + public static int getCatalystMaxDamage(ItemStack aStack) { + if (aStack.getTagCompound() == null || aStack.getTagCompound() + .hasNoTags()) { + createCatalystNBT(aStack); + } + NBTTagCompound aNBT = aStack.getTagCompound(); + return aNBT.getCompoundTag("catalyst") + .getInteger("MaxDamage"); + } + + public static void setCatalystDamage(ItemStack aStack, int aAmount) { + NBTTagCompound aNBT = aStack.getTagCompound(); + aNBT = aNBT.getCompoundTag("catalyst"); + aNBT.setInteger("Damage", aAmount); + } + + public static int getMaxCatalystDurability(ItemStack aStack) { + return 50; + } +} diff --git a/src/main/java/gtPlusPlus/core/item/circuit/GTPP_IntegratedCircuit_Item.java b/src/main/java/gtPlusPlus/core/item/circuit/GTPP_IntegratedCircuit_Item.java new file mode 100644 index 0000000000..11bbac53a3 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/circuit/GTPP_IntegratedCircuit_Item.java @@ -0,0 +1,213 @@ +package gtPlusPlus.core.item.circuit; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.function.BiFunction; +import java.util.function.Predicate; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.ChatComponentTranslation; +import net.minecraft.util.IIcon; +import net.minecraft.util.StatCollector; +import net.minecraft.world.World; +import net.minecraftforge.common.util.Constants; +import net.minecraftforge.common.util.FakePlayer; + +import org.apache.commons.lang3.tuple.Pair; + +import com.gtnewhorizons.modularui.api.UIInfos; + +import cpw.mods.fml.common.registry.GameRegistry; +import gregtech.api.GregTech_API; +import gregtech.api.enums.GT_Values; +import gregtech.api.interfaces.INetworkUpdatableItem; +import gregtech.api.net.GT_Packet_UpdateItem; +import gregtech.api.objects.XSTR; +import gregtech.api.util.GT_LanguageManager; +import gregtech.api.util.GT_Utility; +import gregtech.common.gui.modularui.uifactory.SelectItemUIFactory; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; + +public class GTPP_IntegratedCircuit_Item extends Item implements INetworkUpdatableItem { + + private final List<ItemStack> ALL_VARIANTS = new ArrayList<>(); + + private final String iconLocation; + protected final IIcon[] iconDamage = new IIcon[25]; + + public GTPP_IntegratedCircuit_Item(String unlocalizedName, String iconLocation) { + this.setHasSubtypes(true); + this.setNoRepair(); + this.setMaxStackSize(64); + this.setMaxDamage(0); + this.setUnlocalizedName(unlocalizedName); + this.iconLocation = iconLocation; + GameRegistry.registerItem(this, this.getUnlocalizedName()); + ALL_VARIANTS.add(new ItemStack(this, 0, 0)); + for (int i = 1; i <= 24; i++) { + ItemStack aStack = new ItemStack(this, 0, i); + ALL_VARIANTS.add(aStack); + } + } + + @Override + public boolean isDamageable() { + return false; + } + + @Override + public void addInformation(ItemStack aStack, EntityPlayer p_77624_2_, List aList, boolean p_77624_4_) { + try { + aList.add("Configuration == " + aStack.getItemDamage()); + aList.add( + GT_LanguageManager.addStringLocalization( + new StringBuilder().append(getUnlocalizedName()) + .append(".tooltip.0") + .toString(), + "Right click to reconfigure")); + aList.add( + GT_LanguageManager.addStringLocalization( + new StringBuilder().append(getUnlocalizedName()) + .append(".tooltip.1") + .toString(), + "Needs a screwdriver or circuit programming tool")); + } catch (Throwable t) { + t.printStackTrace(); + } + super.addInformation(aStack, p_77624_2_, aList, p_77624_4_); + } + + @Override + public EnumRarity getRarity(ItemStack p_77613_1_) { + return EnumRarity.common; + } + + @Override + public void getSubItems(Item aItem, CreativeTabs p_150895_2_, List aList) { + aList.add(ItemUtils.simpleMetaStack(aItem, 0, 1)); + } + + @Override + public boolean isRepairable() { + return false; + } + + @Override + public boolean isBookEnchantable(ItemStack stack, ItemStack book) { + return false; + } + + @Override + public boolean showDurabilityBar(ItemStack stack) { + return false; + } + + @Override + public void registerIcons(final IIconRegister u) { + for (int i = 0; i < iconDamage.length; i++) { + this.iconDamage[i] = u.registerIcon(GTPlusPlus.ID + ":" + iconLocation + "/" + i); + } + } + + @Override + public IIcon getIconFromDamage(int meta) { + return this.iconDamage[MathUtils.balance(meta, 0, 24)]; + } + + @Override + public boolean receive(ItemStack stack, EntityPlayerMP player, NBTTagCompound tag) { + int meta = tag.hasKey("meta", Constants.NBT.TAG_BYTE) ? tag.getByte("meta") : -1; + if (meta < 0 || meta > 24) return true; + + if (!player.capabilities.isCreativeMode) { + Pair<Integer, BiFunction<ItemStack, EntityPlayerMP, ItemStack>> toolIndex = findConfiguratorInInv(player); + if (toolIndex == null) return true; + + ItemStack[] mainInventory = player.inventory.mainInventory; + mainInventory[toolIndex.getKey()] = toolIndex.getValue() + .apply(mainInventory[toolIndex.getKey()], player); + } + stack.setItemDamage(meta); + + return true; + } + + @Override + public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { + // nothing on server side or fake player + if (player instanceof FakePlayer || !world.isRemote) return stack; + // check if any screwdriver + ItemStack configuratorStack; + if (player.capabilities.isCreativeMode) { + configuratorStack = null; + } else { + Pair<Integer, ?> configurator = findConfiguratorInInv(player); + if (configurator == null) { + int count; + try { + count = Integer + .parseInt(StatCollector.translateToLocal("GT5U.item.programmed_circuit.no_screwdriver.count")); + } catch (NumberFormatException e) { + player.addChatComponentMessage( + new ChatComponentText( + "Error in translation GT5U.item.programmed_circuit.no_screwdriver.count: " + + e.getMessage())); + count = 1; + } + player.addChatComponentMessage( + new ChatComponentTranslation( + "GT5U.item.programmed_circuit.no_screwdriver." + XSTR.XSTR_INSTANCE.nextInt(count))); + return stack; + } + configuratorStack = player.inventory.mainInventory[configurator.getKey()]; + } + openSelectorGui(configuratorStack, stack.getItemDamage(), player); + return stack; + } + + private void openSelectorGui(ItemStack configurator, int meta, EntityPlayer player) { + UIInfos.openClientUI( + player, + buildContext -> new SelectItemUIFactory( + StatCollector.translateToLocal("GT5U.item.programmed_circuit.select.header"), + configurator, + GTPP_IntegratedCircuit_Item::onConfigured, + ALL_VARIANTS, + meta, + true).createWindow(buildContext)); + } + + private static void onConfigured(ItemStack stack) { + NBTTagCompound tag = new NBTTagCompound(); + tag.setByte("meta", (byte) stack.getItemDamage()); + GT_Values.NW.sendToServer(new GT_Packet_UpdateItem(tag)); + } + + private static Pair<Integer, BiFunction<ItemStack, EntityPlayerMP, ItemStack>> findConfiguratorInInv( + EntityPlayer player) { + ItemStack[] mainInventory = player.inventory.mainInventory; + for (int j = 0, mainInventoryLength = mainInventory.length; j < mainInventoryLength; j++) { + ItemStack toolStack = mainInventory[j]; + + if (!GT_Utility.isStackValid(toolStack)) continue; + + for (Map.Entry<Predicate<ItemStack>, BiFunction<ItemStack, EntityPlayerMP, ItemStack>> p : GregTech_API.sCircuitProgrammerList + .entrySet()) + if (p.getKey() + .test(toolStack)) return Pair.of(j, p.getValue()); + } + return null; + } +} diff --git a/src/main/java/gtPlusPlus/core/item/crafting/ItemDummyResearch.java b/src/main/java/gtPlusPlus/core/item/crafting/ItemDummyResearch.java new file mode 100644 index 0000000000..51bff6f12b --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/crafting/ItemDummyResearch.java @@ -0,0 +1,92 @@ +package gtPlusPlus.core.item.crafting; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.LinkedHashMap; +import java.util.Map; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.core.item.ModItems; +import gtPlusPlus.core.item.general.ItemGenericToken; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.ItemUtils; + +public class ItemDummyResearch extends ItemGenericToken { + + public static enum ASSEMBLY_LINE_RESEARCH { + + RESEARCH_1_CONTAINMENT("Containment Fields", "Advanced scientific study"), + RESEARCH_2_BASIC_CHEM("Basic Chemistry", "Time to start at the beginning"), + RESEARCH_3_ADV_CHEM("Advanced Chemistry", "Best learn more than chemical equations"), + RESEARCH_4_BASIC_PHYSICS("Basic Physics", "Fundamental laws of motion"), + RESEARCH_5_ADV_PHYSICS("Advanced Physics", "Advanced knowledge!"), + RESEARCH_6_BASIC_METALLURGY("Basic Metallurgy", "Information about material smelting"), + RESEARCH_7_ADV_METALLURGY("Advanced Metallurgy", "Advanced Material Sciences!"), + RESEARCH_8_TURBINE_AUTOMATION("Turbine Automation", "You really don't want to share this with anyone!"), + RESEARCH_9_CLOAKING("Cloaking Technologies", "Sneaking around like a mouse"), + RESEARCH_10_SPARGING("Gas Sparging", "Blowing gas for results"), + RESEARCH_11_MOLECULAR_TRANSFORMER("Molecular Transformation", "Turning things into something better"); + + private final String mName; + private final String mDesc; + + private ASSEMBLY_LINE_RESEARCH(String aName, String aDesc) { + mName = aName; + mDesc = aDesc; + ModItems.itemDummyResearch.register(mName, mDesc); + } + } + + private static Map<String, Integer> mInternalNameToIdMap = new LinkedHashMap<>(); + + public static ItemStack getResearchStack(ASSEMBLY_LINE_RESEARCH aResearchName, int aStacksize) { + Integer aMeta = mInternalNameToIdMap.get(Utils.sanitizeString(aResearchName.mName)); + if (aMeta == null) { + aMeta = 0; + } + return ItemUtils.simpleMetaStack(ModItems.itemDummyResearch, aMeta, aStacksize); + } + + private int aID = 0; + + public ItemDummyResearch() { + super("dummyResearch", "Research", new String[] { "This object requires some further study" }, "research"); + } + + /** + * + * @param aResearchType - What is the research for? + * @param aDescriptThe - tooltip for this research + * @return - Did we register a custom research item? + */ + public boolean register(String aResearchType, String aDescript) { + int aNewID = aID++; + mInternalNameToIdMap.put(Utils.sanitizeString(aResearchType), aNewID); + return register(aNewID, "Research on " + aResearchType, 1, aDescript); + } + + @Override + public boolean register(int id, String aLocalName, int aMaxStack, String aDescript) { + return register( + id, + aLocalName, + 1, + new String[] { aDescript, EnumChatFormatting.DARK_GRAY + "Used to further your knowledge" }, + EnumRarity.common, + EnumChatFormatting.LIGHT_PURPLE); + } + + @Override + @SideOnly(Side.CLIENT) + public final void registerIcons(final IIconRegister aIconRegister) { + for (int i = 0, j = mLocalNames.size(); i < j; i++) { + mIcons.put(i, aIconRegister.registerIcon(GTPlusPlus.ID + ":" + "research" + "/" + "note")); + } + } +} diff --git a/src/main/java/gtPlusPlus/core/item/food/BaseItemMetaFood.java b/src/main/java/gtPlusPlus/core/item/food/BaseItemMetaFood.java new file mode 100644 index 0000000000..a307eb48ac --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/food/BaseItemMetaFood.java @@ -0,0 +1,509 @@ +package gtPlusPlus.core.item.food; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemFood; +import net.minecraft.item.ItemStack; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; + +import cpw.mods.fml.common.registry.GameRegistry; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.item.ModItems; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.EntityUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; + +public class BaseItemMetaFood extends ItemFood { + + private static final HashMap<Integer, IIcon> mIconMap = new HashMap<>(); + private static int mTotalMetaItems = 0; + + /* + * 0 - Raw Human Meat 1 - Cooked Human Meat 2 - Raw Horse Meat 3 - Cooked Horse Meat 4 - Raw Wolf Meat 5 - Cooked + * Wolf Meat 6 - Raw Ocelot Meat 7 - Cooked Ocelot Meat 8 - Blaze Flesh + */ + + // listAllmeatraw + // listAllmeatcooked + + public static void registerMetaFoods() { + registerNewMetaFood( + 0, + "I wouldn't eat this unless I was starving", + 2, + 0, + 64, + getPotionEffectPackage(new EffectWeaknessModerate(80), new EffectSlownessModerate(80)), + getOreDictNamesAsArrayList("listAllmeatraw")); + registerNewMetaFood( + 1, + "Doesn't look any better cooked", + 4, + 1, + 64, + getPotionEffectPackage(new EffectWeaknessBasic(50), new EffectSlownessBasic(50)), + getOreDictNamesAsArrayList("listAllmeatcooked")); + registerNewMetaFood( + 2, + "", + 2, + 0, + 64, + getPotionEffectPackage(new EffectWeaknessBasic(30), new EffectSlownessBasic(30)), + getOreDictNamesAsArrayList("listAllmeatraw")); + registerNewMetaFood(3, "", 4, 1, 64, getOreDictNamesAsArrayList("listAllmeatcooked")); + registerNewMetaFood( + 4, + "", + 2, + 0, + 64, + getPotionEffectPackage(new EffectWeaknessBasic(25), new EffectSlownessBasic(30)), + getOreDictNamesAsArrayList("listAllmeatraw")); + registerNewMetaFood(5, "", 4, 1, 64, getOreDictNamesAsArrayList("listAllmeatcooked")); + registerNewMetaFood( + 6, + "", + 2, + 0, + 64, + getPotionEffectPackage(new EffectWeaknessBasic(30), new EffectSlownessBasic(25)), + getOreDictNamesAsArrayList("listAllmeatraw")); + registerNewMetaFood(7, "", 4, 1, 64, getOreDictNamesAsArrayList("listAllmeatcooked")); + registerNewMetaFood( + 8, + "Warm to the touch", + EnumRarity.uncommon, + 4, + 1, + 64, + new AutoMap<>(), + new setOnFire(), + getOreDictNamesAsArrayList("listAllmeatcooked")); + } + + private static final HashMap<Integer, Integer> mMaxStackSizeMap = new HashMap<>(); + private static final HashMap<Integer, String> mTooltipMap = new HashMap<>(); + private static final HashMap<Integer, EnumRarity> mRarityMap = new HashMap<>(); + private static final HashMap<Integer, Integer> mHealAmountMap = new HashMap<>(); + private static final HashMap<Integer, Float> mSaturationAmountMap = new HashMap<>(); + private static final HashMap<Integer, AutoMap<PotionEffectPackage>> mPotionEffectsMap = new HashMap<>(); + private static final HashMap<Integer, Boolean> mHasSpecialBehaviourMap = new HashMap<>(); + private static final HashMap<Integer, SpecialFoodBehaviour> mSpecialBehaviourMap = new HashMap<>(); + private static final HashMap<Integer, ArrayList<String>> mOreDictNames = new HashMap<>(); + + public static void registerNewMetaFood(final int aMetaID, String aTooltip, final int aHealAmount, + final float aSaturationModifier, final int aMaxStacksize) { + registerNewMetaFood( + aMetaID, + aTooltip, + EnumRarity.common, + aHealAmount, + aSaturationModifier, + aMaxStacksize, + new AutoMap<>(), + null, + new ArrayList<>()); + } + + public static void registerNewMetaFood(final int aMetaID, String aTooltip, final int aHealAmount, + final float aSaturationModifier, final int aMaxStacksize, final ArrayList<String> aOreDictNames) { + registerNewMetaFood( + aMetaID, + aTooltip, + EnumRarity.common, + aHealAmount, + aSaturationModifier, + aMaxStacksize, + new AutoMap<>(), + null, + aOreDictNames); + } + + public static void registerNewMetaFood(final int aMetaID, String aTooltip, final int aHealAmount, + final float aSaturationModifier, final int aMaxStacksize, final AutoMap<PotionEffectPackage> aPotionEffects) { + registerNewMetaFood( + aMetaID, + aTooltip, + EnumRarity.common, + aHealAmount, + aSaturationModifier, + aMaxStacksize, + new AutoMap<>(), + null, + new ArrayList<>()); + } + + public static void registerNewMetaFood(final int aMetaID, String aTooltip, final int aHealAmount, + final float aSaturationModifier, final int aMaxStacksize, final AutoMap<PotionEffectPackage> aPotionEffects, + final ArrayList<String> aOreDictNames) { + registerNewMetaFood( + aMetaID, + aTooltip, + EnumRarity.common, + aHealAmount, + aSaturationModifier, + aMaxStacksize, + aPotionEffects, + null, + aOreDictNames); + } + + public static void registerNewMetaFood(final int aMetaID, String aTooltip, EnumRarity aRarity, + final int aHealAmount, final float aSaturationModifier, final int aMaxStacksize, + final AutoMap<PotionEffectPackage> aPotionEffects, final SpecialFoodBehaviour aSpecialBehaviour) { + registerNewMetaFood( + aMetaID, + aTooltip, + EnumRarity.common, + aHealAmount, + aSaturationModifier, + aMaxStacksize, + aPotionEffects, + null, + new ArrayList<>()); + } + + public static void registerNewMetaFood(final int aMetaID, String aTooltip, EnumRarity aRarity, + final int aHealAmount, final float aSaturationModifier, final int aMaxStacksize, + final AutoMap<PotionEffectPackage> aPotionEffects, final SpecialFoodBehaviour aSpecialBehaviour, + final ArrayList<String> aOreDictNames) { + mTotalMetaItems++; + mMaxStackSizeMap.put(aMetaID, aMaxStacksize); + mTooltipMap.put(aMetaID, aTooltip); + mRarityMap.put(aMetaID, aRarity); + mHealAmountMap.put(aMetaID, aHealAmount); + mSaturationAmountMap.put(aMetaID, aSaturationModifier); + mPotionEffectsMap.put(aMetaID, aPotionEffects); + mHasSpecialBehaviourMap.put(aMetaID, (aSpecialBehaviour != null)); + if (aSpecialBehaviour != null) { + mSpecialBehaviourMap.put(aMetaID, aSpecialBehaviour); + } + mOreDictNames.put(aMetaID, aOreDictNames); + } + + public static void registerFoodsToOreDict() { + for (int aMetaID = 0; aMetaID < mTotalMetaItems; aMetaID++) { + ArrayList<String> aOreDictNames = mOreDictNames.get(aMetaID); + if (aOreDictNames != null && !aOreDictNames.isEmpty()) { + ItemStack aFoodStack = ItemUtils.simpleMetaStack(ModItems.itemMetaFood, aMetaID, 1); + for (String aOreName : aOreDictNames) { + ItemUtils.addItemToOreDictionary(aFoodStack, aOreName); + } + } + } + } + + public BaseItemMetaFood() { + super(0, 0, false); + this.setHasSubtypes(true); + this.setNoRepair(); + this.setMaxStackSize(64); + this.setMaxDamage(0); + this.setUnlocalizedName("BasicMetaFood"); + this.setCreativeTab(AddToCreativeTab.tabMisc); + GameRegistry.registerItem(this, this.getUnlocalizedName()); + BaseItemMetaFood.registerMetaFoods(); + } + + private static int getMetaKey(ItemStack aStack) { + return aStack.getItemDamage(); + } + + // Heal Amount + @Override + public int func_150905_g(ItemStack aStack) { + return mHealAmountMap.get(getMetaKey(aStack)); + } + + // Saturation Amount + @Override + public float func_150906_h(ItemStack aStack) { + return mSaturationAmountMap.get(getMetaKey(aStack)); + } + + // Whether wolves like this food, sadly doesn't support meta items + @Override + public boolean isWolfsFavoriteMeat() { + return false; + } + + @Override + protected void onFoodEaten(final ItemStack aStack, final World aWorld, final EntityPlayer aPlayer) { + // super.onFoodEaten(stack, world, player); + AutoMap<PotionEffectPackage> aPotionEffects = mPotionEffectsMap.get(getMetaKey(aStack)); + if (!aWorld.isRemote && aPotionEffects != null && aPotionEffects.size() > 0) { + for (PotionEffectPackage aFoodEffect : aPotionEffects) { + if (MathUtils.randInt(0, 100) <= aFoodEffect.getChance() || aFoodEffect.getChance() == 100) { + PotionEffect aEffect = aFoodEffect.getEffect(); + if (aEffect != null && aEffect.getPotionID() > 0) { + aPlayer.addPotionEffect( + new PotionEffect( + aEffect.getPotionID(), + aEffect.getDuration() * 20, + aEffect.getAmplifier(), + aEffect.getIsAmbient())); + } + } + } + } + + boolean aHasEpcialBehaviour = mHasSpecialBehaviourMap.get(getMetaKey(aStack)); + if (!aWorld.isRemote && aHasEpcialBehaviour) { + SpecialFoodBehaviour aBehaviour = mSpecialBehaviourMap.get(getMetaKey(aStack)); + if (aBehaviour != null) { + aBehaviour.doBehaviour(aPlayer); + } + } + } + + @Override + public ItemStack onEaten(ItemStack aStack, World aWorld, EntityPlayer aPlayer) { + return super.onEaten(aStack, aWorld, aPlayer); + } + + @Override + public int getItemStackLimit(ItemStack aStack) { + return mMaxStackSizeMap.get(getMetaKey(aStack)); + } + + @Override + public boolean isDamageable() { + return false; + } + + @Override + public boolean shouldRotateAroundWhenRendering() { + return super.shouldRotateAroundWhenRendering(); + } + + @Override + public void onUpdate(ItemStack p_77663_1_, World p_77663_2_, Entity p_77663_3_, int p_77663_4_, + boolean p_77663_5_) { + super.onUpdate(p_77663_1_, p_77663_2_, p_77663_3_, p_77663_4_, p_77663_5_); + } + + @Override + public String getItemStackDisplayName(ItemStack aStack) { + return super.getItemStackDisplayName(aStack); + } + + @Override + public void addInformation(ItemStack aStack, EntityPlayer p_77624_2_, List aList, boolean p_77624_4_) { + try { + String aTooltip = mTooltipMap.get(getMetaKey(aStack)); + if (aTooltip != null && aTooltip.length() > 0) { + aList.add(aTooltip); + } + } catch (Throwable t) { + t.printStackTrace(); + } + super.addInformation(aStack, p_77624_2_, aList, p_77624_4_); + } + + @Override + public EnumRarity getRarity(ItemStack aStack) { + return mRarityMap.get(getMetaKey(aStack)); + } + + @Override + public boolean requiresMultipleRenderPasses() { + return false; + } + + @Override + public void getSubItems(Item aItem, CreativeTabs p_150895_2_, List aList) { + for (int i = 0; i < mIconMap.size(); i++) { + aList.add(ItemUtils.simpleMetaStack(aItem, i, 1)); + } + } + + @Override + public boolean getIsRepairable(ItemStack p_82789_1_, ItemStack p_82789_2_) { + return false; + } + + @Override + public boolean isRepairable() { + return false; + } + + @Override + public boolean isBookEnchantable(ItemStack stack, ItemStack book) { + return false; + } + + @Override + public boolean showDurabilityBar(ItemStack stack) { + return false; + } + + @Override + public int getItemEnchantability() { + return 0; + } + + @Override + public int getItemEnchantability(ItemStack stack) { + return 0; + } + + @Override + public void registerIcons(final IIconRegister u) { + for (int i = 0; i < mTotalMetaItems; i++) { + String aPath = GTPlusPlus.ID + ":" + "food/MetaItem1/" + i; + mIconMap.put(i, u.registerIcon(aPath)); + } + } + + @Override + public IIcon getIconFromDamageForRenderPass(final int damage, final int pass) { + return mIconMap.get(damage); + } + + @Override + public IIcon getIconFromDamage(int damage) { + return mIconMap.get(damage); + } + + @Override + public IIcon getIcon(ItemStack aStack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining) { + return mIconMap.get(getMetaKey(aStack)); + } + + @Override + public IIcon getIcon(ItemStack aStack, int pass) { + return mIconMap.get(getMetaKey(aStack)); + } + + @Override + public String getUnlocalizedName(ItemStack stack) { + return super.getUnlocalizedName() + "." + stack.getItemDamage(); + } + + private static class PotionEffectPackage { + + private final PotionEffect mEffect; + private final int mChance; + + private PotionEffectPackage(PotionEffect aEffect, int aChance) { + mEffect = aEffect; + mChance = aChance; + } + + public PotionEffect getEffect() { + return this.mEffect; + } + + public int getChance() { + return this.mChance; + } + } + + private static AutoMap<PotionEffectPackage> getPotionEffectPackage(PotionEffectPackage... aEffects) { + AutoMap<PotionEffectPackage> aPackage = new AutoMap<>(); + if (aEffects != null && aEffects.length > 0) { + for (PotionEffectPackage aEffect : aEffects) { + aPackage.put(aEffect); + } + } + return aPackage; + } + + private static ArrayList<String> getOreDictNamesAsArrayList(String... aOreDictNames) { + ArrayList<String> aPackage = new ArrayList<>(); + if (aOreDictNames != null && aOreDictNames.length > 0) { + for (String aEffect : aOreDictNames) { + aPackage.add(aEffect); + } + } + return aPackage; + } + + private static class EffectWeaknessBasic extends PotionEffectPackage { + + protected EffectWeaknessBasic(int aChance) { + super(new PotionEffect(Potion.weakness.getId(), 1, 20), aChance); + } + } + + private static class EffectWeaknessModerate extends PotionEffectPackage { + + protected EffectWeaknessModerate(int aChance) { + super(new PotionEffect(Potion.weakness.getId(), 2, 40), aChance); + } + } + + private static class EffectWeaknessSevere extends PotionEffectPackage { + + protected EffectWeaknessSevere(int aChance) { + super(new PotionEffect(Potion.weakness.getId(), 3, 60), aChance); + } + } + + private static class EffectSlownessBasic extends PotionEffectPackage { + + protected EffectSlownessBasic(int aChance) { + super(new PotionEffect(Potion.moveSlowdown.getId(), 1, 20), aChance); + } + } + + private static class EffectSlownessModerate extends PotionEffectPackage { + + protected EffectSlownessModerate(int aChance) { + super(new PotionEffect(Potion.moveSlowdown.getId(), 2, 40), aChance); + } + } + + private static class EffectSlownessSevere extends PotionEffectPackage { + + protected EffectSlownessSevere(int aChance) { + super(new PotionEffect(Potion.moveSlowdown.getId(), 3, 60), aChance); + } + } + + private abstract static class SpecialFoodBehaviour { + + protected final int mChance; + + public SpecialFoodBehaviour(int aChance) { + mChance = aChance; + } + + public final void doBehaviour(EntityPlayer aPlayer) { + if (aPlayer != null && !aPlayer.worldObj.isRemote) { + if (MathUtils.randInt(0, 100) < mChance || mChance == 100) { + behaviour(aPlayer); + } + } + } + + protected abstract void behaviour(EntityPlayer aPlayer); + } + + private static class setOnFire extends SpecialFoodBehaviour { + + public setOnFire() { + super(100); + } + + @Override + public void behaviour(EntityPlayer aPlayer) { + EntityUtils.setEntityOnFire(aPlayer, 5); + } + } +} diff --git a/src/main/java/gtPlusPlus/core/item/general/BufferCore.java b/src/main/java/gtPlusPlus/core/item/general/BufferCore.java new file mode 100644 index 0000000000..69257afb0e --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/general/BufferCore.java @@ -0,0 +1,68 @@ +package gtPlusPlus.core.item.general; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.enums.GT_Values; +import gtPlusPlus.core.item.base.BaseItemWithDamageValue; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.math.MathUtils; + +public class BufferCore extends BaseItemWithDamageValue { + + public int coreTier = 0; + + public BufferCore(final String unlocalizedName, final int i) { + super(unlocalizedName + i); + this.setTextureName(GTPlusPlus.ID + ":" + unlocalizedName); + this.setMaxStackSize(32); + this.coreTier = i; + } + + @Override + public String getItemStackDisplayName(final ItemStack stack) { + return super.getItemStackDisplayName(stack) /* +" ["+GT_Values.VN[this.coreTier-1]+"]." */; + } + + @Override + @SideOnly(Side.CLIENT) + public boolean requiresMultipleRenderPasses() { + return true; + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public void addInformation(final ItemStack stack, final EntityPlayer aPlayer, final List list, final boolean bool) { + list.add( + EnumChatFormatting.GRAY + "A key crafting component for " + + GT_Values.VN[this.coreTier - 1] + + " Applicances"); + } + + public final int getCoreTier() { + return this.coreTier; + } + + @Override + public int getColorFromItemStack(final ItemStack stack, int HEX_OxFFFFFF) { + + int[] mTierTypes = new int[] { Utils.rgbtoHexValue(200, 180, 180), Utils.rgbtoHexValue(142, 153, 161), + Utils.rgbtoHexValue(230, 121, 75), Utils.rgbtoHexValue(215, 156, 70), Utils.rgbtoHexValue(97, 97, 96), // EV + Utils.rgbtoHexValue(202, 202, 201), Utils.rgbtoHexValue(247, 159, 157), Utils.rgbtoHexValue(181, 223, 223), + Utils.rgbtoHexValue(187, 219, 185), }; + + if (this.coreTier == 10) { + return Utils + .rgbtoHexValue(MathUtils.randInt(220, 250), MathUtils.randInt(221, 251), MathUtils.randInt(220, 250)); + } + + return mTierTypes[this.coreTier - 1]; + } +} diff --git a/src/main/java/gtPlusPlus/core/item/general/ItemAirFilter.java b/src/main/java/gtPlusPlus/core/item/general/ItemAirFilter.java new file mode 100644 index 0000000000..e82e6f1b44 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/general/ItemAirFilter.java @@ -0,0 +1,143 @@ +package gtPlusPlus.core.item.general; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.List; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IIcon; + +import cpw.mods.fml.common.registry.GameRegistry; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.util.Utils; + +public class ItemAirFilter extends Item { + + public IIcon[] icons = new IIcon[1]; + + public ItemAirFilter() { + super(); + this.setHasSubtypes(true); + String unlocalizedName = "itemAirFilter"; + this.setUnlocalizedName(unlocalizedName); + this.setCreativeTab(AddToCreativeTab.tabMisc); + this.setMaxStackSize(1); + GameRegistry.registerItem(this, unlocalizedName); + } + + @Override + public void registerIcons(IIconRegister reg) { + this.icons[0] = reg.registerIcon(GTPlusPlus.ID + ":" + "itemAirFilter"); + } + + @Override + public IIcon getIconFromDamage(int meta) { + return this.icons[0]; + } + + @Override + public void getSubItems(Item item, CreativeTabs tab, List list) { + for (int i = 0; i < 2; i++) { + list.add(new ItemStack(item, 1, i)); + } + } + + @Override + public String getUnlocalizedName(ItemStack stack) { + return this.getUnlocalizedName() + "_" + stack.getItemDamage(); + } + + @Override + public String getItemStackDisplayName(final ItemStack tItem) { + + if (tItem == null) { + return "Air Filter"; + } + + String itemName = tItem == null ? "Air Filter" : super.getItemStackDisplayName(tItem); + String suffixName = ""; + if (tItem.getItemDamage() == 0) { + suffixName = " [Tier 1]"; + } else if (tItem.getItemDamage() == 1) { + suffixName = " [Tier 2]"; + } + return (itemName + suffixName); + } + + @Override + public int getColorFromItemStack(final ItemStack stack, int HEX_OxFFFFFF) { + int meta = stack.getItemDamage(); + if (meta == 1) { + HEX_OxFFFFFF = Utils.rgbtoHexValue(150, 180, 35); + } + return HEX_OxFFFFFF; + } + + private static boolean createNBT(ItemStack rStack) { + final NBTTagCompound tagMain = new NBTTagCompound(); + final NBTTagCompound tagNBT = new NBTTagCompound(); + tagNBT.setLong("Damage", 0); + tagMain.setTag("AirFilter", tagNBT); + rStack.setTagCompound(tagMain); + return true; + } + + public static final long getFilterMaxDamage(final ItemStack aStack) { + return aStack.getItemDamage() == 0 ? 50 : 2500; + } + + public static final long getFilterDamage(final ItemStack aStack) { + NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag("AirFilter"); + if (aNBT != null) { + return aNBT.getLong("Damage"); + } + } else { + createNBT(aStack); + } + return 0L; + } + + public static final boolean setFilterDamage(final ItemStack aStack, final long aDamage) { + NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag("AirFilter"); + if (aNBT != null) { + aNBT.setLong("Damage", aDamage); + return true; + } + } + return false; + } + + @Override + public double getDurabilityForDisplay(ItemStack stack) { + if (stack.getTagCompound() == null) { + createNBT(stack); + } + double currentDamage = getFilterDamage(stack); + double meta = getFilterMaxDamage(stack); + double durabilitypercent = currentDamage / meta; + return durabilitypercent; + } + + @Override + public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool) { + list.add(EnumChatFormatting.GRAY + "An Air filter for Atmospheric Reconditioning."); + long maxDamage = getFilterMaxDamage(stack); + list.add(EnumChatFormatting.GRAY + "" + (maxDamage - getFilterDamage(stack)) + "/" + maxDamage + " uses left."); + super.addInformation(stack, player, list, bool); + } + + @Override + public boolean showDurabilityBar(ItemStack stack) { + return true; + } +} diff --git a/src/main/java/gtPlusPlus/core/item/general/ItemBasicScrubberTurbine.java b/src/main/java/gtPlusPlus/core/item/general/ItemBasicScrubberTurbine.java new file mode 100644 index 0000000000..ee1afdb6bf --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/general/ItemBasicScrubberTurbine.java @@ -0,0 +1,152 @@ +package gtPlusPlus.core.item.general; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.List; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IIcon; + +import cpw.mods.fml.common.registry.GameRegistry; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.util.Utils; + +public class ItemBasicScrubberTurbine extends Item { + + public IIcon[] icons = new IIcon[1]; + + public ItemBasicScrubberTurbine() { + super(); + this.setHasSubtypes(true); + String unlocalizedName = "itemBasicTurbine"; + this.setUnlocalizedName(unlocalizedName); + this.setCreativeTab(AddToCreativeTab.tabMisc); + this.setMaxStackSize(1); + GameRegistry.registerItem(this, unlocalizedName); + } + + @Override + public void registerIcons(IIconRegister reg) { + this.icons[0] = reg.registerIcon(GTPlusPlus.ID + ":" + "itemBasicTurbine"); + } + + @Override + public IIcon getIconFromDamage(int meta) { + return this.icons[0]; + } + + @Override + public void getSubItems(Item item, CreativeTabs tab, List list) { + for (int i = 0; i < 3; i++) { + list.add(new ItemStack(item, 1, i)); + } + } + + @Override + public String getUnlocalizedName(ItemStack stack) { + return this.getUnlocalizedName() + "_" + stack.getItemDamage(); + } + + @Override + public String getItemStackDisplayName(final ItemStack tItem) { + if (tItem == null) { + return "Basic Turbine"; + } + return super.getItemStackDisplayName(tItem); + } + + @Override + public int getColorFromItemStack(final ItemStack stack, int HEX_OxFFFFFF) { + int meta = stack.getItemDamage(); + if (meta == 0) { + HEX_OxFFFFFF = Utils.rgbtoHexValue(200, 200, 200); + } + if (meta == 1) { + HEX_OxFFFFFF = Utils.rgbtoHexValue(255, 128, 0); + } + if (meta == 2) { + HEX_OxFFFFFF = Utils.rgbtoHexValue(128, 128, 128); + } + return HEX_OxFFFFFF; + } + + private static boolean createNBT(ItemStack rStack) { + final NBTTagCompound tagMain = new NBTTagCompound(); + final NBTTagCompound tagNBT = new NBTTagCompound(); + tagNBT.setLong("Damage", 0); + tagMain.setTag("BasicTurbine", tagNBT); + rStack.setTagCompound(tagMain); + return true; + } + + public static final long getFilterDamage(final ItemStack aStack) { + NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag("BasicTurbine"); + if (aNBT != null) { + return aNBT.getLong("Damage"); + } + } else { + createNBT(aStack); + } + return 0L; + } + + public static final boolean setFilterDamage(final ItemStack aStack, final long aDamage) { + NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag("BasicTurbine"); + if (aNBT != null) { + aNBT.setLong("Damage", aDamage); + return true; + } + } + return false; + } + + public int getMaxDurability(ItemStack aStack) { + if (aStack != null) { + int aMeta = aStack.getItemDamage(); + if (aMeta == 0) { + return 2000; + } + if (aMeta == 1) { + return 4000; + } + if (aMeta == 2) { + return 6000; + } + } + return 0; + } + + @Override + public double getDurabilityForDisplay(ItemStack stack) { + if (stack.getTagCompound() == null) { + createNBT(stack); + } + double currentDamage = getFilterDamage(stack); + double meta = getMaxDurability(stack); + double durabilitypercent = currentDamage / meta; + return durabilitypercent; + } + + @Override + public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool) { + list.add(EnumChatFormatting.GRAY + "An early tier Turbine for Atmospheric Reconditioning."); + int maxDamage = getMaxDurability(stack); + list.add(EnumChatFormatting.GRAY + "" + (maxDamage - getFilterDamage(stack)) + "/" + maxDamage + " uses left."); + super.addInformation(stack, player, list, bool); + } + + @Override + public boolean showDurabilityBar(ItemStack stack) { + return true; + } +} diff --git a/src/main/java/gtPlusPlus/core/item/general/ItemBlueprint.java b/src/main/java/gtPlusPlus/core/item/general/ItemBlueprint.java new file mode 100644 index 0000000000..c6e0743268 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/general/ItemBlueprint.java @@ -0,0 +1,297 @@ +package gtPlusPlus.core.item.general; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.List; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.StatCollector; +import net.minecraft.world.World; + +import cpw.mods.fml.common.registry.GameRegistry; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.interfaces.IItemBlueprint; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; + +public class ItemBlueprint extends Item implements IItemBlueprint { + + public ItemBlueprint(final String unlocalizedName) { + this.setUnlocalizedName(unlocalizedName); + this.setTextureName(GTPlusPlus.ID + ":" + unlocalizedName); + this.setMaxStackSize(1); + this.setCreativeTab(AddToCreativeTab.tabMachines); + // this.bpID = MathUtils.randInt(0, 1000); + GameRegistry.registerItem(this, unlocalizedName); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public void addInformation(final ItemStack itemStack, final EntityPlayer aPlayer, final List list, + final boolean bool) { + // Create some NBT if it's not there, otherwise this does nothing. + if (!itemStack.hasTagCompound()) { + this.createNBT(itemStack); + } + // Set up some default variables. + int id = -1; + String name = ""; + boolean blueprint = false; + // Get proper display vars from NBT if it's there + if (itemStack.hasTagCompound()) { + // Utils.LOG_WARNING("Found TagCompound"); + id = (int) this.getNBT(itemStack, "mID"); + name = (String) this.getNBT(itemStack, "mName"); + blueprint = (boolean) this.getNBT(itemStack, "mBlueprint"); + } + // Write to tooltip list for each viable setting. + if (itemStack.hasTagCompound()) { + if (id != -1) { + list.add( + EnumChatFormatting.GRAY + StatCollector + .translateToLocalFormatted(StatCollector.translateToLocal("item.itemBlueprint.tooltip.0"), id)); + } + if (blueprint) { + list.add( + EnumChatFormatting.BLUE + StatCollector.translateToLocalFormatted( + StatCollector.translateToLocal("item.itemBlueprint.tooltip.1"), + name)); + } else { + list.add(EnumChatFormatting.RED + StatCollector.translateToLocal("item.itemBlueprint.tooltip.2")); + } + } else { + list.add(EnumChatFormatting.RED + StatCollector.translateToLocal("item.itemBlueprint.tooltip.2")); + } + super.addInformation(itemStack, aPlayer, list, bool); + } + + @Override + public void onCreated(final ItemStack itemStack, final World world, final EntityPlayer player) { + this.createNBT(itemStack); + } + + @Override + public void onUpdate(final ItemStack itemStack, final World par2World, final Entity par3Entity, final int par4, + final boolean par5) {} + + @Override + public ItemStack onItemRightClick(final ItemStack itemStack, final World world, final EntityPlayer par3Entity) { + // Let the player know what blueprint is held + if (itemStack.hasTagCompound()) { + PlayerUtils.messagePlayer( + par3Entity, + "This Blueprint holds NBT data. " + "|" + + this.getNBT(itemStack, "mID") + + "|" + + this.getNBT(itemStack, "mBlueprint") + + "|" + + this.getNBT(itemStack, "mName") + + "|" + + ItemUtils.getArrayStackNames(this.readItemsFromNBT(itemStack))); + } else { + this.createNBT(itemStack); + PlayerUtils.messagePlayer(par3Entity, "This is a placeholder. " + this.getNBT(itemStack, "mID")); + } + + return super.onItemRightClick(itemStack, world, par3Entity); + } + + public ItemStack[] readItemsFromNBT(final ItemStack itemStack) { + ItemStack[] blueprint = new ItemStack[9]; + if (itemStack.hasTagCompound()) { + final NBTTagCompound nbt = itemStack.getTagCompound(); + final NBTTagList list = nbt.getTagList("Inventory", 10); + blueprint = new ItemStack[INV_SIZE]; + for (int i = 0; i < list.tagCount(); i++) { + final NBTTagCompound data = list.getCompoundTagAt(i); + final int slot = data.getInteger("Slot"); + if ((slot >= 0) && (slot < INV_SIZE)) { + blueprint[slot] = ItemStack.loadItemStackFromNBT(data); + } + } + return blueprint; + } + return null; + } + + public ItemStack writeItemsToNBT(final ItemStack itemStack, final ItemStack[] craftingGrid) { + final ItemStack[] blueprint = craftingGrid; + if (itemStack.hasTagCompound()) { + final NBTTagCompound nbt = itemStack.getTagCompound(); + final NBTTagList list = new NBTTagList(); + for (int i = 0; i < INV_SIZE; i++) { + final ItemStack stack = blueprint[i]; + if (stack != null) { + final NBTTagCompound data = new NBTTagCompound(); + stack.writeToNBT(data); + data.setInteger("Slot", i); + list.appendTag(data); + } + } + nbt.setTag("Inventory", list); + itemStack.setTagCompound(nbt); + return itemStack; + } + return null; + } + + @Override + public boolean isBlueprint(final ItemStack stack) { + return true; + } + + @Override + public boolean setBlueprint(final ItemStack stack, final IInventory craftingTable, final ItemStack output) { + boolean hasBP = false; + ItemStack[] blueprint = new ItemStack[9]; + + if (stack.hasTagCompound()) { + hasBP = (boolean) this.getNBT(stack, "mBlueprint"); + blueprint = this.readItemsFromNBT(stack); + } + + if (!hasBP) { + try { + for (int o = 0; o < craftingTable.getSizeInventory(); o++) { + blueprint[o] = craftingTable.getStackInSlot(o); + if (blueprint[0] != null) { + blueprint[0].stackSize = 0; + } + } + this.writeItemsToNBT(stack, blueprint); + if (stack.hasTagCompound()) { + if (stack.getTagCompound() + .getCompoundTag("Items") != null) { + stack.stackTagCompound.setBoolean("mBlueprint", true); + } else { + // Invalid BP saved? + } + hasBP = (boolean) this.getNBT(stack, "mBlueprint"); + } + + if (output != null) { + this.setBlueprintName(stack, output.getDisplayName()); + hasBP = true; + return true; + } + return false; + } catch (final Throwable t) { + return false; + } + } + return false; + } + + @Override + public void setBlueprintName(final ItemStack stack, final String name) { + stack.stackTagCompound.setString("mName", name); + } + + @Override + public boolean hasBlueprint(final ItemStack stack) { + if (stack.hasTagCompound()) { + return (boolean) this.getNBT(stack, "mBlueprint"); + } + return false; + } + + @Override + public ItemStack[] getBlueprint(final ItemStack stack) { + ItemStack[] blueprint = new ItemStack[9]; + if (stack.hasTagCompound()) { + blueprint = this.readItemsFromNBT(stack); + } + try { + final ItemStack[] returnStack = new ItemStack[9]; + for (int o = 0; o < blueprint.length; o++) { + returnStack[o] = blueprint[o]; + if (returnStack[0] != null) { + returnStack[0].stackSize = 1; + } + } + return returnStack; + } catch (final Throwable t) { + return null; + } + } + + public boolean createNBT(final ItemStack itemStack) { + if (itemStack.hasTagCompound()) { + if (!itemStack.stackTagCompound.getBoolean("mBlueprint") && !itemStack.stackTagCompound.getString("mName") + .equals("")) { + // No Blueprint and no name Set + Logger.WARNING("No Blueprint and no name Set"); + return false; + } else if (itemStack.stackTagCompound.getBoolean("mBlueprint") + && !itemStack.stackTagCompound.getString("mName") + .equals("")) { + // Has Blueprint but invalid name set + Logger.WARNING("Has Blueprint but invalid name set"); + return false; + } else + if (!itemStack.stackTagCompound.getBoolean("mBlueprint") + && itemStack.stackTagCompound.getString("mName") + .equals("")) { + // Has no Blueprint, but strangely has a name + Logger.WARNING("Has no Blueprint, but strangely has a name"); + return false; + } + return false; + } else if (!itemStack.hasTagCompound()) { + final int bpID = MathUtils.randInt(0, 1000); + final boolean hasRecipe = false; + final String recipeName = ""; + Logger.WARNING("Creating Blueprint, setting up it's NBT data. " + bpID); + itemStack.stackTagCompound = new NBTTagCompound(); + itemStack.stackTagCompound.setInteger("mID", bpID); + itemStack.stackTagCompound.setBoolean("mBlueprint", hasRecipe); + itemStack.stackTagCompound.setString("mName", recipeName); + return true; + } else { + final int bpID = MathUtils.randInt(0, 1000); + final boolean hasRecipe = false; + final String recipeName = ""; + Logger.WARNING("Creating a Blueprint, setting up it's NBT data. " + bpID); + itemStack.stackTagCompound = new NBTTagCompound(); + itemStack.stackTagCompound.setInteger("mID", bpID); + itemStack.stackTagCompound.setBoolean("mBlueprint", hasRecipe); + itemStack.stackTagCompound.setString("mName", recipeName); + return true; + } + } + + public Object getNBT(final ItemStack itemStack, final String tagNBT) { + if (!itemStack.hasTagCompound()) { + return null; + } + Object o = null; + switch (tagNBT) { + case "mID": + o = itemStack.stackTagCompound.getInteger(tagNBT); + break; + case "mBlueprint": + o = itemStack.stackTagCompound.getBoolean(tagNBT); + break; + case "mName": + o = itemStack.stackTagCompound.getString(tagNBT); + break; + case "": + // For More Tag Support + // o = itemStack.stackTagCompound.getInteger(tagNBT); + break; + } + if (o != null) { + return o; + } + return null; + } +} diff --git a/src/main/java/gtPlusPlus/core/item/general/ItemCloakingDevice.java b/src/main/java/gtPlusPlus/core/item/general/ItemCloakingDevice.java new file mode 100644 index 0000000000..9e5cf0a69d --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/general/ItemCloakingDevice.java @@ -0,0 +1,232 @@ +package gtPlusPlus.core.item.general; + +import static gregtech.api.enums.Mods.GTPlusPlus; +import static gregtech.api.enums.Mods.Names; + +import java.util.List; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.StatCollector; +import net.minecraft.world.World; + +import baubles.api.BaubleType; +import baubles.api.IBauble; +import cpw.mods.fml.common.Optional; +import cpw.mods.fml.common.registry.GameRegistry; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import ic2.api.item.ElectricItem; +import ic2.api.item.IElectricItem; +import ic2.api.item.IElectricItemManager; + +@Optional.InterfaceList( + value = { @Optional.Interface(iface = "baubles.api.IBauble", modid = Names.BAUBLES), + @Optional.Interface(iface = "baubles.api.BaubleType", modid = Names.BAUBLES) }) +public class ItemCloakingDevice extends Item implements IElectricItem, IElectricItemManager, IBauble { + + private final String unlocalizedName = "personalCloakingDevice"; + private final ItemStack thisStack; + private static final int maxValueEU = 10000 * 20 * 500; + protected double chargeEU = 0; + + public ItemCloakingDevice(final double charge) { + this.chargeEU = charge; + this.setCreativeTab(AddToCreativeTab.tabMachines); + this.setUnlocalizedName(this.unlocalizedName); + this.setMaxStackSize(1); + this.setTextureName(GTPlusPlus.ID + ":" + "personalCloakingDevice"); + this.thisStack = ItemUtils.getSimpleStack(this); + this.charge(this.thisStack, charge, 3, true, false); + if (charge == (10000 * 20 * 500)) { + this.setDamage(this.thisStack, 13); + } + GameRegistry.registerItem(this, this.unlocalizedName + "-" + charge); + } + + @Override + public void onUpdate(final ItemStack itemStack, final World worldObj, final Entity player, final int p_77663_4_, + final boolean p_77663_5_) { + if (worldObj.isRemote) { + return; + } + + if (player instanceof EntityPlayer) { + for (final ItemStack is : ((EntityPlayer) player).inventory.mainInventory) { + if (is == itemStack) { + continue; + } + if (is != null) { + if (is.getItem() instanceof final IElectricItem electricItem) { + this.chargeEU = ElectricItem.manager.getCharge(is); + } + } + } + } + + super.onUpdate(itemStack, worldObj, player, p_77663_4_, p_77663_5_); + } + + @Override + public boolean canProvideEnergy(final ItemStack itemStack) { + return true; + } + + @Override + public Item getChargedItem(final ItemStack itemStack) { + final ItemStack x = itemStack.copy(); + x.setItemDamage(maxValueEU); + return x.getItem(); + } + + @Override + public Item getEmptyItem(final ItemStack itemStack) { + final ItemStack x = itemStack.copy(); + x.setItemDamage(0); + return x.getItem(); + } + + @Override + public double getMaxCharge(final ItemStack itemStack) { + return maxValueEU; + } + + @Override + public int getTier(final ItemStack itemStack) { + return 5; + } + + @Override + public double getTransferLimit(final ItemStack itemStack) { + return 8196; + } + + @Override + public double getDurabilityForDisplay(final ItemStack stack) { + // return 1.0D - getEnergyStored(stack) / this.capacity; + return 1.0D - (this.getCharge(stack) / this.getMaxCharge(stack)); + } + + @Override + public boolean showDurabilityBar(final ItemStack stack) { + return true; + } + + public int secondsLeft(final ItemStack stack) { + double r; + r = this.getCharge(stack) / (10000 * 20); + return (int) MathUtils.decimalRounding(r); + } + + @Override + public void addInformation(final ItemStack stack, final EntityPlayer aPlayer, final List list, final boolean bool) { + list.add(""); + list.add(StatCollector.translateToLocal("item.personalCloakingDevice.tooltip.0")); + list.add(StatCollector.translateToLocal("item.personalCloakingDevice.tooltip.1")); + list.add(""); + list.add(StatCollector.translateToLocal("item.personalCloakingDevice.tooltip.2")); + list.add( + StatCollector.translateToLocalFormatted( + "item.personalCloakingDevice.tooltip.3", + GT_Utility.formatNumbers(this.getTier(this.thisStack)), + GT_Utility.formatNumbers(this.getTransferLimit(this.thisStack)))); + list.add( + StatCollector.translateToLocalFormatted( + "item.personalCloakingDevice.tooltip.4", + GT_Utility.formatNumbers(this.getCharge(stack)), + MathUtils.findPercentage(this.getCharge(stack), this.getMaxCharge(stack)))); + list.add( + StatCollector.translateToLocalFormatted( + "item.personalCloakingDevice.tooltip.5", + GT_Utility.formatNumbers(this.secondsLeft(stack)))); + super.addInformation(stack, aPlayer, list, bool); + } + + @Override + public double charge(final ItemStack stack, final double amount, final int tier, final boolean ignoreTransferLimit, + final boolean simulate) { + + if (!simulate) { + ElectricItem.manager.charge(stack, amount, tier, true, simulate); + } + return ElectricItem.manager.charge(stack, amount, tier, true, simulate); + } + + @Override + public double discharge(final ItemStack stack, final double amount, final int tier, + final boolean ignoreTransferLimit, final boolean externally, final boolean simulate) { + if (!simulate) { + ElectricItem.manager.discharge(stack, amount, tier, ignoreTransferLimit, externally, simulate); + } + + return ElectricItem.manager.discharge(stack, amount, tier, ignoreTransferLimit, externally, simulate); + } + + @Override + public double getCharge(final ItemStack stack) { + return ElectricItem.manager.getCharge(stack); + } + + @Override + public boolean canUse(final ItemStack stack, final double amount) { + return ElectricItem.manager.canUse(stack, amount); + } + + @Override + public boolean use(final ItemStack stack, final double amount, final EntityLivingBase entity) { + return ElectricItem.manager.use(stack, amount, entity); + } + + @Override + public void chargeFromArmor(final ItemStack stack, final EntityLivingBase entity) { + ElectricItem.manager.chargeFromArmor(stack, entity); + } + + @Override + public String getToolTip(final ItemStack stack) { + return ElectricItem.manager.getToolTip(stack); + } + + @Override + public boolean canEquip(final ItemStack arg0, final EntityLivingBase arg1) { + return true; + } + + @Override + public boolean canUnequip(final ItemStack arg0, final EntityLivingBase arg1) { + return true; + } + + @Override + public BaubleType getBaubleType(final ItemStack arg0) { + return BaubleType.BELT; + } + + @Override // TODO + public void onEquipped(final ItemStack arg0, final EntityLivingBase arg1) {} + + @Override // TODO + public void onUnequipped(final ItemStack arg0, final EntityLivingBase arg1) {} + + @Override // TODO + public void onWornTick(final ItemStack arg0, final EntityLivingBase arg1) { + // Utils.LOG_INFO("Trying to Tick Belt. 1"); + if (!arg1.worldObj.isRemote) { + if (this.getCharge(arg0) >= 10000) { + arg1.addPotionEffect(new PotionEffect(Potion.invisibility.id, 10, 2)); + this.discharge(arg0, 10000, 5, true, true, false); + } else { + if (arg1.isPotionActive((Potion.invisibility))) { + arg1.removePotionEffect(Potion.invisibility.id); + } + } + } + } +} diff --git a/src/main/java/gtPlusPlus/core/item/general/ItemEmpty.java b/src/main/java/gtPlusPlus/core/item/general/ItemEmpty.java new file mode 100644 index 0000000000..773a45aa0a --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/general/ItemEmpty.java @@ -0,0 +1,18 @@ +package gtPlusPlus.core.item.general; + +import net.minecraft.item.ItemStack; + +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.item.base.CoreItem; + +public class ItemEmpty extends CoreItem { + + public ItemEmpty() { + super("item.empty", AddToCreativeTab.tabMisc); + } + + @Override + public String getItemStackDisplayName(ItemStack tItem) { + return "Empty"; + } +} diff --git a/src/main/java/gtPlusPlus/core/item/general/ItemGenericToken.java b/src/main/java/gtPlusPlus/core/item/general/ItemGenericToken.java new file mode 100644 index 0000000000..c1bea0b81d --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/general/ItemGenericToken.java @@ -0,0 +1,197 @@ +package gtPlusPlus.core.item.general; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.HashMap; +import java.util.List; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IIcon; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.util.GT_LanguageManager; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.item.base.CoreItem; + +public class ItemGenericToken extends CoreItem { + + public final HashMap<Integer, String> mLocalNames; + public final HashMap<Integer, Integer> mMaxStackSizes; + public final HashMap<Integer, String[]> mDescriptionArrays; + public final HashMap<Integer, EnumRarity> mRarities; + public final HashMap<Integer, EnumChatFormatting> mCustomNameColours; + public final HashMap<Integer, IIcon> mIcons; + private final String mTextureDir; + + public ItemGenericToken() { + this("itemGenericToken", "Token", new String[] { "Can be reclaimed in some way, shape or form" }, "token"); + } + + public ItemGenericToken(String aUnlocalName, String aInternalName, String[] aBaseTooltip, String aTextureDir) { + super( + aUnlocalName, + aInternalName, + AddToCreativeTab.tabMisc, + 64, + 1000, + aBaseTooltip, + EnumRarity.common, + EnumChatFormatting.RESET, + false, + null); + mLocalNames = new HashMap<>(); + mMaxStackSizes = new HashMap<>(); + mDescriptionArrays = new HashMap<>(); + mRarities = new HashMap<>(); + mCustomNameColours = new HashMap<>(); + mIcons = new HashMap<>(); + mTextureDir = aTextureDir; + setMaxStackSize(64); + } + + public boolean register(int id, String aLocalName, int aMaxStack, String aDescript) { + return register(id, aLocalName, aMaxStack, new String[] { aDescript }); + } + + public boolean register(int id, String aLocalName, int aMaxStack, String[] aDescript) { + return register(id, aLocalName, aMaxStack, aDescript, EnumRarity.common, EnumChatFormatting.RESET); + } + + public boolean register(int id, String aLocalName, int aMaxStack, String[] aDescript, EnumRarity aRarity, + EnumChatFormatting aCustomNameColour) { + int[][] sizes = new int[2][6]; + sizes[0][0] = mLocalNames.size(); + sizes[0][1] = mMaxStackSizes.size(); + sizes[0][2] = mDescriptionArrays.size(); + sizes[0][3] = mRarities.size(); + sizes[0][4] = mCustomNameColours.size(); + // sizes[0][5] = mIcons.size(); + mLocalNames.put(id, aLocalName); + GT_LanguageManager + .addStringLocalization("gtplusplus." + this.getUnlocalizedName() + "." + id + ".name", aLocalName); + mMaxStackSizes.put(id, aMaxStack); + mDescriptionArrays.put(id, aDescript); + for (int i = 0; i < aDescript.length; i++) { + GT_LanguageManager.addStringLocalization( + "gtplusplus." + this.getUnlocalizedName() + "." + id + ".tooltip." + i, + aDescript[i]); + } + mRarities.put(id, aRarity); + mCustomNameColours.put(id, aCustomNameColour); + sizes[1][0] = mLocalNames.size(); + sizes[1][1] = mMaxStackSizes.size(); + sizes[1][2] = mDescriptionArrays.size(); + sizes[1][3] = mRarities.size(); + sizes[1][4] = mCustomNameColours.size(); + // sizes[1][5] = mIcons.size(); + boolean b = sizes[0][0] > sizes[1][0] && sizes[0][1] > sizes[1][1] + && sizes[0][2] > sizes[1][2] + && sizes[0][3] > sizes[1][3] + && sizes[0][4] > sizes[1][4]; + return b; + } + + // Handle Sub items + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + @SideOnly(Side.CLIENT) + public void getSubItems(final Item var1, final CreativeTabs aCreativeTab, final List aList) { + for (int i = 0, j = mIcons.size(); i < j; i++) { + final ItemStack tStack = new ItemStack(this, 1, i); + aList.add(tStack); + } + } + + @Override + public void addInformation(ItemStack stack, EntityPlayer aPlayer, List list, boolean bool) { + super.addInformation(stack, aPlayer, list, bool); + for (int i = 0;; i++) { + String tooltip = GT_LanguageManager.getTranslation( + "gtplusplus." + this + .getUnlocalizedNameInefficiently(stack) + "." + stack.getItemDamage() + ".tooltip." + i); + if (!("gtplusplus." + this + .getUnlocalizedNameInefficiently(stack) + "." + stack.getItemDamage() + ".tooltip." + i) + .equals(tooltip)) { + list.add(tooltip); + } else break; + } + } + + @Override + public String getItemStackDisplayName(final ItemStack tItem) { + String ret = GT_LanguageManager.getTranslation( + "gtplusplus." + this.getUnlocalizedNameInefficiently(tItem) + "." + tItem.getItemDamage() + ".name"); + EnumChatFormatting format = mCustomNameColours.get(tItem.getItemDamage()); + if (format != null) { + ret = format + ret; + } + return ret; + } + + @Override + public EnumRarity getRarity(ItemStack par1ItemStack) { + return mRarities.get(par1ItemStack.getItemDamage()); + } + + @Override + public boolean hasEffect(ItemStack par1ItemStack, final int pass) { + return false; + } + + @Override + public int getMetadata(int p_77647_1_) { + return 0; + } + + @Override + public boolean showDurabilityBar(ItemStack stack) { + return false; + } + + @Override + public double getDurabilityForDisplay(ItemStack stack) { + return 0D; + } + + @Override + public boolean isDamaged(ItemStack stack) { + return false; + } + + @Override + public int getItemStackLimit(ItemStack aStack) { + if (aStack == null) { + return maxStackSize; + } else { + Integer aSize = mMaxStackSizes.get(aStack.getItemDamage()); + if (aSize != null) { + return aSize; + } else { + return maxStackSize; + } + } + } + + @Override + @SideOnly(Side.CLIENT) + public void registerIcons(final IIconRegister aIconRegister) { + for (int i = 0, j = mLocalNames.size(); i < j; i++) { + mIcons.put(i, aIconRegister.registerIcon(GTPlusPlus.ID + ":" + mTextureDir + "/" + i)); + } + } + + @Override + public final IIcon getIconFromDamage(final int aMetaData) { + if (aMetaData < 0) { + return null; + } + return mIcons.get(aMetaData); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/general/ItemHalfCompleteCasings.java b/src/main/java/gtPlusPlus/core/item/general/ItemHalfCompleteCasings.java new file mode 100644 index 0000000000..47cd73a62b --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/general/ItemHalfCompleteCasings.java @@ -0,0 +1,56 @@ +package gtPlusPlus.core.item.general; + +import java.util.List; + +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; + +import gtPlusPlus.core.item.base.BaseItemColourable; +import gtPlusPlus.core.util.Utils; + +public class ItemHalfCompleteCasings extends BaseItemColourable { + + public ItemHalfCompleteCasings(String unlocalizedName, CreativeTabs creativeTab, int stackSize, int maxDmg, + String description, EnumRarity regRarity, EnumChatFormatting colour, boolean Effect, int rgb) { + super(unlocalizedName, creativeTab, stackSize, maxDmg, description, regRarity, colour, Effect, rgb); + } + + @Override + public void getSubItems(Item item, CreativeTabs tab, List list) { + for (int i = 0; i < 4; i++) { + list.add(new ItemStack(item, 1, i)); + } + } + + @Override + public String getItemStackDisplayName(final ItemStack tItem) { + String prefix = super.getItemStackDisplayName(tItem); + String casingType = ""; + if (tItem.getItemDamage() == 0) { + casingType = " I"; + } else if (tItem.getItemDamage() == 1) { + casingType = " II"; + } else if (tItem.getItemDamage() == 2) { + casingType = " III"; + } else if (tItem.getItemDamage() == 3) { + casingType = " IV"; + } + return (prefix + casingType); + } + + @Override + public int getColorFromItemStack(ItemStack stack, int HEX_OxFFFFFF) { + if (this.getDamage(stack) == 0) { + return Utils.rgbtoHexValue(52, 52, 52); + } else if (this.getDamage(stack) == 1) { + return Utils.rgbtoHexValue(80, 90, 222); + } else if (this.getDamage(stack) == 2) { + return Utils.rgbtoHexValue(182, 77, 177); + } else { + return Utils.rgbtoHexValue(77, 175, 182); + } + } +} diff --git a/src/main/java/gtPlusPlus/core/item/general/ItemHealingDevice.java b/src/main/java/gtPlusPlus/core/item/general/ItemHealingDevice.java new file mode 100644 index 0000000000..d80238b99a --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/general/ItemHealingDevice.java @@ -0,0 +1,419 @@ +package gtPlusPlus.core.item.general; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.List; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.FoodStats; +import net.minecraft.util.StatCollector; +import net.minecraft.world.World; + +import baubles.api.BaubleType; +import baubles.api.IBauble; +import cpw.mods.fml.common.Optional; +import cpw.mods.fml.common.registry.GameRegistry; +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.Mods; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.core.util.sys.KeyboardUtils; +import gtPlusPlus.xmod.gregtech.common.helpers.ChargingHelper; +import ic2.api.item.ElectricItem; +import ic2.api.item.IElectricItem; +import ic2.api.item.IElectricItemManager; + +@Optional.InterfaceList( + value = { @Optional.Interface(iface = "baubles.api.IBauble", modid = Mods.Names.BAUBLES), + @Optional.Interface(iface = "baubles.api.BaubleType", modid = Mods.Names.BAUBLES) }) +public class ItemHealingDevice extends Item implements IElectricItem, IElectricItemManager, IBauble { + + private final String unlocalizedName = "personalHealingDevice"; + private static final int maxValueEU = 1000000000; + protected double chargeEU = 0; + + public ItemHealingDevice() { + this.setCreativeTab(AddToCreativeTab.tabMachines); + this.setUnlocalizedName(this.unlocalizedName); + this.setMaxStackSize(1); + this.setTextureName(GTPlusPlus.ID + ":" + "personalCloakingDevice"); + GameRegistry.registerItem(this, this.unlocalizedName); + } + + @Override + public void onUpdate(final ItemStack itemStack, final World worldObj, final Entity player, final int p_77663_4_, + final boolean p_77663_5_) { + if (worldObj.isRemote) { + return; + } + super.onUpdate(itemStack, worldObj, player, p_77663_4_, p_77663_5_); + } + + @Override + public boolean canProvideEnergy(final ItemStack itemStack) { + return true; + } + + @Override + public Item getChargedItem(final ItemStack itemStack) { + final ItemStack x = itemStack.copy(); + x.setItemDamage(maxValueEU); + return x.getItem(); + } + + @Override + public Item getEmptyItem(final ItemStack itemStack) { + final ItemStack x = itemStack.copy(); + x.setItemDamage(0); + return x.getItem(); + } + + @Override + public double getMaxCharge(final ItemStack itemStack) { + return maxValueEU; + } + + @Override + public int getTier(final ItemStack itemStack) { + return 5; + } + + @Override + public double getTransferLimit(final ItemStack itemStack) { + return GT_Values.V[7]; + } + + @Override + public double getDurabilityForDisplay(final ItemStack stack) { + // return 1.0D - getEnergyStored(stack) / this.capacity; + return 1.0D - (this.getCharge(stack) / this.getMaxCharge(stack)); + } + + @Override + public boolean showDurabilityBar(final ItemStack stack) { + return true; + } + + public double secondsLeft(final ItemStack stack) { + + double r = 0; + r = this.getCharge(stack) / (1638400 / 4); + return (int) r; + } + + int EUPerOperation = 1_638_400; + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public void addInformation(final ItemStack stack, final EntityPlayer aPlayer, final List list, final boolean bool) { + + String aString1 = StatCollector.translateToLocal("GTPP.nanohealer.tooltip.1"); + String aString2 = StatCollector.translateToLocal("GTPP.nanohealer.tooltip.2"); + String aString3 = StatCollector.translateToLocal("GTPP.nanohealer.tooltip.3"); + String aString4 = StatCollector.translateToLocal("GTPP.nanohealer.tooltip.4"); + String aString5 = StatCollector.translateToLocal("GTPP.nanohealer.tooltip.5"); + + String aString6 = StatCollector.translateToLocal("GTPP.nanohealer.tooltip.6"); + + String aStringTooltip = StatCollector.translateToLocal("GTPP.nanohealer.hidden"); + String aEuInfo = StatCollector.translateToLocal("GTPP.info.euInfo"); + String aTier = StatCollector.translateToLocal("GTPP.machines.tier"); + String aInputLimit = StatCollector.translateToLocal("GTPP.info.inputLimit"); + String aCurrentPower = StatCollector.translateToLocal("GTPP.info.currentPower"); + String aEU = StatCollector.translateToLocal("GTPP.info.eu"); + String aEUT = aEU + "/t"; + boolean isShowing = getShowMessages(stack); + + list.add(""); + + list.add(EnumChatFormatting.GREEN + aString1 + EnumChatFormatting.GRAY); + list.add( + EnumChatFormatting.GREEN + aString2 + + GT_Utility.formatNumbers(EUPerOperation) + + aString3 + + EnumChatFormatting.GRAY); + list.add(EnumChatFormatting.GREEN + aString4 + EnumChatFormatting.GRAY); + list.add(EnumChatFormatting.RED + aString5 + EnumChatFormatting.GRAY); + + list.add(""); + + list.add(EnumChatFormatting.GOLD + aEuInfo + EnumChatFormatting.GRAY); + list.add( + EnumChatFormatting.GRAY + aTier + + ": [" + + EnumChatFormatting.YELLOW + + GT_Utility.formatNumbers(this.getTier(stack)) + + EnumChatFormatting.GRAY + + "] " + + aInputLimit + + ": [" + + EnumChatFormatting.YELLOW + + GT_Utility.formatNumbers(this.getTransferLimit(stack)) + + EnumChatFormatting.GRAY + + aEUT + + "]"); + list.add( + EnumChatFormatting.GRAY + aCurrentPower + + ": [" + + EnumChatFormatting.YELLOW + + GT_Utility.formatNumbers(this.getCharge(stack)) + + EnumChatFormatting.GRAY + + aEU + + "] [" + + EnumChatFormatting.YELLOW + + GT_Utility.formatNumbers(MathUtils.findPercentage(this.getCharge(stack), this.getMaxCharge(stack))) + + EnumChatFormatting.GRAY + + "%]"); + list.add(EnumChatFormatting.GOLD + aString6 + EnumChatFormatting.GRAY); + list.add( + EnumChatFormatting.GOLD + aStringTooltip + + " " + + (!isShowing ? EnumChatFormatting.DARK_GREEN : EnumChatFormatting.DARK_RED) + + !isShowing + + EnumChatFormatting.GRAY); + super.addInformation(stack, aPlayer, list, bool); + } + + @Override + public double charge(final ItemStack stack, final double amount, final int tier, final boolean ignoreTransferLimit, + final boolean simulate) { + + if (!simulate) { + ElectricItem.manager.charge(stack, amount, tier, true, simulate); + } + return ElectricItem.manager.charge(stack, amount, tier, true, simulate); + } + + @Override + public double discharge(final ItemStack stack, final double amount, final int tier, + final boolean ignoreTransferLimit, final boolean externally, final boolean simulate) { + return ElectricItem.manager.discharge(stack, amount, tier, ignoreTransferLimit, externally, simulate); + } + + @Override + public double getCharge(final ItemStack stack) { + return ElectricItem.manager.getCharge(stack); + } + + @Override + public boolean canUse(final ItemStack stack, final double amount) { + return ElectricItem.manager.canUse(stack, amount); + } + + @Override + public boolean use(final ItemStack stack, final double amount, final EntityLivingBase entity) { + return ElectricItem.manager.use(stack, amount, entity); + } + + @Override + public void chargeFromArmor(final ItemStack stack, final EntityLivingBase entity) { + ElectricItem.manager.chargeFromArmor(stack, entity); + } + + @Override + public String getToolTip(final ItemStack stack) { + return ElectricItem.manager.getToolTip(stack); + } + + @Override + public boolean canEquip(final ItemStack arg0, final EntityLivingBase arg1) { + return true; + } + + @Override + public boolean canUnequip(final ItemStack arg0, final EntityLivingBase arg1) { + return true; + } + + @Override + public BaubleType getBaubleType(final ItemStack arg0) { + return BaubleType.AMULET; + } + + @Override // TODO + public void onEquipped(final ItemStack arg0, final EntityLivingBase arg1) {} + + @Override // TODO + public void onUnequipped(final ItemStack arg0, final EntityLivingBase arg1) {} + + @Override // TODO + public void onWornTick(final ItemStack baubleStack, final EntityLivingBase arg1) { + if (arg1 != null && arg1.worldObj != null && !arg1.worldObj.isRemote) { + + // Try Charge First + + // Inv Slots + for (final ItemStack aInvStack : ((EntityPlayer) arg1).inventory.mainInventory) { + if (aInvStack == baubleStack) { + continue; + } + + if (this.getCharge(baubleStack) == this.getMaxCharge(baubleStack)) { + break; + } + + if (aInvStack != null) { + if (ChargingHelper.isItemValid(aInvStack)) { + + double aTransferRate; + double aCurrentChargeForThisBauble; + int mTier; + final IElectricItem electricItem = (IElectricItem) aInvStack.getItem(); + + if (electricItem != null) { + + aTransferRate = electricItem.getTransferLimit(aInvStack); + mTier = electricItem.getTier(aInvStack); + aCurrentChargeForThisBauble = ElectricItem.manager.getCharge(baubleStack); + + if (aCurrentChargeForThisBauble < maxValueEU) { + if ((ElectricItem.manager.getCharge(aInvStack) >= aTransferRate)) { + if (electricItem.canProvideEnergy(aInvStack)) { + double d = ElectricItem.manager + .discharge(aInvStack, aTransferRate, mTier, false, true, false); + // Logger.INFO("Charging from "+aInvStack.getDisplayName() +" | "+d); + ElectricItem.manager.charge(baubleStack, d, mTier, true, false); + } + } + } + } + } + } + if (this.getCharge(baubleStack) <= (this.getMaxCharge(baubleStack) - getTransferLimit(baubleStack))) { + continue; + } else { + break; + } + } + + // Try Heal + if (this.getCharge(baubleStack) > 0) { + + if (!(arg1 instanceof EntityPlayer g)) { + return; + } + // health Check + float hp = 0; + if (arg1.getHealth() < arg1.getMaxHealth()) { + final float rx = arg1.getMaxHealth() - arg1.getHealth(); + Logger.INFO("rx:" + rx); + arg1.heal(rx * 2); + hp = rx; + this.discharge(baubleStack, (1638400) * rx, 6, true, true, false); + } + + int hunger = 0; + float saturation = 0; + FoodStats aFood = g.getFoodStats(); + if (aFood != null) { + // Hunger Check + hunger = 20 - aFood.getFoodLevel(); + // Saturation Check + if (hunger > 0) { + saturation = 20f - aFood.getSaturationLevel(); + saturation /= hunger * 2f; + this.discharge(baubleStack, (1638400) * (hunger + saturation), 6, true, true, false); + aFood.addStats(hunger, saturation); + } + } + + // Only show Messages if they're enabled. + if (getShowMessages(baubleStack)) { + if (hp > 0 || hunger > 0 || saturation > 0) PlayerUtils + .messagePlayer((EntityPlayer) arg1, "Your NanoBooster Whirs! Leaving you feeling stronger."); + + if (hp > 0) PlayerUtils + .messagePlayer((EntityPlayer) arg1, "Healed " + GT_Utility.formatNumbers(hp) + " hp."); + + if (hunger > 0) PlayerUtils + .messagePlayer((EntityPlayer) arg1, "Healed " + GT_Utility.formatNumbers(hunger) + " hunger."); + + if (saturation > 0) PlayerUtils.messagePlayer( + (EntityPlayer) arg1, + "Satured Hunger by " + GT_Utility.formatNumbers(saturation) + "."); + + if (hp > 0 || hunger > 0 || saturation > 0) PlayerUtils.messagePlayer( + (EntityPlayer) arg1, + "You check it's remaining uses, it has " + GT_Utility.formatNumbers(secondsLeft(baubleStack)) + + " seconds left."); + } + } + } + } + + private static boolean createNBT(ItemStack rStack) { + final NBTTagCompound tagMain = new NBTTagCompound(); + tagMain.setBoolean("ShowMSG", false); + rStack.setTagCompound(tagMain); + return true; + } + + public static final boolean getShowMessages(final ItemStack aStack) { + NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT == null) { + if (!createNBT(aStack)) { + return false; + } else { + aNBT = aStack.getTagCompound(); + } + } + return aNBT.getBoolean("ShowMSG"); + } + + public static final boolean setShowMessages(final ItemStack aStack, final boolean aShow) { + NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT == null) { + if (!createNBT(aStack)) { + return false; + } else { + aNBT = aStack.getTagCompound(); + } + } + aNBT.setBoolean("ShowMSG", aShow); + return true; + } + + @Override + public boolean onItemUse(ItemStack p_77648_1_, EntityPlayer p_77648_2_, World p_77648_3_, int p_77648_4_, + int p_77648_5_, int p_77648_6_, int p_77648_7_, float p_77648_8_, float p_77648_9_, float p_77648_10_) { + // TODO Auto-generated method stub + return super.onItemUse( + p_77648_1_, + p_77648_2_, + p_77648_3_, + p_77648_4_, + p_77648_5_, + p_77648_6_, + p_77648_7_, + p_77648_8_, + p_77648_9_, + p_77648_10_); + } + + @Override + public ItemStack onItemRightClick(ItemStack aStack, World aWorld, EntityPlayer aPlayer) { + ItemStack superStack = super.onItemRightClick(aStack, aWorld, aPlayer); + boolean isShiftHeld = KeyboardUtils.isShiftKeyDown(); + if (isShiftHeld) { + boolean oldState = getShowMessages(superStack); + boolean newState = !oldState; + ItemHealingDevice.setShowMessages(superStack, newState); + PlayerUtils.messagePlayer(aPlayer, (!oldState ? "Showing info messages" : "Hiding info messages")); + } + return superStack; + } + + @Override + public boolean doesSneakBypassUse(World world, int x, int y, int z, EntityPlayer player) { + return true; + } +} diff --git a/src/main/java/gtPlusPlus/core/item/general/ItemLavaFilter.java b/src/main/java/gtPlusPlus/core/item/general/ItemLavaFilter.java new file mode 100644 index 0000000000..2b5dd8883f --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/general/ItemLavaFilter.java @@ -0,0 +1,84 @@ +package gtPlusPlus.core.item.general; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.List; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IIcon; +import net.minecraft.util.StatCollector; + +import gregtech.api.enums.ItemList; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.item.base.CoreItem; + +public class ItemLavaFilter extends CoreItem { + + public IIcon[] mIcon = new IIcon[1]; + + public ItemLavaFilter() { + super( + "itemLavaFilter", + AddToCreativeTab.tabMachines, + 1, + 99, + new String[] { "Lava Filter" }, + EnumRarity.common, + EnumChatFormatting.BLACK, + false, + null); + setGregtechItemList(); + } + + private boolean setGregtechItemList() { + ItemList.Component_LavaFilter.set(this); + return ItemList.Component_LavaFilter.get(1) != null ? true : false; + } + + @Override + public void registerIcons(IIconRegister reg) { + this.mIcon[0] = reg.registerIcon(GTPlusPlus.ID + ":" + "itemLavaFilter"); + } + + @Override + public IIcon getIconFromDamage(int meta) { + return this.mIcon[0]; + } + + @SuppressWarnings("unchecked") + @Override + public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool) { + list.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("item.itemLavaFilter.tooltip")); + + int maxDurability = stack.getMaxDamage() + 1; + int durability = maxDurability - stack.getItemDamage(); + + EnumChatFormatting formatting = EnumChatFormatting.GRAY; + if (durability > maxDurability * 0.8) { + formatting = EnumChatFormatting.GRAY; + } else if (durability > maxDurability * 0.6) { + formatting = EnumChatFormatting.GREEN; + } else if (durability > maxDurability * 0.4) { + formatting = EnumChatFormatting.YELLOW; + } else if (durability > maxDurability * 0.2) { + formatting = EnumChatFormatting.GOLD; + } else if (durability > 0) { + formatting = EnumChatFormatting.RED; + } + list.add("Uses remaining: " + formatting + durability + EnumChatFormatting.GRAY + " / " + maxDurability); + } + + @Override + public boolean showDurabilityBar(ItemStack stack) { + return true; + } + + @Override + public boolean isRepairable() { + return false; + } +} diff --git a/src/main/java/gtPlusPlus/core/item/general/ItemMagicFeather.java b/src/main/java/gtPlusPlus/core/item/general/ItemMagicFeather.java new file mode 100644 index 0000000000..9b4dd86525 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/general/ItemMagicFeather.java @@ -0,0 +1,260 @@ +package gtPlusPlus.core.item.general; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.lang.ref.WeakReference; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.WeakHashMap; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntityBeacon; +import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.living.LivingDeathEvent; + +import cpw.mods.fml.common.eventhandler.EventPriority; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.gameevent.TickEvent; +import cpw.mods.fml.common.gameevent.TickEvent.Phase; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.item.ModItems; +import gtPlusPlus.core.item.base.CoreItem; + +public class ItemMagicFeather extends CoreItem { + + public static final String NAME = "magicfeather"; + private static final WeakHashMap<EntityPlayer, MagicFeatherData> sPlayerData = new WeakHashMap<>(); + private static final WeakHashMap<EntityPlayer, HashSet<TileEntityBeacon>> sBeaconData = new WeakHashMap<>(); + + public ItemMagicFeather() { + super( + "magicfeather", + AddToCreativeTab.tabMisc, + 1, + 100, + new String[] { "Lets you fly around Beacons" }, + EnumRarity.uncommon, + null, + false, + null); + setMaxStackSize(1); + setUnlocalizedName(GTPlusPlus.ID + ":" + NAME); + MinecraftForge.EVENT_BUS.register(this); + } + + @Override + public int getEntityLifespan(ItemStack itemStack, World world) { + return Integer.MAX_VALUE; + } + + @SuppressWarnings("unchecked") + @Override + @SideOnly(Side.CLIENT) + public void addInformation(final ItemStack stack, final EntityPlayer aPlayer, final List list, final boolean bool) { + list.add("Does not need to be the item held in your hand to work"); + super.addInformation(stack, aPlayer, list, bool); + list.add("Needs to be within beacon range"); + list.add("Range is beacon level * 10 + 10"); + } + + @Override + public boolean hasCustomEntity(ItemStack stack) { + return true; + } + + private static boolean isInBeaconRange(EntityPlayer player) { + World world = player.getEntityWorld(); + if (world.isRemote) { + return false; + } + HashSet<TileEntityBeacon> aBeaconData = sBeaconData.computeIfAbsent(player, k -> new HashSet<>()); + int chunkXlo = (int) (player.posX - 50) >> 4, chunkXhi = (int) (player.posX + 50) >> 4, + chunkZlo = (int) (player.posZ - 50) >> 4, chunkZhi = (int) (player.posZ + 50) >> 4; + for (int chunkX = chunkXlo; chunkX < chunkXhi; chunkX++) { + for (int chunkZ = chunkZlo; chunkZ < chunkZhi; chunkZ++) { + if (!world.getChunkProvider() + .chunkExists(chunkX, chunkZ)) continue; + findSuitableBeacon( + player, + world.getChunkFromChunkCoords(chunkX, chunkZ).chunkTileEntityMap.values(), + aBeaconData); + } + } + return aBeaconData.size() > 0; + } + + private static void findSuitableBeacon(EntityPlayer player, Collection<TileEntity> tileEntities, + HashSet<TileEntityBeacon> aBeaconData) { + for (TileEntity t : tileEntities) { + if (!(t instanceof TileEntityBeacon beacon)) { + continue; + } + int level = beacon.getLevels(); + if (level == 0) { + continue; + } + int radius = (level * 10 + 10); + int x = beacon.xCoord; + int z = beacon.zCoord; + if (player.posX < (x - radius) || player.posX > (x + radius)) { + continue; + } + if (player.posZ < (z - radius) || player.posZ > (z + radius)) { + continue; + } + aBeaconData.add(beacon); + } + } + + private static void setMayFly(EntityPlayer player, boolean mayFly) { + if (player.capabilities.allowFlying == mayFly) { + return; + } + if (!mayFly) { + // force the player on the ground then remove ability to fly + // this prevent crashing the the ground and dying + // when you accidentally get out of the beacon range + player.capabilities.isFlying = false; + if (player.onGround && player.fallDistance < 1F) { + player.capabilities.allowFlying = false; + } + } else { + player.capabilities.allowFlying = true; + } + player.sendPlayerAbilities(); + } + + @SubscribeEvent(priority = EventPriority.HIGHEST) + public void onPlayerTick(TickEvent.PlayerTickEvent event) { + if (event.side != Side.SERVER || event.phase != Phase.END) { + return; + } + EntityPlayer player = event.player; + HashSet<TileEntityBeacon> aBeaconData = sBeaconData.get(player); + if (aBeaconData != null && !aBeaconData.isEmpty()) { + for (Iterator<TileEntityBeacon> iterator = aBeaconData.iterator(); iterator.hasNext();) { + TileEntityBeacon aBeacon = iterator.next(); + int level = aBeacon.getLevels(); + if (level == 0) { + iterator.remove(); + continue; + } + int radius = (level * 10 + 10); + int x = aBeacon.xCoord; + int z = aBeacon.zCoord; + if (player.posX < (x - radius) || player.posX > (x + radius) + || player.posZ < (z - radius) + || player.posZ > (z + radius)) { + iterator.remove(); + } + } + } + boolean hasItem = hasItem(player, ModItems.itemMagicFeather); + if (!hasItem) { + ItemMagicFeather.sPlayerData.remove(player); + } + MagicFeatherData data = ItemMagicFeather.sPlayerData.get(player); + if (data == null) { + data = new MagicFeatherData(player); + ItemMagicFeather.sPlayerData.put(player, data); + } + data.onTick(); + } + + @SubscribeEvent(priority = EventPriority.LOWEST) + public void onPlayerDeath(LivingDeathEvent event) { + if (event.entityLiving == null) return; + EntityLivingBase aEntity = event.entityLiving; + if (!(aEntity instanceof EntityPlayer aPlayer) || aEntity.worldObj == null || aEntity.worldObj.isRemote) return; + ItemMagicFeather.sPlayerData.remove(aPlayer); + ItemMagicFeather.sBeaconData.remove(aPlayer); + } + + private static boolean hasItem(EntityPlayer player, Item item) { + for (int i = 0; i < player.inventory.getSizeInventory(); i++) { + ItemStack stack = player.inventory.getStackInSlot(i); + if (stack != null && stack.getItem() != null && stack.getItem() instanceof ItemMagicFeather) { + return true; + } + } + return false; + } + + private static class MagicFeatherData { + + private final WeakReference<EntityPlayer> player; + private boolean hasItem = false; + private int checkTick = 0; + private boolean beaconInRangeCache; + + public MagicFeatherData(EntityPlayer player) { + this.player = new WeakReference<>(player); + this.beaconInRangeCache = player.capabilities.allowFlying; + } + + public void onTick() { + EntityPlayer player = this.player.get(); + if (player == null) return; + try { + boolean hasItem = hasItem(player, ModItems.itemMagicFeather); + if (hasItem != this.hasItem) { + if (hasItem) { + this.onAdd(); + } + if (!hasItem) { + this.onRemove(); + } + this.hasItem = hasItem; + Logger.INFO("Ticking feather " + hasItem); + return; + } + } catch (Throwable t) { + t.printStackTrace(); + } + + if (hasItem) { + // only modify if hasItem. Override other flight methods since you are literally holding this item in + // your own inventory. You have sent your consent. + boolean mayFly = player.capabilities.isCreativeMode || checkBeaconInRange(player); + setMayFly(player, mayFly); + } + } + + private void onAdd() { + if (!ItemMagicFeather.isInBeaconRange(getPlayer())) { + return; + } + setMayFly(getPlayer(), true); + } + + private void onRemove() { + if (getPlayer().capabilities.isCreativeMode) { + return; + } + setMayFly(getPlayer(), false); + } + + private boolean checkBeaconInRange(EntityPlayer player) { + if (checkTick++ % 40 != 0) { + return beaconInRangeCache; + } + beaconInRangeCache = ItemMagicFeather.isInBeaconRange(player); + return beaconInRangeCache; + } + + private EntityPlayer getPlayer() { + return player.get(); + } + } +} diff --git a/src/main/java/gtPlusPlus/core/item/general/books/ItemBaseBook.java b/src/main/java/gtPlusPlus/core/item/general/books/ItemBaseBook.java new file mode 100644 index 0000000000..87c5ab3e74 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/general/books/ItemBaseBook.java @@ -0,0 +1,122 @@ +package gtPlusPlus.core.item.general.books; + +import static gregtech.api.enums.Mods.GTPlusPlus; +import static gtPlusPlus.core.handler.BookHandler.mBookMap; +import static gtPlusPlus.core.util.Utils.addBookTitleLocalization; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.List; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemWritableBook; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; + +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.handler.BookHandler; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.NBTUtils; +import gtPlusPlus.core.util.reflect.ReflectionUtils; + +public class ItemBaseBook extends ItemWritableBook { + + public ItemBaseBook() { + this.setCreativeTab(AddToCreativeTab.tabMisc); + this.setMaxStackSize(1); + this.setTextureName(GTPlusPlus.ID + ":" + "itemBook"); + this.setUnlocalizedName("itembookgt"); + GameRegistry.registerItem(this, "bookGT"); + } + + @Override + public void getSubItems(Item item, CreativeTabs tab, List list) { + for (int i = 0; i < BookHandler.mBookMap.size(); i++) { + ItemStack bookstack = new ItemStack(item, 1, i); + + /* + * bookstack = Utils.getWrittenBook( bookstack, i, mBookMap.get(i).mMapping, mBookMap.get(i).mTitle, + * mBookMap.get(i).mAuthor, mBookMap.get(i).mPages); + */ + + NBTUtils.createIntegerTagCompound(bookstack, "stats", "mMeta", i); + list.add(bookstack); + } + } + + @Override + public String getItemStackDisplayName(final ItemStack tItem) { + if (NBTUtils.hasKey(tItem, "title")) { + return NBTUtils.getString(tItem, "title"); + } else if (tItem.getItemDamage() > -1 && tItem.getItemDamage() <= mBookMap.size()) { + return EnumChatFormatting.ITALIC + "" + + addBookTitleLocalization(mBookMap.get(tItem.getItemDamage()).mTitle); + } + // NBTUtils.tryIterateNBTData(tItem); + return "GT++ Storybook"; + } + + @Override + public void addInformation(ItemStack tItem, EntityPlayer player, List list, boolean bool) { + // TODO Auto-generated method stub + if (NBTUtils.hasKey(tItem, "author")) { + list.add(EnumChatFormatting.GRAY + "Author: " + NBTUtils.getString(tItem, "author")); + } else if (mBookMap.get(tItem.getItemDamage()).mAuthor != null) { + list.add(EnumChatFormatting.WHITE + "Author: " + mBookMap.get(tItem.getItemDamage()).mAuthor); + } + if (NBTUtils.hasKey(tItem, "title")) { + list.add(EnumChatFormatting.GRAY + "Pages: " + NBTUtils.getString(tItem, "pages")); + } else if (mBookMap.get(tItem.getItemDamage()).mPages != null) { + list.add(EnumChatFormatting.WHITE + "Pages: " + mBookMap.get(tItem.getItemDamage()).mPages.length); + } + // super.addInformation(p_77624_1_, p_77624_2_, p_77624_3_, p_77624_4_); + } + + @Override + public boolean isRepairable() { + return false; + } + + @Override + public boolean showDurabilityBar(ItemStack stack) { + return false; + } + + @Override + @SideOnly(Side.CLIENT) + public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player) { + // player.displayGUIBook(item); + int i = item.getItemDamage(); + ItemStack bookstack = Utils.getWrittenBook( + null, + mBookMap.get(i).mMeta, + mBookMap.get(i).mMapping, + mBookMap.get(i).mTitle, + mBookMap.get(i).mAuthor, + mBookMap.get(i).mPages); + + if (player.worldObj.isRemote) { + try { + Class<?> clazz = ReflectionUtils.getClass("net.minecraft.client.gui.GuiScreenBook"); + Constructor<?> ctor = clazz.getConstructor(EntityPlayer.class, ItemStack.class, boolean.class); + Object object = ctor.newInstance(new Object[] { player, bookstack, false }); + Minecraft.getMinecraft() + .displayGuiScreen((GuiScreen) object); + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException + | InvocationTargetException | NoSuchMethodException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + // Minecraft.getMinecraft().displayGuiScreen(new GuiScreenBook(player, bookstack, false)); + } + return item; + } +} diff --git a/src/main/java/gtPlusPlus/core/item/general/chassis/ItemBoilerChassis.java b/src/main/java/gtPlusPlus/core/item/general/chassis/ItemBoilerChassis.java new file mode 100644 index 0000000000..8efcfe6912 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/general/chassis/ItemBoilerChassis.java @@ -0,0 +1,72 @@ +package gtPlusPlus.core.item.general.chassis; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.List; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.util.StatCollector; + +import cpw.mods.fml.common.registry.GameRegistry; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.util.Utils; + +public class ItemBoilerChassis extends Item { + + public IIcon[] icons = new IIcon[1]; + + public ItemBoilerChassis() { + super(); + this.setHasSubtypes(true); + String unlocalizedName = "itemBoilerChassis"; + this.setUnlocalizedName(unlocalizedName); + this.setCreativeTab(AddToCreativeTab.tabMisc); + GameRegistry.registerItem(this, unlocalizedName); + } + + @Override + public void registerIcons(IIconRegister reg) { + this.icons[0] = reg.registerIcon(GTPlusPlus.ID + ":" + "itemBoilerChassis"); + } + + @Override + public IIcon getIconFromDamage(int meta) { + return this.icons[0]; + } + + @Override + public void getSubItems(Item item, CreativeTabs tab, List list) { + for (int i = 0; i < 3; i++) { + list.add(new ItemStack(item, 1, i)); + } + } + + @Override + public String getUnlocalizedName(ItemStack stack) { + return this.getUnlocalizedName() + "_" + stack.getItemDamage(); + } + + @Override + public String getItemStackDisplayName(final ItemStack tItem) { + return StatCollector.translateToLocalFormatted("item.itemBoilerChassis.name", tItem.getItemDamage()); + } + + @Override // TODO + public int getColorFromItemStack(final ItemStack stack, int HEX_OxFFFFFF) { + int meta = stack.getItemDamage(); + if (meta == 0) { + HEX_OxFFFFFF = Utils.rgbtoHexValue(10, 110, 30); + } else if (meta == 1) { + HEX_OxFFFFFF = Utils.rgbtoHexValue(150, 180, 35); + } else if (meta == 2) { + HEX_OxFFFFFF = Utils.rgbtoHexValue(200, 85, 40); + } else if (meta == 3) { + HEX_OxFFFFFF = Utils.rgbtoHexValue(255, 100, 50); + } + return HEX_OxFFFFFF; + } +} diff --git a/src/main/java/gtPlusPlus/core/item/general/chassis/ItemDehydratorCoil.java b/src/main/java/gtPlusPlus/core/item/general/chassis/ItemDehydratorCoil.java new file mode 100644 index 0000000000..24759808ab --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/general/chassis/ItemDehydratorCoil.java @@ -0,0 +1,70 @@ +package gtPlusPlus.core.item.general.chassis; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.List; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.util.StatCollector; + +import cpw.mods.fml.common.registry.GameRegistry; +import gregtech.api.enums.GT_Values; +import gtPlusPlus.core.creative.AddToCreativeTab; + +public class ItemDehydratorCoil extends Item { + + public IIcon[] icons = new IIcon[4]; + + public ItemDehydratorCoil() { + super(); + this.setHasSubtypes(true); + String unlocalizedName = "itemDehydratorCoil"; + this.setUnlocalizedName(unlocalizedName); + this.setCreativeTab(AddToCreativeTab.tabMisc); + GameRegistry.registerItem(this, unlocalizedName); + } + + @Override + public void registerIcons(IIconRegister reg) { + this.icons[0] = reg.registerIcon(GTPlusPlus.ID + ":" + "dehydrator/itemDehydratorCoil_0"); + this.icons[1] = reg.registerIcon(GTPlusPlus.ID + ":" + "dehydrator/itemDehydratorCoil_1"); + this.icons[2] = reg.registerIcon(GTPlusPlus.ID + ":" + "dehydrator/itemDehydratorCoil_2"); + this.icons[3] = reg.registerIcon(GTPlusPlus.ID + ":" + "dehydrator/itemDehydratorCoil_3"); + } + + @Override + public IIcon getIconFromDamage(int meta) { + return this.icons[meta]; + } + + @Override + public void getSubItems(Item item, CreativeTabs tab, List list) { + for (int i = 0; i < 4; i++) { + list.add(new ItemStack(item, 1, i)); + } + } + + @Override + public String getUnlocalizedName(ItemStack stack) { + return this.getUnlocalizedName() + "_" + stack.getItemDamage(); + } + + @Override + public String getItemStackDisplayName(final ItemStack tItem) { + return StatCollector + .translateToLocalFormatted("item.itemDehydratorCoil.name", GT_Values.VN[tItem.getItemDamage() + 4]); + } + + /* + * @Override public int getColorFromItemStack(final ItemStack stack, int HEX_OxFFFFFF) { int meta = + * stack.getItemDamage(); if (meta == 0){ HEX_OxFFFFFF = Utils.rgbtoHexValue(10,110,30); } else if (meta == 1){ + * HEX_OxFFFFFF = Utils.rgbtoHexValue(150,180,35); } else if (meta == 2){ HEX_OxFFFFFF = + * Utils.rgbtoHexValue(200,85,40); } else if (meta == 3){ HEX_OxFFFFFF = Utils.rgbtoHexValue(255,150,50); } return + * HEX_OxFFFFFF; } + */ + +} diff --git a/src/main/java/gtPlusPlus/core/item/general/chassis/ItemDehydratorCoilWire.java b/src/main/java/gtPlusPlus/core/item/general/chassis/ItemDehydratorCoilWire.java new file mode 100644 index 0000000000..b050e4c65c --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/general/chassis/ItemDehydratorCoilWire.java @@ -0,0 +1,70 @@ +package gtPlusPlus.core.item.general.chassis; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.List; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.util.StatCollector; + +import cpw.mods.fml.common.registry.GameRegistry; +import gregtech.api.enums.GT_Values; +import gtPlusPlus.core.creative.AddToCreativeTab; + +public class ItemDehydratorCoilWire extends Item { + + public IIcon[] icons = new IIcon[4]; + + public ItemDehydratorCoilWire() { + super(); + this.setHasSubtypes(true); + String unlocalizedName = "itemDehydratorCoilWire"; + this.setUnlocalizedName(unlocalizedName); + this.setCreativeTab(AddToCreativeTab.tabMisc); + GameRegistry.registerItem(this, unlocalizedName); + } + + @Override + public void registerIcons(IIconRegister reg) { + this.icons[0] = reg.registerIcon(GTPlusPlus.ID + ":" + "dehydrator/itemDehydratorCoilWire_0"); + this.icons[1] = reg.registerIcon(GTPlusPlus.ID + ":" + "dehydrator/itemDehydratorCoilWire_1"); + this.icons[2] = reg.registerIcon(GTPlusPlus.ID + ":" + "dehydrator/itemDehydratorCoilWire_2"); + this.icons[3] = reg.registerIcon(GTPlusPlus.ID + ":" + "dehydrator/itemDehydratorCoilWire_3"); + } + + @Override + public IIcon getIconFromDamage(int meta) { + return this.icons[meta]; + } + + @Override + public void getSubItems(Item item, CreativeTabs tab, List list) { + for (int i = 0; i < 4; i++) { + list.add(new ItemStack(item, 1, i)); + } + } + + @Override + public String getUnlocalizedName(ItemStack stack) { + return this.getUnlocalizedName() + "_" + stack.getItemDamage(); + } + + @Override + public String getItemStackDisplayName(final ItemStack tItem) { + return StatCollector + .translateToLocalFormatted("item.itemDehydratorCoilWire.name", GT_Values.VN[tItem.getItemDamage() + 4]); + } + + /* + * @Override public int getColorFromItemStack(final ItemStack stack, int HEX_OxFFFFFF) { int meta = + * stack.getItemDamage(); if (meta == 0){ HEX_OxFFFFFF = Utils.rgbtoHexValue(10,110,30); } else if (meta == 1){ + * HEX_OxFFFFFF = Utils.rgbtoHexValue(150,180,35); } else if (meta == 2){ HEX_OxFFFFFF = + * Utils.rgbtoHexValue(200,85,40); } else if (meta == 3){ HEX_OxFFFFFF = Utils.rgbtoHexValue(255,150,50); } return + * HEX_OxFFFFFF; } + */ + +} diff --git a/src/main/java/gtPlusPlus/core/item/general/spawn/ItemCustomSpawnEgg.java b/src/main/java/gtPlusPlus/core/item/general/spawn/ItemCustomSpawnEgg.java new file mode 100644 index 0000000000..c186fccd4b --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/general/spawn/ItemCustomSpawnEgg.java @@ -0,0 +1,278 @@ +package gtPlusPlus.core.item.general.spawn; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockLiquid; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityList; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.IEntityLivingData; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemMonsterPlacer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Facing; +import net.minecraft.util.IIcon; +import net.minecraft.util.MathHelper; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.StatCollector; +import net.minecraft.world.World; + +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.core.util.minecraft.ItemUtils; + +public class ItemCustomSpawnEgg extends ItemMonsterPlacer { + + private static final HashMap<Integer, IIcon> mIconMap = new HashMap<>(); + private static int mTotalMetaItems = 0; + + private static final HashMap<Integer, Integer> mMaxStackSizeMap = new HashMap<>(); + private static final HashMap<Integer, EnumRarity> mRarityMap = new HashMap<>(); + private static final HashMap<Integer, ArrayList<String>> mOreDictNames = new HashMap<>(); + + private static final HashMap<Integer, Integer> mColourBaseMap = new HashMap<>(); + private static final HashMap<Integer, Integer> mColourSpotsMap = new HashMap<>(); + private static final HashMap<Integer, String> mEntityNameMap = new HashMap<>(); + private static final HashMap<Integer, String> mEntityFullNameMap = new HashMap<>(); + + private static final HashMap<String, Integer> mReverseEntityMap = new HashMap<>(); + + protected EntityLiving entityToSpawn = null; + + public static void registerEntityForSpawnEgg(final int aMetaID, String parEntityToSpawnName, int aPrimaryColor, + int aSecondaryColor) { + registerEntityForSpawnEgg( + aMetaID, + parEntityToSpawnName, + aPrimaryColor, + aSecondaryColor, + EnumRarity.common, + new ArrayList<String>()); + } + + public static void registerEntityForSpawnEgg(final int aMetaID, String parEntityToSpawnName, int aPrimaryColor, + int aSecondaryColor, EnumRarity aRarity, final ArrayList<String> aOreDictNames) { + mTotalMetaItems++; + mMaxStackSizeMap.put(aMetaID, 64); + mRarityMap.put(aMetaID, aRarity); + mOreDictNames.put(aMetaID, aOreDictNames); + mColourBaseMap.put(aMetaID, aPrimaryColor); + mColourSpotsMap.put(aMetaID, aSecondaryColor); + mReverseEntityMap.put(parEntityToSpawnName, aMetaID); + setEntityToSpawnName(aMetaID, parEntityToSpawnName); + } + + public ItemCustomSpawnEgg() { + super(); + this.setNoRepair(); + this.setMaxStackSize(64); + this.setMaxDamage(0); + this.setUnlocalizedName("BasicMetaSpawnEgg"); + GameRegistry.registerItem(this, this.getUnlocalizedName()); + } + + /** + * Callback for item usage. If the item does something special on right clicking, + * + * he will have one of those. Return True if something happen and false if it don't. This is for ITEMS, not BLOCKS + */ + @Override + public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, + int par5, int par6, int par7, float par8, float par9, float par10) { + if (par3World.isRemote) { + return true; + } else { + Block block = par3World.getBlock(par4, par5, par6); + par4 += Facing.offsetsXForSide[par7]; + par5 += Facing.offsetsYForSide[par7]; + par6 += Facing.offsetsZForSide[par7]; + double d0 = 0.0D; + + if (par7 == 1 && block.getRenderType() == 11) { + d0 = 0.5D; + } + + Entity entity = spawnEntity(par1ItemStack, par3World, par4 + 0.5D, par5 + d0, par6 + 0.5D); + + if (entity != null) { + if (entity instanceof EntityLivingBase && par1ItemStack.hasDisplayName()) { + ((EntityLiving) entity).setCustomNameTag(par1ItemStack.getDisplayName()); + } + + if (!par2EntityPlayer.capabilities.isCreativeMode) { + --par1ItemStack.stackSize; + } + } + + return true; + } + } + + /** + * Called whenever this item is equipped and the right mouse button is pressed. + * + * Args: itemStack, world, entityPlayer + */ + @Override + public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { + if (par2World.isRemote) { + return par1ItemStack; + } else { + MovingObjectPosition movingobjectposition = getMovingObjectPositionFromPlayer( + par2World, + par3EntityPlayer, + true); + + if (movingobjectposition == null) { + return par1ItemStack; + } else { + if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { + int i = movingobjectposition.blockX; + int j = movingobjectposition.blockY; + int k = movingobjectposition.blockZ; + + if (!par2World.canMineBlock(par3EntityPlayer, i, j, k)) { + return par1ItemStack; + } + + if (!par3EntityPlayer.canPlayerEdit(i, j, k, movingobjectposition.sideHit, par1ItemStack)) { + + return par1ItemStack; + } + + if (par2World.getBlock(i, j, k) instanceof BlockLiquid) { + Entity entity = spawnEntity(par1ItemStack, par2World, i, j, k); + + if (entity != null) { + if (entity instanceof EntityLivingBase && par1ItemStack.hasDisplayName()) { + + ((EntityLiving) entity).setCustomNameTag(par1ItemStack.getDisplayName()); + } + + if (!par3EntityPlayer.capabilities.isCreativeMode) { + --par1ItemStack.stackSize; + } + } + } + } + + return par1ItemStack; + } + } + } + + /** + * Spawns the creature specified by the egg's type in the location specified by + * + * the last three parameters. Parameters: world, entityID, x, y, z. + * + * @param par1ItemStack + */ + public Entity spawnEntity(ItemStack par1ItemStack, World parWorld, double parX, double parY, double parZ) { + + if (!parWorld.isRemote) // never spawn entity on client side + { + int aDamage = par1ItemStack.getItemDamage(); + String entityToSpawnNameFull = mEntityFullNameMap.get(aDamage); + String entityToSpawnName = mEntityNameMap.get(aDamage); + // entityToSpawnNameFull = WildAnimals.MODID + "." + entityToSpawnName; + if (EntityList.stringToClassMapping.containsKey(entityToSpawnNameFull)) { + entityToSpawn = (EntityLiving) EntityList.createEntityByName(entityToSpawnNameFull, parWorld); + entityToSpawn.setLocationAndAngles( + parX, + parY, + parZ, + MathHelper.wrapAngleTo180_float(parWorld.rand.nextFloat() * 360.0F), + 0.0F); + parWorld.spawnEntityInWorld(entityToSpawn); + entityToSpawn.onSpawnWithEgg((IEntityLivingData) null); + entityToSpawn.playLivingSound(); + } else { + // DEBUG + System.out.println("Entity not found " + entityToSpawnName); + } + } + + return entityToSpawn; + } + + /** + * returns a list of items with the same ID, but different meta (eg: dye returns 16 items) + */ + @Override + @SideOnly(Side.CLIENT) + public void getSubItems(Item aItem, CreativeTabs p_150895_2_, List aList) { + for (int aMeta : mReverseEntityMap.values()) { + aList.add(ItemUtils.simpleMetaStack(aItem, aMeta, 1)); + } + } + + @Override + @SideOnly(Side.CLIENT) + public int getColorFromItemStack(ItemStack par1ItemStack, int parColorType) { + int aID = par1ItemStack.getItemDamage(); + return (parColorType == 0) ? mColourBaseMap.get(aID) : mColourSpotsMap.get(aID); + } + + @Override + @SideOnly(Side.CLIENT) + public boolean requiresMultipleRenderPasses() { + return true; + } + + @Override + // Doing this override means that there is no localization for language + // unless you specifically check for localization here and convert + public String getItemStackDisplayName(ItemStack par1ItemStack) { + return StatCollector.translateToLocalFormatted( + "item.ItemCustomSpawnEgg.name", + StatCollector.translateToLocal("entity." + mEntityNameMap.get(par1ItemStack.getItemDamage()) + ".name")); + } + + @Override + public void registerIcons(final IIconRegister u) { + mIconMap.put(0, u.registerIcon(GTPlusPlus.ID + ":" + "spawn_egg")); + mIconMap.put(1, u.registerIcon(GTPlusPlus.ID + ":" + "spawn_egg_overlay")); + } + + @Override + public IIcon getIconFromDamageForRenderPass(final int damage, final int renderPass) { + return mIconMap.get(renderPass); + } + + @Override + public IIcon getIconFromDamage(int damage) { + return getIconFromDamageForRenderPass(0, 0); + } + + @Override + public IIcon getIcon(ItemStack aStack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining) { + return getIconFromDamageForRenderPass(0, renderPass); + } + + @Override + public IIcon getIcon(ItemStack aStack, int renderPass) { + return getIconFromDamageForRenderPass(0, renderPass); + } + + @Override + public String getUnlocalizedName(ItemStack stack) { + return super.getUnlocalizedName() + "." + stack.getItemDamage(); + } + + public static void setEntityToSpawnName(int aMetaID, String parEntityToSpawnName) { + mEntityNameMap.put(aMetaID, parEntityToSpawnName); + mEntityFullNameMap.put(aMetaID, GTPlusPlus.ID + "." + parEntityToSpawnName); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/init/ItemsFoods.java b/src/main/java/gtPlusPlus/core/item/init/ItemsFoods.java new file mode 100644 index 0000000000..acddd58a7b --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/init/ItemsFoods.java @@ -0,0 +1,50 @@ +package gtPlusPlus.core.item.init; + +import net.minecraft.entity.monster.EntityBlaze; +import net.minecraft.entity.passive.EntityHorse; +import net.minecraft.entity.passive.EntityOcelot; +import net.minecraft.entity.passive.EntityVillager; +import net.minecraft.entity.passive.EntityWolf; +import net.minecraft.item.ItemStack; + +import gtPlusPlus.core.item.ModItems; +import gtPlusPlus.core.item.food.BaseItemMetaFood; +import gtPlusPlus.core.util.minecraft.EntityUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.minecraft.RecipeUtils; + +public class ItemsFoods { + + public static void load() { + run(); + } + + private static void run() { + + ModItems.itemMetaFood = new BaseItemMetaFood(); + BaseItemMetaFood.registerFoodsToOreDict(); + addCookingRecipes(); + addFoodDropsToMobs(); + } + + private static ItemStack getMetaFoodStack(int aID) { + return ItemUtils.simpleMetaStack(ModItems.itemMetaFood, aID, 1); + } + + private static void addCookingRecipes() { + + RecipeUtils.addSmeltingRecipe(getMetaFoodStack(0), getMetaFoodStack(1), 0.4F); + RecipeUtils.addSmeltingRecipe(getMetaFoodStack(2), getMetaFoodStack(3), 0.35F); + RecipeUtils.addSmeltingRecipe(getMetaFoodStack(4), getMetaFoodStack(5), 0.35F); + RecipeUtils.addSmeltingRecipe(getMetaFoodStack(6), getMetaFoodStack(7), 0.35F); + } + + private static void addFoodDropsToMobs() { + + EntityUtils.registerDropsForMob(EntityVillager.class, getMetaFoodStack(0), 2, 1500); + EntityUtils.registerDropsForMob(EntityHorse.class, getMetaFoodStack(2), 4, 4000); + EntityUtils.registerDropsForMob(EntityWolf.class, getMetaFoodStack(4), 2, 4000); + EntityUtils.registerDropsForMob(EntityOcelot.class, getMetaFoodStack(6), 2, 4000); + EntityUtils.registerDropsForMob(EntityBlaze.class, getMetaFoodStack(8), 1, 500); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/materials/DustDecayable.java b/src/main/java/gtPlusPlus/core/item/materials/DustDecayable.java new file mode 100644 index 0000000000..eaf8c2c9da --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/materials/DustDecayable.java @@ -0,0 +1,97 @@ +package gtPlusPlus.core.item.materials; + +import static gregtech.api.enums.Mods.GregTech; +import static gtPlusPlus.core.util.minecraft.ItemUtils.getSimpleStack; + +import java.util.List; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +import gregtech.api.util.GT_OreDictUnificator; +import gtPlusPlus.core.handler.Recipes.DecayableRecipe; +import gtPlusPlus.core.item.base.BaseItemTickable; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.EntityUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; + +public class DustDecayable extends BaseItemTickable { + + private final Item turnsIntoItem; + private final int radLevel; + + public DustDecayable(String unlocal, int colour, int maxTicks, String[] desc1, Item turnsInto, int radLevel) { + super(true, true, unlocal, colour, (maxTicks / 1), desc1); + this.turnsIntoItem = turnsInto; + this.radLevel = radLevel; + GT_OreDictUnificator.registerOre(unlocal, ItemUtils.getSimpleStack(this)); + new DecayableRecipe(maxTicks, getSimpleStack(this), getSimpleStack(turnsInto)); + } + + @Override + public void registerIcons(IIconRegister reg) { + String gt = GregTech.ID + ":" + "materialicons/" + "NUCLEAR" + "/" + "dust"; + this.mIcon[0] = reg.registerIcon(gt); + String gt2 = GregTech.ID + ":" + "materialicons/" + "NUCLEAR" + "/" + "dust" + "_OVERLAY"; + this.mIcon[1] = reg.registerIcon(gt2); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool) { + super.addInformation(stack, player, list, bool); + if (this.radLevel > 0) { + list.add(CORE.GT_Tooltip_Radioactive.get()); + } + } + + @Override + public void onUpdate(final ItemStack iStack, final World world, final Entity entityHolding, final int p_77663_4_, + final boolean p_77663_5_) { + if (world == null || iStack == null) { + return; + } + if (world.isRemote) { + return; + } + + if (entityHolding instanceof EntityPlayer) { + if (!((EntityPlayer) entityHolding).capabilities.isCreativeMode) { + EntityUtils.applyRadiationDamageToEntity(iStack.stackSize, this.radLevel, world, entityHolding); + } + } + boolean a1, a2; + + a1 = this.isTicking(world, iStack); + a2 = tickItemTag(world, iStack); + + if (!a1 && !a2) { + if (entityHolding instanceof EntityPlayer) { + ItemStack replacement = ItemUtils.getSimpleStack(getDecayResult()); + // Logger.INFO("Replacing "+iStack.getDisplayName()+" with "+replacement.getDisplayName()+"."); + final ItemStack tempTransform = replacement; + if (iStack.stackSize > 1) { + int u = iStack.stackSize; + tempTransform.stackSize = u; + ((EntityPlayer) entityHolding).inventory.addItemStackToInventory((tempTransform)); + for (int l = 0; l < u; l++) { + ((EntityPlayer) entityHolding).inventory.consumeInventoryItem(this); + } + + } else { + tempTransform.stackSize = 1; + ((EntityPlayer) entityHolding).inventory.addItemStackToInventory((tempTransform)); + ((EntityPlayer) entityHolding).inventory.consumeInventoryItem(this); + } + } + } + } + + public Item getDecayResult() { + return turnsIntoItem; + } +} diff --git a/src/main/java/gtPlusPlus/core/item/tool/misc/GregtechPump.java b/src/main/java/gtPlusPlus/core/item/tool/misc/GregtechPump.java new file mode 100644 index 0000000000..5ba3aa1531 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/tool/misc/GregtechPump.java @@ -0,0 +1,1320 @@ +package gtPlusPlus.core.item.tool.misc; + +import static gregtech.api.enums.GT_Values.V; +import static gregtech.api.enums.Mods.GTPlusPlus; +import static gregtech.api.util.GT_Utility.formatNumbers; + +import java.util.ArrayList; +import java.util.BitSet; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IIcon; +import net.minecraft.util.StatCollector; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTankInfo; +import net.minecraftforge.fluids.IFluidContainerItem; +import net.minecraftforge.fluids.IFluidHandler; +import net.minecraftforge.fluids.IFluidTank; + +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.GregTech_API; +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.SubTag; +import gregtech.api.enums.TC_Aspects.TC_AspectStack; +import gregtech.api.interfaces.IItemBehaviour; +import gregtech.api.interfaces.IItemContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicTank; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_MultiInput; +import gregtech.api.objects.ItemData; +import gregtech.api.util.GT_LanguageManager; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_OreDictUnificator; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.item.ModItems; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.core.util.minecraft.NBTUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import ic2.api.item.ElectricItem; +import ic2.api.item.IElectricItem; +import ic2.api.item.IElectricItemManager; +import ic2.api.item.ISpecialElectricItem; + +public class GregtechPump extends Item implements ISpecialElectricItem, IElectricItemManager, IFluidContainerItem { + + /** + * Right Click Functions + */ + @Override + public boolean onItemUse(ItemStack aStack, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ, int a4, + float p_77648_8_, float p_77648_9_, float p_77648_10_) { + if (aStack == null || aPlayer == null || aWorld == null || aWorld.isRemote) { + return false; + } + if (!aWorld.isRemote && tryDrainTile(aStack, aWorld, aPlayer, aX, aY, aZ)) { + return true; + } else { + // return super.onItemUse(aStack, aPlayer, aWorld, aX, aY, aZ, a4, p_77648_8_, p_77648_9_, p_77648_10_); + return false; + } + } + + @Override + public ItemStack onItemRightClick(ItemStack p_77659_1_, World p_77659_2_, EntityPlayer p_77659_3_) { + return p_77659_1_; + } + + /** + * GT Code + */ + + /* ---------- CONSTRUCTOR AND MEMBER VARIABLES ---------- */ + private final HashMap<Short, ArrayList<IItemBehaviour<GregtechPump>>> mItemBehaviors = new HashMap<>(); + + public final short mOffset, mItemAmount; + public final BitSet mEnabledItems; + public final BitSet mVisibleItems; + /** The unlocalized name of this item. */ + private String unlocalizedName; + + private final HashMap<Integer, IIcon> mIconMap = new LinkedHashMap<>(); + private final HashMap<Integer, EnumRarity> rarity = new LinkedHashMap<>(); + private final HashMap<Integer, String> itemName = new LinkedHashMap<>(); + private final HashMap<Integer, Boolean> hasEffect = new LinkedHashMap<>(); + + public final HashMap<Short, Long[]> mElectricStats = new LinkedHashMap<>(); + public final HashMap<Short, Short> mBurnValues = new LinkedHashMap<>(); + + public void registerPumpType(final int aID, final String aPumpName, final int aEuMax, final int aTier) { + ModItems.toolGregtechPump.registerItem( + aID, // ID + aPumpName, // Name + aEuMax, // Eu Storage + (short) aTier, // Tier/ Tooltip + aTier <= 0 ? EnumRarity.common + : aTier == 1 ? EnumRarity.uncommon + : aTier == 2 ? EnumRarity.rare : aTier == 3 ? EnumRarity.epic : EnumRarity.common, // Rarity + false // Effect? + ); + } + + public GregtechPump() { + this("MU-metatool.01", AddToCreativeTab.tabTools, (short) 1000, (short) 31766); + } + + public GregtechPump(final String unlocalizedName, final CreativeTabs creativeTab, final short aOffset, + final short aItemAmount) { + this.mEnabledItems = new BitSet(aItemAmount); + this.mVisibleItems = new BitSet(aItemAmount); + this.mOffset = (short) Math.min(32766, aOffset); + this.mItemAmount = (short) Math.min(aItemAmount, 32766 - this.mOffset); + this.setHasSubtypes(true); + this.setMaxDamage(0); + this.setUnlocalizedName(unlocalizedName); + this.setCreativeTab(creativeTab); + this.setMaxStackSize(1); + if (GameRegistry.findItem(GTPlusPlus.ID, unlocalizedName) == null) { + GameRegistry.registerItem(this, unlocalizedName); + } + } + + public void registerItem(final int id, final String localizedName, final long euStorage, final int tier) { + this.registerItem(id, localizedName, euStorage, (short) tier, EnumRarity.common, false); + } + + public void registerItem(final int id, final String localizedName, final long euStorage, final int tier, + final int burnTime) { + this.registerItem(id, localizedName, euStorage, (short) tier, EnumRarity.common, false); + this.setBurnValue(id, burnTime); + } + + public void registerItem(final int id, final String localizedName, final long euStorage, final short tier, + final EnumRarity regRarity, final boolean Effect) { + this.addItem( + id, + localizedName, + EnumChatFormatting.GRAY + "Can be used to remove fluids from GT machine input & output slots"); + if (euStorage > 0 && tier > 0) + this.setElectricStats(this.mOffset + id, euStorage, GT_Values.V[tier], tier, -3L, true); + this.rarity.put(id, regRarity); + this.itemName.put(id, localizedName); + this.hasEffect.put(id, Effect); + } + + @Override + @SideOnly(Side.CLIENT) + public EnumRarity getRarity(final ItemStack par1ItemStack) { + int h = getCorrectMetaForItemstack(par1ItemStack); + if (this.rarity.get(h) != null) { + return this.rarity.get(h); + } + return EnumRarity.common; + } + + @Override + public boolean hasEffect(final ItemStack par1ItemStack, final int pass) { + int h = getCorrectMetaForItemstack(par1ItemStack); + if (this.hasEffect.get(h) != null) { + return this.hasEffect.get(h); + } + return false; + } + + @SuppressWarnings({ "unchecked" }) + @Override + public void addInformation(final ItemStack aStack, final EntityPlayer aPlayer, List aList, final boolean aF3_H) { + // aList.add("Meta: "+(aStack.getItemDamage()-mOffset)); + int aOffsetMeta = getCorrectMetaForItemstack(aStack); + aList.add( + GT_LanguageManager + .getTranslation("gtplusplus." + this.getUnlocalizedName(aStack) + "." + aOffsetMeta + ".tooltip")); + + if (aOffsetMeta <= 3) { + FluidStack f = getFluid(aStack); + aList.add(StatCollector.translateToLocal("item.itemGregtechPump.tooltip.0")); + aList.add(StatCollector.translateToLocal("item.itemGregtechPump.tooltip.1")); + aList.add(EnumChatFormatting.DARK_GRAY + StatCollector.translateToLocal("item.itemGregtechPump.tooltip.2")); + aList.add( + EnumChatFormatting.BLUE + (f != null ? f.getLocalizedName() + : StatCollector.translateToLocal("item.itemGregtechPump.tooltip.3"))); + aList.add( + EnumChatFormatting.BLUE + (f != null ? "" + f.amount : "" + 0) + + "L" + + " / " + + formatNumbers(getCapacity(aStack)) + + "L"); + } + + final Long[] tStats = this.getElectricStats(aStack); + if (tStats != null) { + if (tStats[3] > 0) { + aList.add( + EnumChatFormatting.AQUA + StatCollector.translateToLocalFormatted( + "item.itemBaseEuItem.tooltip.1", + formatNumbers(tStats[3]), + (tStats[2] >= 0 ? tStats[2] : 0)) + EnumChatFormatting.GRAY); + } else { + final long tCharge = this.getRealCharge(aStack); + if ((tStats[3] == -2) && (tCharge <= 0)) { + aList.add( + EnumChatFormatting.AQUA + StatCollector.translateToLocal("item.itemBaseEuItem.tooltip.2") + + EnumChatFormatting.GRAY); + } else { + aList.add( + EnumChatFormatting.AQUA + + StatCollector.translateToLocalFormatted( + "item.itemBaseEuItem.tooltip.3", + formatNumbers(tCharge), + formatNumbers(Math.abs(tStats[0])) + " EU - Voltage: ", + V[(int) (tStats[2] >= 0 ? tStats[2] < V.length ? tStats[2] : V.length - 1 : 1)]) + + EnumChatFormatting.GRAY); + } + } + } + + final ArrayList<IItemBehaviour<GregtechPump>> tList = this.mItemBehaviors.get((short) this.getDamage(aStack)); + if (tList != null) { + for (final IItemBehaviour<GregtechPump> tBehavior : tList) { + aList = tBehavior.getAdditionalToolTips(this, aList, aStack); + } + } + } + + @Override + public final Item getChargedItem(final ItemStack itemStack) { + return this; + } + + @Override + public final Item getEmptyItem(final ItemStack itemStack) { + return this; + } + + @Override + public final double getMaxCharge(final ItemStack aStack) { + final Long[] tStats = this.getElectricStats(aStack); + if (tStats == null) { + return 0; + } + return Math.abs(tStats[0]); + } + + @Override + public final double getTransferLimit(final ItemStack aStack) { + final Long[] tStats = this.getElectricStats(aStack); + if (tStats == null) { + return 0; + } + return Math.max(tStats[1], tStats[3]); + } + + @Override + public final int getTier(final ItemStack aStack) { + final Long[] tStats = this.getElectricStats(aStack); + return (int) (tStats == null ? Integer.MAX_VALUE : tStats[2]); + } + + @Override + public final double charge(final ItemStack aStack, final double aCharge, final int aTier, + final boolean aIgnoreTransferLimit, final boolean aSimulate) { + final Long[] tStats = this.getElectricStats(aStack); + if ((tStats == null) || (tStats[2] > aTier) + || !((tStats[3] == -1) || (tStats[3] == -3) || ((tStats[3] < 0) && (aCharge == Integer.MAX_VALUE))) + || (aStack.stackSize != 1)) { + return 0; + } + final long tChargeBefore = this.getRealCharge(aStack), + tNewCharge = aCharge == Integer.MAX_VALUE ? Long.MAX_VALUE + : Math.min( + Math.abs(tStats[0]), + tChargeBefore + (aIgnoreTransferLimit ? (long) aCharge : Math.min(tStats[1], (long) aCharge))); + if (!aSimulate) { + this.setCharge(aStack, tNewCharge); + } + return tNewCharge - tChargeBefore; + } + + @Override + public final double discharge(final ItemStack aStack, final double aCharge, final int aTier, + final boolean aIgnoreTransferLimit, final boolean aBatteryAlike, final boolean aSimulate) { + final Long[] tStats = this.getElectricStats(aStack); + if ((tStats == null) || (tStats[2] > aTier)) { + return 0; + } + if (aBatteryAlike && !this.canProvideEnergy(aStack)) { + return 0; + } + if (tStats[3] > 0) { + if ((aCharge < tStats[3]) || (aStack.stackSize < 1)) { + return 0; + } + if (!aSimulate) { + aStack.stackSize--; + } + return tStats[3]; + } + final long tChargeBefore = this.getRealCharge(aStack), tNewCharge = Math + .max(0, tChargeBefore - (aIgnoreTransferLimit ? (long) aCharge : Math.min(tStats[1], (long) aCharge))); + if (!aSimulate) { + this.setCharge(aStack, tNewCharge); + } + return tChargeBefore - tNewCharge; + } + + @Override + public final double getCharge(final ItemStack aStack) { + return this.getRealCharge(aStack); + } + + @Override + public final boolean canUse(final ItemStack aStack, final double aAmount) { + return this.getRealCharge(aStack) >= aAmount; + } + + @Override + public final boolean use(final ItemStack aStack, final double aAmount, final EntityLivingBase aPlayer) { + this.chargeFromArmor(aStack, aPlayer); + if ((aPlayer instanceof EntityPlayer) && ((EntityPlayer) aPlayer).capabilities.isCreativeMode) { + return true; + } + final double tTransfer = this.discharge(aStack, aAmount, Integer.MAX_VALUE, true, false, true); + if (tTransfer == aAmount) { + this.discharge(aStack, aAmount, Integer.MAX_VALUE, true, false, false); + this.chargeFromArmor(aStack, aPlayer); + return true; + } + this.discharge(aStack, aAmount, Integer.MAX_VALUE, true, false, false); + this.chargeFromArmor(aStack, aPlayer); + return false; + } + + @Override + public final boolean canProvideEnergy(final ItemStack aStack) { + final Long[] tStats = this.getElectricStats(aStack); + if (tStats == null) { + return false; + } + return (tStats[3] > 0) || ((aStack.stackSize == 1) && ((tStats[3] == -2) || (tStats[3] == -3))); + } + + @Override + public final void chargeFromArmor(final ItemStack aStack, final EntityLivingBase aPlayer) { + if ((aPlayer == null) || aPlayer.worldObj.isRemote) { + return; + } + for (int i = 1; i < 5; i++) { + final ItemStack tArmor = aPlayer.getEquipmentInSlot(i); + if (GT_ModHandler.isElectricItem(tArmor)) { + final IElectricItem tArmorItem = (IElectricItem) tArmor.getItem(); + if (tArmorItem.canProvideEnergy(tArmor) && (tArmorItem.getTier(tArmor) >= this.getTier(aStack))) { + final double tCharge = ElectricItem.manager.discharge( + tArmor, + this.charge(aStack, Integer.MAX_VALUE - 1, Integer.MAX_VALUE, true, true), + Integer.MAX_VALUE, + true, + true, + false); + if (tCharge > 0) { + this.charge(aStack, tCharge, Integer.MAX_VALUE, true, false); + if (aPlayer instanceof EntityPlayer) { + final Container tContainer = ((EntityPlayer) aPlayer).openContainer; + if (tContainer != null) { + tContainer.detectAndSendChanges(); + } + } + } + } + } + } + } + + public final long getRealCharge(final ItemStack aStack) { + final Long[] tStats = this.getElectricStats(aStack); + if (tStats == null) { + return 0; + } + if (tStats[3] > 0) { + return (int) (long) tStats[3]; + } + final NBTTagCompound tNBT = aStack.getTagCompound(); + return tNBT == null ? 0 : tNBT.getLong("GT.ItemCharge"); + } + + public final boolean setCharge(final ItemStack aStack, long aCharge) { + final Long[] tStats = this.getElectricStats(aStack); + if ((tStats == null) || (tStats[3] > 0)) { + return false; + } + NBTTagCompound tNBT = aStack.getTagCompound(); + if (tNBT == null) { + tNBT = new NBTTagCompound(); + } + tNBT.removeTag("GT.ItemCharge"); + aCharge = Math.min(tStats[0] < 0 ? Math.abs(tStats[0] / 2) : aCharge, Math.abs(tStats[0])); + if (aCharge > 0) { + aStack.setItemDamage(this.getChargedMetaData(aStack)); + tNBT.setLong("GT.ItemCharge", aCharge); + } else { + aStack.setItemDamage(this.getEmptyMetaData(aStack)); + } + if (tNBT.hasNoTags()) { + aStack.setTagCompound(null); + } else { + aStack.setTagCompound(tNBT); + } + this.isItemStackUsable(aStack); + return true; + } + + public short getChargedMetaData(final ItemStack aStack) { + return (short) aStack.getItemDamage(); + } + + public short getEmptyMetaData(final ItemStack aStack) { + return (short) aStack.getItemDamage(); + } + + public boolean isItemStackUsable(final ItemStack aStack) { + final ArrayList<IItemBehaviour<GregtechPump>> tList = this.mItemBehaviors.get((short) this.getDamage(aStack)); + if (tList != null) { + for (final IItemBehaviour<GregtechPump> tBehavior : tList) { + if (!tBehavior.isItemStackUsable(this, aStack)) { + return false; + } + } + } + return true; + } + + @Override + public final String getToolTip(final ItemStack aStack) { + return null; + } // This has its own ToolTip Handler, no need to let the IC2 Handler screw us up + // at this Point + + @Override + public final IElectricItemManager getManager(final ItemStack aStack) { + return this; + } // We are our own Manager + + /** + * Sets the Furnace Burn Value for the Item. + * + * @param aMetaValue the Meta Value of the Item you want to set it to. [0 - 32765] + * @param aValue 200 = 1 Burn Process = 500 EU, max = 32767 (that is 81917.5 EU) + * @return the Item itself for convenience in constructing. + */ + public final GregtechPump setBurnValue(final int aMetaValue, final int aValue) { + if ((aMetaValue < 0) || (aValue < 0)) { + return this; + } + if (aValue == 0) { + this.mBurnValues.remove((short) aMetaValue); + } else { + this.mBurnValues.put((short) aMetaValue, aValue > Short.MAX_VALUE ? Short.MAX_VALUE : (short) aValue); + } + return this; + } + + /** + * @param aMetaValue the Meta Value of the Item you want to set it to. [0 - 32765] + * @param aMaxCharge Maximum Charge. (if this is == 0 it will remove the Electric Behavior) + * @param aTransferLimit Transfer Limit. + * @param aTier The electric Tier. + * @param aSpecialData If this Item has a Fixed Charge, like a SingleUse Battery (if > 0). Use -1 if you want to + * make this Battery chargeable (the use and canUse Functions will still discharge if you just + * use this) Use -2 if you want to make this Battery dischargeable. Use -3 if you want to make + * this Battery charge/discharge-able. + * @return the Item itself for convenience in constructing. + */ + public final GregtechPump setElectricStats(final int aMetaValue, final long aMaxCharge, final long aTransferLimit, + final long aTier, final long aSpecialData, final boolean aUseAnimations) { + if (aMetaValue < 0) { + return this; + } + if (aMaxCharge == 0) { + this.mElectricStats.remove((short) aMetaValue); + } else { + this.mElectricStats.put( + (short) aMetaValue, + new Long[] { aMaxCharge, Math.max(0, aTransferLimit), Math.max(-1, aTier), aSpecialData }); + } + return this; + } + + @SuppressWarnings({ "unchecked" }) + @Override + @SideOnly(Side.CLIENT) + public void getSubItems(final Item var1, final CreativeTabs aCreativeTab, final List aList) { + for (int i = 0, j = this.mEnabledItems.length(); i < j; i++) { + if (this.mVisibleItems.get(i) || (GT_Values.D1 && this.mEnabledItems.get(i))) { + final Long[] tStats = this.mElectricStats.get((short) (this.mOffset + i)); + if ((tStats != null) && (tStats[3] < 0)) { + final ItemStack tStack = new ItemStack(this, 1, this.mOffset + i); + this.setCharge(tStack, Math.abs(tStats[0])); + this.isItemStackUsable(tStack); + aList.add(tStack); + } + if ((tStats == null) || (tStats[3] != -2)) { + final ItemStack tStack = new ItemStack(this, 1, this.mOffset + i); + this.isItemStackUsable(tStack); + aList.add(tStack); + } + } + } + } + + @Override + @SideOnly(Side.CLIENT) + public final void registerIcons(final IIconRegister aIconRegister) { + for (short i = 0, j = (short) this.mEnabledItems.length(); i < j; i++) { + if (this.mEnabledItems.get(i)) { + mIconMap.put( + (int) i, + aIconRegister.registerIcon(GTPlusPlus.ID + ":" + (this.getUnlocalizedName() + "/" + i))); + } + } + } + + @Override + public final IIcon getIconFromDamage(final int aMetaData) { + if (aMetaData < 0) { + return null; + } + if (aMetaData < this.mOffset) { + return mIconMap.get(0); + } else { + int newMeta = aMetaData - this.mOffset; + newMeta = (Math.max(0, Math.min(3, newMeta))); + return mIconMap.get(newMeta); + } + } + + /** + * Sets the unlocalized name of this item to the string passed as the parameter" + */ + @Override + public Item setUnlocalizedName(final String p_77655_1_) { + this.unlocalizedName = p_77655_1_; + super.setUnlocalizedName(p_77655_1_); + return this; + } + + /** + * Returns the unlocalized name of this item. + */ + @Override + public String getUnlocalizedName() { + return this.unlocalizedName; + } + + public final Long[] getElectricStats(final ItemStack aStack) { + return this.mElectricStats.get((short) aStack.getItemDamage()); + } + + @Override + public int getItemEnchantability() { + return 0; + } + + @Override + public boolean isBookEnchantable(final ItemStack aStack, final ItemStack aBook) { + return false; + } + + @Override + public boolean getIsRepairable(final ItemStack aStack, final ItemStack aMaterial) { + return false; + } + + /** + * Adds a special Item Behaviour to the Item. + * <p/> + * Note: the boolean Behaviours sometimes won't be executed if another boolean Behaviour returned true before. + * + * @param aMetaValue the Meta Value of the Item you want to add it to. [0 - 32765] + * @param aBehavior the Click Behavior you want to add. + * @return the Item itself for convenience in constructing. + */ + public final GregtechPump addItemBehavior(final int aMetaValue, final IItemBehaviour<GregtechPump> aBehavior) { + if ((aMetaValue < 0) || (aMetaValue >= 32766) || (aBehavior == null)) { + return this; + } + ArrayList<IItemBehaviour<GregtechPump>> tList = this.mItemBehaviors.get((short) aMetaValue); + if (tList == null) { + tList = new ArrayList<>(1); + this.mItemBehaviors.put((short) aMetaValue, tList); + } + tList.add(aBehavior); + return this; + } + + /** + * This adds a Custom Item to the ending Range. + * + * @param aID The Id of the assigned Item [0 - mItemAmount] (The MetaData gets auto-shifted by +mOffset) + * @param aEnglish The Default Localized Name of the created Item + * @param aToolTip The Default ToolTip of the created Item, you can also insert null for having no ToolTip + * @param aFoodBehavior The Food Value of this Item. Can be null aswell. Just a convenience thing. + * @param aRandomData The OreDict Names you want to give the Item. Also used for TC Aspects and some other things. + * @return An ItemStack containing the newly created Item. + */ + @SuppressWarnings("unchecked") + public final ItemStack addItem(final int aID, final String aEnglish, String aToolTip, final Object... aRandomData) { + if (aToolTip == null) { + aToolTip = ""; + } + if ((aID >= 0) && (aID < this.mItemAmount)) { + final ItemStack rStack = new ItemStack(this, 1, this.mOffset + aID); + GT_ModHandler.registerBoxableItemToToolBox(rStack); + this.mEnabledItems.set(aID); + this.mVisibleItems.set(aID); + GT_LanguageManager + .addStringLocalization("gtplusplus." + this.getUnlocalizedName(rStack) + "." + aID + ".name", aEnglish); + GT_LanguageManager.addStringLocalization( + "gtplusplus." + this.getUnlocalizedName(rStack) + "." + aID + ".tooltip", + aToolTip); + final List<TC_AspectStack> tAspects = new ArrayList<>(); + // Important Stuff to do first + for (final Object tRandomData : aRandomData) { + if (tRandomData instanceof SubTag) { + if (tRandomData == SubTag.INVISIBLE) { + this.mVisibleItems.set(aID, false); + continue; + } + if (tRandomData == SubTag.NO_UNIFICATION) { + GT_OreDictUnificator.addToBlacklist(rStack); + continue; + } + } + } + // now check for the rest + for (final Object tRandomData : aRandomData) { + if (tRandomData != null) { + boolean tUseOreDict = true; + if (tRandomData instanceof IItemBehaviour) { + this.addItemBehavior(this.mOffset + aID, (IItemBehaviour<GregtechPump>) tRandomData); + tUseOreDict = false; + } + if (tRandomData instanceof IItemContainer) { + ((IItemContainer) tRandomData).set(rStack); + tUseOreDict = false; + } + if (tRandomData instanceof SubTag) { + continue; + } + if (tRandomData instanceof TC_AspectStack) { + ((TC_AspectStack) tRandomData).addToAspectList(tAspects); + continue; + } + if (tRandomData instanceof ItemData) { + if (GT_Utility.isStringValid(tRandomData)) { + GT_OreDictUnificator.registerOre(tRandomData, rStack); + } else { + GT_OreDictUnificator.addItemData(rStack, (ItemData) tRandomData); + } + continue; + } + if (tUseOreDict) { + GT_OreDictUnificator.registerOre(tRandomData, rStack); + continue; + } + } + } + if (GregTech_API.sThaumcraftCompat != null) { + GregTech_API.sThaumcraftCompat.registerThaumcraftAspectsToItem(rStack, tAspects, false); + } + return rStack; + } + return null; + } + + @Override + public String getItemStackDisplayName(final ItemStack aStack) { + int keyValue = (getCorrectMetaForItemstack(aStack)); + if (keyValue < 0 || keyValue > 3) { + keyValue = 0; + } + return GT_LanguageManager + .getTranslation("gtplusplus." + this.getUnlocalizedName(aStack) + "." + keyValue + ".name"); + } + + /** + * Fluid Handling + */ + + /* + * IFluidContainer Functions + */ + + public void emptyStoredFluid(ItemStack aStack) { + if (aStack.hasTagCompound()) { + NBTTagCompound t = aStack.getTagCompound(); + if (t.hasKey("mInit")) { + t.removeTag("mInit"); + } + if (t.hasKey("mFluid")) { + t.removeTag("mFluid"); + } + if (t.hasKey("mFluidAmount")) { + t.removeTag("mFluidAmount"); + } + } + } + + public void storeFluid(ItemStack aStack, FluidStack aFluid) { + if (aFluid == null) { + return; + } else { + String fluidname = aFluid.getFluid() + .getName(); + int amount = aFluid.amount; + if (fluidname != null && fluidname.length() > 0 && amount > 0) { + NBTUtils.setString(aStack, "mFluid", fluidname); + NBTUtils.setInteger(aStack, "mFluidAmount", amount); + } + } + } + + @Override + public FluidStack getFluid(ItemStack container) { + if (!container.hasTagCompound() || !container.getTagCompound() + .hasKey("mInit")) { + initNBT(container); + } + if (container.getTagCompound() + .hasKey("mInit") + && container.getTagCompound() + .getBoolean("mInit")) { + String fluidname; + Integer amount = 0; + fluidname = NBTUtils.getString(container, "mFluid"); + amount = NBTUtils.getInteger(container, "mFluidAmount"); + if (fluidname != null && amount != null && amount > 0) { + return FluidUtils.getFluidStack(fluidname, amount); + } else { + return null; + } + } + return null; + } + + @Override + public int getCapacity(ItemStack container) { + if (!container.hasTagCompound() || !container.getTagCompound() + .hasKey("mInit")) { + initNBT(container); + } + if (container.getTagCompound() + .hasKey("mInit") + && container.getTagCompound() + .getBoolean("mInit")) { + return container.getTagCompound() + .getInteger("mCapacity"); + } + int aMeta = this.getCorrectMetaForItemstack(container); + int aCapacity = (aMeta == 0 ? 2000 : (aMeta == 1 ? 8000 : (aMeta == 2 ? 32000 : 128000))); + return aCapacity; + } + + public int fill(ItemStack container, FluidStack resource) { + return fill(container, resource, true); + } + + @Override + public int fill(ItemStack container, FluidStack resource, boolean doFill) { + if (!doFill || resource == null) { + return 0; + } + + if (!container.hasTagCompound() || !container.getTagCompound() + .hasKey("mInit")) { + initNBT(container); + } + if (container.getTagCompound() + .hasKey("mInit") + && container.getTagCompound() + .getBoolean("mInit")) { + String aStored; + int aStoredAmount = 0; + int aCapacity = getCapacity(container); + FluidStack aStoredFluid = getFluid(container); + if (aStoredFluid != null) { + aStored = aStoredFluid.getFluid() + .getName(); + aStoredAmount = aStoredFluid.amount; + if (aStoredAmount == aCapacity) { + return 0; + } + } + // Handle no stored fluid first + if (aStoredFluid == null) { + Logger.INFO("Pump is empty, filling with tank fluids."); + FluidStack toConsume; + int amountToConsume = 0; + if (resource.amount >= aCapacity) { + amountToConsume = aCapacity; + } else { + amountToConsume = resource.amount; + } + toConsume = FluidUtils.getFluidStack(resource, amountToConsume); + if (toConsume != null && amountToConsume > 0) { + storeFluid(container, toConsume); + return amountToConsume; + } + } else { + Logger.INFO("Pump is Partially full, filling with tank fluids."); + if (aStoredFluid.isFluidEqual(resource)) { + Logger.INFO("Found matching fluids."); + int aSpaceLeft = (aCapacity - aStoredAmount); + Logger.INFO( + "Capacity: " + aCapacity + " | Stored: " + aStoredAmount + " | Space left: " + aSpaceLeft); + FluidStack toConsume; + int amountToConsume = 0; + if (resource.amount >= aSpaceLeft) { + amountToConsume = aSpaceLeft; + Logger.INFO("More or equal fluid amount to pump container space."); + } else { + amountToConsume = resource.amount; + Logger.INFO("Less fluid than container space"); + } + Logger.INFO("Amount to consume: " + amountToConsume); + toConsume = FluidUtils.getFluidStack(resource, (aStoredAmount + amountToConsume)); + if (toConsume != null && amountToConsume > 0) { + Logger.INFO("Storing Fluid"); + storeFluid(container, toConsume); + return amountToConsume; + } else { + Logger.INFO("Not storing fluid"); + } + } else { + Logger.INFO("Fluids did not match."); + } + } + } + return 0; + } + + public FluidStack drain(ItemStack container, int drainAmt) { + return drain(container, drainAmt, true); + } + + @Override + public FluidStack drain(ItemStack container, int maxDrain, boolean doDrain) { + if (!doDrain || maxDrain == 0) { + return null; + } + if (!container.hasTagCompound() || !container.getTagCompound() + .hasKey("mInit")) { + initNBT(container); + } + if (container.getTagCompound() + .hasKey("mInit") + && container.getTagCompound() + .getBoolean("mInit")) { + + String aStored; + int aStoredAmount = 0; + FluidStack aStoredFluid = getFluid(container); + + if (aStoredFluid != null) { + aStored = aStoredFluid.getFluid() + .getName(); + aStoredAmount = aStoredFluid.amount; + } + // We cannot drain this if it's empty. + else if (aStoredFluid == null) { + return null; + } + + if (maxDrain >= aStoredAmount) { + emptyStoredFluid(container); + return aStoredFluid; + } else { + // Handle Partial removal + int amountRemaining = (aStoredAmount - maxDrain); + if (amountRemaining == 0) { + emptyStoredFluid(container); + } else { + FluidStack newAmount = FluidUtils.getFluidStack(aStoredFluid, amountRemaining); + FluidStack drained = FluidUtils.getFluidStack(aStoredFluid, maxDrain); + if (newAmount != null && drained != null) { + storeFluid(container, newAmount); + return drained; + } + } + } + } + return null; + } + + /* + * Handle ItemStack NBT + */ + + public void initNBT(ItemStack aStack) { + NBTTagCompound aNewNBT; + if (!aStack.hasTagCompound()) { + aNewNBT = new NBTTagCompound(); + } else { + aNewNBT = aStack.getTagCompound(); + } + + if (!aNewNBT.hasKey("mInit")) { + int aMeta = this.getCorrectMetaForItemstack(aStack); + aNewNBT.setInteger("mMeta", aMeta); + aNewNBT.setBoolean("mInit", true); + aNewNBT.setString("mFluid", "@@@@@"); + aNewNBT.setInteger("mFluidAmount", 0); + int aCapacity = (aMeta == 0 ? 2000 : (aMeta == 1 ? 8000 : (aMeta == 2 ? 32000 : 128000))); + aNewNBT.setInteger("mCapacity", aCapacity); + aStack.setTagCompound(aNewNBT); + } + } + + /** + * Tile Handling + */ + + /* + * Custom Fluid Handling for Tiles and GT Tiles. + */ + + public boolean tryDrainTile(ItemStack aStack, World aWorld, EntityPlayer aPlayer, int aX, int aY, int aZ) { + try { + if (aWorld.isRemote || aStack == null) { + return false; + } else { + int aTier = (aStack.getItemDamage() - 1000); + int removal; + if (aTier == 0) { + removal = 0; + } else if (aTier == 1) { + removal = 32; + } else if (aTier == 2) { + removal = 128; + } else if (aTier == 3) { + removal = 512; + } else { + removal = 8; + } + if (!canUse(aStack, removal) && aTier > 0) { + PlayerUtils.messagePlayer(aPlayer, "Not enough power."); + Logger.INFO("No Power"); + return false; + } + + final Block aBlock = aWorld.getBlock(aX, aY, aZ); + if (aBlock == null) { + return false; + } + TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ); + if (tTileEntity == null) { + return false; + } else { + double aCharge = this.getCharge(aStack); + boolean didDrain = false; + if (aTier > 0 && aCharge > 0) { + if (discharge(aStack, removal, aTier, true, true, false) > 0) { + didDrain = true; + } + } else if (aTier == 0) { + didDrain = true; + } else { + didDrain = false; + } + + if (didDrain) { + if ((tTileEntity instanceof IGregTechTileEntity)) { + return this.drainTankGT(tTileEntity, aStack, aWorld, aPlayer, aX, aY, aZ); + } + // Try support Standard Fluid Tanks too (May disable if dupes appear again) + else if ((tTileEntity instanceof IFluidTank || tTileEntity instanceof IFluidHandler)) { + // return this.drainIFluidTank(tTileEntity, aStack, aWorld, aPlayer, aX, aY, aZ); + return false; + } + } + } + } + } catch (Throwable t) {} + return false; + } + + /* + * Vanilla IFluidTank + */ + + public boolean drainIFluidTank(TileEntity tTileEntity, ItemStack aStack, World aWorld, EntityPlayer aPlayer, int aX, + int aY, int aZ) { + if (tTileEntity == null) { + Logger.INFO("Invalid Tile, somehow."); + return false; + } + if ((tTileEntity instanceof IFluidTank || tTileEntity instanceof IFluidHandler)) { + if (this.getFluid(aStack) == null + || (this.getFluid(aStack) != null && this.getFluid(aStack).amount < this.getCapacity(aStack))) { + Logger.INFO("Trying to find Stored Fluid - Behaviour Class."); + FluidStack aStored = getStoredFluidOfVanillaTank(tTileEntity); + if (aStored != null) { + int mAmountInserted = fill(aStack, aStored); + FluidStack newStackRemainingInTank; + if (mAmountInserted > 0) { + if (mAmountInserted == aStored.amount) { + newStackRemainingInTank = null; + } else { + newStackRemainingInTank = FluidUtils + .getFluidStack(aStored, (aStored.amount - mAmountInserted)); + } + boolean b = setStoredFluidOfVanillaTank(tTileEntity, newStackRemainingInTank); + Logger.INFO("Cleared Tank? " + b + " | mAmountInserted: " + mAmountInserted); + Logger.INFO("Returning " + b + " - drainTankVanilla."); + if (b) { + PlayerUtils.messagePlayer( + aPlayer, + "Drained " + mAmountInserted + "L of " + aStored.getLocalizedName() + "."); + } + return b; + } + } else { + Logger.INFO("Found no valid Fluidstack - drainTankVanilla."); + } + } else { + Logger.INFO("Pump is full."); + } + } + Logger.INFO("Could not drain vanilla tank."); + return false; + } + + /* + * GT Tanks + */ + + public boolean drainTankGT(TileEntity tTileEntity, ItemStack aStack, World aWorld, EntityPlayer aPlayer, int aX, + int aY, int aZ) { + if (tTileEntity == null) { + return false; + } + if ((tTileEntity instanceof IGregTechTileEntity)) { + Logger.INFO("Right Clicking on GT Tile - drainTankGT."); + if (((IGregTechTileEntity) tTileEntity).getTimer() < 50L) { + Logger.INFO("Returning False - Behaviour Class. Timer < 50"); + return false; + } else if ((!aWorld.isRemote) && (!((IGregTechTileEntity) tTileEntity).isUseableByPlayer(aPlayer))) { + Logger.INFO("Returning True - drainTankGT. NotUsable()"); + return true; + } else { + if (this.getFluid(aStack) == null + || (this.getFluid(aStack) != null && this.getFluid(aStack).amount < this.getCapacity(aStack))) { + Logger.INFO("Trying to find Stored Fluid - drainTankGT."); + FluidStack aStored = getStoredFluidOfGTMachine((IGregTechTileEntity) tTileEntity); + if (aStored != null) { + int mAmountInserted = fill(aStack, aStored); + FluidStack newStackRemainingInTank; + if (mAmountInserted > 0) { + if (mAmountInserted == aStored.amount) { + newStackRemainingInTank = null; + } else { + newStackRemainingInTank = FluidUtils + .getFluidStack(aStored, (aStored.amount - mAmountInserted)); + } + boolean b = setStoredFluidOfGTMachine( + (IGregTechTileEntity) tTileEntity, + newStackRemainingInTank); + Logger.INFO("Cleared Tank? " + b + " | mAmountInserted: " + mAmountInserted); + Logger.INFO("Returning " + b + " - drainTankGT."); + if (b) { + PlayerUtils.messagePlayer( + aPlayer, + "Drained " + mAmountInserted + "L of " + aStored.getLocalizedName() + "."); + } else { + drain(aStack, mAmountInserted); + } + return b; + } + } else { + Logger.INFO("Found no valid Fluidstack - drainTankGT."); + } + } else { + Logger.INFO("Pump is full."); + } + } + } + Logger.INFO("Could not drain GT tank."); + return false; + } + + /* + * Vanilla Tanks + */ + + public FluidStack getStoredFluidOfVanillaTank(TileEntity aTileEntity) { + if (aTileEntity == null) { + return null; + } else if ((aTileEntity instanceof IFluidTank || aTileEntity instanceof IFluidHandler)) { + if (aTileEntity instanceof IFluidTank) { + return getStoredFluidOfVanillaTank((IFluidTank) aTileEntity); + } else { + return getStoredFluidOfVanillaTank((IFluidHandler) aTileEntity); + } + } else { + return null; + } + } + + public FluidStack getStoredFluidOfVanillaTank(IFluidTank aTileEntity) { + FluidStack f = aTileEntity.getFluid(); + Logger.INFO( + "Returning Fluid stack from tile. Found: " + + (f != null ? f.getLocalizedName() + " - " + f.amount + "L" : "Nothing")); + return f; + } + + public FluidStack getStoredFluidOfVanillaTank(IFluidHandler aTileEntity) { + if (aTileEntity instanceof IFluidTank) { + return getStoredFluidOfVanillaTank((IFluidTank) aTileEntity); + } + FluidStack f; + AutoMap<FluidTankInfo[]> m = new AutoMap<>(); + for (int i = 0; i < 6; i++) { + m.put(aTileEntity.getTankInfo(ForgeDirection.getOrientation(i))); + } + if (m.get(0) != null && m.get(0)[0] != null && m.get(0)[0].fluid != null) { + return m.get(0)[0].fluid; + } else { + return null; + } + } + + public boolean setStoredFluidOfVanillaTank(TileEntity aTileEntity, FluidStack aSetFluid) { + Logger.INFO("Trying to clear Tile's tank. - Behaviour Class. [1]"); + + if (aTileEntity == null) { + return false; + } else if ((aTileEntity instanceof IFluidTank || aTileEntity instanceof IFluidHandler)) { + if (aTileEntity instanceof IFluidTank) { + Logger.INFO("Tile Was instanceof IFluidTank."); + FluidStack f = ((IFluidTank) aTileEntity).getFluid(); + if (aSetFluid == null) { + aSetFluid = f; + aSetFluid.amount = f.amount; + } + int toDrain = (f.amount - aSetFluid.amount); + FluidStack newStack; + if (toDrain <= 0) { + newStack = f; + } else { + newStack = ((IFluidTank) aTileEntity).drain(toDrain, true); + } + + if (newStack.isFluidEqual(aSetFluid) && newStack.amount == aSetFluid.amount) { + Logger.INFO("Removed fluid from vanilla IFluidTank successfully."); + return true; + } else { + Logger.INFO("Failed trying to remove fluid from vanilla IFluidTank."); + return false; + } + } else { + + // Rewrite Fluid handling for Vanilla type tanks + if (!IFluidHandler.class.isInstance(aTileEntity)) { + Logger.INFO("Tile Was not an instance of IFluidHandler."); + return false; + } + + IFluidHandler aTank = (IFluidHandler) aTileEntity; + FluidStack aTankContents = null; + FluidTankInfo[] a1 = aTank.getTankInfo(ForgeDirection.UNKNOWN); + if (a1 != null) { + if (a1[0] != null) { + aTankContents = a1[0].fluid; + Logger.INFO( + "Found Fluid in Tank. " + aTankContents.getLocalizedName() + " - " + aTankContents.amount); + } + } + if (aSetFluid == null) { + Logger.INFO("Setting fluid to tank contents, as we're going to empty it totally."); + aSetFluid = aTankContents.copy(); + } else { + Logger.INFO("Setting fluid to tank contents, as we're going to empty it totally."); + } + Logger.INFO( + "Tile Was instance of IFluidHandler. Trying to Drain " + aSetFluid.getLocalizedName() + + " - " + + aSetFluid.amount); + + if (a1 == null || aTankContents == null) { + Logger.INFO("Tank is empty."); + return false; + } + // Found some Fluid in the tank + else { + FluidStack aDrainedStack = aTank.drain(ForgeDirection.UNKNOWN, aSetFluid, true); + if (aDrainedStack.isFluidStackIdentical(aSetFluid)) { + Logger.INFO("Drained!"); + return true; + } else { + Logger.INFO("Partially Drained! This is probably an error."); + return true; + } + } + } + } else { + Logger.INFO("Bad Tank Tile to drain."); + return false; + } + } + + /* + * GT Tanks + */ + + public FluidStack getStoredFluidOfGTMachine(IGregTechTileEntity aTileEntity) { + if (aTileEntity == null) { + return null; + } + final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity();; + if (aMetaTileEntity == null || aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_MultiInput) { + // blacklist multiinput hatch as it's too complex + return null; + } + if (aMetaTileEntity instanceof GT_MetaTileEntity_BasicTank) { + Logger.INFO("Tile Was Instanceof BasicTank."); + return getStoredFluidOfGTMachine((GT_MetaTileEntity_BasicTank) aMetaTileEntity); + } else { + return null; + } + } + + public FluidStack getStoredFluidOfGTMachine(GT_MetaTileEntity_BasicTank aTileEntity) { + FluidStack f = aTileEntity.mFluid; + + // Let's see if this machine has output fluid too + /* + * if (f == null) { Logger.INFO("Could not find any input fluid, checking output if possible."); if (aTileEntity + * instanceof GT_MetaTileEntity_BasicMachine) { GT_MetaTileEntity_BasicMachine g = + * (GT_MetaTileEntity_BasicMachine) aTileEntity; + * Logger.INFO("Tile is a Basic Machine of some sort - "+g.mNEIName); if (g != null) { f = g.mOutputFluid; if (f + * != null) { Logger.INFO("Found output fluid! "+f.getLocalizedName()); } else { + * Logger.INFO("Did not find anything!"); f = g.getFluid(); if (f != null) { + * Logger.INFO("Found fluid! "+f.getLocalizedName()); } else { Logger.INFO("Did not find anything!"); f = + * g.getFluid(); } } } } } + */ + + Logger.INFO( + "Returning Fluid stack from tile. Found: " + + (f != null ? f.getLocalizedName() + " - " + f.amount + "L" : "Nothing")); + return f; + } + + public boolean setStoredFluidOfGTMachine(IGregTechTileEntity aTileEntity, FluidStack aSetFluid) { + Logger.INFO("Trying to clear Tile's tank. - Behaviour Class. [1]"); + if (aTileEntity == null) { + return false; + } + final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) { + return false; + } + if (aMetaTileEntity instanceof GT_MetaTileEntity_BasicTank) { + Logger.INFO("Trying to clear Tile's tank. - Behaviour Class. [2]"); + return setStoredFluidOfGTMachine((GT_MetaTileEntity_BasicTank) aMetaTileEntity, aSetFluid); + } else { + return false; + } + } + + public boolean setStoredFluidOfGTMachine(GT_MetaTileEntity_BasicTank aTileEntity, FluidStack aSetFluid) { + try { + + // Try Handle Outputs First + /* + * if (aTileEntity.setDrainableStack(aSetFluid) != null) { return true; } + */ + + aTileEntity.mFluid = aSetFluid; + boolean b = aTileEntity.mFluid == aSetFluid; + Logger.INFO("Trying to set Tile's tank. - Behaviour Class. [3] " + b); + return b; + } catch (Throwable t) { + Logger.INFO("Trying to clear Tile's tank. FAILED - Behaviour Class. [x]"); + return false; + } + } + + public int getCorrectMetaForItemstack(ItemStack aStack) { + if (aStack == null) { + return 0; + } else { + if (aStack.getItemDamage() < this.mOffset) { + return 0; + } else { + int newMeta = aStack.getItemDamage() - this.mOffset; + newMeta = (Math.max(0, Math.min(3, newMeta))); + return newMeta; + } + } + } +} diff --git a/src/main/java/gtPlusPlus/core/item/wearable/WearableLoader.java b/src/main/java/gtPlusPlus/core/item/wearable/WearableLoader.java new file mode 100644 index 0000000000..8044b4364f --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/wearable/WearableLoader.java @@ -0,0 +1,14 @@ +package gtPlusPlus.core.item.wearable; + +import gtPlusPlus.core.item.wearable.armour.ArmourLoader; + +public class WearableLoader { + + public static void run() { + execute(); + } + + private static void execute() { + ArmourLoader.run(); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/wearable/armour/ArmourLoader.java b/src/main/java/gtPlusPlus/core/item/wearable/armour/ArmourLoader.java new file mode 100644 index 0000000000..e929d6cb7f --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/wearable/armour/ArmourLoader.java @@ -0,0 +1,38 @@ +package gtPlusPlus.core.item.wearable.armour; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemArmor.ArmorMaterial; +import net.minecraftforge.common.util.EnumHelper; + +import cpw.mods.fml.common.registry.GameRegistry; +import gtPlusPlus.core.item.wearable.armour.tinfoil.ArmourTinFoilHat; + +public class ArmourLoader { + + // Glass + public static Item ClearGlassChestplate; + public static Item ClearGlassBoots; + public static Item ClearGlassLeggings; + public static Item ClearGlassHelmet; + + // Tin Foil + public static Item TinFoilHat; + + public static ArmorMaterial ClearGlassArmour = EnumHelper + .addArmorMaterial("ClearGlassArmor", 1, new int[] { 1, 1, 1, 1 }, 100); + public static ArmorMaterial TinFoilArmour = EnumHelper.addArmorMaterial("TINFOIL", 5, new int[] { 1, 1, 1, 1 }, 50); + + public static void run() { + glassArmour(); + tinfoilArmour(); + } + + private static void glassArmour() {} + + private static void tinfoilArmour() { + TinFoilHat = new ArmourTinFoilHat().setUnlocalizedName("itemHatTinFoil"); + GameRegistry.registerItem(TinFoilHat, "itemHatTinFoil", GTPlusPlus.ID); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/wearable/armour/base/BaseArmour.java b/src/main/java/gtPlusPlus/core/item/wearable/armour/base/BaseArmour.java new file mode 100644 index 0000000000..e7ce975eca --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/wearable/armour/base/BaseArmour.java @@ -0,0 +1,10 @@ +package gtPlusPlus.core.item.wearable.armour.base; + +import gtPlusPlus.core.item.wearable.base.BaseItemWearable; + +public abstract class BaseArmour extends BaseItemWearable { + + public BaseArmour(ArmorMaterial material, int renderIndex, int armourType) { + super(material, renderIndex, armourType); + } +} diff --git a/src/main/java/gtPlusPlus/core/item/wearable/armour/base/BaseArmourHelm.java b/src/main/java/gtPlusPlus/core/item/wearable/armour/base/BaseArmourHelm.java new file mode 100644 index 0000000000..d121a90ade --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/wearable/armour/base/BaseArmourHelm.java @@ -0,0 +1,9 @@ +package gtPlusPlus.core.item.wearable.armour.base; + +public abstract class BaseArmourHelm extends BaseArmour { + + public BaseArmourHelm(ArmorMaterial material, int renderIndex) { + super(material, renderIndex, 0); + // TODO Auto-generated constructor stub + } +} diff --git a/src/main/java/gtPlusPlus/core/item/wearable/armour/tinfoil/ArmourTinFoilHat.java b/src/main/java/gtPlusPlus/core/item/wearable/armour/tinfoil/ArmourTinFoilHat.java new file mode 100644 index 0000000000..0703ac3b93 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/wearable/armour/tinfoil/ArmourTinFoilHat.java @@ -0,0 +1,179 @@ +package gtPlusPlus.core.item.wearable.armour.tinfoil; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.List; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.item.EntityBoat; +import net.minecraft.entity.item.EntityEnderEye; +import net.minecraft.entity.item.EntityEnderPearl; +import net.minecraft.entity.item.EntityExpBottle; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.item.EntityXPOrb; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.projectile.EntityEgg; +import net.minecraft.entity.projectile.EntityFireball; +import net.minecraft.entity.projectile.EntitySnowball; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.ItemStack; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.DamageSource; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.item.wearable.armour.ArmourLoader; +import gtPlusPlus.core.item.wearable.armour.base.BaseArmourHelm; + +public class ArmourTinFoilHat extends BaseArmourHelm { + + public IIcon iconHelm; + + public ArmourTinFoilHat() { + super(ArmourLoader.TinFoilArmour, 0); + } + + @Override + @SideOnly(Side.CLIENT) + public void registerIcons(IIconRegister ir) { + this.iconHelm = ir.registerIcon(GTPlusPlus.ID + ":itemHatTinFoil"); + } + + @Override + public int getRenderIndex() { + return 0; + } + + @Override + @SideOnly(Side.CLIENT) + public IIcon getIconFromDamage(int par1) { + return this.iconHelm; + } + + @Override + public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type) { + return GTPlusPlus.ID + ":textures/models/TinFoil.png"; + } + + @Override + public EnumRarity getRarity(ItemStack itemstack) { + return EnumRarity.uncommon; + } + + @Override + public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack) { + return false; + } + + @Override + public int getArmorDisplay(EntityPlayer player, ItemStack armor, int slot) { + return super.getArmorDisplay(player, armor, slot); + } + + @Override + public void damageArmor(EntityLivingBase entity, ItemStack stack, DamageSource source, int damage, int slot) {} + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public void addInformation(ItemStack p_77624_1_, EntityPlayer p_77624_2_, List aList, boolean p_77624_4_) { + aList.add("DoomSquirter's protection against cosmic radiation!"); + aList.add("General paranoia makes the wearer unable to collect xp"); + aList.add("Movement speed is also reduced, to keep you safe"); + aList.add("This hat may also have other strange powers"); + } + + @Override + public ArmorProperties getProperties(EntityLivingBase player, ItemStack armor, DamageSource source, double damage, + int slot) { + return new ArmorProperties(0, 0, 0); + } + + @Override + public boolean isDamageable() { + return false; + } + + @Override + public boolean itemInteractionForEntity(ItemStack p_111207_1_, EntityPlayer p_111207_2_, + EntityLivingBase p_111207_3_) { + return super.itemInteractionForEntity(p_111207_1_, p_111207_2_, p_111207_3_); + } + + @Override + public void onUpdate(ItemStack aStack, World aWorld, Entity aEntity, int p_77663_4_, boolean p_77663_5_) { + super.onUpdate(aStack, aWorld, aEntity, p_77663_4_, p_77663_5_); + } + + @Override + public boolean onEntityItemUpdate(EntityItem entityItem) { + return super.onEntityItemUpdate(entityItem); + } + + @Override + public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) { + if (itemStack != null && player != null && world != null && !world.isRemote) { + if (player instanceof EntityPlayer) { + + // Apply Slow + if (!GT_Utility.getPotion(player, Potion.moveSlowdown.id)) { + player.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 2, 1, true)); + } + + // Move Xp orbs away + try { + AxisAlignedBB box = player.boundingBox; + box.maxX = player.posX + 5; + box.maxY = player.posY + 5; + box.maxZ = player.posZ + 5; + box.minX = player.posX - 5; + box.minY = player.posY - 5; + box.minZ = player.posZ - 5; + @SuppressWarnings("unchecked") + List<Entity> g = world.getEntitiesWithinAABBExcludingEntity(player, box); + if (g.size() > 0) { + for (Entity e : g) { + if (e != null) { + if (!EntityXPOrb.class.isInstance(e) && !EntityBoat.class.isInstance(e) + && !EntitySnowball.class.isInstance(e) + && !EntityFireball.class.isInstance(e) + && !EntityEgg.class.isInstance(e) + && !EntityExpBottle.class.isInstance(e) + && !EntityEnderEye.class.isInstance(e) + && !EntityEnderPearl.class.isInstance(e)) { + continue; + } else { + // Logger.INFO("Found "+e.getClass().getName()); + double distX = player.posX - e.posX; + double distZ = player.posZ - e.posZ; + double distY = e.posY + 1.5D - player.posY; + double dir = Math.atan2(distZ, distX); + double speed = 1F / e.getDistanceToEntity(player) * 0.5; + speed = -speed; + if (distY < 0) { + e.motionY += speed; + } + e.motionX = Math.cos(dir) * speed; + e.motionZ = Math.sin(dir) * speed; + } + } + } + } + } catch (Throwable t) {} + } + } + + super.onArmorTick(world, player, itemStack); + } + + @Override + public boolean showDurabilityBar(ItemStack stack) { + return false; + } +} diff --git a/src/main/java/gtPlusPlus/core/item/wearable/base/BaseItemWearable.java b/src/main/java/gtPlusPlus/core/item/wearable/base/BaseItemWearable.java new file mode 100644 index 0000000000..84b1d2ff51 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/wearable/base/BaseItemWearable.java @@ -0,0 +1,61 @@ +package gtPlusPlus.core.item.wearable.base; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemArmor; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.DamageSource; +import net.minecraftforge.common.ISpecialArmor; + +public abstract class BaseItemWearable extends ItemArmor implements ISpecialArmor { + + public BaseItemWearable(ArmorMaterial material, int renderIndex, int armourType) { + super(material, renderIndex, armourType); + } + + public abstract int getRenderIndex(); + + @Override + public abstract ArmorProperties getProperties(EntityLivingBase player, ItemStack armor, DamageSource source, + double damage, int slot); + + @Override + public int getArmorDisplay(EntityPlayer player, ItemStack armor, int slot) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public abstract void damageArmor(EntityLivingBase entity, ItemStack stack, DamageSource source, int damage, + int slot); + + public void dyeArmour(ItemStack aArmour, int aColour) { + func_82813_b(aArmour, aColour); + } + + @Override + public void func_82813_b(ItemStack p_82813_1_, int p_82813_2_) { + NBTTagCompound nbttagcompound = p_82813_1_.getTagCompound(); + if (nbttagcompound == null) { + nbttagcompound = new NBTTagCompound(); + p_82813_1_.setTagCompound(nbttagcompound); + } + NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("display"); + if (!nbttagcompound.hasKey("display", 10)) { + nbttagcompound.setTag("display", nbttagcompound1); + } + nbttagcompound1.setInteger("color", p_82813_2_); + } + + @Override + public void removeColor(ItemStack p_82815_1_) { + NBTTagCompound nbttagcompound = p_82815_1_.getTagCompound(); + if (nbttagcompound != null) { + NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("display"); + if (nbttagcompound1.hasKey("color")) { + nbttagcompound1.removeTag("color"); + } + } + } +} diff --git a/src/main/java/gtPlusPlus/core/item/wearable/hazmat/ItemArmorHazmatEx.java b/src/main/java/gtPlusPlus/core/item/wearable/hazmat/ItemArmorHazmatEx.java new file mode 100644 index 0000000000..e01c89d827 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/item/wearable/hazmat/ItemArmorHazmatEx.java @@ -0,0 +1,35 @@ +package gtPlusPlus.core.item.wearable.hazmat; + +import net.minecraft.entity.Entity; +import net.minecraft.item.ItemStack; + +import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; +import gtPlusPlus.xmod.ic2.CustomInternalName; +import ic2.core.IC2; +import ic2.core.init.InternalName; +import ic2.core.item.armor.ItemArmorHazmat; + +public class ItemArmorHazmatEx extends ItemArmorHazmat { + + public static void init() { + GregtechItemList.Armour_Hazmat_Advanced_Helmet + .set(new ItemStack(new ItemArmorHazmatEx(CustomInternalName.aHazmatHelmetEx, 0))); + GregtechItemList.Armour_Hazmat_Advanced_Chest + .set(new ItemStack(new ItemArmorHazmatEx(CustomInternalName.aHazmatChestEx, 1))); + GregtechItemList.Armour_Hazmat_Advanced_Legs + .set(new ItemStack(new ItemArmorHazmatEx(CustomInternalName.aHazmatLegsEx, 2))); + GregtechItemList.Armour_Hazmat_Advanced_Boots + .set(new ItemStack(new ItemArmorHazmatEx(CustomInternalName.aHazmatBootsEx, 3))); + } + + private ItemArmorHazmatEx(InternalName internalName, int type) { + super(internalName, type); + this.setMaxDamage(256); + } + + @Override + public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type) { + int suffix = this.armorType == 2 ? 2 : 1; + return IC2.textureDomain + ":textures/armor/" + "hazmatEx_" + suffix + ".png"; + } +} |