diff options
Diffstat (limited to 'src/main/java/gtPlusPlus/xmod/gregtech/api')
55 files changed, 13762 insertions, 0 deletions
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/enums/GregtechItemList.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/enums/GregtechItemList.java new file mode 100644 index 0000000000..6367d22f77 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/enums/GregtechItemList.java @@ -0,0 +1,980 @@ +package gtPlusPlus.xmod.gregtech.api.enums; + +import static gregtech.api.enums.GT_Values.W; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_OreDictUnificator; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.xmod.gregtech.api.interfaces.GregtechItemContainer; + +/** + * Class containing all non-OreDict Items of GregTech. + */ +public enum GregtechItemList implements GregtechItemContainer { + + /** + * Items + */ + + // Advanced Hazmat Suit + Armour_Hazmat_Advanced_Helmet, + Armour_Hazmat_Advanced_Chest, + Armour_Hazmat_Advanced_Legs, + Armour_Hazmat_Advanced_Boots, + + // Gregtech Machine Parts + Electric_Motor_LuV, + Electric_Motor_ZPM, + Electric_Motor_UV, + Electric_Pump_LuV, + Electric_Pump_ZPM, + Electric_Pump_UV, + Conveyor_Module_LuV, + Conveyor_Module_ZPM, + Conveyor_Module_UV, + Electric_Piston_LuV, + Electric_Piston_ZPM, + Electric_Piston_UV, + Robot_Arm_LuV, + Robot_Arm_ZPM, + Robot_Arm_UV, + Field_Generator_LuV, + Field_Generator_ZPM, + Field_Generator_UV, + Emitter_LuV, + Emitter_ZPM, + Emitter_UV, + Sensor_LuV, + Sensor_ZPM, + Sensor_UV, + + // Mixed Components + TransmissionComponent_LV, + TransmissionComponent_MV, + TransmissionComponent_HV, + TransmissionComponent_EV, + TransmissionComponent_IV, + TransmissionComponent_LuV, + TransmissionComponent_ZPM, + TransmissionComponent_UV, + TransmissionComponent_UHV, + + // Recipe Circuit + Circuit_BioRecipeSelector, + Circuit_T3RecipeSelector, + + // Circuits + Old_Circuit_Primitive, + Old_Circuit_Basic, + Old_Circuit_Good, + Old_Circuit_Advanced, + Old_Circuit_Data, + Old_Circuit_Elite, + Old_Circuit_Master, + Old_Tool_DataOrb, + Old_Circuit_Ultimate, + Old_Tool_DataStick, + Circuit_IV, + Circuit_LuV, + Circuit_ZPM, + + // Circuit Parts + Circuit_Board_IV, + Circuit_Board_LuV, + Circuit_Board_ZPM, + Circuit_Parts_Crystal_Chip_IV, + Circuit_Parts_Crystal_Chip_LuV, + Circuit_Parts_Crystal_Chip_ZPM, + Circuit_Parts_IV, + Circuit_Parts_LuV, + Circuit_Parts_ZPM, + Circuit_Parts_Wiring_IV, + Circuit_Parts_Wiring_LuV, + Circuit_Parts_Wiring_ZPM, + + // Old Style Circuits + Old_Circuit_Board_Basic, + Old_Circuit_Board_Advanced, + Old_Circuit_Board_Elite, + Old_Circuit_Parts_Crystal_Chip_Elite, + Old_Circuit_Parts_Crystal_Chip_Master, + Old_Circuit_Parts_Advanced, + Old_Circuit_Parts_Wiring_Basic, + Old_Circuit_Parts_Wiring_Advanced, + Old_Circuit_Parts_Wiring_Elite, + Old_Empty_Board_Basic, + Old_Empty_Board_Elite, + + // Batteries + Battery_RE_EV_Sodium, + Battery_RE_EV_Cadmium, + Battery_RE_EV_Lithium, + + // Shapes for Extruder + Shape_Extruder_WindmillShaft, + Shape_Extruder_SmallGear, + + // Cooked Raisin Toast for ImQ009 + Food_Baked_Raisin_Bread, + + // Fluid Cells to regulate flows. + Fluid_Cell_1L, + Fluid_Cell_16L, + Fluid_Cell_36L, + Fluid_Cell_144L, + + // Debug + TESTITEM, + + // Larger Volumetric Flasks + VOLUMETRIC_FLASK_8k, + VOLUMETRIC_FLASK_32k, + + // RTG Fuels + Pellet_RTG_PU238, + Pellet_RTG_SR90, + Pellet_RTG_PO210, + Pellet_RTG_AM241, + + // Computer Cube + Gregtech_Computer_Cube, + + // Casings for batteries + Battery_Casing_Gem_1, + Battery_Casing_Gem_2, + Battery_Casing_Gem_3, + Battery_Casing_Gem_4, + + // Custom Batteries + Battery_Gem_1, + Battery_Gem_2, + Battery_Gem_3, + Battery_Gem_4, + + // Compressed Fusion MK3 + Compressed_Fusion_Reactor, + + // Carbon Materials + + // End Game Laser Engraver Lens + Laser_Lens_WoodsGlass, + Laser_Lens_Special, + + // Pellet Mold + Pellet_Mold, + + // Upgrade chip for Distillus + Distillus_Upgrade_Chip, + Maceration_Upgrade_Chip, + + // Milling Balls + Milling_Ball_Alumina, + Milling_Ball_Soapstone, + + // ---------------------------------------------------------------------------- + + /** + * MultiBlocks + */ + + // Tier GT++ Casings + GTPP_Casing_ULV, + GTPP_Casing_LV, + GTPP_Casing_MV, + GTPP_Casing_HV, + GTPP_Casing_EV, + GTPP_Casing_IV, + GTPP_Casing_LuV, + GTPP_Casing_ZPM, + GTPP_Casing_UV, + GTPP_Casing_UHV, + + // IronBlastFurnace Machine_Bronze_BlastFurnace + Casing_IronPlatedBricks, + + // Large Centrifuge + Industrial_Centrifuge, + Casing_Centrifuge1, + + // Large Alloy Smelter + Industrial_AlloySmelter, + + // Coke Oven + Industrial_CokeOven, + Casing_CokeOven, + Casing_CokeOven_Coil1, + Casing_CokeOven_Coil2, + + // Bending Maching // Plate Press // Press + Industrial_PlatePress, + Casing_MaterialPress, + + // Matter Fab + Industrial_MassFab, + Casing_MatterGen, + Casing_MatterFab, + + // ABS + Industrial_AlloyBlastSmelter, + Casing_Coil_BlastSmelter, + Casing_BlastSmelter, + Mega_AlloyBlastSmelter, + + // Quantum Force Transformer + QuantumForceTransformer, + Casing_Coil_QuantumForceTransformer, + NeutronPulseManipulator, + CosmicFabricManipulator, + InfinityInfusedManipulator, + SpaceTimeContinuumRipper, + NeutronShieldingCore, + CosmicFabricShieldingCore, + InfinityInfusedShieldingCore, + SpaceTimeBendingCore, + ForceFieldGlass, + + // Industrial Electrolyzer + Industrial_Electrolyzer, + Casing_Electrolyzer, + + // Industrial Maceration Stack + Industrial_MacerationStack, + Casing_MacerationStack, + + // Industrial Wire Factory + Industrial_WireFactory, + Casing_WireFactory, + + // Power sub-station for mass storage. 3 hatches for input and output, whatever voltages you desire. + PowerSubStation, + Casing_Vanadium_Redox, + Casing_Vanadium_Redox_IV, + Casing_Vanadium_Redox_LuV, + Casing_Vanadium_Redox_ZPM, + Casing_Vanadium_Redox_UV, + Casing_Vanadium_Redox_MAX, + Casing_Power_SubStation, + + // LFTR + ThoriumReactor, + Casing_Reactor_I, + Casing_Reactor_II, + + // Nuclear Salt Processing Plant + Nuclear_Salt_Processing_Plant, + + // Multitank + /* Industrial_MultiTank, */ + Industrial_MultiTankDense, + Casing_MultitankExterior, + + // Fission Fuel Refinery + Industrial_FuelRefinery, + Casing_Refinery_External, + Casing_Refinery_Structural, + Casing_Refinery_Internal, + + // Industrial Sifter + Industrial_Sifter, + Casing_Sifter, + Casing_SifterGrate, + + // Large Thermal Centrifuge + Industrial_ThermalCentrifuge, + Casing_ThermalCentrifuge, + + // Cyclotron + COMET_Cyclotron, + Casing_Cyclotron_Coil, + Casing_Cyclotron_External, + + // Thermal Boiler + GT4_Thermal_Boiler, + Casing_ThermalContainment, + + // Tree Farm + Industrial_TreeFarm, + TreeFarmer_Structural, + Casing_PLACEHOLDER_TreeFarmer, + + // Fish Pond + Industrial_FishingPond, + Casing_FishPond, + + // Algae + AlgaeFarm_Controller, + + // Chemical Plant + ChemicalPlant_Controller, + + // GT4 autoCrafter + GT4_Multi_Crafter, + Casing_Autocrafter, + + // industrial Ore-Washer + Industrial_WashPlant, + Casing_WashPlant, + + // Cutting Factory Controller + Industrial_CuttingFactoryController, + Casing_CuttingFactoryFrame, + + // Large Extruder + Industrial_Extruder, + Casing_Extruder, + + // Multi-Machine + Industrial_MultiMachine, + Casing_Multi_Use, + + // Bedrock Mining Platforms + /* BedrockMiner_MKI, */ + /* BedrockMiner_MKII, */ + /* BedrockMiner_MKIII, */ + Casing_BedrockMiner, + + // Large Packager + Amazon_Warehouse_Controller, + Casing_AmazonWarehouse, + + // Advanced GT vanilla Multis + Machine_Adv_BlastFurnace, + Casing_Adv_BlastFurnace, + Machine_Adv_ImplosionCompressor, + Machine_Adv_DistillationTower, + + // Advanced Vacuum Freezer + Industrial_Cryogenic_Freezer, + Casing_AdvancedVacuum, + + // FusionTek MK IV + FusionComputer_UV2, + Casing_Fusion_External, + Casing_Fusion_Internal, + + // FusionTech MK V + + FusionComputer_UV3, + Casing_Fusion_External2, + Casing_Fusion_Internal2, + + // large mixer + Industrial_Mixer, + + // Naq Reactor + Casing_Naq_Reactor_A, + Casing_Naq_Reactor_B, + Casing_Naq_Reactor_C, + /* Controller_Naq_Reactor, */ + Casing_Containment, + + // Arc Furnace + Industrial_Arc_Furnace, + Casing_Industrial_Arc_Furnace, + + // Solar Tower + Industrial_Solar_Tower, + Casing_SolarTower_Structural, + Casing_SolarTower_SaltContainment, + Casing_SolarTower_HeatContainment, + + // Larger Turbines + Large_Steam_Turbine, + Large_HPSteam_Turbine, + Large_Gas_Turbine, + Large_Plasma_Turbine, + Large_SCSteam_Turbine, + Casing_Turbine_Shaft, + Casing_Turbine_LP, + Casing_Turbine_HP, + Casing_Turbine_Gas, + Casing_Turbine_Plasma, + Casing_Turbine_SC, + XL_HeatExchanger, + Casing_XL_HeatExchanger, + + // Large Engine + Casing_Reinforced_Engine_Casing, + + // Large Vacuum Furnace + Casing_Vacuum_Furnace, + Controller_Vacuum_Furnace, + + // Large Rocket Engine + Casing_RocketEngine, + Controller_RocketEngine, + + // Large Semi-Fluid + Controller_LargeSemifluidGenerator, + + // IsaMill + Controller_IsaMill, + Casing_IsaMill_Casing, + Casing_IsaMill_Gearbox, + Casing_IsaMill_Pipe, + + // Flotation Cell + Controller_Flotation_Cell, + Casing_Flotation_Cell, + + // Sparge Tower + Controller_Sparge_Tower, + Casing_Sparge_Tower_Exterior, + Casing_Sparge_Tower_Interior, + + // Elemental Duplicator + Controller_ElementalDuplicator, + Casing_ElementalDuplicator, + + // Forge Hammer + Controller_IndustrialForgeHammer, + Casing_IndustrialForgeHammer, + + // Molecular Transformer + Controller_MolecularTransformer, + Casing_Molecular_Transformer_1, + Casing_Molecular_Transformer_2, + Casing_Molecular_Transformer_3, + + // Big Steam Macerator + Controller_SteamMaceratorMulti, + // Big Steam Compressor + Controller_SteamCompressorMulti, + + // Industrial Rock Breaker + Controller_IndustrialRockBreaker, + + // Industrial Chisel + Controller_IndustrialAutoChisel, + Casing_IndustrialAutoChisel, + + // Industrial Fluid Heater + Controller_IndustrialFluidHeater, + + // Custom Machine Casings + Casing_Machine_Custom_1, + Casing_Machine_Custom_2, + Casing_Machine_Custom_3, + Casing_Machine_Custom_4, + Casing_Machine_Custom_5, + Casing_Machine_Custom_6, + + // ---------------------------------------------------------------------------- + + /** + * Custom hatches/Busses + */ + + // Buffer Dynamos + Hatch_Buffer_Dynamo_ULV, + Hatch_Buffer_Dynamo_LV, + Hatch_Buffer_Dynamo_MV, + Hatch_Buffer_Dynamo_HV, + Hatch_Buffer_Dynamo_EV, + Hatch_Buffer_Dynamo_IV, + Hatch_Buffer_Dynamo_LuV, + Hatch_Buffer_Dynamo_ZPM, + Hatch_Buffer_Dynamo_UV, + Hatch_Buffer_Dynamo_MAX, + + // Air Intake hatch + Hatch_Air_Intake, + Hatch_Air_Intake_Extreme, + + // Reservoir Hatch + Hatch_Reservoir, + + // XL Turbine Rotor Hatch + Hatch_Turbine_Rotor, + + // Standard Turbine Rotor Hatch + Hatch_Input_TurbineHousing, + + // Milling Ball Bus + Bus_Milling_Balls, + + // Catalyst Bus + Bus_Catalysts, + + // Custom Fluid Hatches + Hatch_Input_Cryotheum, + Hatch_Input_Pyrotheum, + Hatch_Input_Naquadah, + Hatch_Input_Steam, + + // Steam Multi Buses + Hatch_Input_Bus_Steam, + Hatch_Output_Bus_Steam, + + // Elemental Duplicator Data Orb Bus + Hatch_Input_Elemental_Duplicator, + + // RTG Hatch + + // Battery hatches for PSS + Hatch_Input_Battery_MV, + Hatch_Input_Battery_EV, + Hatch_Output_Battery_MV, + Hatch_Output_Battery_EV, + + // Advanced Mufflers + Hatch_Muffler_Adv_LV, + Hatch_Muffler_Adv_MV, + Hatch_Muffler_Adv_HV, + Hatch_Muffler_Adv_EV, + Hatch_Muffler_Adv_IV, + Hatch_Muffler_Adv_LuV, + Hatch_Muffler_Adv_ZPM, + Hatch_Muffler_Adv_UV, + Hatch_Muffler_Adv_MAX, + + // Super Input Busses + Hatch_SuperBus_Input_LV, + Hatch_SuperBus_Input_MV, + Hatch_SuperBus_Input_HV, + Hatch_SuperBus_Input_EV, + Hatch_SuperBus_Input_IV, + Hatch_SuperBus_Input_LuV, + Hatch_SuperBus_Input_ZPM, + Hatch_SuperBus_Input_UV, + Hatch_SuperBus_Input_MAX, + + // Super Output Busses + Hatch_SuperBus_Output_LV, + Hatch_SuperBus_Output_MV, + Hatch_SuperBus_Output_HV, + Hatch_SuperBus_Output_EV, + Hatch_SuperBus_Output_IV, + Hatch_SuperBus_Output_LuV, + Hatch_SuperBus_Output_ZPM, + Hatch_SuperBus_Output_UV, + Hatch_SuperBus_Output_MAX, + + // Chisel Buses for Industrial Chisel + GT_MetaTileEntity_ChiselBus_LV, + GT_MetaTileEntity_ChiselBus_MV, + GT_MetaTileEntity_ChiselBus_HV, + + // Solidifier Hatches for Industrial Multi Machine + GT_MetaTileEntity_Solidifier_I, + GT_MetaTileEntity_Solidifier_II, + GT_MetaTileEntity_Solidifier_III, + GT_MetaTileEntity_Solidifier_IV, + + // ---------------------------------------------------------------------------- + + /** + * Blocks + */ + ResonanceChamber_I, + ResonanceChamber_II, + ResonanceChamber_III, + ResonanceChamber_IV, + + Modulator_I, + Modulator_II, + Modulator_III, + Modulator_IV, + + // ---------------------------------------------------------------------------- + + /** + * Single Block Tile Entities + */ + + // Crate Box + CrateStorage, + + // Auto TC Research Creator + Thaumcraft_Researcher, + + // infinite Items + Infinite_Item_Chest, + + // GT4 automation + GT4_Electric_Auto_Workbench_LV, + GT4_Electric_Auto_Workbench_MV, + GT4_Electric_Auto_Workbench_HV, + GT4_Electric_Auto_Workbench_EV, + GT4_Electric_Auto_Workbench_IV, + GT4_Electric_Auto_Workbench_LuV, + GT4_Electric_Auto_Workbench_ZPM, + GT4_Electric_Auto_Workbench_UV, + GT4_Electric_Inventory_Manager_LV, + GT4_Electric_Inventory_Manager_MV, + GT4_Electric_Inventory_Manager_HV, + GT4_Electric_Inventory_Manager_EV, + GT4_Electric_Inventory_Manager_IV, + GT4_Electric_Inventory_Manager_LuV, + GT4_Electric_Inventory_Manager_ZPM, + GT4_Electric_Inventory_Manager_UV, + + // GT4 Crop Harvester + GT4_Crop_Harvester_LV, + GT4_Crop_Harvester_MV, + GT4_Crop_Harvester_HV, + GT4_Crop_Harvester_EV, + GT4_Crop_Harvester_IV, + GT4_Crop_Harvester_LuV, + GT4_Crop_Harvester_ZPM, + GT4_Crop_Harvester_UV, + + // Geothermal Engines + Geothermal_Engine_EV, + Geothermal_Engine_IV, + Geothermal_Engine_LuV, + + // Tesseracts + GT4_Tesseract_Generator, + GT4_Tesseract_Terminal, + + // Advanced Boilers + Boiler_Advanced_LV, + Boiler_Advanced_MV, + Boiler_Advanced_HV, + + // Fancy Pollution Devices + Pollution_Detector, + Pollution_Cleaner_LV, + Pollution_Cleaner_MV, + Pollution_Cleaner_HV, + Pollution_Cleaner_EV, + Pollution_Cleaner_IV, + Pollution_Cleaner_LuV, + Pollution_Cleaner_ZPM, + Pollution_Cleaner_UV, + Pollution_Cleaner_MAX, + + // Debug machine + Pollution_Creator, + + // Basically is an automatic Cauldron + SimpleDustWasher_ULV, + SimpleDustWasher_MV, + SimpleDustWasher_EV, + SimpleDustWasher_LuV, + SimpleDustWasher_UV, + + // Solar Tower Reflector + Solar_Tower_Reflector, + + // Super Tier Chests + Super_Chest_LV, + Super_Chest_MV, + Super_Chest_HV, + Super_Chest_EV, + Super_Chest_IV, + + // Wireless Chargers + Charger_LV, + Charger_MV, + Charger_HV, + Charger_EV, + Charger_IV, + Charger_LuV, + Charger_ZPM, + Charger_UV, + Charger_UHV, + + // Reactor Processing Unit + ReactorProcessingUnit_IV, + ReactorProcessingUnit_ZPM, + + // Cold Trap + ColdTrap_IV, + ColdTrap_ZPM, + + // Solar Generators + GT_Solar_ULV, + GT_Solar_LV, + GT_Solar_MV, + GT_Solar_HV, + GT_Solar_EV, + GT_Solar_IV, + GT_Solar_LuV, + GT_Solar_ZPM, + GT_Solar_UV, + GT_Solar_MAX, + + // Variable voltage RF convertor + Energy_Buffer_1by1_ULV, + Energy_Buffer_1by1_LV, + Energy_Buffer_1by1_MV, + Energy_Buffer_1by1_HV, + Energy_Buffer_1by1_EV, + Energy_Buffer_1by1_IV, + Energy_Buffer_1by1_LuV, + Energy_Buffer_1by1_ZPM, + Energy_Buffer_1by1_UV, + Energy_Buffer_1by1_MAX, + + // Rocket Engines + Rocket_Engine_EV, + Rocket_Engine_IV, + Rocket_Engine_LuV, + + // Hi Amp Transformers + Transformer_HA_LV_ULV, + Transformer_HA_MV_LV, + Transformer_HA_HV_MV, + Transformer_HA_EV_HV, + Transformer_HA_IV_EV, + Transformer_HA_LuV_IV, + Transformer_HA_ZPM_LuV, + Transformer_HA_UV_ZPM, + Transformer_HA_MAX_UV, + + // Semi-Fluid generators + Generator_SemiFluid_LV, + Generator_SemiFluid_MV, + Generator_SemiFluid_HV, + Generator_SemiFluid_EV, + Generator_SemiFluid_IV, + + // Advanced Mixer 4x4 + Machine_Advanced_LV_Mixer, + Machine_Advanced_MV_Mixer, + Machine_Advanced_HV_Mixer, + Machine_Advanced_EV_Mixer, + Machine_Advanced_IV_Mixer, + Machine_Advanced_LuV_Mixer, + Machine_Advanced_ZPM_Mixer, + Machine_Advanced_UV_Mixer, + + // Block that enables uplink to a superconductor network + SuperConductorInputNode, + + // Heat Pipes + HeatPipe_Tier_1, + HeatPipe_Tier_2, + HeatPipe_Tier_3, + + // Chemical Dehydrators for nuclear fuels + GT_Dehydrator_MV, + GT_Dehydrator_HV, + GT_Dehydrator_EV, + GT_Dehydrator_IV, + GT_Dehydrator_LuV, + GT_Dehydrator_ZPM, + + // Fluid Storage Tanks + GT_FluidTank_ULV, + GT_FluidTank_LV, + GT_FluidTank_MV, + GT_FluidTank_HV, + GT_FluidTank_EV, + GT_FluidTank_IV, + GT_FluidTank_LuV, + GT_FluidTank_ZPM, + GT_FluidTank_UV, + GT_FluidTank_MAX, + + // GT RTG + RTG, + + // Chisel Machines + GT_Chisel_LV, + GT_Chisel_MV, + GT_Chisel_HV, + + // Plasma Tank + /* Plasma_Tank, */ + + // ---------------------------------------------------------------------------- + + /** + * Covers + */ + + // Fluid Void Covers + Cover_Overflow_LV, + Cover_Overflow_MV, + Cover_Overflow_HV, + Cover_Overflow_EV, + Cover_Overflow_IV, + + // Item Void Covers + Cover_Overflow_Item_ULV, + Cover_Overflow_Item_LV, + Cover_Overflow_Item_MV, + Cover_Overflow_Item_HV, + Cover_Overflow_Item_EV, + Cover_Overflow_Item_IV, + + // ---------------------------------------------------------------------------- + // Additional washers + SimpleDustWasher_LV, + SimpleDustWasher_HV, + SimpleDustWasher_IV, + SimpleDustWasher_ZPM, + + ; + + public static final GregtechItemList[] DYE_ONLY_ITEMS = { Energy_Buffer_1by1_EV, Energy_Buffer_1by1_EV }; + private ItemStack mStack; + private boolean mHasNotBeenSet = true; + + @Override + public GregtechItemList set(final Item aItem) { + this.mHasNotBeenSet = false; + if (aItem == null) { + return this; + } + final ItemStack aStack = new ItemStack(aItem, 1, 0); + this.mStack = GT_Utility.copyAmount(1, aStack); + return this; + } + + @Override + public GregtechItemList set(final ItemStack aStack) { + this.mHasNotBeenSet = false; + this.mStack = GT_Utility.copyAmount(1, aStack); + return this; + } + + @Override + public Item getItem() { + if (this.mHasNotBeenSet) { + throw new IllegalAccessError("The Enum '" + this.name() + "' has not been set to an Item at this time!"); + } + if (GT_Utility.isStackInvalid(this.mStack)) { + return null; + } + return this.mStack.getItem(); + } + + @Override + public Block getBlock() { + if (this.mHasNotBeenSet) { + throw new IllegalAccessError("The Enum '" + this.name() + "' has not been set to an Item at this time!"); + } + return getBlockFromStack(this.getItem()); + } + + @Override + public final boolean hasBeenSet() { + return !this.mHasNotBeenSet; + } + + @Override + public boolean isStackEqual(final Object aStack) { + return this.isStackEqual(aStack, false, false); + } + + @Override + public boolean isStackEqual(final Object aStack, final boolean aWildcard, final boolean aIgnoreNBT) { + if (GT_Utility.isStackInvalid(aStack)) { + return false; + } + return GT_Utility + .areUnificationsEqual((ItemStack) aStack, aWildcard ? this.getWildcard(1) : this.get(1), aIgnoreNBT); + } + + public static Block getBlockFromStack(Object aStack) { + if (GT_Utility.isStackInvalid(aStack)) return Blocks.air; + return Block.getBlockFromItem(((ItemStack) aStack).getItem()); + } + + @Override + public ItemStack get(final long aAmount, final Object... aReplacements) { + if (this.mHasNotBeenSet) { + throw new IllegalAccessError("The Enum '" + this.name() + "' has not been set to an Item at this time!"); + } + if (GT_Utility.isStackInvalid(this.mStack)) { + return GT_Utility.copyAmount(aAmount, aReplacements); + } + return GT_Utility.copyAmount(aAmount, GT_OreDictUnificator.get(this.mStack)); + } + + @Override + public ItemStack getWildcard(final long aAmount, final Object... aReplacements) { + if (this.mHasNotBeenSet) { + throw new IllegalAccessError("The Enum '" + this.name() + "' has not been set to an Item at this time!"); + } + if (GT_Utility.isStackInvalid(this.mStack)) { + return GT_Utility.copyAmount(aAmount, aReplacements); + } + return GT_Utility.copyAmountAndMetaData(aAmount, W, GT_OreDictUnificator.get(this.mStack)); + } + + @Override + public ItemStack getUndamaged(final long aAmount, final Object... aReplacements) { + if (this.mHasNotBeenSet) { + throw new IllegalAccessError("The Enum '" + this.name() + "' has not been set to an Item at this time!"); + } + if (GT_Utility.isStackInvalid(this.mStack)) { + return GT_Utility.copyAmount(aAmount, aReplacements); + } + return GT_Utility.copyAmountAndMetaData(aAmount, 0, GT_OreDictUnificator.get(this.mStack)); + } + + @Override + public ItemStack getAlmostBroken(final long aAmount, final Object... aReplacements) { + if (this.mHasNotBeenSet) { + throw new IllegalAccessError("The Enum '" + this.name() + "' has not been set to an Item at this time!"); + } + if (GT_Utility.isStackInvalid(this.mStack)) { + return GT_Utility.copyAmount(aAmount, aReplacements); + } + return GT_Utility + .copyAmountAndMetaData(aAmount, this.mStack.getMaxDamage() - 1, GT_OreDictUnificator.get(this.mStack)); + } + + @Override + public ItemStack getWithName(final long aAmount, final String aDisplayName, final Object... aReplacements) { + final ItemStack rStack = this.get(1, aReplacements); + if (GT_Utility.isStackInvalid(rStack)) { + return null; + } + rStack.setStackDisplayName(aDisplayName); + return GT_Utility.copyAmount(aAmount, rStack); + } + + @Override + public ItemStack getWithCharge(final long aAmount, final int aEnergy, final Object... aReplacements) { + final ItemStack rStack = this.get(1, aReplacements); + if (GT_Utility.isStackInvalid(rStack)) { + return null; + } + GT_ModHandler.chargeElectricItem(rStack, aEnergy, Integer.MAX_VALUE, true, false); + return GT_Utility.copyAmount(aAmount, rStack); + } + + @Override + public ItemStack getWithDamage(final long aAmount, final long aMetaValue, final Object... aReplacements) { + if (this.mHasNotBeenSet) { + throw new IllegalAccessError("The Enum '" + this.name() + "' has not been set to an Item at this time!"); + } + if (GT_Utility.isStackInvalid(this.mStack)) { + return GT_Utility.copyAmount(aAmount, aReplacements); + } + return GT_Utility.copyAmountAndMetaData(aAmount, aMetaValue, GT_OreDictUnificator.get(this.mStack)); + } + + @Override + public GregtechItemList registerOre(final Object... aOreNames) { + if (this.mHasNotBeenSet) { + throw new IllegalAccessError("The Enum '" + this.name() + "' has not been set to an Item at this time!"); + } + for (final Object tOreName : aOreNames) { + GT_OreDictUnificator.registerOre(tOreName, this.get(1)); + } + return this; + } + + @Override + public GregtechItemList registerWildcardAsOre(final Object... aOreNames) { + if (this.mHasNotBeenSet) { + throw new IllegalAccessError("The Enum '" + this.name() + "' has not been set to an Item at this time!"); + } + for (final Object tOreName : aOreNames) { + GT_OreDictUnificator.registerOre(tOreName, this.getWildcard(1)); + } + return this; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/enums/GregtechOreDictNames.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/enums/GregtechOreDictNames.java new file mode 100644 index 0000000000..4bd8831098 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/enums/GregtechOreDictNames.java @@ -0,0 +1,39 @@ +package gtPlusPlus.xmod.gregtech.api.enums; + +/* + * Electric Components. usual Materials for this are: Primitive (Tier 1) Basic (Tier 2) as used by UE as well : IC2 + * Circuit and RE-Battery Good (Tier 3) Advanced (Tier 4) as used by UE as well : Advanced Circuit, Advanced Battery and + * Lithium Battery Data (Tier 5) : Data Storage Circuit Elite (Tier 6) as used by UE as well : Energy Crystal and Data + * Control Circuit Master (Tier 7) : Energy Flow Circuit and Lapotron Crystal Ultimate (Tier 8) : Data Orb and + * Lapotronic Energy Orb Infinite (Cheaty) Circuits Circuit_Primitive, Circuit_Basic, Circuit_Good, Circuit_Advanced, + * Circuit_Data, Circuit_Elite, Circuit_Master, Tool_DataOrb, Circuit_Ultimate, Tool_DataStick, Circuit_IV, Circuit_LuV, + * Circuit_ZPM, Circuit Parts Circuit_Board_IV, Circuit_Board_LuV, Circuit_Board_ZPM, Circuit_Parts_Crystal_Chip_IV, + * Circuit_Parts_Crystal_Chip_LuV, Circuit_Parts_Crystal_Chip_ZPM, Circuit_Parts_IV, Circuit_Parts_LuV, + * Circuit_Parts_ZPM, Circuit_Parts_Wiring_IV, Circuit_Parts_Wiring_LuV, Circuit_Parts_Wiring_ZPM; + */ +public enum GregtechOreDictNames { + + buffer_core, + itemGregConduit, + Circuit_IV, + Circuit_LuV, + Circuit_ZPM, + Circuit_Board_IV, + Circuit_Board_LuV, + Circuit_Board_ZPM, + Circuit_Parts_Crystal_Chip_IV, + Circuit_Parts_Crystal_Chip_LuV, + Circuit_Parts_Crystal_Chip_ZPM, + Circuit_Parts_IV, + Circuit_Parts_LuV, + Circuit_Parts_ZPM, + Circuit_Parts_Wiring_IV, + Circuit_Parts_Wiring_LuV, + Circuit_Parts_Wiring_ZPM; + + public String unlocalisedName; + + private void ModObject() { + this.unlocalisedName = this.name(); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/enums/GregtechOrePrefixes.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/enums/GregtechOrePrefixes.java new file mode 100644 index 0000000000..3185810495 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/enums/GregtechOrePrefixes.java @@ -0,0 +1,1324 @@ +package gtPlusPlus.xmod.gregtech.api.enums; + +import static gregtech.api.enums.GT_Values.B; +import static gregtech.api.enums.GT_Values.D2; +import static gregtech.api.enums.GT_Values.M; +import static gtPlusPlus.core.util.Utils.getTcAspectStack; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; + +import net.minecraft.enchantment.Enchantment; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; + +import gregtech.api.enums.ConfigCategories; +import gregtech.api.enums.Dyes; +import gregtech.api.enums.Element; +import gregtech.api.enums.Materials; +import gregtech.api.enums.SubTag; +import gregtech.api.enums.TC_Aspects; +import gregtech.api.enums.TC_Aspects.TC_AspectStack; +import gregtech.api.enums.TextureSet; +import gregtech.api.interfaces.IColorModulationContainer; +import gregtech.api.interfaces.ICondition; +import gregtech.api.interfaces.ISubTagContainer; +import gregtech.api.objects.MaterialStack; +import gregtech.api.util.GT_Config; +import gregtech.api.util.GT_Log; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.interfaces.internal.Interface_OreRecipeRegistrator; +import gtPlusPlus.xmod.gregtech.api.objects.GregtechItemData; +import gtPlusPlus.xmod.gregtech.api.objects.GregtechMaterialStack; + +public enum GregtechOrePrefixes { + + /* + * Electric Components. usual Materials for this are: Primitive (Tier 1) Basic (Tier 2) as used by UE as well : IC2 + * Circuit and RE-Battery Good (Tier 3) Advanced (Tier 4) as used by UE as well : Advanced Circuit, Advanced Battery + * and Lithium Battery Data (Tier 5) : Data Storage Circuit Elite (Tier 6) as used by UE as well : Energy Crystal + * and Data Control Circuit Master (Tier 7) : Energy Flow Circuit and Lapotron Crystal Ultimate (Tier 8) : Data Orb + * and Lapotronic Energy Orb Infinite (Cheaty) + */ + ingotHot("Hot Ingots", "Hot ", " Ingot", true, true, false, false, false, false, false, true, false, false, B[1], + M * 1, 16, 12), // A hot Ingot, which has to be cooled down by a Vacuum Freezer. + ingot("Ingots", "", " Ingot", true, true, false, false, false, false, false, true, false, false, B[1], M * 1, 64, + 11), // A regular Ingot. Introduced by Eloraam + dustTiny("Tiny Dusts", "Tiny Pile of ", " Dust", true, true, false, false, false, false, false, true, false, false, + B[0] | B[1] | B[2] | B[3], M / 9, 64, 0), // 1/9th of a Dust. + dustSmall("Small Dusts", "Small Pile of ", " Dust", true, true, false, false, false, false, false, true, false, + false, B[0] | B[1] | B[2] | B[3], M / 4, 64, 1), // 1/4th of a Dust. + dustImpure("Impure Dusts", "Impure Pile of ", " Dust", true, true, false, false, false, false, false, true, false, + true, B[3], M * 1, 64, 3), // Dust with impurities. 1 Unit of Main Material and 1/9 - 1/4 Unit of secondary + // Material + dustRefined("Refined Dusts", "Refined Pile of ", " Dust", true, true, false, false, false, false, false, true, + false, true, B[3], M * 1, 64, 2), + dustPure("Purified Dusts", "Purified Pile of ", " Dust", true, true, false, false, false, false, false, true, false, + true, B[3], M * 1, 64, 4), + dust("Dusts", "", " Dust", true, true, false, false, false, false, false, true, false, false, + B[0] | B[1] | B[2] | B[3], M * 1, 64, 2), // Pure Dust worth of one Ingot or Gem. Introduced by Alblaka. + nugget("Nuggets", "", " Nugget", true, true, false, false, false, false, false, true, false, false, B[1], M / 9, 64, + 9), // A Nugget. Introduced by Eloraam + plate("Plates", "", " Plate", true, true, false, false, false, false, true, true, false, false, B[1] | B[2], M * 1, + 64, 17), // Regular Plate made of one Ingot/Dust. Introduced by Calclavia + block("Storage Blocks", "Block of ", "", true, true, false, false, false, true, true, false, false, false, 0, M * 9, + 64, 71), // Storage Block consisting out of 9 Ingots/Gems/Dusts. Introduced by CovertJaguar + gem("Gemstones", "", "", true, true, true, false, false, false, true, true, false, false, B[2], M * 1, 64, 8), // A + // regular + // Gem + // worth + // one + // Dust. + // Introduced + // by + // Eloraam + gemChipped("Chipped Gemstones", "Chipped ", "", true, true, true, false, false, false, true, true, false, false, + B[2], M / 4, 64, 59), // A regular Gem worth one small Dust. Introduced by TerraFirmaCraft + gemFlawed("Flawed Gemstones", "Flawed ", "", true, true, true, false, false, false, true, true, false, false, B[2], + M / 2, 64, 60), // A regular Gem worth two small Dusts. Introduced by TerraFirmaCraft + gemFlawless("Flawless Gemstones", "Flawless ", "", true, true, true, false, false, false, true, true, false, false, + B[2], M * 2, 32, 61), // A regular Gem worth two Dusts. Introduced by TerraFirmaCraft + gemExquisite("Exquisite Gemstones", "Exquisite ", "", true, true, true, false, false, false, true, true, false, + false, B[2], M * 4, 16, 62), // A regular Gem worth four Dusts. Introduced by TerraFirmaCraft + stick("Sticks/Rods", "", " Rod", true, true, false, false, false, false, true, true, false, false, B[1] | B[2], + M / 2, 64, 23), // Stick made of half an Ingot. Introduced by Eloraam + type2("16x Wires", "16x ", " Wire", true, true, false, false, false, false, true, false, false, false, 0, M * 8, 64, + -1), + + toolAngleGrinder("Angle Grinder", "", "Angle Grinder", true, true, false, false, false, false, true, true, false, + false, B[6], M * 6, 16, 37), // consisting out of 6 Ingots. + toolElectricSnips("Electric Snips", "", "Electric Snips", true, true, false, false, false, false, true, true, false, + false, B[6], M * 6, 16, 37), // consisting out of 6 Ingots. + toolElectricLighter("Electric Lighter", "", "Electric Lighter", true, true, false, false, false, false, true, true, + false, false, B[6], M * 6, 16, 37), // consisting out of 6 Ingots. + toolElectricButcherKnife("Electric Butcher Knife", "", "Electric Butcher Knife", true, true, false, false, false, + false, true, true, false, false, B[6], M * 6, 16, 37), // consisting out of 6 Ingots. + + batterySingleuse("Single Use Batteries", "", "", false, true, false, false, false, false, false, false, false, + false, 0, -1, 64, -1), + battery("Reusable Batteries", "", "", false, true, false, false, false, false, false, false, false, false, 0, -1, + 64, -1), // Introduced by Calclavia + circuit("Circuits", "", "", true, true, false, false, false, false, false, false, false, false, 0, -1, 64, -1), // Introduced + // by + // Calclavia + chipset("Chipsets", "", "", true, true, false, false, false, false, false, false, false, false, 0, -1, 64, -1), // Introduced + ; + + public static final int VERSION = 508; + + static { + ingotHot.mHeatDamage = 3.0F; + } + + public final ArrayList<ItemStack> mPrefixedItems = new ArrayList<>(); + public final short mTextureIndex; + public final String mRegularLocalName, mLocalizedMaterialPre, mLocalizedMaterialPost; + public final boolean mIsUsedForOreProcessing, mIsEnchantable, mIsUnificatable, mIsMaterialBased, mIsSelfReferencing, + mIsContainer, mDontUnificateActively, mIsUsedForBlocks, mAllowNormalRecycling, mGenerateDefaultItem; + public final List<TC_AspectStack> mAspects = new ArrayList<>(); + public final Collection<GregtechOrePrefixes> mFamiliarPrefixes = new HashSet<>(); + /** + * Used to determine the amount of Material this Prefix contains. Multiply or Divide GregTech_API.MATERIAL_UNIT to + * get the Amounts in comparision to one Ingot. 0 = Null Negative = Undefined Amount + */ + public final long mMaterialAmount; + + private final Collection<Materials> mNotGeneratedItems = new HashSet<>(), mIgnoredMaterials = new HashSet<>(), + mGeneratedItems = new HashSet<>(); + private final ArrayList<Interface_OreRecipeRegistrator> mOreProcessing = new ArrayList<>(); + private final ArrayList<Interface_OreRecipeRegistrator> mOreProcessingFake = new ArrayList<>(); + public final ItemStack mContainerItem = null; + public final ICondition<ISubTagContainer> mCondition = null; + public byte mDefaultStackSize = 64; + public final GregtechMaterialStack mSecondaryMaterial = null; + public final GregtechOrePrefixes mPrefixInto = this; + public float mHeatDamage = 0.0F; // Negative for Frost Damage + /** + * Yes this Value can be changed to add Bits for the MetaGenerated-Item-Check. + */ + public int mMaterialGenerationBits = 0; + + private GregtechOrePrefixes(final String aRegularLocalName, final String aLocalizedMaterialPre, + final String aLocalizedMaterialPost, final boolean aIsUnificatable, final boolean aIsMaterialBased, + final boolean aIsSelfReferencing, final boolean aIsContainer, final boolean aDontUnificateActively, + final boolean aIsUsedForBlocks, final boolean aAllowNormalRecycling, final boolean aGenerateDefaultItem, + final boolean aIsEnchantable, final boolean aIsUsedForOreProcessing, final int aMaterialGenerationBits, + final long aMaterialAmount, final int aDefaultStackSize, final int aTextureindex) { + this.mIsUnificatable = aIsUnificatable; + this.mIsMaterialBased = aIsMaterialBased; + this.mIsSelfReferencing = aIsSelfReferencing; + this.mIsContainer = aIsContainer; + this.mDontUnificateActively = aDontUnificateActively; + this.mIsUsedForBlocks = aIsUsedForBlocks; + this.mAllowNormalRecycling = aAllowNormalRecycling; + this.mGenerateDefaultItem = aGenerateDefaultItem; + this.mIsEnchantable = aIsEnchantable; + this.mIsUsedForOreProcessing = aIsUsedForOreProcessing; + this.mMaterialGenerationBits = aMaterialGenerationBits; + this.mMaterialAmount = aMaterialAmount; + this.mRegularLocalName = aRegularLocalName; + this.mLocalizedMaterialPre = aLocalizedMaterialPre; + this.mLocalizedMaterialPost = aLocalizedMaterialPost; + this.mDefaultStackSize = (byte) aDefaultStackSize; + this.mTextureIndex = (short) aTextureindex; + + // TODO - Utilise some form of way to check if it's gt 5.9 if so, use string switch. + if (this.name() + .startsWith("ore")) { + getTcAspectStack(TC_Aspects.TERRA.name(), 1).addToAspectList(this.mAspects); + } else if (this.name() + .startsWith("wire") + || this.name() + .startsWith("cable")) { + getTcAspectStack(TC_Aspects.ELECTRUM.name(), 1).addToAspectList(this.mAspects); + } else + if (this.name() + .startsWith("dust")) { + getTcAspectStack(TC_Aspects.PERDITIO.name(), 1).addToAspectList(this.mAspects); + } else if (this.name() + .startsWith("crushed")) { + getTcAspectStack(TC_Aspects.PERFODIO.name(), 1).addToAspectList(this.mAspects); + } else if (this.name() + .startsWith("ingot") + || this.name() + .startsWith("nugget")) { + getTcAspectStack(TC_Aspects.METALLUM.name(), 1).addToAspectList(this.mAspects); + } else + if (this.name() + .startsWith("armor")) { + getTcAspectStack(TC_Aspects.TUTAMEN.name(), 1).addToAspectList(this.mAspects); + } else if (this.name() + .startsWith("stone")) { + getTcAspectStack(TC_Aspects.TERRA.name(), 1).addToAspectList(this.mAspects); + } else if (this.name() + .startsWith("pipe")) { + getTcAspectStack(TC_Aspects.ITER.name(), 1).addToAspectList(this.mAspects); + } else if (this.name() + .startsWith("gear")) { + getTcAspectStack(TC_Aspects.MOTUS.name(), 1).addToAspectList(this.mAspects); + getTcAspectStack(TC_Aspects.MACHINA.name(), 1) + .addToAspectList(this.mAspects); + } else if (this.name() + .startsWith("frame") + || this.name() + .startsWith("plate")) { + getTcAspectStack(TC_Aspects.FABRICO.name(), 1) + .addToAspectList(this.mAspects); + } else + if (this.name() + .startsWith("tool")) { + getTcAspectStack(TC_Aspects.INSTRUMENTUM.name(), 2) + .addToAspectList(this.mAspects); + } else if (this.name() + .startsWith("gem") + || this.name() + .startsWith("crystal") + || this.name() + .startsWith("lens")) { + getTcAspectStack(TC_Aspects.VITREUS.name(), 1) + .addToAspectList(this.mAspects); + } else + if (this.name() + .startsWith("crate")) { + getTcAspectStack(TC_Aspects.ITER.name(), 2) + .addToAspectList(this.mAspects); + } else if (this.name() + .startsWith("circuit")) { + getTcAspectStack("COGNITIO", 1); + } else if (this.name() + .startsWith("battery")) { + getTcAspectStack(TC_Aspects.ELECTRUM.name(), 1) + .addToAspectList(this.mAspects); + } + } + + public static GregtechOrePrefixes getOrePrefix(final String aOre) { + for (final GregtechOrePrefixes tPrefix : values()) { + if (aOre.startsWith(tPrefix.toString())) { + return tPrefix; + } + } + return null; + } + + public static String stripPrefix(final String aOre) { + for (final GregtechOrePrefixes tPrefix : values()) { + if (aOre.startsWith(tPrefix.toString())) { + return aOre.replaceFirst(tPrefix.toString(), ""); + } + } + return aOre; + } + + public static String replacePrefix(final String aOre, final GregtechOrePrefixes aPrefix) { + for (final GregtechOrePrefixes tPrefix : values()) { + if (aOre.startsWith(tPrefix.toString())) { + return aOre.replaceFirst(tPrefix.toString(), aPrefix.toString()); + } + } + return ""; + } + + public static GregtechOrePrefixes getPrefix(final String aPrefixName) { + return getPrefix(aPrefixName, null); + } + + public static GregtechOrePrefixes getPrefix(final String aPrefixName, final GregtechOrePrefixes aReplacement) { + final Object tObject = GT_Utility.getFieldContent(GregtechOrePrefixes.class, aPrefixName, false, false); + if ((tObject != null) && (tObject instanceof GregtechOrePrefixes)) { + return (GregtechOrePrefixes) tObject; + } + return aReplacement; + } + + public static Materials getMaterial(final String aOre) { + return Materials.get(stripPrefix(aOre)); + } + + public static Materials getMaterial(final String aOre, final GregtechOrePrefixes aPrefix) { + return Materials.get(aOre.replaceFirst(aPrefix.toString(), "")); + } + + public static Materials getRealMaterial(final String aOre, final GregtechOrePrefixes aPrefix) { + return Materials.getRealMaterial(aOre.replaceFirst(aPrefix.toString(), "")); + } + + public static boolean isInstanceOf(final String aName, final GregtechOrePrefixes aPrefix) { + return aName == null ? false : aName.startsWith(aPrefix.toString()); + } + + public boolean add(final ItemStack aStack) { + if (aStack == null) { + return false; + } + if (!this.contains(aStack)) { + this.mPrefixedItems.add(aStack); + } + while (this.mPrefixedItems.contains(null)) { + this.mPrefixedItems.remove(null); + } + return true; + } + + public boolean contains(final ItemStack aStack) { + if (aStack == null) { + return false; + } + for (final ItemStack tStack : this.mPrefixedItems) { + if (GT_Utility.areStacksEqual(aStack, tStack, !tStack.hasTagCompound())) { + return true; + } + } + return false; + } + + public boolean doGenerateItem(final Materials aMaterial) { + return (aMaterial != null) && (aMaterial != Materials._NULL) + && (((aMaterial.mTypes & this.mMaterialGenerationBits) != 0) || this.mGeneratedItems.contains(aMaterial)) + && !this.mNotGeneratedItems.contains(aMaterial) + && ((this.mCondition == null) || this.mCondition.isTrue(aMaterial)); + } + + public boolean ignoreMaterials(final Materials... aMaterials) { + for (final Materials tMaterial : aMaterials) { + if (tMaterial != null) { + this.mIgnoredMaterials.add(tMaterial); + } + } + return true; + } + + public boolean addFamiliarPrefix(final GregtechOrePrefixes aPrefix) { + if ((aPrefix == null) || this.mFamiliarPrefixes.contains(aPrefix) || (aPrefix == this)) { + return false; + } + return this.mFamiliarPrefixes.add(aPrefix); + } + + public boolean add(final Interface_OreRecipeRegistrator aRegistrator) { + if (aRegistrator == null) { + return false; + } + return this.mOreProcessing.add(aRegistrator); + } + + public void processOre(final GT_Materials aMaterial, final String aOreDictName, final String aModName, + final ItemStack aStack) { + if ((aMaterial != null) + && ((aMaterial != GT_Materials._NULL) || this.mIsSelfReferencing || !this.mIsMaterialBased) + && GT_Utility.isStackValid(aStack)) { + for (final Interface_OreRecipeRegistrator tRegistrator : this.mOreProcessing) { + if (D2) { + GT_Log.ore.println( + "Processing '" + aOreDictName + + "' with the Prefix '" + + this.name() + + "' and the Material '" + + aMaterial.name() + + "' at " + + GT_Utility.getClassName(tRegistrator)); + } + tRegistrator.registerOre(this, aMaterial, aOreDictName, aModName, GT_Utility.copyAmount(1, aStack)); + } + } + } + + // TODO + public void processOre(final Materials aMaterial, final String aOreDictName, final String aModName, + final ItemStack aStack) { + if ((aMaterial != null) && ((aMaterial != Materials._NULL) || this.mIsSelfReferencing || !this.mIsMaterialBased) + && GT_Utility.isStackValid(aStack)) { + for (final Interface_OreRecipeRegistrator tRegistrator : this.mOreProcessingFake) { + if (D2) { + GT_Log.ore.println( + "Processing '" + aOreDictName + + "' with the Prefix '" + + this.name() + + "' and the Material '" + + aMaterial.mName + + "' at " + + GT_Utility.getClassName(tRegistrator)); + } + tRegistrator.registerOre(this, aMaterial, aOreDictName, aModName, GT_Utility.copyAmount(1, aStack)); + } + } + } + + public Object get(final Object aMaterial) { + if (aMaterial instanceof GT_Materials) { + return new GregtechItemData(this, (GT_Materials) aMaterial); + } + return this.name() + aMaterial; + } + + public String getDefaultLocalNameForItem(final Materials aMaterial) { + + // Use Standard Localization + return this.mLocalizedMaterialPre + aMaterial.mDefaultLocalName + this.mLocalizedMaterialPost; + } + + public enum GT_Materials implements IColorModulationContainer, ISubTagContainer { + + /** + * This is the Default Material returned in case no Material has been found or a NullPointer has been inserted + * at a location where it shouldn't happen. + * <p/> + * Mainly for preventing NullPointer Exceptions and providing Default Values. + * + * Unknown Material Components. Dead End Section. + * + * Alkalus Range 730-799 & 970-998 (aMetaItemSubID, TextureSet, aToolSpeed, aToolDurability, aToolQuality, + * aTypes, R, G, B, Alpha, aLocalName, aFuelType, aFuelPower, aMeltingPoint, aBlastFurnaceTemp, + * aBlastFurnaceRequired, aTransparent, aOreValue, aDensityMultiplier, aDensityDivider, aColor + * this(aMetaItemSubID, aIconSet, aToolSpeed, aToolDurability, aToolQuality, true); + * + */ + _NULL(-1, TextureSet.SET_NONE, 1.0F, 0, 0, 0, 255, 255, 255, 0, "NULL", 0, 0, 0, 0, false, false, 1, 1, 1, + Dyes._NULL, Element._NULL, Arrays.asList(getTcAspectStack(TC_Aspects.VACUOS.name(), 1))), + + // Lapis(526, TextureSet.SET_LAPIS, 1.0F, 0, 1, 1 | 4 | 8, 70, 70, 220, 0, "Lapis", 0, 0, -1, 0, false, false, + // 3, 1, 1, Dyes.dyeBlue, 2, Arrays.asList(new MaterialStack(Materials.Lazurite, 12), new + // MaterialStack(Materials.Sodalite, 2), new MaterialStack(Materials.Pyrite, 1), new + // MaterialStack(Materials.Calcite, 1)), Arrays.asList(getTcAspectStack(TC_Aspects.SENSUS, 1))), + Pyrotheum(20, TextureSet.SET_FLUID, 1.0F, 0, 1, 2 | 16 | 32, 255, 128, 0, 0, "Pyrotheum", 0, 0, -1, 0, false, + false, 2, 3, 1, Dyes.dyeYellow, 2, + Arrays.asList( + new MaterialStack(Materials.Coal, 1), + new MaterialStack(Materials.Redstone, 1), + new MaterialStack(Materials.Blaze, 1), + new MaterialStack(Materials.Sulfur, 1)), + Arrays.asList(getTcAspectStack("PRAECANTATIO", 2), getTcAspectStack(TC_Aspects.IGNIS, 1))), + Cryotheum(21, TextureSet.SET_FLUID, 1.0F, 0, 1, 2 | 16 | 32, 102, 178, 255, 0, "Cryotheum", 0, 0, -1, 0, false, + false, 2, 3, 1, Dyes.dyeLightBlue, 2, + Arrays.asList( + new MaterialStack(Materials.Blizz, 1), + new MaterialStack(Materials.Redstone, 1), + new MaterialStack(Materials.Snow, 1), + new MaterialStack(Materials.Niter, 1)), + Arrays.asList(getTcAspectStack("PRAECANTATIO", 2), getTcAspectStack(TC_Aspects.GELUM, 1))), + Ender(22, TextureSet.SET_FLUID, 1.0F, 0, 2, 1, 255, 255, 255, 0, "Ender", 0, 0, -1, 0, false, false, 3, 1, 1, + Dyes.dyeGreen), + + /** + * Circuitry, Batteries and other Technical things + */ + Symbiotic(-1, TextureSet.SET_NONE, 1.0F, 0, 0, 0, 255, 255, 255, 0, "IV Tier", 0, 0, -1, 0, false, false, 1, 1, + 1, Dyes.dyeLightGray, + Arrays.asList(getTcAspectStack(TC_Aspects.ELECTRUM, 4), getTcAspectStack(TC_Aspects.MACHINA, 4))), + Neutronic(-1, TextureSet.SET_NONE, 1.0F, 0, 0, 0, 255, 255, 255, 0, "LuV Tier", 0, 0, -1, 0, false, false, 1, 1, + 1, Dyes.dyeLightGray, + Arrays.asList(getTcAspectStack(TC_Aspects.ELECTRUM, 6), getTcAspectStack(TC_Aspects.MACHINA, 6))), + Quantum(-1, TextureSet.SET_NONE, 1.0F, 0, 0, 0, 255, 255, 255, 0, "ZPM Tier", 0, 0, -1, 0, false, false, 1, 1, + 1, Dyes.dyeLightGray, + Arrays.asList(getTcAspectStack(TC_Aspects.ELECTRUM, 8), getTcAspectStack(TC_Aspects.MACHINA, 8))), + + Superconductor(-1, TextureSet.SET_NONE, 1.0F, 0, 0, 0, 190, 240, 190, 0, "Superconductor", 0, 0, -1, 0, false, + false, 1, 1, 1, Dyes.dyeGreen, Arrays.asList(getTcAspectStack(TC_Aspects.ELECTRUM, 8))), + + Staballoy(30, TextureSet.SET_ROUGH, 10.0F, 5120, 4, 1 | 2 | 16 | 32 | 64 | 128, 68, 75, 66, 0, "Staballoy", 0, + 0, 1500, 2800, true, false, 1, 3, 1, Dyes.dyeGreen, 2, + Arrays.asList(new MaterialStack(Materials.Titanium, 1), new MaterialStack(Materials.Uranium, 9)), + Arrays.asList(getTcAspectStack(TC_Aspects.METALLUM, 8), getTcAspectStack(TC_Aspects.STRONTIO, 3))), + Bedrockium(31, TextureSet.SET_FINE, 8.0F, 8196, 3, 1 | 2 | 16 | 32 | 64 | 128, 39, 39, 39, 0, "Bedrockium", 0, + 0, -1, 0, false, false, 1, 5, 1, Dyes.dyeLightGray, 2, + Arrays.asList(new MaterialStack(Materials.Carbon, 63), new MaterialStack(Materials.Carbon, 56)), + Arrays.asList(getTcAspectStack(TC_Aspects.VACUOS, 8), getTcAspectStack(TC_Aspects.TUTAMEN, 3))), + BloodSteel(32, TextureSet.SET_METALLIC, 11.0F, 768, 4, 1 | 2 | 16 | 32 | 64 | 128, 142, 28, 0, 0, "Blood Steel", + 0, 0, -1, 0, false, false, 1, 1, 1, Dyes.dyeRed, 2, Arrays.asList(new MaterialStack(Materials.Steel, 3)), + Arrays.asList(getTcAspectStack(TC_Aspects.VICTUS, 8), getTcAspectStack(TC_Aspects.IGNIS, 3))), + Void(33, TextureSet.SET_METALLIC, 6.0F, 1280, 3, 1 | 2 | 16 | 32 | 64 | 128, 82, 17, 82, 0, "Void Metal", 0, 0, + -1, 0, false, false, 3, 1, 1, Dyes.dyeBlack, + Arrays.asList(getTcAspectStack("PRAECANTATIO", 5), getTcAspectStack(TC_Aspects.VACUOS, 7))), + ConductiveIron(34, TextureSet.SET_METALLIC, 5.0F, 256, 2, 1 | 2, 164, 109, 100, 0, "Conductive Iron", 0, 0, -1, + 0, false, false, 3, 1, 1, Dyes.dyeRed, 2, + Arrays.asList(new MaterialStack(Materials.Iron, 6), new MaterialStack(Materials.Redstone, 2)), + Arrays.asList(getTcAspectStack(TC_Aspects.POTENTIA, 2), getTcAspectStack(TC_Aspects.METALLUM, 2))), + ElectricalSteel(35, TextureSet.SET_METALLIC, 7.0F, 768, 3, 1 | 2 | 64 | 128, 194, 194, 194, 0, + "Electrical Steel", 0, 0, 1811, 1000, true, false, 3, 1, 1, Dyes.dyeLightGray, 2, + Arrays.asList( + new MaterialStack(Materials.Iron, 3), + new MaterialStack(Materials.Coal, 2), + new MaterialStack(Materials.Silicon, 2)), + Arrays.asList(getTcAspectStack(TC_Aspects.MAGNETO, 2), getTcAspectStack(TC_Aspects.ELECTRUM, 5))), + EnergeticAlloy(36, TextureSet.SET_SHINY, 5.0F, 512, 3, 1 | 2 | 64 | 128, 252, 152, 45, 0, "Energetic Alloy", 0, + 0, -1, 0, false, false, 3, 1, 1, Dyes.dyeOrange, 2, + Arrays.asList( + new MaterialStack(Materials.Gold, 3), + new MaterialStack(Materials.Glowstone, 2), + new MaterialStack(Materials.Redstone, 2)), + Arrays.asList(getTcAspectStack(TC_Aspects.POTENTIA, 4), getTcAspectStack(TC_Aspects.LUX, 3))), + VibrantAlloy(37, TextureSet.SET_SHINY, 7.0F, 1280, 4, 1 | 2 | 64 | 128, 204, 242, 142, 0, "Vibrant Alloy", 0, 0, + -1, 0, false, false, 3, 1, 1, Dyes.dyeLime, 2, + Arrays.asList(new MaterialStack(Materials.EnergeticAlloy, 1), new MaterialStack(Materials.EnderPearl, 3)), + Arrays.asList(getTcAspectStack(TC_Aspects.MACHINA, 5), getTcAspectStack(TC_Aspects.TELUM, 4))), + PulsatingIron(38, TextureSet.SET_SHINY, 5.0F, 256, 2, 1 | 2 | 64 | 128, 50, 91, 21, 0, "Pulsating Iron", 0, 0, + -1, 0, false, false, 3, 1, 1, Dyes.dyeGreen, 2, + Arrays.asList(new MaterialStack(Materials.Iron, 2), new MaterialStack(Materials.EnderPearl, 2)), + Arrays.asList(getTcAspectStack(TC_Aspects.ALIENIS, 3), getTcAspectStack(TC_Aspects.METALLUM, 3))), + /* TODO */ RedstoneAlloy(39, TextureSet.SET_METALLIC, 1.0F, 256, 2, 1 | 2 | 16 | 32 | 64, 178, 34, 34, 0, + "Redstone Alloy", 0, 0, -1, 0, false, false, 3, 1, 1, Dyes.dyeRed, 2, + Arrays.asList(new MaterialStack(Materials.Iron, 2), new MaterialStack(Materials.Redstone, 4))), + + // Needs more Use, I think. + Tantalloy60(40, TextureSet.SET_DULL, 8.0F, 5120, 3, 1 | 2 | 16 | 32 | 64 | 128, 68, 75, 166, 0, "Tantalloy-60", + 0, 0, 3035, 2200, true, false, 1, 2, 1, Dyes.dyeLightBlue, 2, + Arrays.asList(new MaterialStack(Materials.Tungsten, 1), new MaterialStack(Materials.Tantalum, 9)), + Arrays.asList(getTcAspectStack(TC_Aspects.METALLUM, 8), getTcAspectStack(TC_Aspects.STRONTIO, 3))), + Tantalloy61(41, TextureSet.SET_DULL, 7.0F, 5120, 2, 1 | 2 | 16 | 32 | 64 | 128, 122, 135, 196, 0, + "Tantalloy-61", 0, 0, 3015, 2150, true, false, 1, 2, 1, Dyes.dyeLightBlue, 2, + Arrays.asList( + new MaterialStack(Materials.Tungsten, 1), + new MaterialStack(Materials.Tantalum, 9), + new MaterialStack(Materials.Titanium, 1)), + Arrays.asList(getTcAspectStack(TC_Aspects.METALLUM, 8), getTcAspectStack(TC_Aspects.STRONTIO, 3))), + + Potin(42, TextureSet.SET_METALLIC, 7.0F, 5120, 2, 1 | 2 | 16 | 32 | 64 | 128, 201, 151, 129, 0, "Potin", 0, 0, + 3015, 2150, true, false, 1, 2, 1, Dyes.dyeLightBlue, 2, + Arrays.asList( + new MaterialStack(Materials.Tungsten, 1), + new MaterialStack(Materials.Tantalum, 9), + new MaterialStack(Materials.Titanium, 1)), + Arrays.asList(getTcAspectStack(TC_Aspects.METALLUM, 8), getTcAspectStack(TC_Aspects.STRONTIO, 3))), + Inconel792(43, TextureSet.SET_METALLIC, 7.0F, 5120, 2, 1 | 2 | 16 | 32 | 64 | 128, 108, 240, 118, 0, + "Inconel-792", 0, 0, 3015, 2150, true, false, 1, 2, 1, Dyes.dyeLightBlue, 2, + Arrays.asList( + new MaterialStack(Materials.Tungsten, 1), + new MaterialStack(Materials.Tantalum, 9), + new MaterialStack(Materials.Titanium, 1)), + Arrays.asList(getTcAspectStack(TC_Aspects.METALLUM, 8), getTcAspectStack(TC_Aspects.STRONTIO, 3))), + Inconel690(44, TextureSet.SET_DULL, 7.0F, 5120, 2, 1 | 2 | 16 | 32 | 64 | 128, 118, 220, 138, 0, "Inconel-690", + 0, 0, 3015, 2150, true, false, 1, 2, 1, Dyes.dyeLightBlue, 2, + Arrays.asList( + new MaterialStack(Materials.Tungsten, 1), + new MaterialStack(Materials.Tantalum, 9), + new MaterialStack(Materials.Titanium, 1)), + Arrays.asList(getTcAspectStack(TC_Aspects.METALLUM, 8), getTcAspectStack(TC_Aspects.STRONTIO, 3))), + MaragingSteel300(45, TextureSet.SET_METALLIC, 7.0F, 5120, 2, 1 | 2 | 16 | 32 | 64 | 128, 150, 150, 150, 0, + "Maraging Steel 300", 0, 0, 3015, 2150, true, false, 1, 2, 1, Dyes.dyeLightBlue, 2, + Arrays.asList( + new MaterialStack(Materials.Tungsten, 1), + new MaterialStack(Materials.Tantalum, 9), + new MaterialStack(Materials.Titanium, 1)), + Arrays.asList(getTcAspectStack(TC_Aspects.METALLUM, 8), getTcAspectStack(TC_Aspects.STRONTIO, 3))), + MaragingSteel350(46, TextureSet.SET_METALLIC, 7.0F, 5120, 2, 1 | 2 | 16 | 32 | 64 | 128, 160, 160, 160, 0, + "Maraging Steel 350", 0, 0, 3015, 2150, true, false, 1, 2, 1, Dyes.dyeLightBlue, 2, + Arrays.asList( + new MaterialStack(Materials.Tungsten, 1), + new MaterialStack(Materials.Tantalum, 9), + new MaterialStack(Materials.Titanium, 1)), + Arrays.asList(getTcAspectStack(TC_Aspects.METALLUM, 8), getTcAspectStack(TC_Aspects.STRONTIO, 3))), + HastelloyX(47, TextureSet.SET_SHINY, 7.0F, 5120, 2, 1 | 2 | 16 | 32 | 64 | 128, 255, 193, 37, 0, "Hastelloy-X", + 0, 0, 3015, 2150, true, false, 1, 2, 1, Dyes.dyeLightBlue, 2, + Arrays.asList( + new MaterialStack(Materials.Tungsten, 1), + new MaterialStack(Materials.Tantalum, 9), + new MaterialStack(Materials.Titanium, 1)), + Arrays.asList(getTcAspectStack(TC_Aspects.METALLUM, 8), getTcAspectStack(TC_Aspects.STRONTIO, 3))), + + TriniumNaquadahCarbonite(48, TextureSet.SET_SHINY, 7.0F, 5120, 2, 1 | 2 | 16 | 32 | 64 | 128, 255, 233, 0, 0, + "Trinium Naquadah Carbonite", 0, 0, 3015, 2150, true, false, 1, 2, 1, Dyes.dyeLightBlue, 2, + Arrays.asList( + new MaterialStack(Materials.Tungsten, 1), + new MaterialStack(Materials.Tantalum, 9), + new MaterialStack(Materials.Titanium, 1)), + Arrays.asList(getTcAspectStack(TC_Aspects.METALLUM, 8), getTcAspectStack(TC_Aspects.STRONTIO, 3))), + + // Radioactive Materials + HydrofluoricAcid(-1, TextureSet.SET_FLUID, 1.0F, 0, 1, 2 | 16 | 32, 200, 200, 200, 0, "Hydrofluoric Acid", 0, 0, + -1, 0, false, false, 2, 3, 1, Dyes.dyeWhite, 2, + Arrays.asList( + new MaterialStack(Materials.Coal, 1), + new MaterialStack(Materials.Redstone, 1), + new MaterialStack(Materials.Blaze, 1), + new MaterialStack(Materials.Sulfur, 1))), + UraniumHexaFluoride(-1, TextureSet.SET_FLUID, 1.0F, 0, 1, 2 | 16 | 32, 73, 220, 83, 0, "Uranium Hexafluoride", + 0, 0, -1, 0, false, false, 2, 3, 1, Dyes.dyeLime, 2, + Arrays.asList( + new MaterialStack(Materials.Coal, 1), + new MaterialStack(Materials.Redstone, 1), + new MaterialStack(Materials.Blaze, 1), + new MaterialStack(Materials.Sulfur, 1))), + UraniumTetraFluoride(-1, TextureSet.SET_FLUID, 1.0F, 0, 1, 2 | 16 | 32, 73, 220, 83, 0, "Uranium Tetrafluoride", + 0, 0, -1, 0, false, false, 2, 3, 1, Dyes.dyeLime, 2, + Arrays.asList( + new MaterialStack(Materials.Coal, 1), + new MaterialStack(Materials.Redstone, 1), + new MaterialStack(Materials.Blaze, 1), + new MaterialStack(Materials.Sulfur, 1))), + ThoriumTetraFluoride(-1, TextureSet.SET_FLUID, 1.0F, 0, 1, 2 | 16 | 32, 15, 120, 15, 0, "Thorium Tetrafluoride", + 0, 0, -1, 0, false, false, 2, 3, 1, Dyes.dyeGreen, 2, + Arrays.asList( + new MaterialStack(Materials.Coal, 1), + new MaterialStack(Materials.Redstone, 1), + new MaterialStack(Materials.Blaze, 1), + new MaterialStack(Materials.Sulfur, 1))), + + SulfurousAcid(-1, TextureSet.SET_FLUID, 1.0F, 0, 1, 2 | 16 | 32, 110, 220, 30, 0, "Sulfurous Acid", 0, 0, -1, 0, + false, false, 2, 3, 1, Dyes.dyeWhite, 2, + Arrays.asList( + new MaterialStack(Materials.Coal, 1), + new MaterialStack(Materials.Redstone, 1), + new MaterialStack(Materials.Blaze, 1), + new MaterialStack(Materials.Sulfur, 1))), + SulfurDioxide(-1, TextureSet.SET_FLUID, 1.0F, 0, 1, 2 | 16 | 32, 150, 200, 50, 0, "Sulfur Dioxide", 0, 0, -1, 0, + false, false, 2, 3, 1, Dyes.dyeWhite, 2, + Arrays.asList( + new MaterialStack(Materials.Coal, 1), + new MaterialStack(Materials.Redstone, 1), + new MaterialStack(Materials.Blaze, 1), + new MaterialStack(Materials.Sulfur, 1))), + HydrogenChloride(-1, TextureSet.SET_FLUID, 1.0F, 0, 1, 2 | 16 | 32, 150, 240, 90, 0, "Hydrogen Chloride", 0, 0, + -1, 0, false, false, 2, 3, 1, Dyes.dyeWhite, 2, + Arrays.asList( + new MaterialStack(Materials.Coal, 1), + new MaterialStack(Materials.Redstone, 1), + new MaterialStack(Materials.Blaze, 1), + new MaterialStack(Materials.Sulfur, 1))), + SulfuricApatite(-1, TextureSet.SET_FLUID, 1.0F, 0, 1, 2 | 16 | 32, 0, 105, 105, 0, "Sulfuric Apatite Solution", + 0, 0, -1, 0, false, false, 2, 3, 1, Dyes.dyeWhite, 2, + Arrays.asList( + new MaterialStack(Materials.Coal, 1), + new MaterialStack(Materials.Redstone, 1), + new MaterialStack(Materials.Blaze, 1), + new MaterialStack(Materials.Sulfur, 1))), + + SulfuricLithium(-1, TextureSet.SET_FLUID, 1.0F, 0, 1, 2 | 16 | 32, 0, 105, 105, 0, "Sulfuric Lithium Solution", + 0, 0, -1, 0, false, false, 2, 3, 1, Dyes.dyeWhite, 2, + Arrays.asList( + new MaterialStack(Materials.Coal, 1), + new MaterialStack(Materials.Redstone, 1), + new MaterialStack(Materials.Blaze, 1), + new MaterialStack(Materials.Sulfur, 1))), + LithiumHydroxide(-1, TextureSet.SET_FLUID, 1.0F, 0, 1, 2 | 16 | 32, 0, 105, 105, 0, "Lithium Hydroxide", 0, 0, + -1, 0, false, false, 2, 3, 1, Dyes.dyeWhite, 2, + Arrays.asList( + new MaterialStack(Materials.Coal, 1), + new MaterialStack(Materials.Redstone, 1), + new MaterialStack(Materials.Blaze, 1), + new MaterialStack(Materials.Sulfur, 1))),; + + /** + * List of all Materials. + */ + public static final Collection<GT_Materials> VALUES = new HashSet<>(Arrays.asList(values())); + + static { + /* + * Primitive.add(SubTag.NO_SMASHING, SubTag.NO_SMELTING); Basic.add(SubTag.NO_SMASHING, SubTag.NO_SMELTING); + * Good.add(SubTag.NO_SMASHING, SubTag.NO_SMELTING); Advanced.add(SubTag.NO_SMASHING, SubTag.NO_SMELTING); + * Data.add(SubTag.NO_SMASHING, SubTag.NO_SMELTING); Elite.add(SubTag.NO_SMASHING, SubTag.NO_SMELTING); + * Master.add(SubTag.NO_SMASHING, SubTag.NO_SMELTING); Ultimate.add(SubTag.NO_SMASHING, SubTag.NO_SMELTING); + * Superconductor.add(SubTag.NO_SMASHING, SubTag.NO_SMELTING); Infinite.add(SubTag.NO_SMASHING, + * SubTag.NO_SMELTING); + */ + Symbiotic.add(SubTag.NO_SMASHING, SubTag.NO_SMELTING); + Neutronic.add(SubTag.NO_SMASHING, SubTag.NO_SMELTING); + Quantum.add(SubTag.NO_SMASHING, SubTag.NO_SMELTING); + } + + /** + * This Array can be changed dynamically by a Tick Handler in order to get a glowing Effect on all GT Meta Items + * out of this Material. + */ + public final short[] mRGBa = new short[] { 255, 255, 255, 0 }, mMoltenRGBa = new short[] { 255, 255, 255, 0 }; + + public final TextureSet mIconSet; + public final int mMetaItemSubID; + public final boolean mUnificatable; + public final GT_Materials mMaterialInto; + public final List<MaterialStack> mMaterialList = new ArrayList<>(); + public final List<GT_Materials> mOreByProducts = new ArrayList<>(), mOreReRegistrations = new ArrayList<>(); + public final List<TC_AspectStack> mAspects = new ArrayList<>(); + private final ArrayList<ItemStack> mMaterialItems = new ArrayList<>(); + private final Collection<SubTag> mSubTags = new HashSet<>(); + public Enchantment mEnchantmentTools = null, mEnchantmentArmors = null; + public byte mEnchantmentToolsLevel = 0, mEnchantmentArmorsLevel = 0; + public boolean mBlastFurnaceRequired = false; + public float mToolSpeed = 1.0F, mHeatDamage = 0.0F; + public String mChemicalFormula = "?", mDefaultLocalName = "null"; + public Dyes mColor = Dyes._NULL; + public short mMeltingPoint = 0, mBlastFurnaceTemp = 0; + public int mTypes = 0, mDurability = 16, mFuelPower = 0, mFuelType = 0, mExtraData = 0, mOreValue = 0, + mOreMultiplier = 1, mByProductMultiplier = 1, mSmeltingMultiplier = 1; + public long mDensity = M; + public Element mElement = null; + public GT_Materials mDirectSmelting = this; + public GT_Materials mOreReplacement = this; + public GT_Materials mMacerateInto = this; + public GT_Materials mSmeltInto = this; + public GT_Materials mArcSmeltInto = this; + public final GT_Materials mHandleMaterial = this; + public byte mToolQuality = 0; + public final Fluid mSolid = null; + public Fluid mFluid = null; + public Fluid mGas = null; + public Fluid mPlasma = null; + /** + * This Fluid is used as standard Unit for Molten Materials. 1296 is a Molten Block, what means 144 is one + * Material Unit worth + */ + public final Fluid mStandardMoltenFluid = null; + + private GT_Materials(final int aMetaItemSubID, final TextureSet aIconSet, final float aToolSpeed, + final int aToolDurability, final int aToolQuality, final boolean aUnificatable) { + this.mUnificatable = aUnificatable; + this.mMaterialInto = this; + this.mMetaItemSubID = aMetaItemSubID; + this.mToolQuality = (byte) aToolQuality; + this.mDurability = aToolDurability; + this.mToolSpeed = aToolSpeed; + this.mIconSet = aIconSet; + if (aMetaItemSubID >= 0) { + if (CORE.sMU_GeneratedMaterials[aMetaItemSubID] == null) { + CORE.sMU_GeneratedMaterials[aMetaItemSubID] = this; + } else { + throw new IllegalArgumentException("The Index " + aMetaItemSubID + " is already used!"); + } + } + } + + private GT_Materials(final GT_Materials aMaterialInto, final boolean aReRegisterIntoThis) { + this.mUnificatable = false; + this.mDefaultLocalName = aMaterialInto.mDefaultLocalName; + this.mMaterialInto = aMaterialInto.mMaterialInto; + if (aReRegisterIntoThis) { + this.mMaterialInto.mOreReRegistrations.add(this); + } + this.mChemicalFormula = aMaterialInto.mChemicalFormula; + this.mMetaItemSubID = -1; + this.mIconSet = TextureSet.SET_NONE; + } + + /** + * @param aMetaItemSubID the Sub-ID used in my own MetaItems. Range 0-1000. -1 for no Material + * @param aTypes which kind of Items should be generated. Bitmask as follows: 1 = Dusts of all + * kinds. 2 = Dusts, Ingots, Plates, Rods/Sticks, Machine Components and other + * Metal specific things. 4 = Dusts, Gems, Plates, Lenses (if transparent). 8 = + * Dusts, Impure Dusts, crushed Ores, purified Ores, centrifuged Ores etc. 16 = + * Cells 32 = Plasma Cells 64 = Tool Heads 128 = Gears + * @param aR, aG, aB Color of the Material 0-255 each. + * @param aA transparency of the Material Texture. 0 = fully visible, 255 = Invisible. + * @param aLocalName The Name used as Default for localization. + * @param aFuelType Type of Generator to get Energy from this Material. + * @param aFuelPower EU generated. Will be multiplied by 1000, also additionally multiplied by 2 for + * Gems. + * @param aAmplificationValue Amount of UUM amplifier gotten from this. + * @param aUUMEnergy Amount of EU needed to shape the UUM into this Material. + * @param aMeltingPoint Used to determine the smelting Costs in Furnii. + * @param aBlastFurnaceTemp Used to determine the needed Heat capactiy Costs in Blast Furnii. + * @param aBlastFurnaceRequired If this requires a Blast Furnace. + * @param aColor Vanilla MC Wool Color which comes the closest to this. + */ + private GT_Materials(final int aMetaItemSubID, final TextureSet aIconSet, final float aToolSpeed, + final int aToolDurability, final int aToolQuality, final int aTypes, final int aR, final int aG, + final int aB, final int aA, final String aLocalName, final int aFuelType, final int aFuelPower, + final int aMeltingPoint, final int aBlastFurnaceTemp, final boolean aBlastFurnaceRequired, + final boolean aTransparent, final int aOreValue, final int aDensityMultiplier, final int aDensityDivider, + final Dyes aColor) { + this(aMetaItemSubID, aIconSet, aToolSpeed, aToolDurability, aToolQuality, true); + this.mDefaultLocalName = aLocalName; + this.mMeltingPoint = (short) aMeltingPoint; + this.mBlastFurnaceTemp = (short) aBlastFurnaceTemp; + this.mBlastFurnaceRequired = aBlastFurnaceRequired; + if (aTransparent) { + this.add(SubTag.TRANSPARENT); + } + this.mFuelPower = aFuelPower; + this.mFuelType = aFuelType; + this.mOreValue = aOreValue; + this.mDensity = (M * aDensityMultiplier) / aDensityDivider; + this.mColor = aColor == null ? Dyes._NULL : aColor; + if (this.mColor != null) { + this.add(SubTag.HAS_COLOR); + } + this.mRGBa[0] = this.mMoltenRGBa[0] = (short) aR; + this.mRGBa[1] = this.mMoltenRGBa[1] = (short) aG; + this.mRGBa[2] = this.mMoltenRGBa[2] = (short) aB; + this.mRGBa[3] = this.mMoltenRGBa[3] = (short) aA; + this.mTypes = aTypes; + if ((this.mTypes & 2) != 0) { + this.add(SubTag.SMELTING_TO_FLUID); + } + } + + private GT_Materials(final int aMetaItemSubID, final TextureSet aIconSet, final float aToolSpeed, + final int aToolDurability, final int aToolQuality, final int aTypes, final int aR, final int aG, + final int aB, final int aA, final String aLocalName, final int aFuelType, final int aFuelPower, + final int aMeltingPoint, final int aBlastFurnaceTemp, final boolean aBlastFurnaceRequired, + final boolean aTransparent, final int aOreValue, final int aDensityMultiplier, final int aDensityDivider, + final Dyes aColor, final List<TC_AspectStack> aAspects) { + this( + aMetaItemSubID, + aIconSet, + aToolSpeed, + aToolDurability, + aToolQuality, + aTypes, + aR, + aG, + aB, + aA, + aLocalName, + aFuelType, + aFuelPower, + aMeltingPoint, + aBlastFurnaceTemp, + aBlastFurnaceRequired, + aTransparent, + aOreValue, + aDensityMultiplier, + aDensityDivider, + aColor); + this.mAspects.addAll(aAspects); + } + + /** + * @param aElement The Element Enum represented by this Material + */ + private GT_Materials(final int aMetaItemSubID, final TextureSet aIconSet, final float aToolSpeed, + final int aToolDurability, final int aToolQuality, final int aTypes, final int aR, final int aG, + final int aB, final int aA, final String aLocalName, final int aFuelType, final int aFuelPower, + final int aMeltingPoint, final int aBlastFurnaceTemp, final boolean aBlastFurnaceRequired, + final boolean aTransparent, final int aOreValue, final int aDensityMultiplier, final int aDensityDivider, + final Dyes aColor, final Element aElement, final List<TC_AspectStack> aAspects) { + this( + aMetaItemSubID, + aIconSet, + aToolSpeed, + aToolDurability, + aToolQuality, + aTypes, + aR, + aG, + aB, + aA, + aLocalName, + aFuelType, + aFuelPower, + aMeltingPoint, + aBlastFurnaceTemp, + aBlastFurnaceRequired, + aTransparent, + aOreValue, + aDensityMultiplier, + aDensityDivider, + aColor); + this.mElement = aElement; + // mElement.mLinkedMaterials.add(this); + if (aElement == Element._NULL) { + this.mChemicalFormula = "Empty"; + } else { + this.mChemicalFormula = aElement.toString(); + this.mChemicalFormula = this.mChemicalFormula.replaceAll("_", "-"); + } + this.mAspects.addAll(aAspects); + } + + private GT_Materials(final int aMetaItemSubID, final TextureSet aIconSet, final float aToolSpeed, + final int aToolDurability, final int aToolQuality, final int aTypes, final int aR, final int aG, + final int aB, final int aA, final String aLocalName, final int aFuelType, final int aFuelPower, + final int aMeltingPoint, final int aBlastFurnaceTemp, final boolean aBlastFurnaceRequired, + final boolean aTransparent, final int aOreValue, final int aDensityMultiplier, final int aDensityDivider, + final Dyes aColor, final int aExtraData, final List<MaterialStack> aMaterialList) { + this( + aMetaItemSubID, + aIconSet, + aToolSpeed, + aToolDurability, + aToolQuality, + aTypes, + aR, + aG, + aB, + aA, + aLocalName, + aFuelType, + aFuelPower, + aMeltingPoint, + aBlastFurnaceTemp, + aBlastFurnaceRequired, + aTransparent, + aOreValue, + aDensityMultiplier, + aDensityDivider, + aColor, + aExtraData, + aMaterialList, + null); + } + + private GT_Materials(final int aMetaItemSubID, final TextureSet aIconSet, final float aToolSpeed, + final int aToolDurability, final int aToolQuality, final int aTypes, final int aR, final int aG, + final int aB, final int aA, final String aLocalName, final int aFuelType, final int aFuelPower, + final int aMeltingPoint, final int aBlastFurnaceTemp, final boolean aBlastFurnaceRequired, + final boolean aTransparent, final int aOreValue, final int aDensityMultiplier, final int aDensityDivider, + final Dyes aColor, final int aExtraData, final List<MaterialStack> aMaterialList, + final List<TC_AspectStack> aAspects) { + this( + aMetaItemSubID, + aIconSet, + aToolSpeed, + aToolDurability, + aToolQuality, + aTypes, + aR, + aG, + aB, + aA, + aLocalName, + aFuelType, + aFuelPower, + aMeltingPoint, + aBlastFurnaceTemp, + aBlastFurnaceRequired, + aTransparent, + aOreValue, + aDensityMultiplier, + aDensityDivider, + aColor); + this.mExtraData = aExtraData; + this.mMaterialList.addAll(aMaterialList); + this.mChemicalFormula = ""; + for (final MaterialStack tMaterial : this.mMaterialList) { + this.mChemicalFormula += tMaterial.toString(); + } + this.mChemicalFormula = this.mChemicalFormula.replaceAll("_", "-"); + + int tAmountOfComponents = 0, tMeltingPoint = 0; + for (final MaterialStack tMaterial : this.mMaterialList) { + tAmountOfComponents += tMaterial.mAmount; + if (tMaterial.mMaterial.mMeltingPoint > 0) { + tMeltingPoint += tMaterial.mMaterial.mMeltingPoint * tMaterial.mAmount; + } + if (aAspects == null) { + for (final TC_AspectStack tAspect : tMaterial.mMaterial.mAspects) { + tAspect.addToAspectList(this.mAspects); + } + } + } + + if (this.mMeltingPoint < 0) { + this.mMeltingPoint = (short) (tMeltingPoint / tAmountOfComponents); + } + + tAmountOfComponents *= aDensityMultiplier; + tAmountOfComponents /= aDensityDivider; + if (aAspects == null) { + for (final TC_AspectStack tAspect : this.mAspects) { + tAspect.mAmount = Math.max(1, tAspect.mAmount / Math.max(1, tAmountOfComponents)); + } + } else { + this.mAspects.addAll(aAspects); + } + } + + public static GT_Materials get(final String aMaterialName) { + final Object tObject = GT_Utility.getFieldContent(GT_Materials.class, aMaterialName, false, false); + if ((tObject != null) && (tObject instanceof GT_Materials)) { + return (GT_Materials) tObject; + } + return _NULL; + } + + public static GT_Materials getRealMaterial(final String aMaterialName) { + return get(aMaterialName).mMaterialInto; + } + + /** + * Called in preInit with the Config to set Values. + * + * @param aConfiguration + */ + public static void init(final GT_Config aConfiguration) { + for (final GT_Materials tMaterial : VALUES) { + final String tString = tMaterial.toString() + .toLowerCase(); + tMaterial.mHeatDamage = (float) aConfiguration + .get(ConfigCategories.Materials.heatdamage, tString, tMaterial.mHeatDamage); + if (tMaterial.mBlastFurnaceRequired) { + tMaterial.mBlastFurnaceRequired = aConfiguration + .get(ConfigCategories.Materials.blastfurnacerequirements, tString, true); + } + if (tMaterial.mBlastFurnaceRequired && aConfiguration.get( + ConfigCategories.Materials.blastinductionsmelter, + tString, + tMaterial.mBlastFurnaceTemp < 1500)) {} + } + } + + public boolean isRadioactive() { + if (this.mElement != null) { + return this.mElement.mHalfLifeSeconds >= 0; + } + for (final MaterialStack tMaterial : this.mMaterialList) { + if (tMaterial.mMaterial.isRadioactive()) { + return true; + } + } + return false; + } + + public long getProtons() { + if (this.mElement != null) { + return this.mElement.getProtons(); + } + if (this.mMaterialList.size() <= 0) { + return Element.Tc.getProtons(); + } + long rAmount = 0, tAmount = 0; + for (final MaterialStack tMaterial : this.mMaterialList) { + tAmount += tMaterial.mAmount; + rAmount += tMaterial.mAmount * tMaterial.mMaterial.getProtons(); + } + return (this.getDensity() * rAmount) / (tAmount * M); + } + + public long getNeutrons() { + if (this.mElement != null) { + return this.mElement.getNeutrons(); + } + if (this.mMaterialList.size() <= 0) { + return Element.Tc.getNeutrons(); + } + long rAmount = 0, tAmount = 0; + for (final MaterialStack tMaterial : this.mMaterialList) { + tAmount += tMaterial.mAmount; + rAmount += tMaterial.mAmount * tMaterial.mMaterial.getNeutrons(); + } + return (this.getDensity() * rAmount) / (tAmount * M); + } + + public long getMass() { + if (this.mElement != null) { + return this.mElement.getMass(); + } + if (this.mMaterialList.size() <= 0) { + return Element.Tc.getMass(); + } + long rAmount = 0, tAmount = 0; + for (final MaterialStack tMaterial : this.mMaterialList) { + tAmount += tMaterial.mAmount; + rAmount += tMaterial.mAmount * tMaterial.mMaterial.getMass(); + } + return (this.getDensity() * rAmount) / (tAmount * M); + } + + public long getDensity() { + return this.mDensity; + } + + public String getToolTip() { + return this.getToolTip(1, false); + } + + public String getToolTip(final boolean aShowQuestionMarks) { + return this.getToolTip(1, aShowQuestionMarks); + } + + public String getToolTip(final long aMultiplier) { + return this.getToolTip(aMultiplier, false); + } + + public String getToolTip(final long aMultiplier, final boolean aShowQuestionMarks) { + if (!aShowQuestionMarks && this.mChemicalFormula.equals("?")) { + return ""; + } + if ((aMultiplier >= (M * 2)) && !this.mMaterialList.isEmpty()) { + return (((this.mElement != null) + || ((this.mMaterialList.size() < 2) && (this.mMaterialList.get(0).mAmount == 1))) + ? this.mChemicalFormula + : "(" + this.mChemicalFormula + ")") + + aMultiplier; + } + return this.mChemicalFormula; + } + + /** + * Adds an ItemStack to this Material. + */ + public GT_Materials add(final ItemStack aStack) { + if ((aStack != null) && !this.contains(aStack)) { + this.mMaterialItems.add(aStack); + } + return this; + } + + /** + * This is used to determine if any of the ItemStacks belongs to this Material. + */ + public boolean contains(final ItemStack... aStacks) { + if ((aStacks == null) || (aStacks.length <= 0)) { + return false; + } + for (final ItemStack tStack : this.mMaterialItems) { + for (final ItemStack aStack : aStacks) { + if (GT_Utility.areStacksEqual(aStack, tStack, !tStack.hasTagCompound())) { + return true; + } + } + } + return false; + } + + /** + * This is used to determine if an ItemStack belongs to this Material. + */ + public boolean remove(final ItemStack aStack) { + if (aStack == null) { + return false; + } + boolean temp = false; + for (int i = 0; i < this.mMaterialItems.size(); i++) { + if (GT_Utility.areStacksEqual(aStack, this.mMaterialItems.get(i))) { + this.mMaterialItems.remove(i--); + temp = true; + } + } + return temp; + } + + /** + * Adds a SubTag to this Material + */ + @Override + public ISubTagContainer add(final SubTag... aTags) { + if (aTags != null) { + for (final SubTag aTag : aTags) { + if ((aTag != null) && !this.contains(aTag)) { + aTag.addContainerToList(this); + this.mSubTags.add(aTag); + } + } + } + return this; + } + + /** + * If this Material has this exact SubTag + */ + @Override + public boolean contains(final SubTag aTag) { + return this.mSubTags.contains(aTag); + } + + /** + * Removes a SubTag from this Material + */ + @Override + public boolean remove(final SubTag aTag) { + return this.mSubTags.remove(aTag); + } + + /** + * Sets the Heat Damage for this Material (negative = frost) + */ + public GT_Materials setHeatDamage(final float aHeatDamage) { + this.mHeatDamage = aHeatDamage; + return this; + } + + /** + * Adds a Material to the List of Byproducts when grinding this Ore. Is used for more precise Ore grinding, so + * that it is possible to choose between certain kinds of Materials. + */ + public GT_Materials addOreByProduct(final GT_Materials aMaterial) { + if (!this.mOreByProducts.contains(aMaterial.mMaterialInto)) { + this.mOreByProducts.add(aMaterial.mMaterialInto); + } + return this; + } + + /** + * Adds multiple Materials to the List of Byproducts when grinding this Ore. Is used for more precise Ore + * grinding, so that it is possible to choose between certain kinds of Materials. + */ + public GT_Materials addOreByProducts(final GT_Materials... aMaterials) { + for (final GT_Materials tMaterial : aMaterials) { + if (tMaterial != null) { + this.addOreByProduct(tMaterial); + } + } + return this; + } + + /** + * If this Ore gives multiple drops of its Main Material. Lapis Ore for example gives about 6 drops. + */ + public GT_Materials setOreMultiplier(final int aOreMultiplier) { + if (aOreMultiplier > 0) { + this.mOreMultiplier = aOreMultiplier; + } + return this; + } + + /** + * If this Ore gives multiple drops of its Byproduct Material. + */ + public GT_Materials setByProductMultiplier(final int aByProductMultiplier) { + if (aByProductMultiplier > 0) { + this.mByProductMultiplier = aByProductMultiplier; + } + return this; + } + + /** + * If this Ore gives multiple drops of its Main Material. Lapis Ore for example gives about 6 drops. + */ + public GT_Materials setSmeltingMultiplier(final int aSmeltingMultiplier) { + if (aSmeltingMultiplier > 0) { + this.mSmeltingMultiplier = aSmeltingMultiplier; + } + return this; + } + + /** + * This Ore should be smolten directly into an Ingot of this Material instead of an Ingot of itself. + */ + public GT_Materials setDirectSmelting(final GT_Materials aMaterial) { + if (aMaterial != null) { + this.mDirectSmelting = aMaterial.mMaterialInto.mDirectSmelting; + } + return this; + } + + /** + * This Material should be the Main Material this Ore gets ground into. Example, Chromite giving Chrome or + * Tungstate giving Tungsten. + */ + public GT_Materials setOreReplacement(final GT_Materials aMaterial) { + if (aMaterial != null) { + this.mOreReplacement = aMaterial.mMaterialInto.mOreReplacement; + } + return this; + } + + /** + * This Material smelts always into an instance of aMaterial. Used for Magnets. + */ + public GT_Materials setSmeltingInto(final GT_Materials aMaterial) { + if (aMaterial != null) { + this.mSmeltInto = aMaterial.mMaterialInto.mSmeltInto; + } + return this; + } + + /** + * This Material arc smelts always into an instance of aMaterial. Used for Wrought Iron. + */ + public GT_Materials setArcSmeltingInto(final GT_Materials aMaterial) { + if (aMaterial != null) { + this.mArcSmeltInto = aMaterial.mMaterialInto.mArcSmeltInto; + } + return this; + } + + /** + * This Material macerates always into an instance of aMaterial. + */ + public GT_Materials setMaceratingInto(final GT_Materials aMaterial) { + if (aMaterial != null) { + this.mMacerateInto = aMaterial.mMaterialInto.mMacerateInto; + } + return this; + } + + public GT_Materials setEnchantmentForTools(final Enchantment aEnchantment, final int aEnchantmentLevel) { + this.mEnchantmentTools = aEnchantment; + this.mEnchantmentToolsLevel = (byte) aEnchantmentLevel; + return this; + } + + public GT_Materials setEnchantmentForArmors(final Enchantment aEnchantment, final int aEnchantmentLevel) { + this.mEnchantmentArmors = aEnchantment; + this.mEnchantmentArmorsLevel = (byte) aEnchantmentLevel; + return this; + } + + public FluidStack getSolid(final long aAmount) { + if (this.mSolid == null) { + return null; + } + return new FluidStack(this.mSolid, (int) aAmount); + } + + public FluidStack getFluid(final long aAmount) { + if (this.mFluid == null) { + return null; + } + return new FluidStack(this.mFluid, (int) aAmount); + } + + public FluidStack getGas(final long aAmount) { + if (this.mGas == null) { + return null; + } + return new FluidStack(this.mGas, (int) aAmount); + } + + public FluidStack getPlasma(final long aAmount) { + if (this.mPlasma == null) { + return null; + } + return new FluidStack(this.mPlasma, (int) aAmount); + } + + public FluidStack getMolten(final long aAmount) { + if (this.mStandardMoltenFluid == null) { + return null; + } + return new FluidStack(this.mStandardMoltenFluid, (int) aAmount); + } + + @Override + public short[] getRGBA() { + return this.mRGBa; + } + + public static final int VERSION = 508; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/enums/GregtechToolDictNames.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/enums/GregtechToolDictNames.java new file mode 100644 index 0000000000..0a116b1b9f --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/enums/GregtechToolDictNames.java @@ -0,0 +1,9 @@ +package gtPlusPlus.xmod.gregtech.api.enums; + +public enum GregtechToolDictNames { + craftingToolHandPump, + craftingToolAngleGrinder, + craftingToolElectricSnips, + craftingToolElectricLighter, + craftingToolElectricButcherKnife; +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/gui/GTPP_UITextures.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/gui/GTPP_UITextures.java new file mode 100644 index 0000000000..e6276713f3 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/gui/GTPP_UITextures.java @@ -0,0 +1,139 @@ +package gtPlusPlus.xmod.gregtech.api.gui; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +import com.gtnewhorizons.modularui.api.drawable.AdaptableUITexture; +import com.gtnewhorizons.modularui.api.drawable.UITexture; + +public class GTPP_UITextures { + + public static final UITexture OVERLAY_SLOT_COAL = UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_slot/coal"); + public static final UITexture OVERLAY_SLOT_CANISTER_DARK = UITexture + .fullImage(GTPlusPlus.ID, "gui/overlay_slot/canister_dark"); + + public static final AdaptableUITexture BACKGROUND_YELLOW = AdaptableUITexture + .of(GTPlusPlus.ID, "gui/background/yellow", 176, 166, 4); + + public static final AdaptableUITexture SLOT_ITEM_YELLOW = AdaptableUITexture + .of(GTPlusPlus.ID, "gui/slot/item_yellow", 18, 18, 1); + public static final AdaptableUITexture[] SLOT_INVENTORY_MANAGER = new AdaptableUITexture[] { + AdaptableUITexture.of(GTPlusPlus.ID, "gui/slot/red", 18, 18, 1), + AdaptableUITexture.of(GTPlusPlus.ID, "gui/slot/green", 18, 18, 1), + AdaptableUITexture.of(GTPlusPlus.ID, "gui/slot/blue", 18, 18, 1), + AdaptableUITexture.of(GTPlusPlus.ID, "gui/slot/cyan", 18, 18, 1), + AdaptableUITexture.of(GTPlusPlus.ID, "gui/slot/magenta", 18, 18, 1), + AdaptableUITexture.of(GTPlusPlus.ID, "gui/slot/yellow", 18, 18, 1), }; + + public static final UITexture BUTTON_STANDARD_BRONZE = UITexture + .fullImage(GTPlusPlus.ID, "gui/button/standard_bronze"); + + public static final UITexture OVERLAY_SLOT_WEED_EX = UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_slot/weed_ex"); + public static final UITexture OVERLAY_SLOT_FERTILIZER = UITexture + .fullImage(GTPlusPlus.ID, "gui/overlay_slot/fertilizer"); + public static final UITexture OVERLAY_SLOT_ELECTRIC_TOOL = UITexture + .fullImage(GTPlusPlus.ID, "gui/overlay_slot/electric_tool"); + public static final UITexture OVERLAY_SLOT_PAGE_PRINTED_BRONZE = UITexture + .fullImage(GTPlusPlus.ID, "gui/overlay_slot/page_printed_bronze"); + public static final UITexture OVERLAY_SLOT_ARROW = UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_slot/arrow"); + public static final UITexture OVERLAY_SLOT_ARROW_BRONZE = UITexture + .fullImage(GTPlusPlus.ID, "gui/overlay_slot/arrow_bronze"); + public static final UITexture OVERLAY_SLOT_CRAFT_OUTPUT = UITexture + .fullImage(GTPlusPlus.ID, "gui/overlay_slot/craft_output"); + public static final UITexture OVERLAY_SLOT_CRAFT_OUTPUT_BRONZE = UITexture + .fullImage(GTPlusPlus.ID, "gui/overlay_slot/craft_output_bronze"); + public static final UITexture OVERLAY_SLOT_PARK = UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_slot/park"); + public static final UITexture OVERLAY_SLOT_PARK_BRONZE = UITexture + .fullImage(GTPlusPlus.ID, "gui/overlay_slot/park_bronze"); + public static final UITexture OVERLAY_SLOT_INGOT = UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_slot/ingot"); + public static final UITexture OVERLAY_SLOT_ARROW_4 = UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_slot/arrow_4"); + public static final UITexture OVERLAY_SLOT_TURBINE = UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_slot/turbine"); + public static final UITexture OVERLAY_SLOT_CHEST = UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_slot/chest"); + public static final UITexture[] OVERLAY_SLOT_INVENTORY_MANAGER_COLOR = new UITexture[] { + UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_slot/red"), + UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_slot/green"), + UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_slot/blue"), + UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_slot/cyan"), + UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_slot/magenta"), + UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_slot/yellow"), }; + public static final UITexture[] OVERLAY_SLOT_INVENTORY_MANAGER_ARROW = new UITexture[] { + UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_slot/arrow_red"), + UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_slot/arrow_green"), + UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_slot/arrow_blue"), + UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_slot/arrow_cyan"), + UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_slot/arrow_magenta"), + UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_slot/arrow_yellow"), }; + + public static final UITexture PROGRESSBAR_FLUID_REACTOR = UITexture + .fullImage(GTPlusPlus.ID, "gui/progressbar/fluid_reactor"); + public static final UITexture PROGRESSBAR_BOILER_EMPTY = UITexture + .fullImage(GTPlusPlus.ID, "gui/progressbar/boiler_empty"); + public static final UITexture PROGRESSBAR_FUEL = UITexture.fullImage(GTPlusPlus.ID, "gui/progressbar/fuel"); + public static final UITexture PROGRESSBAR_ARROW_2 = UITexture.fullImage(GTPlusPlus.ID, "gui/progressbar/arrow_2"); + public static final UITexture PROGRESSBAR_PSS_ENERGY = UITexture + .fullImage(GTPlusPlus.ID, "gui/progressbar/pss_energy"); + + public static final AdaptableUITexture TAB_TITLE_YELLOW = AdaptableUITexture + .of(GTPlusPlus.ID, "gui/tab/title_yellow", 28, 28, 4); + public static final AdaptableUITexture TAB_TITLE_ANGULAR_YELLOW = AdaptableUITexture + .of(GTPlusPlus.ID, "gui/tab/title_angular_yellow", 28, 28, 4); + public static final AdaptableUITexture TAB_TITLE_DARK_YELLOW = AdaptableUITexture + .of(GTPlusPlus.ID, "gui/tab/title_dark_yellow", 28, 28, 4); + + public static final UITexture OVERLAY_BUTTON_HARVESTER_MODE = UITexture + .fullImage(GTPlusPlus.ID, "gui/overlay_button/harvester_mode"); + public static final UITexture OVERLAY_BUTTON_HARVESTER_TOGGLE = UITexture + .fullImage(GTPlusPlus.ID, "gui/overlay_button/harvester_toggle"); + public static final UITexture OVERLAY_BUTTON_FLUSH = UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_button/flush"); + public static final UITexture OVERLAY_BUTTON_FLUSH_BRONZE = UITexture + .fullImage(GTPlusPlus.ID, "gui/overlay_button/flush_bronze"); + public static final UITexture OVERLAY_BUTTON_AUTOMATION = UITexture + .fullImage(GTPlusPlus.ID, "gui/overlay_button/automation"); + public static final UITexture OVERLAY_BUTTON_LOCK = UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_button/lock"); + public static final UITexture[] OVERLAY_BUTTON_THROUGHPUT = IntStream.range(0, 4) // GT_MetaTileEntity_ElectricAutoWorkbench#MAX_THROUGHPUT + .mapToObj(i -> UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_button/throughput_" + i)) + .collect(Collectors.toList()) + .toArray(new UITexture[0]); + public static final UITexture[] OVERLAY_BUTTON_MODE = IntStream.range(0, 10) // GT_MetaTileEntity_ElectricAutoWorkbench#MAX_MODES + .mapToObj(i -> UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_button/mode_" + i)) + .collect(Collectors.toList()) + .toArray(new UITexture[0]); + public static final UITexture[] OVERLAY_BUTTON_DIRECTION = new UITexture[] { + UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_button/bottom"), + UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_button/top"), + UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_button/north"), + UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_button/south"), + UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_button/west"), + UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_button/east"), }; + public static final UITexture[] OVERLAY_BUTTON_DIRECTION_GRAY = new UITexture[] { + UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_button/bottom_gray"), + UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_button/top_gray"), + UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_button/north_gray"), + UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_button/south_gray"), + UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_button/west_gray"), + UITexture.fullImage(GTPlusPlus.ID, "gui/overlay_button/east_gray"), }; + public static final UITexture OVERLAY_BUTTON_TIP_GREEN = UITexture + .fullImage(GTPlusPlus.ID, "gui/overlay_button/tip_green"); + public static final UITexture OVERLAY_BUTTON_TIP_RED = UITexture + .fullImage(GTPlusPlus.ID, "gui/overlay_button/tip_red"); + public static final UITexture OVERLAY_BUTTON_ACTIVE_STATE = UITexture + .fullImage(GTPlusPlus.ID, "gui/overlay_button/active_state"); + public static final UITexture OVERLAY_BUTTON_CHANGE_MODE = UITexture + .fullImage(GTPlusPlus.ID, "gui/overlay_button/change_mode"); + public static final UITexture OVERLAY_BUTTON_PLUS_MINUS = UITexture + .fullImage(GTPlusPlus.ID, "gui/overlay_button/plus_minus"); + + public static final UITexture PICTURE_WORKBENCH_CIRCLE = UITexture + .fullImage(GTPlusPlus.ID, "gui/picture/workbench_circle"); + public static final UITexture PICTURE_ARROW_WHITE_DOWN = UITexture + .fullImage(GTPlusPlus.ID, "gui/picture/arrow_white_down"); + public static final UITexture PICTURE_REDSTONE_CIRCUIT_SCREEN = UITexture + .fullImage(GTPlusPlus.ID, "gui/picture/redstone_circuit_screen"); + public static final UITexture PICTURE_ELECTRICITY_ERROR = UITexture + .fullImage(GTPlusPlus.ID, "gui/picture/electricity_error"); + public static final UITexture PICTURE_ELECTRICITY_FINE = UITexture + .fullImage(GTPlusPlus.ID, "gui/picture/electricity_fine"); + public static final UITexture PICTURE_ENERGY_FRAME = UITexture.fullImage(GTPlusPlus.ID, "gui/picture/energy_frame"); +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/gui/widget/ElectricSlotWidget.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/gui/widget/ElectricSlotWidget.java new file mode 100644 index 0000000000..e522d41799 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/gui/widget/ElectricSlotWidget.java @@ -0,0 +1,40 @@ +package gtPlusPlus.xmod.gregtech.api.gui.widget; + +import net.minecraft.item.ItemStack; + +import com.gtnewhorizons.modularui.api.forge.IItemHandlerModifiable; +import com.gtnewhorizons.modularui.common.internal.wrapper.BaseSlot; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; + +import gregtech.api.items.GT_MetaGenerated_Tool; +import ic2.api.info.Info; +import ic2.api.item.ElectricItem; +import ic2.api.item.IElectricItem; + +public class ElectricSlotWidget extends SlotWidget { + + public ElectricSlotWidget(IItemHandlerModifiable handler, int index) { + this(new BaseSlot(handler, index, false) { + + @Override + public int getSlotStackLimit() { + return 1; + } + }); + } + + private ElectricSlotWidget(BaseSlot slot) { + super(slot); + setFilter( + stack -> (accepts(stack)) || (stack.getItem() instanceof GT_MetaGenerated_Tool) + || (stack.getItem() instanceof IElectricItem)); + } + + private boolean accepts(final ItemStack stack) { + if (stack == null) { + return false; + } + return (Info.itemEnergy.getEnergyValue(stack) > 0.0D) + || (ElectricItem.manager.discharge(stack, (1.0D / 0.0D), 4, true, true, true) > 0.0D); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/interfaces/GregtechItemContainer.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/interfaces/GregtechItemContainer.java new file mode 100644 index 0000000000..9431739c45 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/interfaces/GregtechItemContainer.java @@ -0,0 +1,40 @@ +package gtPlusPlus.xmod.gregtech.api.interfaces; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +public interface GregtechItemContainer { + + public Item getItem(); + + public Block getBlock(); + + public boolean isStackEqual(Object aStack); + + public boolean isStackEqual(Object aStack, boolean aWildcard, boolean aIgnoreNBT); + + public ItemStack get(long aAmount, Object... aReplacements); + + public ItemStack getWildcard(long aAmount, Object... aReplacements); + + public ItemStack getUndamaged(long aAmount, Object... aReplacements); + + public ItemStack getAlmostBroken(long aAmount, Object... aReplacements); + + public ItemStack getWithDamage(long aAmount, long aMetaValue, Object... aReplacements); + + public GregtechItemContainer set(Item aItem); + + public GregtechItemContainer set(ItemStack aStack); + + public GregtechItemContainer registerOre(Object... aOreNames); + + public GregtechItemContainer registerWildcardAsOre(Object... aOreNames); + + public ItemStack getWithCharge(long aAmount, int aEnergy, Object... aReplacements); + + public ItemStack getWithName(long aAmount, String aDisplayName, Object... aReplacements); + + public boolean hasBeenSet(); +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/interfaces/internal/IGregtech_RecipeAdder.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/interfaces/internal/IGregtech_RecipeAdder.java new file mode 100644 index 0000000000..faa39dadc3 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/interfaces/internal/IGregtech_RecipeAdder.java @@ -0,0 +1,380 @@ +package gtPlusPlus.xmod.gregtech.api.interfaces.internal; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +import gregtech.api.enums.Materials; +import gtPlusPlus.core.material.Material; + +@SuppressWarnings("UnusedReturnValue") +public interface IGregtech_RecipeAdder { + + /** + * Adds a Coke Oven Recipe + * + * @param aInput1 = first Input (not null, and respects StackSize) + * @param aInput2 = second Input (can be null, and respects StackSize) + * @param aFluidOutput = Output of the Creosote (not null, and respects StackSize) + * @param aFluidInput = fluid Input (can be null, and respects StackSize) + * @param aOutput = Output of the Coal/coke (can be null, and respects StackSize) + * @param aDuration = Duration (must be >= 0) + * @param aEUt = EU needed for heating up (must be >= 0) + * @return true if the Recipe got added, otherwise false. + */ + boolean addCokeOvenRecipe(ItemStack aInput1, ItemStack aInput2, FluidStack aFluidInput, FluidStack aFluidOutput, + ItemStack aOutput, int aDuration, int aEUt); + + boolean addCokeOvenRecipe(int aCircuit, ItemStack aInput2, FluidStack[] aFluidInputs, FluidStack[] aFluidOutputs, + ItemStack[] aOutputs, int aDuration, int aEUt); + + boolean addCokeOvenRecipe(ItemStack aInput1, ItemStack aInput2, FluidStack[] aFluidInputs, + FluidStack[] aFluidOutputs, ItemStack[] aOutputs, int aDuration, int aEUt); + + /** + * Adds a Matter Fabricator Recipe + * + * @param aFluidOutput = Output of the UU-Matter (not null, and respects StackSize) + * @param aFluidInput = fluid Input (can be UU_Amp or null, and respects StackSize) + * @param aDuration = Duration (must be >= 0) + * @param aEUt = EU needed for heating up (must be >= 0) + * @return true if the Recipe got added, otherwise false. + */ + @Deprecated + boolean addMatterFabricatorRecipe(FluidStack aFluidInput, FluidStack aFluidOutput, int aDuration, int aEUt); + + /** + * Adds a Recipe for the Dehydrator. (up to 9 Outputs) + * + * @param aInput = ItemStack[] (not null, and respects StackSize) + * @param aFluidInput = fluid Input (can be UU_Amp or null, and respects StackSize) + * @param aFluidOutput = Output of the UU-Matter (not null, and respects StackSize) + * @param aOutputItems = ItemStack[] (not null, and respects StackSize) + * @param aChances = Output Change (can be == 0) + * @param aDuration = Duration (must be >= 0) + * @param aEUt = EU needed for heating up (must be >= 0) + * @return true if the Recipe got added, otherwise false. + */ + boolean addDehydratorRecipe(ItemStack[] aInput, FluidStack aFluidInput, FluidStack aFluidOutput, + ItemStack[] aOutputItems, int[] aChances, int aDuration, int aEUt); + + /** + * Adds a Recipe for the Alloy Blast Smelter. (up to 9 Inputs) + * + * @param aInput = ItemStack[] (not null, and respects StackSize) + * @param aOutput = Output of the Molten Metal (not null, and respects StackSize) + * @param aChance = Output Chance (can be == 0) + * @param aDuration = Duration (must be >= 0) + * @param aEUt = EU per tick needed for heating up (must be >= 0) + * @return true if the Recipe got added, otherwise false. + */ + + boolean addBlastSmelterRecipe(ItemStack[] aInput, FluidStack aOutput, int aChance, int aDuration, int aEUt); + + /** + * Adds a Recipe for the Alloy Blast Smelter. (up to 9 Inputs) + * + * @param aInput = ItemStack[] (not null, and respects StackSize) + * @param aInputFluid = Input of a fluid (can be null, and respects StackSize) + * @param aOutput = Output of the Molten Metal (not null, and respects StackSize) + * @param aChance = Output Chance (can be == 0) + * @param aDuration = Duration (must be >= 0) + * @param aEUt = EU per tick needed for heating up (must be >= 0) + * @return true if the Recipe got added, otherwise false. + */ + + boolean addBlastSmelterRecipe(ItemStack[] aInput, FluidStack aInputFluid, FluidStack aOutput, int aChance, + int aDuration, int aEUt); + + /** + * Adds a Recipe for the Alloy Blast Smelter. (up to 9 Inputs, More than 1 Fluids) + * + * @param aInput = ItemStack[] (not null, and respects StackSize) + * @param aInputFluid = FluidStack[] (can be null, and respects StackSize) + * @param aOutput = Output of the Molten Metal (not null, and respects StackSize) + * @param aChance = Output Chance (can be == 0) + * @param aDuration = Duration (must be >= 0) + * @param aEUt = EU per tick needed for heating up (must be >= 0) + * @return true if the Recipe got added, otherwise false. + */ + + boolean addBlastSmelterRecipe(ItemStack[] aInput, FluidStack[] aInputFluid, FluidStack aOutput, int aChance, + int aDuration, int aEUt); + + /** + * Adds a Recipe for the Alloy Blast Smelter. (up to 9 Inputs) + * + * @param aInput = ItemStack[] (not null, and respects StackSize) + * @param aInputFluid = Input of a fluid (can be null, and respects StackSize) + * @param aOutput = Output of the Molten Metal (not null, and respects StackSize) + * @param aOutputStack = Item Output (Can be null) + * @param aChance = Output Chance (can be == 0) + * @param aDuration = Duration (must be >= 0) + * @param aEUt = EU per tick needed for heating up (must be >= 0) + * @return true if the Recipe got added, otherwise false. + */ + + boolean addBlastSmelterRecipe(ItemStack[] aInput, FluidStack aInputFluid, FluidStack aOutput, + ItemStack[] aOutputStack, int[] aChance, int aDuration, int aEUt); + + boolean addBlastSmelterRecipe(ItemStack[] aInput, FluidStack aInputFluid, FluidStack aOutput, int aChance, + int aDuration, int aEUt, int aSpecialValue); + + boolean addBlastSmelterRecipe(ItemStack[] aInput, FluidStack aInputFluid, FluidStack aOutput, + ItemStack[] aOutputStack, int[] aChance, int aDuration, int aEUt, int aSpecialValue, boolean aOptimizeRecipe); + + /** + * Adds a Recipe for the Alloy Blast Smelter. (up to 9 Inputs, More than 1 fluids) + * + * @param aInput = ItemStack[] (not null, and respects StackSize) + * @param aInputFluid = FluidStack[] (can be null, and respects StackSize) + * @param aOutput = Output of the Molten Metal (not null, and respects StackSize) + * @param aOutputStack = Item Output (Can be null) + * @param aChance = Output Chance (can be == 0) + * @param aDuration = Duration (must be >= 0) + * @param aEUt = EU per tick needed for heating up (must be >= 0) + * @return true if the Recipe got added, otherwise false. + */ + + boolean addBlastSmelterRecipe(ItemStack[] aInput, FluidStack[] aInputFluid, FluidStack aOutput, + ItemStack[] aOutputStack, int[] aChance, int aDuration, int aEUt); + + boolean addBlastSmelterRecipe(ItemStack[] aInput, FluidStack[] aInputFluid, FluidStack aOutput, int aChance, + int aDuration, int aEUt, int aSpecialValue); + + boolean addBlastSmelterRecipe(ItemStack[] aInput, FluidStack[] aInputFluid, FluidStack aOutput, + ItemStack[] aOutputStack, int[] aChance, int aDuration, int aEUt, int aSpecialValue, boolean aOptimizeRecipe); + + /** + * Adds a Recipe for the LFTRr. (up to 9 Inputs) + * + * @param aInput = ItemStack[] (not null, and respects StackSize) + * @param aInputFluid = Input of a fluid (can be null, and respects StackSize) + * @param aOutput = Output of the Molten Salts (not null, and respects StackSize) + * @param aOutputStack = Item Output (Can be null) + * @param aChance = Output Chance (can be == 0) + * @param aDuration = Duration (must be >= 0) + * @param aEUt = EU per tick needed for heating up (must be >= 0) + * @param aSpecialValue = Power produced in EU/t per dynamo + * @return true if the Recipe got added, otherwise false. + */ + + boolean addBlastSmelterRecipe(ItemStack[] aInput, FluidStack aInputFluid, FluidStack aOutput, + ItemStack[] aOutputStack, int[] aChance, int aDuration, int aEUt, int aSpecialValue); + + /** + * Adds a Recipe for the Quantum Force Smelter (up to 9 Inputs) + * + * + **/ + boolean addQuantumTransformerRecipe(ItemStack[] aInput, FluidStack[] aFluidInput, FluidStack[] aFluidOutput, + ItemStack[] aOutputStack, int[] aChances, int aDuration, int aEUt, int aSpecialValue); + + /** + * Adds a Recipe for the LFTRr. (up to 9 Inputs, More than 1 fluids) + * + * @param aInput = ItemStack[] (not null, and respects StackSize) + * @param aInputFluid = FluidStack[] (can be null, and respects StackSize) + * @param aOutput = Output of the Molten Salts (not null, and respects StackSize) + * @param aOutputStack = Item Output (Can be null) + * @param aChance = Output Chance (can be == 0) + * @param aDuration = Duration (must be >= 0) + * @param aEUt = EU per tick needed for heating up (must be >= 0) + * @param aSpecialValue = Power produced in EU/t per dynamo + * @return true if the Recipe got added, otherwise false. + */ + @Deprecated + boolean addBlastSmelterRecipe(ItemStack[] aInput, FluidStack[] aInputFluid, FluidStack aOutput, + ItemStack[] aOutputStack, int[] aChance, int aDuration, int aEUt, int aSpecialValue); + + /** + * Adds a custom Semifluid fuel for the GT++ SemiFluid Generators. + * + * @param aFuelItem - A Fluidstack to be consumed. + * @param aFuelValue - Fuel value in thousands (1 = 1000) + * @return - Was the Fuel added? + */ + boolean addSemifluidFuel(FluidStack aFuelItem, int aFuelValue); + + /** + * Adds a custom Semifluid fuel for the GT++ SemiFluid Generators. + * + * @param aFuelItem - A Fluidstack to be consumed. + * @param aFuelValue - Fuel value in thousands (1 = 1000) + * @return - Was the Fuel added? + */ + boolean addSemifluidFuel(ItemStack aFuelItem, int aFuelValue); + + boolean addFissionFuel(FluidStack aInput1, FluidStack aInput2, FluidStack aInput3, FluidStack aInput4, + FluidStack aInput5, FluidStack aInput6, FluidStack aInput7, FluidStack aInput8, FluidStack aInput9, + FluidStack aOutput1, FluidStack aOutput2, int aDuration, int aEUt); + + boolean addFissionFuel(boolean aOptimise, FluidStack aInput1, FluidStack aInput2, FluidStack aInput3, + FluidStack aInput4, FluidStack aInput5, FluidStack aInput6, FluidStack aInput7, FluidStack aInput8, + FluidStack aInput9, FluidStack aOutput1, FluidStack aOutput2, int aDuration, int aEUt); + + boolean addCyclotronRecipe(ItemStack aInput, FluidStack aFluidInput, ItemStack[] aOutputs, FluidStack aFluidOutput, + int[] aChances, int aDuration, int aEUt, int aSpecialValue); + + boolean addCyclotronRecipe(ItemStack[] aInputs, FluidStack aFluidInput, ItemStack[] aOutput, + FluidStack aFluidOutput, int[] aChances, int aDuration, int aEUt, int aSpecialValue); + + @Deprecated + boolean addMixerRecipe(ItemStack aInput1, ItemStack aInput2, ItemStack aInput3, ItemStack aInput4, + FluidStack aFluidInput, FluidStack aFluidOutput, ItemStack aOutput1, ItemStack aOutput2, ItemStack aOutput3, + ItemStack aOutput4, int aDuration, int aEUt); + + boolean addMultiblockCentrifugeRecipe(ItemStack[] aInputs, FluidStack[] aFluidInputs, FluidStack[] aFluidOutputs, + ItemStack[] aOutputs, int[] aChances, int aDuration, int aEUtick, int aSpecial); + + boolean addMultiblockElectrolyzerRecipe(ItemStack[] aInputs, FluidStack[] aFluidInputs, FluidStack[] aFluidOutputs, + ItemStack[] aOutputs, int[] aChances, int aDuration, int aEUtick, int aSpecial); + + boolean addAdvancedFreezerRecipe(ItemStack[] aInputs, FluidStack[] aFluidInputs, FluidStack[] aFluidOutputs, + ItemStack[] aOutputs, int[] aChances, int aDuration, int aEUtick, int aSpecial); + + @Deprecated + boolean addSixSlotAssemblingRecipe(ItemStack[] aInputs, FluidStack aInputFluid, ItemStack aOutput1, int aDuration, + int aEUt); + + /** + * Adds an Assemblyline Recipe + * + * @param aInputs must be != null, 4-16 inputs + * @param aFluidInputs 0-4 fluids + * @param aOutput must be != null + * @param aDuration must be > 0 + * @param aEUt should be > 0 + */ + @Deprecated + boolean addAssemblylineRecipe(ItemStack aResearchItem, int aResearchTime, ItemStack[] aInputs, + FluidStack[] aFluidInputs, ItemStack aOutput, int aDuration, int aEUt); + + /** + * Adds a Assemblyline Recipe + * + * @param aInputs elements should be: ItemStack for single item; ItemStack[] for multiple equivalent items; + * {OreDict, amount} for oredict. + */ + @Deprecated + boolean addAssemblylineRecipe(ItemStack aResearchItem, int aResearchTime, Object[] aInputs, + FluidStack[] aFluidInputs, ItemStack aOutput1, int aDuration, int aEUt); + + @Deprecated + boolean addChemicalRecipe(ItemStack input1, ItemStack input2, FluidStack inputFluid, FluidStack outputFluid, + ItemStack output, int time, int eu); + + @Deprecated + boolean addChemicalRecipe(ItemStack input1, ItemStack input2, FluidStack inputFluid, FluidStack outputFluid, + ItemStack output, Object object, int time, int eu); + + @Deprecated + boolean addChemicalRecipe(ItemStack input1, ItemStack input2, FluidStack inputFluid, FluidStack outputFluid, + ItemStack output, ItemStack object, int time); + + @Deprecated + boolean addChemicalRecipe(ItemStack input1, ItemStack input2, int aCircuit, FluidStack inputFluid, + FluidStack outputFluid, ItemStack output, ItemStack output2, int time, int eu); + + @Deprecated + boolean addMultiblockChemicalRecipe(ItemStack[] itemStacks, FluidStack[] fluidStacks, FluidStack[] fluidStacks2, + ItemStack[] outputs, int time, int eu); + + @Deprecated + boolean addCompressorRecipe(ItemStack aInput1, ItemStack aOutput1, int aDuration, int aEUt); + + @Deprecated + boolean addBrewingRecipe(ItemStack aIngredient, FluidStack aInput, FluidStack aOutput, int aTime, int aEu, + boolean aHidden); + + @Deprecated + boolean addBrewingRecipe(int aCircuit, FluidStack aInput, FluidStack aOutput, int aTime, int aEu, boolean aHidden); + + @Deprecated + boolean addSmeltingAndAlloySmeltingRecipe(ItemStack aDust, ItemStack aOutput); + + @Deprecated + boolean addFluidExtractionRecipe(ItemStack input, FluidStack output, int aTime, int aEu); + + @Deprecated + boolean addFluidExtractionRecipe(ItemStack aContainer, ItemStack aFullContainer, FluidStack rFluidOut, int aTime, + int aEu); + + @Deprecated + boolean addFluidCannerRecipe(ItemStack aContainer, ItemStack aFullContainer, FluidStack rFluidIn); + + @Deprecated + boolean addFluidCannerRecipe(ItemStack aContainer, ItemStack aFullContainer, FluidStack rFluidIn, + FluidStack rFluidOut); + + @Deprecated + boolean addFluidCannerRecipe(ItemStack aContainer, ItemStack aFullContainer, FluidStack rFluidIn, + FluidStack rFluidOut, int aTime, int aEu); + + boolean addVacuumFurnaceRecipe(ItemStack aInput1, ItemStack aInput2, FluidStack aFluidInput, + FluidStack aFluidOutput, ItemStack aOutput1, ItemStack aOutput2, int aDuration, int aEUt, int aLevel); + + boolean addVacuumFurnaceRecipe(ItemStack[] aInputs, FluidStack[] aFluidInputs, ItemStack[] aOutputs, + FluidStack[] aFluidOutputs, int aDuration, int aEUt, int aLevel); + + @Deprecated + boolean addUvLaserRecipe(ItemStack aInput1, ItemStack aOutput, int time, long eu); + + boolean addChemicalPlantRecipe(ItemStack[] aInputs, FluidStack[] aInputFluids, ItemStack[] aOutputs, + FluidStack[] aFluidOutputs, int time, long eu, int aTier); + + boolean addChemicalPlantRecipe(ItemStack[] aInputs, FluidStack[] aInputFluids, ItemStack[] aOutputs, + FluidStack[] aFluidOutputs, int[] aChances, int time, long eu, int aTier); + + @Deprecated + boolean addBlastRecipe(ItemStack[] aInputs, FluidStack[] aInputFluids, ItemStack[] aOutputs, + FluidStack[] aFluidOutputs, int time, long eu, int aHeat); + + @Deprecated + boolean addPyrolyseRecipe(ItemStack aInput, FluidStack aFluidInput, int intCircuit, ItemStack aOutput, + FluidStack aFluidOutput, int aDuration, int aEUt); + + @Deprecated + boolean addExtractorRecipe(ItemStack aInput, ItemStack aOutput, int aDuration, int aEUt); + + @Deprecated + boolean addExtractorRecipe(ItemStack aInput, ItemStack aOutput, int aChance, int aDuration, int aEUt); + + @Deprecated + boolean addDistilleryRecipe(ItemStack aCircuit, FluidStack aInput, FluidStack aOutput, ItemStack aSolidOutput, + int aDuration, int aEUt, boolean aHidden); + + @Deprecated + boolean addPulverisationRecipe(final ItemStack aInput, ItemStack aOutput1, ItemStack aOutput2, + final ItemStack aOutput3); + + boolean addMillingRecipe(Materials aMat, int aEU); + + boolean addMillingRecipe(Material aMat, int aEU); + + boolean addFlotationRecipe(Materials aMat, ItemStack aXanthate, FluidStack[] aInputFluids, + FluidStack[] aOutputFluids, int aTime, int aEU); + + boolean addFlotationRecipe(Material aMat, ItemStack aXanthate, FluidStack[] aInputFluids, + FluidStack[] aOutputFluids, int aTime, int aEU); + + @Deprecated + boolean addpackagerRecipe(ItemStack aRecipeType, ItemStack aInput1, ItemStack aInput2, ItemStack aOutputStack1); + + boolean addFuelForRTG(ItemStack aFuelPellet, int aFuelDays, int aVoltage); + + boolean addColdTrapRecipe(int aCircuit, ItemStack aInput, FluidStack aFluidInput, ItemStack[] aOutputs, + int[] aChances, FluidStack aFluidOutput, int aTime, int aEU); + + boolean addReactorProcessingUnitRecipe(ItemStack aInput1, ItemStack aInput2, FluidStack aFluidInput, + ItemStack[] aOutputs, int[] aChances, FluidStack aFluidOutput, int aTime, int aEU); + + @Deprecated + boolean addFluidHeaterRecipe(ItemStack aCircuit, FluidStack aInput, FluidStack aOutput, int aDuration, int aEUt); + + @Deprecated + boolean addVacuumFreezerRecipe(ItemStack aInput, ItemStack aOutput, int aDuration, int aEU); + + boolean addMolecularTransformerRecipe(ItemStack aInput, ItemStack aOutput, int aDuration, int aEU); + + boolean addMolecularTransformerRecipe(ItemStack aInput, ItemStack aOutput, int aDuration, int aEU, int aAmps); +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/interfaces/internal/Interface_ItemBehaviour.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/interfaces/internal/Interface_ItemBehaviour.java new file mode 100644 index 0000000000..545a97288f --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/interfaces/internal/Interface_ItemBehaviour.java @@ -0,0 +1,46 @@ +package gtPlusPlus.xmod.gregtech.api.interfaces.internal; + +import java.util.List; + +import net.minecraft.dispenser.IBlockSource; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.projectile.EntityArrow; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +import gregtech.api.enums.SubTag; +import gtPlusPlus.xmod.gregtech.api.items.Gregtech_MetaItem_Base; + +public interface Interface_ItemBehaviour<E extends Item> { + + public boolean onLeftClickEntity(E aItem, ItemStack aStack, EntityPlayer aPlayer, Entity aEntity); + + public boolean onItemUse(E aItem, ItemStack aStack, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ, + int aSide, float hitX, float hitY, float hitZ); + + public boolean onItemUseFirst(E aItem, ItemStack aStack, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ, + int aSide, float hitX, float hitY, float hitZ); + + public ItemStack onItemRightClick(E aItem, ItemStack aStack, World aWorld, EntityPlayer aPlayer); + + public List<String> getAdditionalToolTips(E aItem, List<String> aList, ItemStack aStack); + + public void onUpdate(E aItem, ItemStack aStack, World aWorld, Entity aPlayer, int aTimer, boolean aIsInHand); + + public boolean isItemStackUsable(E aItem, ItemStack aStack); + + public boolean canDispense(E aItem, IBlockSource aSource, ItemStack aStack); + + public ItemStack onDispense(E aItem, IBlockSource aSource, ItemStack aStack); + + public boolean hasProjectile(Gregtech_MetaItem_Base aItem, SubTag aProjectileType, ItemStack aStack); + + public EntityArrow getProjectile(E aItem, SubTag aProjectileType, ItemStack aStack, World aWorld, double aX, + double aY, double aZ); + + public EntityArrow getProjectile(E aItem, SubTag aProjectileType, ItemStack aStack, World aWorld, + EntityLivingBase aEntity, float aSpeed); +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/interfaces/internal/Interface_OreRecipeRegistrator.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/interfaces/internal/Interface_OreRecipeRegistrator.java new file mode 100644 index 0000000000..6ae25525bd --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/interfaces/internal/Interface_OreRecipeRegistrator.java @@ -0,0 +1,24 @@ +package gtPlusPlus.xmod.gregtech.api.interfaces.internal; + +import net.minecraft.item.ItemStack; + +import gregtech.api.enums.Materials; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechOrePrefixes; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechOrePrefixes.GT_Materials; + +public interface Interface_OreRecipeRegistrator { + + /** + * Contains a Code Fragment, used in the OrePrefix to register Recipes. Better than using a switch/case, like I did + * before. + * + * @param aPrefix always != null + * @param aMaterial always != null, and can be == _NULL if the Prefix is Self Referencing or not Material based! + * @param aStack always != null + */ + public void registerOre(GregtechOrePrefixes aPrefix, GT_Materials aMaterial, String aOreDictName, String aModName, + ItemStack aStack); + + public void registerOre(GregtechOrePrefixes aPrefix, Materials aMaterial, String aOreDictName, String aModName, + ItemStack copyAmount); +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/interfaces/internal/Interface_ToolStats.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/interfaces/internal/Interface_ToolStats.java new file mode 100644 index 0000000000..97d952d4a1 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/interfaces/internal/Interface_ToolStats.java @@ -0,0 +1,202 @@ +package gtPlusPlus.xmod.gregtech.api.interfaces.internal; + +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.DamageSource; +import net.minecraftforge.event.world.BlockEvent; + +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.IToolStats; +import gregtech.api.items.GT_MetaGenerated_Tool; +import gtPlusPlus.xmod.gregtech.api.items.Gregtech_MetaTool; + +/** + * The Stats for GT Tools. Not including any Material Modifiers. + * <p/> + * And this is supposed to not have any ItemStack Parameters as these are generic Stats. + */ +public interface Interface_ToolStats extends IToolStats { + + /** + * Called when aPlayer crafts this Tool + */ + @Override + public void onToolCrafted(ItemStack aStack, EntityPlayer aPlayer); + + /** + * Called when this gets added to a Tool Item + */ + public void onStatsAddedToTool(Gregtech_MetaTool gregtech_MetaTool, int aID); + + /** + * @return Damage the Tool receives when breaking a Block. 100 is one Damage Point (or 100 EU). + */ + @Override + public int getToolDamagePerBlockBreak(); + + /** + * @return Damage the Tool receives when converting the drops of a Block. 100 is one Damage Point (or 100 EU). + */ + @Override + public int getToolDamagePerDropConversion(); + + /** + * @return Damage the Tool receives when being used as Container Item. 100 is one use, however it is usually 8 times + * more than normal. + */ + @Override + public int getToolDamagePerContainerCraft(); + + /** + * @return Damage the Tool receives when being used as Weapon, 200 is the normal Value, 100 for actual Weapons. + */ + @Override + public int getToolDamagePerEntityAttack(); + + /** + * @return Basic Quality of the Tool, 0 is normal. If increased, it will increase the general quality of all Tools + * of this Type. Decreasing is also possible. + */ + @Override + public int getBaseQuality(); + + /** + * @return The Damage Bonus for this Type of Tool against Mobs. 1.0F is normal punch. + */ + @Override + public float getBaseDamage(); + + /** + * @return This gets the Hurt Resistance time for Entities getting hit. (always does 1 as minimum) + */ + @Override + public int getHurtResistanceTime(int aOriginalHurtResistance, Entity aEntity); + + /** + * @return This is a multiplier for the Tool Speed. 1.0F = no special Speed. + */ + @Override + public float getSpeedMultiplier(); + + /** + * @return This is a multiplier for the Tool Speed. 1.0F = no special Durability. + */ + @Override + public float getMaxDurabilityMultiplier(); + + @Override + public DamageSource getDamageSource(EntityLivingBase aPlayer, Entity aEntity); + + @Override + public String getMiningSound(); + + @Override + public String getCraftingSound(); + + @Override + public String getEntityHitSound(); + + @Override + public String getBreakingSound(); + + @Override + public Enchantment[] getEnchantments(ItemStack aStack); + + @Override + public int[] getEnchantmentLevels(ItemStack aStack); + + /** + * @return If this Tool can be used for blocking Damage like a Sword. + */ + @Override + public boolean canBlock(); + + /** + * @return If this Tool can be used as an RC Crowbar. + */ + @Override + public boolean isCrowbar(); + + /** + * @return If this Tool can be used as an BC Wrench. + */ + @Override + public boolean isWrench(); + + /** + * @return If this Tool can be used as Weapon i.e. if that is the main purpose. + */ + @Override + public boolean isWeapon(); + + /** + * @return If this Tool is a Ranged Weapon. Return false at isWeapon unless you have a Blade attached to your + * Bow/Gun or something + */ + @Override + public boolean isRangedWeapon(); + + /** + * @return If this Tool can be used as Weapon i.e. if that is the main purpose. + */ + @Override + public boolean isMiningTool(); + + /** + * aBlock.getHarvestTool(aMetaData) can return the following Values for example. "axe", "pickaxe", "sword", + * "shovel", "hoe", "grafter", "saw", "wrench", "crowbar", "file", "hammer", "plow", "plunger", "scoop", + * "screwdriver", "sense", "scythe", "softhammer", "cutter", "plasmatorch" + * + * @return If this is a minable Block. Tool Quality checks (like Diamond Tier or something) are separate from this + * check. + */ + @Override + public boolean isMinableBlock(Block aBlock, byte aMetaData); + + /** + * This lets you modify the Drop List, when this type of Tool has been used. + * + * @return the Amount of modified Items. + */ + @Override + public int convertBlockDrops(List<ItemStack> aDrops, ItemStack aStack, EntityPlayer aPlayer, Block aBlock, int aX, + int aY, int aZ, byte aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent); + + /** + * @return Returns a broken Version of the Item. + */ + @Override + public ItemStack getBrokenItem(ItemStack aStack); + + /** + * @return the Damage actually done to the Mob. + */ + @Override + public float getNormalDamageAgainstEntity(float aOriginalDamage, Entity aEntity, ItemStack aStack, + EntityPlayer aPlayer); + + /** + * @return the Damage actually done to the Mob. + */ + @Override + public float getMagicDamageAgainstEntity(float aOriginalDamage, Entity aEntity, ItemStack aStack, + EntityPlayer aPlayer); + + @Override + public IIconContainer getIcon(boolean aIsToolHead, ItemStack aStack); + + @Override + public short[] getRGBa(boolean aIsToolHead, ItemStack aStack); + + /** + * Called when this gets added to a Tool Item + */ + @Override + public void onStatsAddedToTool(GT_MetaGenerated_Tool aItem, int aID); +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/items/Gregtech_Generic_Item.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/items/Gregtech_Generic_Item.java new file mode 100644 index 0000000000..3ad04ab014 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/items/Gregtech_Generic_Item.java @@ -0,0 +1,204 @@ +package gtPlusPlus.xmod.gregtech.api.items; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.List; + +import net.minecraft.block.BlockDispenser; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.dispenser.BehaviorDefaultDispenseItem; +import net.minecraft.dispenser.BehaviorProjectileDispense; +import net.minecraft.dispenser.IBlockSource; +import net.minecraft.dispenser.IPosition; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.IProjectile; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.projectile.EntityArrow; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumFacing; +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.SubTag; +import gregtech.api.interfaces.IProjectileItem; +import gregtech.api.util.GT_LanguageManager; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.util.Utils; + +/** + * Extended by most Items, also used as a fallback Item, to prevent the accidental deletion when Errors occur. + */ +public class Gregtech_Generic_Item extends Item implements IProjectileItem { + + private final String mName, mTooltip; + protected IIcon mIcon; + + public Gregtech_Generic_Item(final String aUnlocalized, final String aEnglish, final String aEnglishTooltip) { + this(aUnlocalized, aEnglish, aEnglishTooltip, true); + } + + public Gregtech_Generic_Item(final String aUnlocalized, final String aEnglish, final String aEnglishTooltip, + final boolean aWriteToolTipIntoLangFile) { + super(); + this.mName = aUnlocalized; + GT_LanguageManager.addStringLocalization(this.mName + ".name", aEnglish); + if (GT_Utility.isStringValid(aEnglishTooltip)) { + GT_LanguageManager.addStringLocalization( + this.mTooltip = this.mName + ".tooltip_main", + aEnglishTooltip, + aWriteToolTipIntoLangFile); + } else { + this.mTooltip = null; + } + this.setCreativeTab(AddToCreativeTab.tabMachines); + GameRegistry.registerItem(this, this.mName, GTPlusPlus.ID); + BlockDispenser.dispenseBehaviorRegistry.putObject(this, new GT_Item_Dispense()); + } + + @Override + public final Item setUnlocalizedName(final String aName) { + return this; + } + + @Override + public final String getUnlocalizedName() { + return this.mName; + } + + @Override + public String getUnlocalizedName(final ItemStack aStack) { + return this.getHasSubtypes() ? this.mName + "." + this.getDamage(aStack) : this.mName; + } + + @Override + @SideOnly(Side.CLIENT) + public void registerIcons(final IIconRegister aIconRegister) { + this.mIcon = aIconRegister.registerIcon(GTPlusPlus.ID + ":" + this.mName); + } + + @Override + public boolean doesSneakBypassUse(final World aWorld, final int aX, final int aY, final int aZ, + final EntityPlayer aPlayer) { + return true; + } + + @Override + public IIcon getIconFromDamage(final int par1) { + return this.mIcon; + } + + public int getTier(final ItemStack aStack) { + return 0; + } + + @Override + public void addInformation(final ItemStack aStack, final EntityPlayer aPlayer, final List aList, + final boolean aF3_H) { + if ((this.getMaxDamage() > 0) && !this.getHasSubtypes()) { + aList.add((aStack.getMaxDamage() - this.getDamage(aStack)) + " / " + aStack.getMaxDamage()); + } + if (this.mTooltip != null) { + aList.add(GT_LanguageManager.getTranslation(this.mTooltip)); + } + if (GT_ModHandler.isElectricItem(aStack)) { + aList.add("Tier: " + this.getTier(aStack)); + } + this.addAdditionalToolTips(aList, aStack); + } + + protected void addAdditionalToolTips(final List aList, final ItemStack aStack) { + // + } + + @Override + public void onCreated(final ItemStack aStack, final World aWorld, final EntityPlayer aPlayer) { + this.isItemStackUsable(aStack); + } + + public boolean isItemStackUsable(final ItemStack aStack) { + return true; + } + + public ItemStack onDispense(final IBlockSource aSource, final ItemStack aStack) { + final EnumFacing enumfacing = BlockDispenser.func_149937_b(aSource.getBlockMetadata()); + final IPosition iposition = BlockDispenser.func_149939_a(aSource); + final ItemStack itemstack1 = aStack.splitStack(1); + BehaviorDefaultDispenseItem.doDispense(aSource.getWorld(), itemstack1, 6, enumfacing, iposition); + return aStack; + } + + @Override + public EntityArrow getProjectile(final SubTag aProjectileType, final ItemStack aStack, final World aWorld, + final double aX, final double aY, final double aZ) { + return null; + } + + @Override + public EntityArrow getProjectile(final SubTag aProjectileType, final ItemStack aStack, final World aWorld, + final EntityLivingBase aEntity, final float aSpeed) { + return null; + } + + @Override + public boolean hasProjectile(final SubTag aProjectileType, final ItemStack aStack) { + return false; + } + + @Override + public ItemStack getContainerItem(final ItemStack aStack) { + return null; + } + + @Override + public boolean hasContainerItem(final ItemStack aStack) { + return this.getContainerItem(aStack) != null; + } + + public static class GT_Item_Dispense extends BehaviorProjectileDispense { + + @Override + public ItemStack dispenseStack(final IBlockSource aSource, final ItemStack aStack) { + return ((Gregtech_Generic_Item) aStack.getItem()).onDispense(aSource, aStack); + } + + @Override + protected IProjectile getProjectileEntity(final World aWorld, final IPosition aPosition) { + return null; + } + } + + @Override + public int getColorFromItemStack(final ItemStack stack, int HEX_OxFFFFFF) { + if (stack.getDisplayName() + .contains("LuV")) { + HEX_OxFFFFFF = 0xffffcc; + } else if (stack.getDisplayName() + .contains("ZPM")) { + HEX_OxFFFFFF = 0xace600; + } else if (stack.getDisplayName() + .contains("UV")) { + HEX_OxFFFFFF = 0xffff00; + } else if (stack.getDisplayName() + .contains("MAX")) { + HEX_OxFFFFFF = 0xff0000; + } else if (stack.getDisplayName() + .contains("Sodium")) { + HEX_OxFFFFFF = Utils.rgbtoHexValue(0, 0, 150); + } else if (stack.getDisplayName() + .contains("Cadmium")) { + HEX_OxFFFFFF = Utils.rgbtoHexValue(50, 50, 60); + } else if (stack.getDisplayName() + .contains("Lithium")) { + HEX_OxFFFFFF = Utils.rgbtoHexValue(225, 220, 255); + } else { + HEX_OxFFFFFF = 0xffffff; + } + return HEX_OxFFFFFF; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/items/Gregtech_MetaItem.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/items/Gregtech_MetaItem.java new file mode 100644 index 0000000000..015ba9d716 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/items/Gregtech_MetaItem.java @@ -0,0 +1,357 @@ +package gtPlusPlus.xmod.gregtech.api.items; + +import static gregtech.api.enums.GT_Values.D1; +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.BitSet; +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.EnumAction; +import net.minecraft.item.Item; +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.GregTech_API; +import gregtech.api.enums.Materials; +import gregtech.api.enums.SubTag; +import gregtech.api.enums.TC_Aspects.TC_AspectStack; +import gregtech.api.interfaces.IFoodStat; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.IItemContainer; +import gregtech.api.objects.ItemData; +import gregtech.api.util.GT_LanguageManager; +import gregtech.api.util.GT_OreDictUnificator; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.xmod.gregtech.api.interfaces.internal.Interface_ItemBehaviour; + +public abstract class Gregtech_MetaItem extends Gregtech_MetaItem_Base { + + /** + * All instances of this Item Class are listed here. This gets used to register the Renderer to all Items of this + * Type, if useStandardMetaItemRenderer() returns true. + * <p/> + * You can also use the unlocalized Name gotten from getUnlocalizedName() as Key if you want to get a specific Item. + */ + public static final HashMap<String, Gregtech_MetaItem> sInstances = new HashMap<>(); + + /* ---------- CONSTRUCTOR AND MEMBER VARIABLES ---------- */ + + public final short mOffset, mItemAmount; + public final BitSet mEnabledItems; + public final BitSet mVisibleItems; + public final IIcon[][] mIconList; + + public final HashMap<Short, IFoodStat> mFoodStats = new HashMap<>(); + public final HashMap<Short, Long[]> mElectricStats = new HashMap<>(); + public final HashMap<Short, Long[]> mFluidContainerStats = new HashMap<>(); + public final HashMap<Short, Short> mBurnValues = new HashMap<>(); + + /** + * Creates the Item using these Parameters. + * + * @param aUnlocalized The Unlocalized Name of this Item. + */ + public Gregtech_MetaItem(final String aUnlocalized, final short aOffset, final short aItemAmount) { + super(aUnlocalized); + this.setCreativeTab(AddToCreativeTab.tabMachines); + this.setHasSubtypes(true); + this.setMaxDamage(0); + 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.mIconList = new IIcon[aItemAmount][1]; + + sInstances.put(this.getUnlocalizedName(), 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. + */ + 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); + this.mEnabledItems.set(aID); + this.mVisibleItems.set(aID); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName(rStack) + ".name", aEnglish); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName(rStack) + ".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 Interface_ItemBehaviour) { + this.addItemBehavior( + this.mOffset + aID, + (Interface_ItemBehaviour<Gregtech_MetaItem_Base>) 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; + } + + /** + * 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 Gregtech_MetaItem setBurnValue(final int aMetaValue, final int aValue) { + if ((aMetaValue < 0) || (aMetaValue >= (this.mOffset + this.mEnabledItems.length())) || (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 Gregtech_MetaItem setElectricStats(final int aMetaValue, final long aMaxCharge, + final long aTransferLimit, final long aTier, final long aSpecialData, final boolean aUseAnimations) { + if ((aMetaValue < 0) || (aMetaValue >= (this.mOffset + this.mEnabledItems.length()))) { + 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 }); + if ((aMetaValue >= this.mOffset) && aUseAnimations) { + this.mIconList[aMetaValue - this.mOffset] = Arrays.copyOf( + this.mIconList[aMetaValue - this.mOffset], + Math.max(9, this.mIconList[aMetaValue - this.mOffset].length)); + } + } + 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 Gregtech_MetaItem setFluidContainerStats(final int aMetaValue, final long aCapacity, + final long aStacksize) { + if ((aMetaValue < 0) || (aMetaValue >= (this.mOffset + this.mEnabledItems.length()))) { + return this; + } + if (aCapacity < 0) { + this.mElectricStats.remove((short) aMetaValue); + } else { + this.mFluidContainerStats.put((short) aMetaValue, new Long[] { aCapacity, Math.max(1, aStacksize) }); + } + return this; + } + + /** + * @return if this MetaGenerated Item should use my Default Renderer System. + */ + public boolean useStandardMetaItemRenderer() { + return true; + } + + /** + * @return the Color Modulation the Material is going to be rendered with. + */ + public short[] getRGBa(final ItemStack aStack) { + return Materials._NULL.getRGBA(); + } + + /** + * @return the Icon the Material is going to be rendered with. + */ + public IIconContainer getIconContainer(final int aMetaData) { + return null; + } + + /* ---------- INTERNAL OVERRIDES ---------- */ + + @Override + public ItemStack onItemRightClick(final ItemStack aStack, final World aWorld, final EntityPlayer aPlayer) { + return super.onItemRightClick(aStack, aWorld, aPlayer); + } + + @Override + public int getMaxItemUseDuration(final ItemStack aStack) { + return this.mFoodStats.get((short) this.getDamage(aStack)) == null ? 0 : 32; + } + + @Override + public EnumAction getItemUseAction(final ItemStack aStack) { + return EnumAction.none; + } + + @Override + public final ItemStack onEaten(final ItemStack aStack, final World aWorld, final EntityPlayer aPlayer) { + final IFoodStat tStat = this.mFoodStats.get((short) this.getDamage(aStack)); + if (tStat != null) {} + + return aStack; + } + + @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) || (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)) { + for (byte k = 1; k < this.mIconList[i].length; k++) { + this.mIconList[i][k] = aIconRegister + .registerIcon(GTPlusPlus.ID + ":" + this.getUnlocalizedName() + "/" + i + "/" + k); + } + this.mIconList[i][0] = aIconRegister + .registerIcon(GTPlusPlus.ID + ":" + this.getUnlocalizedName() + "/" + i); + } + } + } + + @Override + public final Long[] getElectricStats(final ItemStack aStack) { + return this.mElectricStats.get((short) aStack.getItemDamage()); + } + + @Override + public final Long[] getFluidContainerStats(final ItemStack aStack) { + return this.mFluidContainerStats.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; + } + + @Override + public int getColorFromItemStack(final ItemStack stack, int HEX_OxFFFFFF) { + if (stack.getDisplayName() + .contains("LuV")) { + HEX_OxFFFFFF = 0xffffcc; + } else if (stack.getDisplayName() + .contains("ZPM")) { + HEX_OxFFFFFF = 0xace600; + } else if (stack.getDisplayName() + .contains("UV")) { + HEX_OxFFFFFF = 0xffff00; + } else if (stack.getDisplayName() + .contains("MAX")) { + HEX_OxFFFFFF = 0xff0000; + } else { + HEX_OxFFFFFF = 0xffffff; + } + return HEX_OxFFFFFF; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/items/Gregtech_MetaItem_Base.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/items/Gregtech_MetaItem_Base.java new file mode 100644 index 0000000000..3c4418c2bf --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/items/Gregtech_MetaItem_Base.java @@ -0,0 +1,745 @@ +package gtPlusPlus.xmod.gregtech.api.items; + +import static gregtech.api.enums.GT_Values.D1; +import static gregtech.api.enums.GT_Values.V; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import net.minecraft.dispenser.IBlockSource; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.projectile.EntityArrow; +import net.minecraft.inventory.Container; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.IFluidContainerItem; + +import gregtech.api.enums.SubTag; +import gregtech.api.util.GT_LanguageManager; +import gregtech.api.util.GT_Log; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.xmod.gregtech.api.interfaces.internal.Interface_ItemBehaviour; +import ic2.api.item.ElectricItem; +import ic2.api.item.IElectricItem; +import ic2.api.item.IElectricItemManager; +import ic2.api.item.ISpecialElectricItem; + +public abstract class Gregtech_MetaItem_Base extends Gregtech_Generic_Item + implements ISpecialElectricItem, IElectricItemManager, IFluidContainerItem { + + /* ---------- CONSTRUCTOR AND MEMBER VARIABLES ---------- */ + private final HashMap<Short, ArrayList<Interface_ItemBehaviour<Gregtech_MetaItem_Base>>> mItemBehaviors = new HashMap<>(); + + /** + * Creates the Item using these Parameters. + * + * @param aUnlocalized The Unlocalized Name of this Item. + * @param aGeneratedPrefixList The OreDict Prefixes you want to have generated. + */ + public Gregtech_MetaItem_Base(final String aUnlocalized) { + super(aUnlocalized, "Generated Item", null, false); + this.setHasSubtypes(true); + this.setMaxDamage(0); + } + + /** + * 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 Gregtech_MetaItem_Base addItemBehavior(final int aMetaValue, + final Interface_ItemBehaviour<Gregtech_MetaItem_Base> aBehavior) { + if ((aMetaValue < 0) || (aMetaValue >= 32766) || (aBehavior == null)) { + return this; + } + ArrayList<Interface_ItemBehaviour<Gregtech_MetaItem_Base>> tList = this.mItemBehaviors.get((short) aMetaValue); + if (tList == null) { + tList = new ArrayList<>(1); + this.mItemBehaviors.put((short) aMetaValue, tList); + } + tList.add(aBehavior); + return this; + } + + public abstract Long[] getElectricStats(ItemStack aStack); + + public abstract Long[] getFluidContainerStats(ItemStack aStack); + + @Override + public boolean hasProjectile(final SubTag aProjectileType, final ItemStack aStack) { + final ArrayList<Interface_ItemBehaviour<Gregtech_MetaItem_Base>> tList = this.mItemBehaviors + .get((short) this.getDamage(aStack)); + if (tList != null) { + for (final Interface_ItemBehaviour<Gregtech_MetaItem_Base> tBehavior : tList) { + if (tBehavior.hasProjectile(this, aProjectileType, aStack)) { + return true; + } + } + } + return super.hasProjectile(aProjectileType, aStack); + } + + @Override + public EntityArrow getProjectile(final SubTag aProjectileType, final ItemStack aStack, final World aWorld, + final double aX, final double aY, final double aZ) { + final ArrayList<Interface_ItemBehaviour<Gregtech_MetaItem_Base>> tList = this.mItemBehaviors + .get((short) this.getDamage(aStack)); + if (tList != null) { + for (final Interface_ItemBehaviour<Gregtech_MetaItem_Base> tBehavior : tList) { + final EntityArrow rArrow = tBehavior.getProjectile(this, aProjectileType, aStack, aWorld, aX, aY, aZ); + if (rArrow != null) { + return rArrow; + } + } + } + return super.getProjectile(aProjectileType, aStack, aWorld, aX, aY, aZ); + } + + @Override + public EntityArrow getProjectile(final SubTag aProjectileType, final ItemStack aStack, final World aWorld, + final EntityLivingBase aEntity, final float aSpeed) { + final ArrayList<Interface_ItemBehaviour<Gregtech_MetaItem_Base>> tList = this.mItemBehaviors + .get((short) this.getDamage(aStack)); + if (tList != null) { + for (final Interface_ItemBehaviour<Gregtech_MetaItem_Base> tBehavior : tList) { + final EntityArrow rArrow = tBehavior + .getProjectile(this, aProjectileType, aStack, aWorld, aEntity, aSpeed); + if (rArrow != null) { + return rArrow; + } + } + } + return super.getProjectile(aProjectileType, aStack, aWorld, aEntity, aSpeed); + } + + @Override + public ItemStack onDispense(final IBlockSource aSource, final ItemStack aStack) { + final ArrayList<Interface_ItemBehaviour<Gregtech_MetaItem_Base>> tList = this.mItemBehaviors + .get((short) this.getDamage(aStack)); + if (tList != null) { + for (final Interface_ItemBehaviour<Gregtech_MetaItem_Base> tBehavior : tList) { + if (tBehavior.canDispense(this, aSource, aStack)) { + return tBehavior.onDispense(this, aSource, aStack); + } + } + } + return super.onDispense(aSource, aStack); + } + + @Override + public boolean isItemStackUsable(final ItemStack aStack) { + final ArrayList<Interface_ItemBehaviour<Gregtech_MetaItem_Base>> tList = this.mItemBehaviors + .get((short) this.getDamage(aStack)); + if (tList != null) { + for (final Interface_ItemBehaviour<Gregtech_MetaItem_Base> tBehavior : tList) { + if (!tBehavior.isItemStackUsable(this, aStack)) { + return false; + } + } + } + return super.isItemStackUsable(aStack); + } + + @Override + public boolean onLeftClickEntity(final ItemStack aStack, final EntityPlayer aPlayer, final Entity aEntity) { + this.use(aStack, 0, aPlayer); + this.isItemStackUsable(aStack); + final ArrayList<Interface_ItemBehaviour<Gregtech_MetaItem_Base>> tList = this.mItemBehaviors + .get((short) this.getDamage(aStack)); + if (tList != null) { + for (final Interface_ItemBehaviour<Gregtech_MetaItem_Base> tBehavior : tList) { + try { + if (tBehavior.onLeftClickEntity(this, aStack, aPlayer, aEntity)) { + if (aStack.stackSize <= 0) { + aPlayer.destroyCurrentEquippedItem(); + } + return true; + } + if (aStack.stackSize <= 0) { + aPlayer.destroyCurrentEquippedItem(); + return false; + } + } catch (final Throwable e) { + if (D1) { + e.printStackTrace(GT_Log.err); + } + } + } + } + return false; + } + + @Override + public boolean onItemUse(final ItemStack aStack, final EntityPlayer aPlayer, final World aWorld, final int aX, + final int aY, final int aZ, final int ordinalSide, final float hitX, final float hitY, final float hitZ) { + this.use(aStack, 0, aPlayer); + this.isItemStackUsable(aStack); + final ArrayList<Interface_ItemBehaviour<Gregtech_MetaItem_Base>> tList = this.mItemBehaviors + .get((short) this.getDamage(aStack)); + if (tList != null) { + for (final Interface_ItemBehaviour<Gregtech_MetaItem_Base> tBehavior : tList) { + try { + if (tBehavior.onItemUse(this, aStack, aPlayer, aWorld, aX, aY, aZ, ordinalSide, hitX, hitY, hitZ)) { + if (aStack.stackSize <= 0) { + aPlayer.destroyCurrentEquippedItem(); + } + return true; + } + if (aStack.stackSize <= 0) { + aPlayer.destroyCurrentEquippedItem(); + return false; + } + } catch (final Throwable e) { + if (D1) { + e.printStackTrace(GT_Log.err); + } + } + } + } + return false; + } + + @Override + public boolean onItemUseFirst(final ItemStack aStack, final EntityPlayer aPlayer, final World aWorld, final int aX, + final int aY, final int aZ, final int ordinalSide, final float hitX, final float hitY, final float hitZ) { + this.use(aStack, 0, aPlayer); + this.isItemStackUsable(aStack); + final ArrayList<Interface_ItemBehaviour<Gregtech_MetaItem_Base>> tList = this.mItemBehaviors + .get((short) this.getDamage(aStack)); + if (tList != null) { + for (final Interface_ItemBehaviour<Gregtech_MetaItem_Base> tBehavior : tList) { + try { + if (tBehavior + .onItemUseFirst(this, aStack, aPlayer, aWorld, aX, aY, aZ, ordinalSide, hitX, hitY, hitZ)) { + if (aStack.stackSize <= 0) { + aPlayer.destroyCurrentEquippedItem(); + } + return true; + } + if (aStack.stackSize <= 0) { + aPlayer.destroyCurrentEquippedItem(); + return false; + } + } catch (final Throwable e) { + if (D1) { + e.printStackTrace(GT_Log.err); + } + } + } + } + return false; + } + + @Override + public ItemStack onItemRightClick(ItemStack aStack, final World aWorld, final EntityPlayer aPlayer) { + this.use(aStack, 0, aPlayer); + this.isItemStackUsable(aStack); + final ArrayList<Interface_ItemBehaviour<Gregtech_MetaItem_Base>> tList = this.mItemBehaviors + .get((short) this.getDamage(aStack)); + if (tList != null) { + for (final Interface_ItemBehaviour<Gregtech_MetaItem_Base> tBehavior : tList) { + try { + aStack = tBehavior.onItemRightClick(this, aStack, aWorld, aPlayer); + } catch (final Throwable e) { + if (D1) { + e.printStackTrace(GT_Log.err); + } + } + } + } + return aStack; + } + + @Override + public final void addInformation(final ItemStack aStack, final EntityPlayer aPlayer, List aList, + final boolean aF3_H) { + final String tKey = this.getUnlocalizedName(aStack) + ".tooltip", + tString = GT_LanguageManager.getTranslation(tKey); + if (GT_Utility.isStringValid(tString) && !tKey.equals(tString)) { + aList.add(tString); + } + + Long[] tStats = this.getElectricStats(aStack); + if (tStats != null) { + if (tStats[3] > 0) { + aList.add( + EnumChatFormatting.AQUA + "Contains " + + GT_Utility.formatNumbers(tStats[3]) + + " EU Tier: " + + (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 + "Empty. You should recycle it properly." + EnumChatFormatting.GRAY); + } else { + aList.add( + EnumChatFormatting.AQUA + "" + + GT_Utility.formatNumbers(tCharge) + + " / " + + GT_Utility.formatNumbers(Math.abs(tStats[0])) + + " EU - Voltage: " + + GT_Utility.formatNumbers( + V[(int) (tStats[2] >= 0 ? tStats[2] < V.length ? tStats[2] : V.length - 1 : 1)]) + + EnumChatFormatting.GRAY); + } + } + } + + tStats = this.getFluidContainerStats(aStack); + if ((tStats != null) && (tStats[0] > 0)) { + final FluidStack tFluid = this.getFluidContent(aStack); + aList.add( + EnumChatFormatting.BLUE + + ((tFluid == null ? "No Fluids Contained" : GT_Utility.getFluidName(tFluid, true))) + + EnumChatFormatting.GRAY); + aList.add( + EnumChatFormatting.BLUE + + (GT_Utility.formatNumbers(tFluid == null ? 0 : tFluid.amount) + "L / " + + GT_Utility.formatNumbers(tStats[0]) + + "L") + + EnumChatFormatting.GRAY); + } + + final ArrayList<Interface_ItemBehaviour<Gregtech_MetaItem_Base>> tList = this.mItemBehaviors + .get((short) this.getDamage(aStack)); + if (tList != null) { + for (final Interface_ItemBehaviour<Gregtech_MetaItem_Base> tBehavior : tList) { + aList = tBehavior.getAdditionalToolTips(this, aList, aStack); + } + } + + this.addAdditionalToolTips(aList, aStack); + } + + @Override + public void onUpdate(final ItemStack aStack, final World aWorld, final Entity aPlayer, final int aTimer, + final boolean aIsInHand) { + final ArrayList<Interface_ItemBehaviour<Gregtech_MetaItem_Base>> tList = this.mItemBehaviors + .get((short) this.getDamage(aStack)); + if (tList != null) { + for (final Interface_ItemBehaviour<Gregtech_MetaItem_Base> tBehavior : tList) { + tBehavior.onUpdate(this, aStack, aWorld, aPlayer, aTimer, aIsInHand); + } + } + } + + @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 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 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 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(); + } + + @Override + public FluidStack getFluid(final ItemStack aStack) { + return this.getFluidContent(aStack); + } + + @Override + public int getCapacity(final ItemStack aStack) { + final Long[] tStats = this.getFluidContainerStats(aStack); + return tStats == null ? 0 : (int) Math.max(0, tStats[0]); + } + + @Override + public int fill(final ItemStack aStack, final FluidStack aFluid, final boolean doFill) { + if ((aStack == null) || (aStack.stackSize != 1)) { + return 0; + } + + final ItemStack tStack = GT_Utility.fillFluidContainer(aFluid, aStack, false, false); + if (tStack != null) { + aStack.setItemDamage(tStack.getItemDamage()); + aStack.func_150996_a(tStack.getItem()); + return GT_Utility.getFluidForFilledItem(tStack, false).amount; + } + + final Long[] tStats = this.getFluidContainerStats(aStack); + if ((tStats == null) || (tStats[0] <= 0) + || (aFluid == null) + || (aFluid.getFluid() + .getID() <= 0) + || (aFluid.amount <= 0)) { + return 0; + } + + FluidStack tFluid = this.getFluidContent(aStack); + + if ((tFluid == null) || (tFluid.getFluid() + .getID() <= 0)) { + if (aFluid.amount <= tStats[0]) { + if (doFill) { + this.setFluidContent(aStack, aFluid); + } + return aFluid.amount; + } + if (doFill) { + tFluid = aFluid.copy(); + tFluid.amount = (int) (long) tStats[0]; + this.setFluidContent(aStack, tFluid); + } + return (int) (long) tStats[0]; + } + + if (!tFluid.isFluidEqual(aFluid)) { + return 0; + } + + final int space = (int) (long) tStats[0] - tFluid.amount; + if (aFluid.amount <= space) { + if (doFill) { + tFluid.amount += aFluid.amount; + this.setFluidContent(aStack, tFluid); + } + return aFluid.amount; + } + if (doFill) { + tFluid.amount = (int) (long) tStats[0]; + this.setFluidContent(aStack, tFluid); + } + return space; + } + + @Override + public FluidStack drain(final ItemStack aStack, final int maxDrain, final boolean doDrain) { + if ((aStack == null) || (aStack.stackSize != 1)) { + return null; + } + + FluidStack tFluid = GT_Utility.getFluidForFilledItem(aStack, false); + if ((tFluid != null) && (maxDrain >= tFluid.amount)) { + final ItemStack tStack = GT_Utility.getContainerItem(aStack, false); + if (tStack == null) { + aStack.stackSize = 0; + return tFluid; + } + aStack.setItemDamage(tStack.getItemDamage()); + aStack.func_150996_a(tStack.getItem()); + return tFluid; + } + + final Long[] tStats = this.getFluidContainerStats(aStack); + if ((tStats == null) || (tStats[0] <= 0)) { + return null; + } + + tFluid = this.getFluidContent(aStack); + if (tFluid == null) { + return null; + } + + int used = maxDrain; + if (tFluid.amount < used) { + used = tFluid.amount; + } + if (doDrain) { + tFluid.amount -= used; + this.setFluidContent(aStack, tFluid); + } + + final FluidStack drained = tFluid.copy(); + drained.amount = used; + return drained; + } + + public FluidStack getFluidContent(final ItemStack aStack) { + final Long[] tStats = this.getFluidContainerStats(aStack); + if ((tStats == null) || (tStats[0] <= 0)) { + return GT_Utility.getFluidForFilledItem(aStack, false); + } + final NBTTagCompound tNBT = aStack.getTagCompound(); + return tNBT == null ? null : FluidStack.loadFluidStackFromNBT(tNBT.getCompoundTag("GT.FluidContent")); + } + + public void setFluidContent(final ItemStack aStack, final FluidStack aFluid) { + NBTTagCompound tNBT = aStack.getTagCompound(); + if (tNBT == null) { + tNBT = new NBTTagCompound(); + } else { + tNBT.removeTag("GT.FluidContent"); + } + if ((aFluid != null) && (aFluid.amount > 0)) { + tNBT.setTag("GT.FluidContent", aFluid.writeToNBT(new NBTTagCompound())); + } + if (tNBT.hasNoTags()) { + aStack.setTagCompound(null); + } else { + aStack.setTagCompound(tNBT); + } + this.isItemStackUsable(aStack); + } + + @Override + public int getItemStackLimit(final ItemStack aStack) { + Long[] tStats = this.getElectricStats(aStack); + if ((tStats != null) && ((tStats[3] == -1) || (tStats[3] == -3)) && (this.getRealCharge(aStack) > 0)) { + return 1; + } + tStats = this.getFluidContainerStats(aStack); + if (tStats != null) { + return (int) (long) tStats[1]; + } + return 64; + } + + @Override + public final Item getChargedItem(final ItemStack itemStack) { + return this; + } + + @Override + public final Item getEmptyItem(final ItemStack itemStack) { + return this; + } + + @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 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 + + @Override + public final boolean getShareTag() { + return true; + } // just to be sure. + + @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; + } + + @Override + public int getColorFromItemStack(final ItemStack stack, int HEX_OxFFFFFF) { + if (stack.getDisplayName() + .contains("LuV")) { + HEX_OxFFFFFF = 0xffffcc; + } else if (stack.getDisplayName() + .contains("ZPM")) { + HEX_OxFFFFFF = 0xace600; + } else if (stack.getDisplayName() + .contains("UV")) { + HEX_OxFFFFFF = 0xffff00; + } else if (stack.getDisplayName() + .contains("MAX")) { + HEX_OxFFFFFF = 0xff0000; + } else if (stack.getDisplayName() + .contains("Sodium")) { + HEX_OxFFFFFF = Utils.rgbtoHexValue(0, 0, 150); + } else if (stack.getDisplayName() + .contains("Cadmium")) { + HEX_OxFFFFFF = Utils.rgbtoHexValue(50, 50, 60); + } else if (stack.getDisplayName() + .contains("Lithium")) { + HEX_OxFFFFFF = Utils.rgbtoHexValue(225, 220, 255); + } else { + HEX_OxFFFFFF = 0xffffff; + } + return HEX_OxFFFFFF; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/items/Gregtech_MetaItem_X32.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/items/Gregtech_MetaItem_X32.java new file mode 100644 index 0000000000..c04acb9537 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/items/Gregtech_MetaItem_X32.java @@ -0,0 +1,266 @@ +package gtPlusPlus.xmod.gregtech.api.items; + +import java.util.Arrays; +import java.util.List; + +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; + +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.Materials; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.util.GT_LanguageManager; +import gregtech.api.util.GT_OreDictUnificator; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.math.MathUtils; + +/** + * @author Gregorius Techneticies + * <p/> + * One Item for everything! + * <p/> + * This brilliant Item Class is used for automatically generating all possible variations of Material Items, + * like Dusts, Ingots, Gems, Plates and similar. It saves me a ton of work, when adding Items, because I always + * have to make a new Item SubType for each OreDict Prefix, when adding a new Material. + * <p/> + * As you can see, up to 32766 Items can be generated using this Class. And the last 766 Items can be custom + * defined, just to save space and MetaData. + * <p/> + * These Items can also have special RightClick abilities, electric Charge or even be set to become a Food alike + * Item. + */ +public abstract class Gregtech_MetaItem_X32 extends Gregtech_MetaItem { + + protected final OrePrefixes[] mGeneratedPrefixList; + + /** + * Creates the Item using these Parameters. + * + * @param aUnlocalized The Unlocalized Name of this Item. + * @param aGeneratedPrefixList The OreDict Prefixes you want to have generated. + */ + public Gregtech_MetaItem_X32(final String aUnlocalized, final OrePrefixes... aGeneratedPrefixList) { + super(aUnlocalized, (short) 32000, (short) 766); + this.mGeneratedPrefixList = Arrays.copyOf(aGeneratedPrefixList, 32); + + for (int i = 0; i < 32000; i++) { + final OrePrefixes tPrefix = this.mGeneratedPrefixList[i / 1000]; + if (tPrefix == null) { + continue; + } + final Materials tMaterial = GregTech_API.sGeneratedMaterials[i % 1000]; + if (tMaterial == null) { + continue; + } + if (this.doesMaterialAllowGeneration(tPrefix, tMaterial)) { + final ItemStack tStack = new ItemStack(this, 1, i); + GT_LanguageManager.addStringLocalization( + this.getUnlocalizedName(tStack) + ".name", + this.getDefaultLocalization(tPrefix, tMaterial, i)); + GT_LanguageManager.addStringLocalization( + this.getUnlocalizedName(tStack) + ".tooltip", + tMaterial.getToolTip(tPrefix.mMaterialAmount / GT_Values.M)); + if (tPrefix.mIsUnificatable) { + GT_OreDictUnificator.set(tPrefix, tMaterial, tStack); + } else { + GT_OreDictUnificator.registerOre(tPrefix.get(tMaterial), tStack); + } + if (((tPrefix == OrePrefixes.stick) || (tPrefix == OrePrefixes.wireFine)) + && ((tMaterial == Materials.Lead) || (tMaterial == Materials.Tin) + || (tMaterial == Materials.SolderingAlloy))) { + GregTech_API.sSolderingMetalList.add(tStack); + } + } + } + } + + /* ---------- OVERRIDEABLE FUNCTIONS ---------- */ + + /** + * @return the Color Modulation the Material is going to be rendered with. + */ + @Override + public short[] getRGBa(final ItemStack aStack) { + final Materials tMaterial = GregTech_API.sGeneratedMaterials[this.getDamage(aStack) % 1000]; + return tMaterial == null ? Materials._NULL.mRGBa : tMaterial.mRGBa; + } + + /** + * @param aPrefix this can be null, you have to return false in that case + * @param aMaterial this can be null, you have to return false in that case + * @return if this Item should be generated and visible. + */ + public boolean doesMaterialAllowGeneration(final OrePrefixes aPrefix, final Materials aMaterial) { + // You have to check for at least these Conditions in every Case! So add a super Call like the following for + // this before executing your Code: + // if (!super.doesMaterialAllowGeneration(aPrefix, aMaterial)) return false; + return (aPrefix != null) && (aMaterial != null) && aPrefix.doGenerateItem(aMaterial); + } + + /* ---------- OVERRIDEABLE FUNCTIONS ---------- */ + + /** + * @param aPrefix the OreDict Prefix + * @param aMaterial the Material + * @param aMetaData a Index from [0 - 31999] + * @return the Localized Name when default LangFiles are used. + */ + public String getDefaultLocalization(final OrePrefixes aPrefix, final Materials aMaterial, final int aMetaData) { + return aPrefix.getDefaultLocalNameForItem(aMaterial); + } + + /** + * @param aMetaData a Index from [0 - 31999] + * @param aMaterial the Material + * @return an Icon Container for the Item Display. + */ + public final IIconContainer getIconContainer(final int aMetaData, final Materials aMaterial) { + return (this.mGeneratedPrefixList[aMetaData / 1000] != null) + && (this.mGeneratedPrefixList[aMetaData / 1000].mTextureIndex >= 0) + ? aMaterial.mIconSet.mTextures[this.mGeneratedPrefixList[aMetaData / 1000].mTextureIndex] + : null; + } + + /** + * @param aPrefix always != null + * @param aMaterial always != null + * @param aDoShowAllItems this is the Configuration Setting of the User, if he wants to see all the Stuff like Tiny + * Dusts or Crushed Ores as well. + * @return if this Item should be visible in NEI or Creative + */ + public boolean doesShowInCreative(final OrePrefixes aPrefix, final Materials aMaterial, + final boolean aDoShowAllItems) { + return true; + } + + /* ---------- INTERNAL OVERRIDES ---------- */ + + @Override + public ItemStack getContainerItem(final ItemStack aStack) { + final int aDamage = aStack.getItemDamage(); + if ((aDamage < 32000) && (aDamage >= 0)) { + final Materials aMaterial = GregTech_API.sGeneratedMaterials[aDamage % 1000]; + if ((aMaterial != null) && (aMaterial != Materials.Empty) && (aMaterial != Materials._NULL)) { + final OrePrefixes aPrefix = this.mGeneratedPrefixList[aDamage / 1000]; + if (aPrefix != null) { + return GT_Utility.copyAmount(1, aPrefix.mContainerItem); + } + } + } + return null; + } + + @Override + public final IIconContainer getIconContainer(final int aMetaData) { + return GregTech_API.sGeneratedMaterials[aMetaData % 1000] == null ? null + : this.getIconContainer(aMetaData, GregTech_API.sGeneratedMaterials[aMetaData % 1000]); + } + + @Override + @SideOnly(Side.CLIENT) + public final void getSubItems(final Item var1, final CreativeTabs aCreativeTab, final List aList) { + for (int i = 0; i < 32000; i++) { + if (this.doesMaterialAllowGeneration( + this.mGeneratedPrefixList[i / 1000], + GregTech_API.sGeneratedMaterials[i % 1000]) + && this.doesShowInCreative( + this.mGeneratedPrefixList[i / 1000], + GregTech_API.sGeneratedMaterials[i % 1000], + GregTech_API.sDoShowAllItemsInCreative)) { + final ItemStack tStack = new ItemStack(this, 1, i); + this.isItemStackUsable(tStack); + aList.add(tStack); + } + } + super.getSubItems(var1, aCreativeTab, aList); + } + + @Override + public final IIcon getIconFromDamage(final int aMetaData) { + if (aMetaData < 0) { + return null; + } + if (aMetaData < 32000) { + final Materials tMaterial = GregTech_API.sGeneratedMaterials[aMetaData % 1000]; + if (tMaterial == null) { + return null; + } + final IIconContainer tIcon = this.getIconContainer(aMetaData, tMaterial); + if (tIcon != null) { + return tIcon.getIcon(); + } + return null; + } + return (aMetaData - 32000) < this.mIconList.length ? this.mIconList[aMetaData - 32000][0] : null; + } + + @Override + public int getItemStackLimit(final ItemStack aStack) { + final int tDamage = this.getDamage(aStack); + if ((tDamage < 32000) && (this.mGeneratedPrefixList[tDamage / 1000] != null)) { + return Math + .min(super.getItemStackLimit(aStack), this.mGeneratedPrefixList[tDamage / 1000].mDefaultStackSize); + } + return super.getItemStackLimit(aStack); + } + + @Override + public int getColorFromItemStack(final ItemStack stack, int HEX_OxFFFFFF) { + + int aMeta = stack.getItemDamage(); + if (stack.getDisplayName() + .contains("Sodium")) { + HEX_OxFFFFFF = Utils.rgbtoHexValue(90, 90, 255); + } else if (stack.getDisplayName() + .contains("Cadmium")) { + HEX_OxFFFFFF = Utils.rgbtoHexValue(150, 150, 80); + } else if (stack.getDisplayName() + .contains("Lithium")) { + HEX_OxFFFFFF = Utils.rgbtoHexValue(225, 220, 255); + } else if (stack.getDisplayName() + .contains("Wrought")) { + HEX_OxFFFFFF = Utils.rgbtoHexValue(200, 180, 180); + } else if (stack.getDisplayName() + .contains("Bronze")) { + HEX_OxFFFFFF = Utils.rgbtoHexValue(255, 128, 0); + } else if (stack.getDisplayName() + .contains("Brass")) { + HEX_OxFFFFFF = Utils.rgbtoHexValue(255, 180, 0); + } else if (stack.getDisplayName() + .contains("Invar")) { + HEX_OxFFFFFF = Utils.rgbtoHexValue(180, 180, 120); + } else { + if (aMeta > 50 && aMeta != 150) { + HEX_OxFFFFFF = 0xffffff; + } else if (stack.getDisplayName() + .contains("ULV")) { + HEX_OxFFFFFF = Utils.rgbtoHexValue(200, 180, 180); + } else if (stack.getDisplayName() + .contains("LuV")) { + HEX_OxFFFFFF = 0xffffcc; + } else if (stack.getDisplayName() + .contains("ZPM")) { + HEX_OxFFFFFF = 0xffe600; + } else if (stack.getDisplayName() + .contains("UV")) { + HEX_OxFFFFFF = 0xffb300; + } else if (stack.getDisplayName() + .contains("MAX")) { + HEX_OxFFFFFF = Utils.rgbtoHexValue( + MathUtils.randInt(220, 250), + MathUtils.randInt(221, 251), + MathUtils.randInt(220, 250)); + } else { + HEX_OxFFFFFF = 0xffffff; + } + } + return HEX_OxFFFFFF; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/items/Gregtech_MetaTool.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/items/Gregtech_MetaTool.java new file mode 100644 index 0000000000..fcfa5fae50 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/items/Gregtech_MetaTool.java @@ -0,0 +1,692 @@ +package gtPlusPlus.xmod.gregtech.api.items; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; + +import net.minecraft.block.Block; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.enchantment.EnchantmentHelper; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.SharedMonsterAttributes; +import net.minecraft.entity.item.EntityMinecart; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.potion.Potion; +import net.minecraft.stats.AchievementList; +import net.minecraft.stats.StatList; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import net.minecraftforge.event.world.BlockEvent; + +import buildcraft.api.tools.IToolWrench; +import cpw.mods.fml.common.Optional; +import gregtech.api.enchants.Enchantment_Radioactivity; +import gregtech.api.enums.Materials; +import gregtech.api.enums.Mods; +import gregtech.api.interfaces.IDamagableItem; +import gregtech.api.interfaces.IToolStats; +import gregtech.api.items.GT_MetaGenerated_Tool; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.xmod.gregtech.api.interfaces.internal.Interface_ToolStats; +import mods.railcraft.api.core.items.IToolCrowbar; + +/** + * This is an example on how you can create a Tool ItemStack, in this case a Bismuth Wrench: + * GT_MetaGenerated_Tool.sInstances.get("gt.metatool.01").getToolWithStats(16, 1, Materials.Bismuth, Materials.Bismuth, + * null); + */ +@Optional.InterfaceList({ + @Optional.Interface(iface = "forestry.api.arboriculture.IToolGrafter", modid = Mods.Names.FORESTRY), + @Optional.Interface(iface = "mods.railcraft.api.core.items.IToolCrowbar", modid = Mods.Names.RAILCRAFT), + @Optional.Interface(iface = "buildcraft.api.tools.IToolWrench", modid = "BuildCraft"), + @Optional.Interface(iface = "crazypants.enderio.api.tool.ITool", modid = Mods.Names.ENDER_I_O) }) +public abstract class Gregtech_MetaTool extends GT_MetaGenerated_Tool + implements IDamagableItem, IToolCrowbar, IToolWrench { + + /** + * All instances of this Item Class are listed here. This gets used to register the Renderer to all Items of this + * Type, if useStandardMetaItemRenderer() returns true. + * <p/> + * You can also use the unlocalized Name gotten from getUnlocalizedName() as Key if you want to get a specific Item. + */ + public static final HashMap<String, Gregtech_MetaTool> sInstances = new HashMap<>(); + + /* ---------- CONSTRUCTOR AND MEMBER VARIABLES ---------- */ + + public final HashMap<Short, IToolStats> mToolStats = new HashMap<>(); + + /** + * Creates the Item using these Parameters. + * + * @param aUnlocalized The Unlocalized Name of this Item. + */ + public Gregtech_MetaTool(final String aUnlocalized) { + super(aUnlocalized); + GT_ModHandler.registerBoxableItemToToolBox(new ItemStack(this)); + this.setCreativeTab(AddToCreativeTab.tabMachines); + this.setMaxStackSize(1); + sInstances.put(this.getUnlocalizedName(), this); + } + + /** + * Called by the Block Harvesting Event within the GT_Proxy + */ + @Override + public void onHarvestBlockEvent(final ArrayList<ItemStack> aDrops, final ItemStack aStack, + final EntityPlayer aPlayer, final Block aBlock, final int aX, final int aY, final int aZ, final byte aMetaData, + final int aFortune, final boolean aSilkTouch, final BlockEvent.HarvestDropsEvent aEvent) { + final IToolStats tStats = this.getToolStats(aStack); + if (this.isItemStackUsable(aStack) && (this.getDigSpeed(aStack, aBlock, aMetaData) > 0.0F)) { + this.doDamage( + aStack, + tStats.convertBlockDrops( + aDrops, + aStack, + aPlayer, + aBlock, + aX, + aY, + aZ, + aMetaData, + aFortune, + aSilkTouch, + aEvent) * tStats.getToolDamagePerDropConversion()); + } + } + + @Override + public boolean onLeftClickEntity(final ItemStack aStack, final EntityPlayer aPlayer, final Entity aEntity) { + final IToolStats tStats = this.getToolStats(aStack); + if ((tStats == null) || !this.isItemStackUsable(aStack)) { + return true; + } + GT_Utility.doSoundAtClient(tStats.getEntityHitSound(), 1, 1.0F); + if (super.onLeftClickEntity(aStack, aPlayer, aEntity)) { + return true; + } + if (aEntity.canAttackWithItem() && !aEntity.hitByEntity(aPlayer)) { + final float tMagicDamage = tStats.getMagicDamageAgainstEntity( + aEntity instanceof EntityLivingBase + ? EnchantmentHelper.getEnchantmentModifierLiving(aPlayer, (EntityLivingBase) aEntity) + : 0.0F, + aEntity, + aStack, + aPlayer); + float tDamage = tStats.getNormalDamageAgainstEntity( + (float) aPlayer.getEntityAttribute(SharedMonsterAttributes.attackDamage) + .getAttributeValue() + this.getToolCombatDamage(aStack), + aEntity, + aStack, + aPlayer); + if ((tDamage + tMagicDamage) > 0.0F) { + final boolean tCriticalHit = (aPlayer.fallDistance > 0.0F) && !aPlayer.onGround + && !aPlayer.isOnLadder() + && !aPlayer.isInWater() + && !aPlayer.isPotionActive(Potion.blindness) + && (aPlayer.ridingEntity == null) + && (aEntity instanceof EntityLivingBase); + if (tCriticalHit && (tDamage > 0.0F)) { + tDamage *= 1.5F; + } + tDamage += tMagicDamage; + if (aEntity.attackEntityFrom(tStats.getDamageSource(aPlayer, aEntity), tDamage)) { + if (aEntity instanceof EntityLivingBase) { + aEntity.setFire(EnchantmentHelper.getFireAspectModifier(aPlayer) * 4); + } + final int tKnockcack = (aPlayer.isSprinting() ? 1 : 0) + (aEntity instanceof EntityLivingBase + ? EnchantmentHelper.getKnockbackModifier(aPlayer, (EntityLivingBase) aEntity) + : 0); + if (tKnockcack > 0) { + aEntity.addVelocity( + -MathHelper.sin((aPlayer.rotationYaw * (float) Math.PI) / 180.0F) * tKnockcack * 0.5F, + 0.1D, + MathHelper.cos((aPlayer.rotationYaw * (float) Math.PI) / 180.0F) * tKnockcack * 0.5F); + aPlayer.motionX *= 0.6D; + aPlayer.motionZ *= 0.6D; + aPlayer.setSprinting(false); + } + if (tCriticalHit) { + aPlayer.onCriticalHit(aEntity); + } + if (tMagicDamage > 0.0F) { + aPlayer.onEnchantmentCritical(aEntity); + } + if (tDamage >= 18.0F) { + aPlayer.triggerAchievement(AchievementList.overkill); + } + aPlayer.setLastAttacker(aEntity); + if (aEntity instanceof EntityLivingBase) { + EnchantmentHelper.func_151384_a((EntityLivingBase) aEntity, aPlayer); + } + EnchantmentHelper.func_151385_b(aPlayer, aEntity); + if (aEntity instanceof EntityLivingBase) { + aPlayer.addStat(StatList.damageDealtStat, Math.round(tDamage * 10.0F)); + } + aEntity.hurtResistantTime = Math + .max(1, tStats.getHurtResistanceTime(aEntity.hurtResistantTime, aEntity)); + aPlayer.addExhaustion(0.3F); + this.doDamage(aStack, tStats.getToolDamagePerEntityAttack()); + } + } + } + if (aStack.stackSize <= 0) { + aPlayer.destroyCurrentEquippedItem(); + } + return true; + } + + @Override + public ItemStack onItemRightClick(final ItemStack aStack, final World aWorld, final EntityPlayer aPlayer) { + final IToolStats tStats = this.getToolStats(aStack); + if ((tStats != null) && tStats.canBlock()) { + aPlayer.setItemInUse(aStack, 72000); + } + return super.onItemRightClick(aStack, aWorld, aPlayer); + } + + @SuppressWarnings("unchecked") + public void addAdditionalToolTips(final List aList, final ItemStack aStack) { + final long tMaxDamage = getToolMaxDamage(aStack); + final Materials tMaterial = getPrimaryMaterial(aStack); + final IToolStats tStats = this.getToolStats(aStack); + final int tOffset = this.getElectricStats(aStack) != null ? 2 : 1; + if (tStats != null) { + final String name = aStack.getUnlocalizedName(); + if (name.equals("gt.metatool.01.170") || name.equals("gt.metatool.01.172") + || name.equals("gt.metatool.01.174") + || name.equals("gt.metatool.01.176")) { + aList.add( + tOffset + 0, + EnumChatFormatting.WHITE + "Durability: " + + EnumChatFormatting.GREEN + + (tMaxDamage - getToolDamage(aStack)) + + " / " + + tMaxDamage + + EnumChatFormatting.GRAY); + aList.add( + tOffset + 1, + EnumChatFormatting.WHITE + tMaterial.mDefaultLocalName + + EnumChatFormatting.YELLOW + + " lvl " + + this.getHarvestLevel(aStack, "") + + EnumChatFormatting.GRAY); + aList.add( + tOffset + 2, + EnumChatFormatting.WHITE + "Turbine Efficency: " + + EnumChatFormatting.BLUE + + (50.0F + (10.0F * this.getToolCombatDamage(aStack))) + + EnumChatFormatting.GRAY); + aList.add( + tOffset + 3, + EnumChatFormatting.WHITE + "Optimal Steam flow: " + + EnumChatFormatting.LIGHT_PURPLE + + Math.max( + Float.MIN_NORMAL, + tStats.getSpeedMultiplier() * getPrimaryMaterial(aStack).mToolSpeed * 1000) + + EnumChatFormatting.GRAY + + "L/sec"); + aList.add( + tOffset + 3, + EnumChatFormatting.WHITE + "Optimal Gas flow(EU burnvalue per tick): " + + EnumChatFormatting.LIGHT_PURPLE + + Math.max( + Float.MIN_NORMAL, + tStats.getSpeedMultiplier() * getPrimaryMaterial(aStack).mToolSpeed * 25) + + EnumChatFormatting.GRAY + + "EU/t"); + aList.add( + tOffset + 3, + EnumChatFormatting.WHITE + "Optimal Plasma flow(Plasma energyvalue per tick): " + + EnumChatFormatting.LIGHT_PURPLE + + Math.max( + Float.MIN_NORMAL, + tStats.getSpeedMultiplier() * getPrimaryMaterial(aStack).mToolSpeed * 1000) + + EnumChatFormatting.GRAY + + "EU/t"); + + } else { + aList.add( + tOffset + 0, + EnumChatFormatting.WHITE + "Durability: " + + EnumChatFormatting.GREEN + + (tMaxDamage - getToolDamage(aStack)) + + " / " + + tMaxDamage + + EnumChatFormatting.GRAY); + aList.add( + tOffset + 1, + EnumChatFormatting.WHITE + tMaterial.mDefaultLocalName + + EnumChatFormatting.YELLOW + + " lvl " + + this.getHarvestLevel(aStack, "") + + EnumChatFormatting.GRAY); + aList.add( + tOffset + 2, + EnumChatFormatting.WHITE + "Attack Damage: " + + EnumChatFormatting.BLUE + + this.getToolCombatDamage(aStack) + + EnumChatFormatting.GRAY); + aList.add( + tOffset + 3, + EnumChatFormatting.WHITE + "Mining Speed: " + + EnumChatFormatting.LIGHT_PURPLE + + Math + .max(Float.MIN_NORMAL, tStats.getSpeedMultiplier() * getPrimaryMaterial(aStack).mToolSpeed) + + EnumChatFormatting.GRAY); + } + } + } + + @Override + @SuppressWarnings("unchecked") + public void addAdditionalToolTips(final List aList, final ItemStack aStack, final EntityPlayer aPlayer) { + final long tMaxDamage = getToolMaxDamage(aStack); + final Materials tMaterial = getPrimaryMaterial(aStack); + final IToolStats tStats = this.getToolStats(aStack); + final int tOffset = this.getElectricStats(aStack) != null ? 2 : 1; + if (tStats != null) { + final String name = aStack.getUnlocalizedName(); + if (name.equals("gt.metatool.01.170") || name.equals("gt.metatool.01.172") + || name.equals("gt.metatool.01.174") + || name.equals("gt.metatool.01.176")) { + aList.add( + tOffset + 0, + EnumChatFormatting.WHITE + "Durability: " + + EnumChatFormatting.GREEN + + (tMaxDamage - getToolDamage(aStack)) + + " / " + + tMaxDamage + + EnumChatFormatting.GRAY); + aList.add( + tOffset + 1, + EnumChatFormatting.WHITE + tMaterial.mDefaultLocalName + + EnumChatFormatting.YELLOW + + " lvl " + + this.getHarvestLevel(aStack, "") + + EnumChatFormatting.GRAY); + aList.add( + tOffset + 2, + EnumChatFormatting.WHITE + "Turbine Efficency: " + + EnumChatFormatting.BLUE + + (50.0F + (10.0F * this.getToolCombatDamage(aStack))) + + EnumChatFormatting.GRAY); + aList.add( + tOffset + 3, + EnumChatFormatting.WHITE + "Optimal Steam flow: " + + EnumChatFormatting.LIGHT_PURPLE + + Math.max( + Float.MIN_NORMAL, + tStats.getSpeedMultiplier() * getPrimaryMaterial(aStack).mToolSpeed * 1000) + + EnumChatFormatting.GRAY + + "L/sec"); + aList.add( + tOffset + 3, + EnumChatFormatting.WHITE + "Optimal Gas flow(EU burnvalue per tick): " + + EnumChatFormatting.LIGHT_PURPLE + + Math.max( + Float.MIN_NORMAL, + tStats.getSpeedMultiplier() * getPrimaryMaterial(aStack).mToolSpeed * 50) + + EnumChatFormatting.GRAY + + "EU/t"); + aList.add( + tOffset + 3, + EnumChatFormatting.WHITE + "Optimal Plasma flow(Plasma energyvalue per tick): " + + EnumChatFormatting.LIGHT_PURPLE + + Math.max( + Float.MIN_NORMAL, + tStats.getSpeedMultiplier() * getPrimaryMaterial(aStack).mToolSpeed * 1000) + + EnumChatFormatting.GRAY + + "EU/t"); + + } else { + aList.add( + tOffset + 0, + EnumChatFormatting.WHITE + "Durability: " + + EnumChatFormatting.GREEN + + (tMaxDamage - getToolDamage(aStack)) + + " / " + + tMaxDamage + + EnumChatFormatting.GRAY); + aList.add( + tOffset + 1, + EnumChatFormatting.WHITE + tMaterial.mDefaultLocalName + + EnumChatFormatting.YELLOW + + " lvl " + + this.getHarvestLevel(aStack, "") + + EnumChatFormatting.GRAY); + aList.add( + tOffset + 2, + EnumChatFormatting.WHITE + "Attack Damage: " + + EnumChatFormatting.BLUE + + this.getToolCombatDamage(aStack) + + EnumChatFormatting.GRAY); + aList.add( + tOffset + 3, + EnumChatFormatting.WHITE + "Mining Speed: " + + EnumChatFormatting.LIGHT_PURPLE + + Math + .max(Float.MIN_NORMAL, tStats.getSpeedMultiplier() * getPrimaryMaterial(aStack).mToolSpeed) + + EnumChatFormatting.GRAY); + NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag("GT.ToolStats"); + if ((aNBT != null) && aNBT.hasKey("Heat")) { + int tHeat = aNBT.getInteger("Heat"); + final long tWorldTime = aPlayer.getEntityWorld() + .getWorldTime(); + if (aNBT.hasKey("HeatTime")) { + final long tHeatTime = aNBT.getLong("HeatTime"); + if (tWorldTime > (tHeatTime + 10)) { + tHeat = (int) (tHeat - ((tWorldTime - tHeatTime) / 10)); + if ((tHeat < 300) && (tHeat > -10000)) { + tHeat = 300; + } + } + aNBT.setLong("HeatTime", tWorldTime); + if (tHeat > -10000) { + aNBT.setInteger("Heat", tHeat); + } + } + + aList.add( + tOffset + 3, + EnumChatFormatting.RED + "Heat: " + + aNBT.getInteger("Heat") + + " K" + + EnumChatFormatting.GRAY); + } + } + } + } + } + + @Override + public Long[] getFluidContainerStats(final ItemStack aStack) { + return null; + } + + @Override + public Long[] getElectricStats(final ItemStack aStack) { + NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag("GT.ToolStats"); + if ((aNBT != null) && aNBT.getBoolean("Electric")) { + return new Long[] { aNBT.getLong("MaxCharge"), aNBT.getLong("Voltage"), aNBT.getLong("Tier"), + aNBT.getLong("SpecialData") }; + } + } + return new Long[] {}; + } + + @Override + public float getToolCombatDamage(final ItemStack aStack) { + final IToolStats tStats = this.getToolStats(aStack); + if (tStats == null) { + return 0; + } + return tStats.getBaseDamage() + getPrimaryMaterial(aStack).mToolQuality; + } + + @Override + public float getDigSpeed(final ItemStack aStack, final Block aBlock, final int aMetaData) { + if (!this.isItemStackUsable(aStack)) { + return 0.0F; + } + final IToolStats tStats = this.getToolStats(aStack); + if ((tStats == null) || (Math.max(0, this.getHarvestLevel(aStack, "")) < aBlock.getHarvestLevel(aMetaData))) { + return 0.0F; + } + return tStats.isMinableBlock(aBlock, (byte) aMetaData) + ? Math.max(Float.MIN_NORMAL, tStats.getSpeedMultiplier() * getPrimaryMaterial(aStack).mToolSpeed) + : 0.0F; + } + + @Override + public boolean onBlockDestroyed(final ItemStack aStack, final World aWorld, final Block aBlock, final int aX, + final int aY, final int aZ, final EntityLivingBase aPlayer) { + if (!this.isItemStackUsable(aStack)) { + return false; + } + final IToolStats tStats = this.getToolStats(aStack); + if (tStats == null) { + return false; + } + GT_Utility.doSoundAtClient(tStats.getMiningSound(), 1, 1.0F); + this.doDamage( + aStack, + (int) Math.max(1, aBlock.getBlockHardness(aWorld, aX, aY, aZ) * tStats.getToolDamagePerBlockBreak())); + return this.getDigSpeed(aStack, aBlock, aWorld.getBlockMetadata(aX, aY, aZ)) > 0.0F; + } + + private ItemStack getContainerItem(ItemStack aStack, final boolean playSound) { + if (!this.isItemStackUsable(aStack)) { + return null; + } + aStack = GT_Utility.copyAmount(1, aStack); + final IToolStats tStats = this.getToolStats(aStack); + if (tStats == null) { + return null; + } + this.doDamage(aStack, tStats.getToolDamagePerContainerCraft()); + aStack = aStack.stackSize > 0 ? aStack : null; + if (playSound) {} + return aStack; + } + + @Override + public Interface_ToolStats getToolStats(final ItemStack aStack) { + this.isItemStackUsable(aStack); + return this.getToolStatsInternal(aStack); + } + + private Interface_ToolStats getToolStatsInternal(final ItemStack aStack) { + return (Interface_ToolStats) (aStack == null ? null : this.mToolStats.get((short) aStack.getItemDamage())); + } + + @Override + public boolean canWhack(final EntityPlayer aPlayer, final ItemStack aStack, final int aX, final int aY, + final int aZ) { + if (!this.isItemStackUsable(aStack)) { + return false; + } + final IToolStats tStats = this.getToolStats(aStack); + return (tStats != null) && tStats.isCrowbar(); + } + + @Override + public void onWhack(final EntityPlayer aPlayer, final ItemStack aStack, final int aX, final int aY, final int aZ) { + final IToolStats tStats = this.getToolStats(aStack); + if (tStats != null) { + this.doDamage(aStack, tStats.getToolDamagePerEntityAttack()); + } + } + + @Override + public boolean canWrench(final EntityPlayer player, final int x, final int y, final int z) { + // System.out.println("canWrench"); + if (player == null) { + return false; + } + if (player.getCurrentEquippedItem() == null) { + return false; + } + if (!this.isItemStackUsable(player.getCurrentEquippedItem())) { + return false; + } + final Interface_ToolStats tStats = this.getToolStats(player.getCurrentEquippedItem()); + return (tStats != null) && tStats.isWrench(); + } + + @Override + public void wrenchUsed(final EntityPlayer player, final int x, final int y, final int z) { + if (player == null) { + return; + } + if (player.getCurrentEquippedItem() == null) { + return; + } + final IToolStats tStats = this.getToolStats(player.getCurrentEquippedItem()); + if (tStats != null) { + this.doDamage(player.getCurrentEquippedItem(), tStats.getToolDamagePerEntityAttack()); + } + } + + @Override + public boolean canLink(final EntityPlayer aPlayer, final ItemStack aStack, final EntityMinecart cart) { + if (!this.isItemStackUsable(aStack)) { + return false; + } + final IToolStats tStats = this.getToolStats(aStack); + return (tStats != null) && tStats.isCrowbar(); + } + + @Override + public void onLink(final EntityPlayer aPlayer, final ItemStack aStack, final EntityMinecart cart) { + final IToolStats tStats = this.getToolStats(aStack); + if (tStats != null) { + this.doDamage(aStack, tStats.getToolDamagePerEntityAttack()); + } + } + + @Override + public boolean canBoost(final EntityPlayer aPlayer, final ItemStack aStack, final EntityMinecart cart) { + if (!this.isItemStackUsable(aStack)) { + return false; + } + final IToolStats tStats = this.getToolStats(aStack); + return (tStats != null) && tStats.isCrowbar(); + } + + @Override + public void onBoost(final EntityPlayer aPlayer, final ItemStack aStack, final EntityMinecart cart) { + final IToolStats tStats = this.getToolStats(aStack); + if (tStats != null) { + this.doDamage(aStack, tStats.getToolDamagePerEntityAttack()); + } + } + + @Override + public void onCreated(final ItemStack aStack, final World aWorld, final EntityPlayer aPlayer) { + final IToolStats tStats = this.getToolStats(aStack); + if ((tStats != null) && (aPlayer != null)) { + tStats.onToolCrafted(aStack, aPlayer); + } + super.onCreated(aStack, aWorld, aPlayer); + } + + @Override + public boolean isFull3D() { + return true; + } + + @Override + public boolean isItemStackUsable(final ItemStack aStack) { + final IToolStats tStats = this.getToolStatsInternal(aStack); + if (((aStack.getItemDamage() % 2) == 1) || (tStats == null)) { + final NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT != null) { + aNBT.removeTag("ench"); + } + return false; + } + final Materials aMaterial = getPrimaryMaterial(aStack); + final HashMap<Integer, Integer> tMap = new HashMap<>(), tResult = new HashMap<>(); + if (aMaterial.mEnchantmentTools != null) { + tMap.put(aMaterial.mEnchantmentTools.effectId, (int) aMaterial.mEnchantmentToolsLevel); + if (aMaterial.mEnchantmentTools == Enchantment.fortune) { + tMap.put(Enchantment.looting.effectId, (int) aMaterial.mEnchantmentToolsLevel); + } + if (aMaterial.mEnchantmentTools == Enchantment.knockback) { + tMap.put(Enchantment.power.effectId, (int) aMaterial.mEnchantmentToolsLevel); + } + if (aMaterial.mEnchantmentTools == Enchantment.fireAspect) { + tMap.put(Enchantment.flame.effectId, (int) aMaterial.mEnchantmentToolsLevel); + } + } + final Enchantment[] tEnchants = tStats.getEnchantments(aStack); + final int[] tLevels = tStats.getEnchantmentLevels(aStack); + for (int i = 0; i < tEnchants.length; i++) { + if (tLevels[i] > 0) { + final Integer tLevel = tMap.get(tEnchants[i].effectId); + tMap.put( + tEnchants[i].effectId, + tLevel == null ? tLevels[i] : tLevel == tLevels[i] ? tLevel + 1 : Math.max(tLevel, tLevels[i])); + } + } + for (final Entry<Integer, Integer> tEntry : tMap.entrySet()) { + if ((tEntry.getKey() == 33) || ((tEntry.getKey() == 20) && (tEntry.getValue() > 2)) + || (tEntry.getKey() == Enchantment_Radioactivity.INSTANCE.effectId)) { + tResult.put(tEntry.getKey(), tEntry.getValue()); + } else { + switch (Enchantment.enchantmentsList[tEntry.getKey()].type) { + case weapon: + if (tStats.isWeapon()) { + tResult.put(tEntry.getKey(), tEntry.getValue()); + } + break; + case all: + tResult.put(tEntry.getKey(), tEntry.getValue()); + break; + case armor: + case armor_feet: + case armor_head: + case armor_legs: + case armor_torso: + break; + case bow: + if (tStats.isRangedWeapon()) { + tResult.put(tEntry.getKey(), tEntry.getValue()); + } + break; + case breakable: + break; + case fishing_rod: + break; + case digger: + if (tStats.isMiningTool()) { + tResult.put(tEntry.getKey(), tEntry.getValue()); + } + break; + } + } + } + EnchantmentHelper.setEnchantments(tResult, aStack); + return true; + } + + @Override + public short getChargedMetaData(final ItemStack aStack) { + return (short) (aStack.getItemDamage() - (aStack.getItemDamage() % 2)); + } + + @Override + public short getEmptyMetaData(final ItemStack aStack) { + final NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT != null) { + aNBT.removeTag("ench"); + } + return (short) ((aStack.getItemDamage() + 1) - (aStack.getItemDamage() % 2)); + } + + @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; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_ChiselBus.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_ChiselBus.java new file mode 100644 index 0000000000..3009c80c80 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_ChiselBus.java @@ -0,0 +1,78 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; + +import net.minecraft.util.EnumChatFormatting; + +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.Scrollable; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; + +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.modularui.IAddUIWidgets; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBus; + +public class GT_MetaTileEntity_ChiselBus extends GT_MetaTileEntity_Hatch_InputBus implements IAddUIWidgets { + + public GT_MetaTileEntity_ChiselBus(int id, String name, String nameRegional, int tier) { + super(id, name, nameRegional, tier); + } + + public GT_MetaTileEntity_ChiselBus(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { + super(aName, aTier, getSlots(aTier), aDescription, aTextures); + } + + @Override + public boolean isValidSlot(int aIndex) { + return aIndex < getSlots(this.mTier); + } + + public static int getSlots(int aTier) { + return (1 + aTier) * 16 + 1; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_ChiselBus(this.mName, this.mTier, this.mDescriptionArray, this.mTextures); + } + + @Override + public boolean allowSelectCircuit() { + return false; + } + + @Override + public String[] getDescription() { + return new String[] { "Item Input Bus for Industrial Chisel", getSlots(this.mTier) - 1 + " + 1 " + " Slots", + "Added by: " + EnumChatFormatting.AQUA + + "Quetz4l" + + " - " + + EnumChatFormatting.RED + + "[GT++]" + + EnumChatFormatting.RESET }; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + int slotIndex = 0; + final Scrollable scrollable = new Scrollable().setVerticalScroll(); + for (int row = 0; row * 4 < inventoryHandler.getSlots() - 1; row++) { + int columnsToMake = Math.min(inventoryHandler.getSlots() - row * 4, 4); + for (int column = 0; column < columnsToMake; column++) { + scrollable.widget( + new SlotWidget(inventoryHandler, slotIndex++).setPos(column * 18, row * 18) + .setSize(18, 18)); + + } + } + + builder.widget( + scrollable.setSize(18 * 4 + 4, 18 * 4) + .setPos(52, 7)); // main slots + builder.widget( + new SlotWidget(inventoryHandler, slotIndex).setPos(18, 18) + .setSize(18, 18)); // slot for target + } + +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_AirIntake.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_AirIntake.java new file mode 100644 index 0000000000..bab504910e --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_AirIntake.java @@ -0,0 +1,128 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; + +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.Fluid; + +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.FluidUtils; + +public class GT_MetaTileEntity_Hatch_AirIntake extends GT_MetaTileEntity_Hatch_FluidGenerator { + + public GT_MetaTileEntity_Hatch_AirIntake(final int aID, final String aName, final String aNameRegional, + final int aTier) { + super(aID, aName, aNameRegional, aTier); + } + + public GT_MetaTileEntity_Hatch_AirIntake(final String aName, final int aTier, final String[] aDescription, + final ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } + + @Override + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Hatch_AirIntake(this.mName, this.mTier, this.mDescriptionArray, this.mTextures); + } + + @Override + public String[] getCustomTooltip() { + String[] aTooltip = new String[3]; + aTooltip[0] = "DO NOT OBSTRUCT THE INPUT!"; + aTooltip[1] = "Draws in Air from the surrounding environment"; + aTooltip[2] = "Creates " + getAmountOfFluidToGenerate() + "L of Air every " + getMaxTickTime() + " ticks"; + return aTooltip; + } + + @Override + public Fluid getFluidToGenerate() { + return FluidUtils.getAir(1) + .getFluid(); + } + + @Override + public int getAmountOfFluidToGenerate() { + return 1000; + } + + @Override + public int getMaxTickTime() { + return 4; + } + + @Override + public int getCapacity() { + return 128000; + } + + @Override + public boolean doesHatchMeetConditionsToGenerate() { + return this.getBaseMetaTileEntity() + .getAirAtSide( + this.getBaseMetaTileEntity() + .getFrontFacing()); + } + + @Override + public void generateParticles(World aWorld, String name) { + if (this.getBaseMetaTileEntity() + .isServerSide()) { + return; + } + final float ran1 = GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat(); + float ran2 = 0.0f; + float ran3 = 0.0f; + ran2 = GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat(); + ran3 = GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat(); + + final IGregTechTileEntity aMuffler = this.getBaseMetaTileEntity(); + final ForgeDirection aDir = aMuffler.getFrontFacing(); + final float xPos = aDir.offsetX * 0.76f + aMuffler.getXCoord() + 0.25f; + float yPos = aDir.offsetY * 0.76f + aMuffler.getYCoord() + 0.65f; + final float zPos = aDir.offsetZ * 0.76f + aMuffler.getZCoord() + 0.25f; + float ySpd = aDir.offsetY * 0.1f + 0.2f + 0.1f * GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat(); + float xSpd; + float zSpd; + if (aDir.offsetY == -1) { + // Logger.INFO("Y = -1"); + final float temp = GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat() * 2.0f * CORE.PI; + xSpd = (float) Math.sin(temp) * 0.1f; + zSpd = (float) Math.cos(temp) * 0.1f; + ySpd = -ySpd; + yPos = yPos - 0.8f; + } else { + xSpd = aDir.offsetX * (0.1f + 0.2f * GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat()); + zSpd = aDir.offsetZ * (0.1f + 0.2f * GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat()); + + xSpd = -xSpd; + zSpd = -zSpd; + } + + aWorld.spawnParticle( + name, + (double) (xPos + ran1 * 0.5f), + (double) (yPos + GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat() * 0.5f), + (double) (zPos + GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat() * 0.5f), + (double) xSpd, + (double) -ySpd, + (double) zSpd); + aWorld.spawnParticle( + name, + (double) (xPos + ran2 * 0.5f), + (double) (yPos + GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat() * 0.5f), + (double) (zPos + GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat() * 0.5f), + (double) xSpd, + (double) -ySpd, + (double) zSpd); + aWorld.spawnParticle( + name, + (double) (xPos + ran3 * 0.5f), + (double) (yPos + GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat() * 0.5f), + (double) (zPos + GT_MetaTileEntity_Hatch_AirIntake.floatGen.nextFloat() * 0.5f), + (double) xSpd, + (double) -ySpd, + (double) zSpd); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_AirIntake_Extreme.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_AirIntake_Extreme.java new file mode 100644 index 0000000000..007310fc06 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_AirIntake_Extreme.java @@ -0,0 +1,37 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; + +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; + +public class GT_MetaTileEntity_Hatch_AirIntake_Extreme extends GT_MetaTileEntity_Hatch_AirIntake { + + public GT_MetaTileEntity_Hatch_AirIntake_Extreme(final int aID, final String aName, final String aNameRegional, + final int aTier) { + super(aID, aName, aNameRegional, aTier); + } + + public GT_MetaTileEntity_Hatch_AirIntake_Extreme(final String aName, final int aTier, final String[] aDescription, + final ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } + + @Override + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Hatch_AirIntake_Extreme( + this.mName, + this.mTier, + this.mDescriptionArray, + this.mTextures); + } + + @Override + public int getAmountOfFluidToGenerate() { + return 8000; + } + + @Override + public int getCapacity() { + return 256000; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_DynamoBuffer.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_DynamoBuffer.java new file mode 100644 index 0000000000..f375900800 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_DynamoBuffer.java @@ -0,0 +1,67 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; + +import gregtech.api.enums.GT_Values; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Dynamo; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GT_MetaTileEntity_Hatch_DynamoBuffer extends GT_MetaTileEntity_Hatch_Dynamo { + + public GT_MetaTileEntity_Hatch_DynamoBuffer(final int aID, final String aName, final String aNameRegional, + final int aTier) { + super(aID, aName, aNameRegional, aTier); + } + + public GT_MetaTileEntity_Hatch_DynamoBuffer(final String aName, final int aTier, final String[] aDescription, + final ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } + + @Override + public ITexture[] getTexturesActive(final ITexture aBaseTexture) { + return new ITexture[] { aBaseTexture, TexturesGtBlock.OVERLAYS_ENERGY_OUT_MULTI_BUFFER[this.mTier] }; + } + + @Override + public ITexture[] getTexturesInactive(final ITexture aBaseTexture) { + return new ITexture[] { aBaseTexture, TexturesGtBlock.OVERLAYS_ENERGY_OUT_MULTI_BUFFER[this.mTier] }; + } + + @Override + public long getMinimumStoredEU() { + return 0L; + } + + @Override + public long maxEUStore() { + return 512L + GT_Values.V[this.mTier + 1] * 2048L; + } + + @Override + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Hatch_DynamoBuffer(this.mName, this.mTier, this.mDescriptionArray, this.mTextures); + } + + @Override + public String[] getDescription() { + String[] g; + g = new String[] { "Dynamo with internal storage and additional Amp capacity", + "Does not accept more than " + (this.maxEUOutput() * this.maxAmperesIn()) + "EU/t as input", + CORE.GT_Tooltip.get() }; + + return g; + } + + @Override + public long maxAmperesIn() { + return 4; + } + + @Override + public long maxAmperesOut() { + return 4; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_ElementalDataOrbHolder.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_ElementalDataOrbHolder.java new file mode 100644 index 0000000000..336c6eb011 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_ElementalDataOrbHolder.java @@ -0,0 +1,229 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; + +import java.util.ArrayList; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; + +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.SlotGroup; + +import gregtech.api.enums.ItemList; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.gui.modularui.GT_UITextures; +import gregtech.api.interfaces.IConfigurationCircuitSupport; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; +import gregtech.api.objects.GT_RenderedTexture; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GT_MetaTileEntity_Hatch_ElementalDataOrbHolder extends GT_MetaTileEntity_Hatch + implements IConfigurationCircuitSupport { + + public GT_MetaTileEntity_Hatch_ElementalDataOrbHolder(int aID, String aName, String aNameRegional, int aTier) { + super( + aID, + aName, + aNameRegional, + aTier, + 17, + new String[] { "Holds Data Orbs for the Elemental Duplicator", "Can insert/extract the circuit slot", + "A circuit must be used to select a slot (1-16)", CORE.GT_Tooltip.get() }); + } + + public GT_MetaTileEntity_Hatch_ElementalDataOrbHolder(String aName, int aTier, String aDescription, + ITexture[][][] aTextures) { + super(aName, aTier, 17, aDescription, aTextures); + } + + public GT_MetaTileEntity_Hatch_ElementalDataOrbHolder(String aName, int aTier, String[] aDescription, + ITexture[][][] aTextures) { + super(aName, aTier, 17, aDescription, aTextures); + } + + @Override + public ITexture[] getTexturesActive(ITexture aBaseTexture) { + return new ITexture[] { aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Hatch_Data_Orb) }; + } + + @Override + public ITexture[] getTexturesInactive(ITexture aBaseTexture) { + return new ITexture[] { aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Hatch_Data_Orb) }; + } + + @Override + public boolean isSimpleMachine() { + return true; + } + + @Override + public boolean isFacingValid(ForgeDirection facing) { + return true; + } + + @Override + public boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean isValidSlot(int aIndex) { + return true; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Hatch_ElementalDataOrbHolder(mName, mTier, mDescriptionArray, mTextures); + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); + return true; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { + if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.hasInventoryBeenModified()) { + fillStacksIntoFirstSlots(); + } + } + + public void updateSlots() { + for (int i = 0; i < mInventory.length - 1; i++) + if (mInventory[i] != null && mInventory[i].stackSize <= 0) mInventory[i] = null; + fillStacksIntoFirstSlots(); + } + + protected void fillStacksIntoFirstSlots() { + for (int i = 0; i < mInventory.length - 1; i++) { + if (mInventory[i] != null && mInventory[i].stackSize <= 0) { + mInventory[i] = null; + } + } + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + } + + @Override + public void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) {} + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + Logger.INFO("Checking if we can pull " + aStack.getDisplayName() + " from slot " + aIndex); + if (aIndex == mInventory.length - 1 && ItemUtils.isControlCircuit(aStack) + && side == getBaseMetaTileEntity().getFrontFacing()) { + return true; + } + return false; + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + Logger.INFO("Checking if we can put " + aStack.getDisplayName() + " into slot " + aIndex); + if (aIndex == mInventory.length - 1 && ItemUtils.isControlCircuit(aStack) + && side == getBaseMetaTileEntity().getFrontFacing()) { + return true; + } + return false; + } + + public ArrayList<ItemStack> getInventory() { + ArrayList<ItemStack> aContents = new ArrayList<>(); + for (int i = getBaseMetaTileEntity().getSizeInventory() - 2; i >= 0; i--) { + if (getBaseMetaTileEntity().getStackInSlot(i) != null) + aContents.add(getBaseMetaTileEntity().getStackInSlot(i)); + } + return aContents; + } + + public ItemStack getOrbByCircuit() { + ItemStack aCirc = getBaseMetaTileEntity().getStackInSlot(getCircuitSlot()); + if (aCirc != null && ItemUtils.isControlCircuit(aCirc)) { + int slot = aCirc.getItemDamage() - 1; // slots are 0 indexed but there's no 0 circuit + if (slot < getBaseMetaTileEntity().getSizeInventory() - 1) { + return getBaseMetaTileEntity().getStackInSlot(slot); + } else { + return null; + } + } else { + return null; + } + } + + @Override + public boolean canInsertItem(int aIndex, ItemStack aStack, int ordinalSide) { + if (aIndex == mInventory.length - 1 && ItemUtils.isControlCircuit(aStack) + && ordinalSide == getBaseMetaTileEntity().getFrontFacing() + .ordinal()) { + Logger.INFO("Putting " + aStack.getDisplayName() + " into slot " + aIndex); + return true; + } + return false; + } + + @Override + public boolean canExtractItem(int aIndex, ItemStack aStack, int ordinalSide) { + if (aIndex == mInventory.length - 1 && ItemUtils.isControlCircuit(aStack)) { + Logger.INFO("Pulling " + aStack.getDisplayName() + " from slot " + aIndex); + return true; + } + return false; + } + + @Override + public boolean allowSelectCircuit() { + return true; + } + + @Override + public int getCircuitSlot() { + return getSlots(mTier); + } + + @Override + public int getCircuitSlotX() { + return 153; + } + + @Override + public int getCircuitSlotY() { + return 63; + } + + @Override + public boolean useModularUI() { + return true; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + builder.widget( + SlotGroup.ofItemHandler(inventoryHandler, 4) + .startFromSlot(0) + .endAtSlot(15) + .background(getGUITextureSet().getItemSlot(), GT_UITextures.OVERLAY_SLOT_DATA_ORB) + .applyForWidget( + widget -> widget.setFilter(stack -> ItemList.Tool_DataOrb.isStackEqual(stack, false, true))) + .build() + .setPos(52, 7)); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_FluidGenerator.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_FluidGenerator.java new file mode 100644 index 0000000000..b4e213e829 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_FluidGenerator.java @@ -0,0 +1,255 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; + +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.objects.XSTR; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.FluidUtils; + +public abstract class GT_MetaTileEntity_Hatch_FluidGenerator extends GT_MetaTileEntity_Hatch_Input { + + protected static XSTR floatGen = new XSTR(); + public int mProgresstime = 0, mMaxProgresstime = 0; + + public GT_MetaTileEntity_Hatch_FluidGenerator(final int aID, final String aName, final String aNameRegional, + final int aTier) { + super(aID, aName, aNameRegional, aTier); + } + + public GT_MetaTileEntity_Hatch_FluidGenerator(final String aName, final int aTier, final String[] aDescription, + final ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } + + public abstract String[] getCustomTooltip(); + + public abstract Fluid getFluidToGenerate(); + + public abstract int getAmountOfFluidToGenerate(); + + public abstract int getMaxTickTime(); + + @Override + public synchronized String[] getDescription() { + mDescriptionArray[1] = "Capacity: " + GT_Utility.formatNumbers(getCapacity()) + "L"; + final String[] hatchTierString = new String[] { "Hatch Tier: " + GT_Utility.getColoredTierNameFromTier(mTier) }; + + String[] aCustomTips = getCustomTooltip(); + final String[] desc = new String[mDescriptionArray.length + aCustomTips.length + 2]; + System.arraycopy(mDescriptionArray, 0, desc, 0, mDescriptionArray.length); + System.arraycopy(hatchTierString, 0, desc, mDescriptionArray.length, 1); + System.arraycopy(aCustomTips, 0, desc, mDescriptionArray.length + 1, aCustomTips.length); + desc[mDescriptionArray.length + aCustomTips.length] = CORE.GT_Tooltip.get(); + return desc; + } + + @Override + public ITexture[] getTexturesActive(final ITexture aBaseTexture) { + return new ITexture[] { aBaseTexture, + new GT_RenderedTexture((IIconContainer) Textures.BlockIcons.OVERLAY_MUFFLER) }; + } + + @Override + public ITexture[] getTexturesInactive(final ITexture aBaseTexture) { + return new ITexture[] { aBaseTexture, + new GT_RenderedTexture((IIconContainer) Textures.BlockIcons.OVERLAY_MUFFLER) }; + } + + @Override + public boolean isSimpleMachine() { + return true; + } + + @Override + public boolean isFacingValid(final ForgeDirection facing) { + return true; + } + + @Override + public boolean isAccessAllowed(final EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean isValidSlot(final int aIndex) { + return false; + } + + @Override + public abstract MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity); + + public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, + final ForgeDirection side, final ItemStack aStack) { + return false; + } + + public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, + final ForgeDirection side, final ItemStack aStack) { + return false; + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (!aBaseMetaTileEntity.isAllowedToWork()) { + aBaseMetaTileEntity.setActive(false); + mProgresstime = 0; + mMaxProgresstime = 0; + } else { + aBaseMetaTileEntity.setActive(true); + mMaxProgresstime = getMaxTickTime(); + if (++mProgresstime >= mMaxProgresstime) { + if (this.canTankBeFilled()) { + addFluidToHatch(aTick); + } + mProgresstime = 0; + } + } + } + + @Override + public int getProgresstime() { + return mProgresstime; + } + + @Override + public int maxProgresstime() { + return mMaxProgresstime; + } + + @Override + public int increaseProgress(int aProgress) { + mProgresstime += aProgress; + return mMaxProgresstime - mProgresstime; + } + + public abstract void generateParticles(final World aWorld, final String name); + + @Override + public int getTankPressure() { + return 100; + } + + @Override + public abstract int getCapacity(); + + @Override + public boolean canTankBeEmptied() { + return true; + } + + public abstract boolean doesHatchMeetConditionsToGenerate(); + + public boolean addFluidToHatch(long aTick) { + if (!doesHatchMeetConditionsToGenerate()) { + return false; + } + int aFillAmount = this.fill(FluidUtils.getFluidStack(getFluidToGenerate(), getAmountOfFluidToGenerate()), true); + if (aFillAmount > 0) { + if (this.getBaseMetaTileEntity() + .isClientSide()) { + generateParticles( + this.getBaseMetaTileEntity() + .getWorld(), + "cloud"); + } + } + return aFillAmount > 0; + } + + @Override + public boolean canTankBeFilled() { + return true; + } + + @Override + public boolean doesEmptyContainers() { + return false; + } + + @Override + public boolean doesFillContainers() { + return true; + } + + @Override + public int fill(FluidStack aFluid, boolean doFill) { + if (aFluid == null || aFluid.getFluid() + .getID() <= 0 || aFluid.amount <= 0 || aFluid.getFluid() != getFluidToGenerate() || !canTankBeFilled()) { + return 0; + } + + if (getFillableStack() == null || getFillableStack().getFluid() + .getID() <= 0) { + if (aFluid.amount <= getCapacity()) { + if (doFill) { + setFillableStack(aFluid.copy()); + getBaseMetaTileEntity().markDirty(); + } + return aFluid.amount; + } + if (doFill) { + setFillableStack(aFluid.copy()); + getFillableStack().amount = getCapacity(); + getBaseMetaTileEntity().markDirty(); + } + return getCapacity(); + } + + if (!getFillableStack().isFluidEqual(aFluid)) return 0; + + int space = getCapacity() - getFillableStack().amount; + if (aFluid.amount <= space) { + if (doFill) { + getFillableStack().amount += aFluid.amount; + getBaseMetaTileEntity().markDirty(); + } + return aFluid.amount; + } + if (doFill) getFillableStack().amount = getCapacity(); + return space; + } + + @Override + public boolean canFill(ForgeDirection aSide, Fluid aFluid) { + return false; + } + + @Override + public int fill(ForgeDirection arg0, FluidStack arg1, boolean arg2) { + return 0; + } + + @Override + public int fill_default(ForgeDirection aSide, FluidStack aFluid, boolean doFill) { + return 0; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setInteger("mProgresstime", mProgresstime); + aNBT.setInteger("mMaxProgresstime", mMaxProgresstime); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + mProgresstime = aNBT.getInteger("mProgresstime"); + mMaxProgresstime = aNBT.getInteger("mMaxProgresstime"); + super.loadNBTData(aNBT); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBattery.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBattery.java new file mode 100644 index 0000000000..c55ddda47d --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBattery.java @@ -0,0 +1,235 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; + +import static gregtech.api.enums.GT_Values.V; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; + +import org.apache.commons.lang3.ArrayUtils; + +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; + +import gregtech.api.enums.GT_Values; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.gui.widget.ElectricSlotWidget; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GT_MetaTileEntity_Hatch_InputBattery extends GT_MetaTileEntity_Hatch { + + public final RecipeMap<?> mRecipeMap = null; + + public GT_MetaTileEntity_Hatch_InputBattery(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, getSlots(aTier), "Chargeable Item Bus for Multiblocks"); + } + + public GT_MetaTileEntity_Hatch_InputBattery(String aName, int aTier, String[] aDescription, + ITexture[][][] aTextures) { + super(aName, aTier, aTier < 1 ? 1 : aTier == 1 ? 4 : aTier == 2 ? 4 : 16, aDescription, aTextures); + } + + @Override + public String[] getDescription() { + int mSlots = 0; + if (this.mTier == 2) { + mSlots = 4; + } else if (this.mTier == 4) { + mSlots = 16; + } else { + mSlots = 16; + } + return ArrayUtils.addAll(this.mDescriptionArray, "Capacity: " + mSlots + " slots", CORE.GT_Tooltip.get()); + } + + @Override + public boolean isEnetInput() { + return true; + } + + @Override + public boolean isInputFacing(ForgeDirection side) { + return side == getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public long getMinimumStoredEU() { + return 0; + } + + @Override + public long maxEUInput() { + return V[mTier]; + } + + @Override + public long maxEUStore() { + return 512 + V[mTier + 1] * 16; + } + + @Override + public long maxAmperesIn() { + return 4; + } + + @Override + public ITexture[] getTexturesActive(ITexture aBaseTexture) { + return new ITexture[] { aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Hatch_Charger) }; + } + + @Override + public ITexture[] getTexturesInactive(ITexture aBaseTexture) { + return new ITexture[] { aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Hatch_Charger) }; + } + + @Override + public boolean isSimpleMachine() { + return true; + } + + @Override + public boolean isFacingValid(ForgeDirection facing) { + return true; + } + + @Override + public boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean isValidSlot(int aIndex) { + return true; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Hatch_InputBattery(mName, mTier, mDescriptionArray, mTextures); + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); + return true; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { + if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.hasInventoryBeenModified()) { + fillStacksIntoFirstSlots(); + } + if (aBaseMetaTileEntity.isServerSide()) { + if (aBaseMetaTileEntity.getMetaTileEntity() instanceof MetaTileEntity mMetaTileEntity) { + if (mMetaTileEntity.rechargerSlotCount() > 0 && aBaseMetaTileEntity.getStoredEU() > 0) { + for (int i = mMetaTileEntity.rechargerSlotStartIndex(), + k = mMetaTileEntity.rechargerSlotCount() + i; i < k; i++) { + if (aBaseMetaTileEntity.getStoredEU() > 0 && mMetaTileEntity.mInventory[i] != null) { + for (int u = 0; u < 10; u++) { + aBaseMetaTileEntity.decreaseStoredEnergyUnits( + GT_ModHandler.chargeElectricItem( + mMetaTileEntity.mInventory[i], + (int) Math.min(V[this.mTier] * 15, aBaseMetaTileEntity.getStoredEU()), + (int) Math.min(Integer.MAX_VALUE, GT_Values.V[u]), + false, + false), + true); + if (mMetaTileEntity.mInventory[i].stackSize <= 0) { + mMetaTileEntity.mInventory[i] = null; + } + } + } + } + } else {} + } + } + super.onPostTick(aBaseMetaTileEntity, aTimer); + } + + public void updateSlots() { + for (int i = 0; i < mInventory.length; i++) + if (mInventory[i] != null && mInventory[i].stackSize <= 0) mInventory[i] = null; + fillStacksIntoFirstSlots(); + } + + protected void fillStacksIntoFirstSlots() { + for (int i = 0; i < mInventory.length; i++) + for (int j = i + 1; j < mInventory.length; j++) if (mInventory[j] != null + && (mInventory[i] == null || GT_Utility.areStacksEqual(mInventory[i], mInventory[j]))) { + GT_Utility.moveStackFromSlotAToSlotB( + getBaseMetaTileEntity(), + getBaseMetaTileEntity(), + j, + i, + (byte) 64, + (byte) 1, + (byte) 64, + (byte) 1); + } + } + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return side == getBaseMetaTileEntity().getFrontFacing() + && (mRecipeMap == null || mRecipeMap.containsInput(aStack)); + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return side == getBaseMetaTileEntity().getFrontFacing() + && (mRecipeMap == null || mRecipeMap.containsInput(aStack)); + } + + @Override + public int rechargerSlotStartIndex() { + return 0; + } + + @Override + public int rechargerSlotCount() { + return switch (mTier) { + case 2 -> 4; + case 4 -> 16; + default -> 16; + }; + } + + @Override + public int dechargerSlotStartIndex() { + return 0; + } + + @Override + public int dechargerSlotCount() { + return 0; + } + + @Override + public boolean useModularUI() { + return true; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + if (mTier == 2) { + for (int i = 0; i < 4; i++) { + builder + .widget(new ElectricSlotWidget(inventoryHandler, i).setPos(70 + (i % 2) * 18, 25 + (i / 2) * 18)); + } + } else { + for (int i = 0; i < 16; i++) { + builder.widget(new ElectricSlotWidget(inventoryHandler, i).setPos(52 + (i % 4) * 18, 7 + (i / 4) * 18)); + } + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler_Adv.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler_Adv.java new file mode 100644 index 0000000000..a3261af6f6 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler_Adv.java @@ -0,0 +1,370 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; + +import gregtech.GT_Mod; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.gui.modularui.GUITextureSet; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.modularui.IAddGregtechLogo; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Muffler; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Config; +import gregtech.common.GT_Pollution; +import gtPlusPlus.core.item.general.ItemAirFilter; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.gregtech.PollutionUtils; +import gtPlusPlus.xmod.gregtech.api.gui.GTPP_UITextures; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GT_MetaTileEntity_Hatch_Muffler_Adv extends GT_MetaTileEntity_Hatch_Muffler implements IAddGregtechLogo { + + protected int SLOT_FILTER = 0; + + @Override + public void onConfigLoad(GT_Config aConfig) { + super.onConfigLoad(aConfig); + try { + int a1 = GT_Mod.gregtechproxy.mPollutionSmogLimit; + if (a1 > 0) { + mPollutionSmogLimit = a1; + } + } catch (Throwable t) { + mPollutionSmogLimit = 500000; + } + } + + private int mPollutionSmogLimit = 500000; + + public GT_MetaTileEntity_Hatch_Muffler_Adv(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, 1, new String[] { "" }); + } + + public GT_MetaTileEntity_Hatch_Muffler_Adv(String aName, int aTier, String[] aDescription, + ITexture[][][] aTextures) { + super(aName, aTier, 1, aDescription, aTextures); + } + + final String[] mDescription = new String[] { "Outputs pollution from a multiblock", "DO NOT OBSTRUCT THE OUTPUT!", + "Requires 3 Air Blocks in front of the exhaust face", + mTier < 5 ? "Requires an Air Filter" + : "Requires an Air Filter " + EnumChatFormatting.WHITE + "[Tier 2]" + EnumChatFormatting.GRAY, + "Can take Air Filters from an input bus of the multiblock", + "Reduces Pollution to " + calculatePollutionReduction(100, true) + "%", + "Recovers " + (100 - calculatePollutionReduction(100, true)) + "% of CO2/CO/SO2", CORE.GT_Tooltip.get() }; + + @Override + public String[] getDescription() { + return mDescription; + } + + @Override + public ITexture[] getTexturesActive(ITexture aBaseTexture) { + return new ITexture[] { aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Hatch_Muffler_Adv) }; + } + + @Override + public ITexture[] getTexturesInactive(ITexture aBaseTexture) { + return new ITexture[] { aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Hatch_Muffler_Adv) }; + } + + @Override + public boolean isValidSlot(int aIndex) { + return aIndex == SLOT_FILTER; + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return (aIndex == this.SLOT_FILTER && isAirFilter(aStack)); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Hatch_Muffler_Adv(this.mName, this.mTier, mDescriptionArray, this.mTextures); + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); + return true; + } + + @Override + public boolean polluteEnvironment(MetaTileEntity parentTileEntity) { + if (!airCheck()) return false; // Muffler obstructed. + + int emission = 10000; + if (damageAirFilter(parentTileEntity)) { + // damageAirFilter already checks that we have a valid filter. + emission = calculatePollutionReduction(emission, true); + } else { + // Revert to reduction of the basic muffler. + emission = super.calculatePollutionReduction(emission); + } + GT_Pollution.addPollution(getBaseMetaTileEntity(), emission); + return true; + } + + @Override + public int calculatePollutionReduction(int aPollution) { + // This is called by EBF to calculate exhaust gas amounts, we need to check the filter. + return calculatePollutionReduction(aPollution, false); + } + + /** + * Calculates pollution reduction. + * + * @param aPollution Amount of pollution to be reduced. + * @param ignoreFilter If this is true, assumes that a valid filter is present without checking (for example, to + * build tooltips). + * @return Amount of pollution after reduction. + */ + protected int calculatePollutionReduction(int aPollution, boolean ignoreFilter) { + if (!ignoreFilter && !hasAirFilter()) { + // Without a filter, downgrade to basic muffler reduction. + return super.calculatePollutionReduction(aPollution); + } + + // Special case to be always better than a basic muffler. + if (mTier < 2) return (int) (aPollution * 0.95); + if (mTier > 8) return 0; + + return (int) (aPollution * Math.pow(0.64D, mTier - 1)); + } + + /** + * + * @return True if enough blocks in front of the muffler are air. + */ + private boolean airCheck() { + IGregTechTileEntity bmte = getBaseMetaTileEntity(); + ForgeDirection facing = bmte.getFrontFacing(); + return bmte.getAirAtSide(facing) && bmte.getAirAtSideAndDistance(facing, 1) + && bmte.getAirAtSideAndDistance(facing, 2); + } + + /** + * Try to damage an air filter. Will first try to find a valid filter in the hatch's own inventory, then in the + * input buses of the parent multiblock. If the filter is destroyed, will try to replace it from the parent + * multiblock's input buses again. + * + * @param parentTileEntity Which multiblock this hatch is a part of. If this is null, only checks inventory of the + * muffler. + * @return True if the filter has been successfully damaged. + */ + private boolean damageAirFilter(MetaTileEntity parentTileEntity) { + if (!findAirFilter(parentTileEntity)) return false; // No filter available. + + ItemStack filter = mInventory[SLOT_FILTER]; + if (filter == null) return false; // This should never happen if findAirFilter() above succeeded. + + long currentDamage = ItemAirFilter.getFilterDamage(filter); + if (currentDamage < ItemAirFilter.getFilterMaxDamage(filter) - 1) { + // Damage filter by one step. + ItemAirFilter.setFilterDamage(filter, currentDamage + 1); + return true; + } else { + // Destroy the filter. + mInventory[SLOT_FILTER] = null; + + // Try to find a new one. + findAirFilter(parentTileEntity); + + // Regardless of whether we have a new filter or not, *this* operation succeeded. + return true; + } + } + + /** + * Try to find a valid air filter in the input buses of the parent multiblock. + * + * @param parentTileEntity Which multiblock this hatch is a part of. If this is null, only checks inventory of the + * muffler. + * @return True if the inventory of the muffler already contains an air filter, or if one was retrieved from the + * parent multiblock. + */ + private boolean findAirFilter(MetaTileEntity parentTileEntity) { + if (hasAirFilter()) return true; // Has a filter in inventory. + if (mInventory[SLOT_FILTER] != null) return false; // Has a non-filter item in inventory. + if (parentTileEntity == null) return false; // Unknown parent multiblock. + + if (parentTileEntity instanceof GT_MetaTileEntity_MultiBlockBase GTMultiBase) { + for (var inputBus : GTMultiBase.mInputBusses) { + for (ItemStack stack : inputBus.mInventory) { + if (isAirFilter(stack)) { + ItemStack stackCopy = stack.copy(); + if (GTMultiBase.depleteInput(stack)) { + mInventory[SLOT_FILTER] = stackCopy; + return true; + } + } + } + } + } + + return false; + } + + /** + * + * @return True if the item currently in the inventory is an air filter valid for this tier of muffler hatch. + */ + private boolean hasAirFilter() { + return isAirFilter(mInventory[SLOT_FILTER]); + } + + /** + * + * @param filter + * @return True if the argument is an air filter valid for this tier of muffler hatch. + */ + public boolean isAirFilter(ItemStack filter) { + if (filter == null) return false; + if (filter.getItem() instanceof ItemAirFilter) { + if (mTier < 5) { + // Accept any filter. + return true; + } else { + // Accept only T2 filter. + return filter.getItemDamage() == 1; + } + } + return false; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + + if (aBaseMetaTileEntity.isClientSide()) { + if (this.getBaseMetaTileEntity() + .isActive()) { + String aParticleName; + if ((aTick % 2) == 0) { + aParticleName = "cloud"; + } else { + aParticleName = "smoke"; + } + this.pollutionParticles( + this.getBaseMetaTileEntity() + .getWorld(), + aParticleName); + } + } + } + + @Override + public void pollutionParticles(World aWorld, String name) { + float ran1 = CORE.RANDOM.nextFloat(); + float ran2 = 0.0F; + float ran3 = 0.0F; + boolean chk1 = ran1 * 100.0F < (float) this.calculatePollutionReduction(100); + boolean chk2; + boolean chk3; + int aPollutionAmount = PollutionUtils.getPollution(getBaseMetaTileEntity()); + if (aPollutionAmount >= mPollutionSmogLimit) { + ran2 = CORE.RANDOM.nextFloat(); + ran3 = CORE.RANDOM.nextFloat(); + chk2 = ran2 * 100.0F < (float) this.calculatePollutionReduction(100); + chk3 = ran3 * 100.0F < (float) this.calculatePollutionReduction(100); + if (!chk1 && !chk2 && !chk3) { + return; + } + } else { + if (!chk1) { + return; + } + + chk3 = false; + chk2 = false; + } + + IGregTechTileEntity aMuffler = this.getBaseMetaTileEntity(); + ForgeDirection aDir = aMuffler.getFrontFacing(); + float xPos = (float) aDir.offsetX * 0.76F + (float) aMuffler.getXCoord() + 0.25F; + float yPos = (float) aDir.offsetY * 0.76F + (float) aMuffler.getYCoord() + 0.25F; + float zPos = (float) aDir.offsetZ * 0.76F + (float) aMuffler.getZCoord() + 0.25F; + float ySpd = (float) aDir.offsetY * 0.1F + 0.2F + 0.1F * CORE.RANDOM.nextFloat(); + float xSpd; + float zSpd; + if (aDir.offsetY == -1) { + float temp = CORE.RANDOM.nextFloat() * 2.0F * CORE.PI; + xSpd = (float) Math.sin((double) temp) * 0.1F; + zSpd = (float) Math.cos((double) temp) * 0.1F; + } else { + xSpd = (float) aDir.offsetX * (0.1F + 0.2F * CORE.RANDOM.nextFloat()); + zSpd = (float) aDir.offsetZ * (0.1F + 0.2F * CORE.RANDOM.nextFloat()); + } + + if (chk1) { + aWorld.spawnParticle( + name, + (double) (xPos + ran1 * 0.5F), + (double) (yPos + CORE.RANDOM.nextFloat() * 0.5F), + (double) (zPos + CORE.RANDOM.nextFloat() * 0.5F), + (double) xSpd, + (double) ySpd, + (double) zSpd); + } + + if (chk2) { + aWorld.spawnParticle( + name, + (double) (xPos + ran2 * 0.5F), + (double) (yPos + CORE.RANDOM.nextFloat() * 0.5F), + (double) (zPos + CORE.RANDOM.nextFloat() * 0.5F), + (double) xSpd, + (double) ySpd, + (double) zSpd); + } + + if (chk3) { + aWorld.spawnParticle( + name, + (double) (xPos + ran3 * 0.5F), + (double) (yPos + CORE.RANDOM.nextFloat() * 0.5F), + (double) (zPos + CORE.RANDOM.nextFloat() * 0.5F), + (double) xSpd, + (double) ySpd, + (double) zSpd); + } + } + + @Override + public boolean useModularUI() { + return true; + } + + @Override + public void addGregTechLogo(ModularWindow.Builder builder) {} + + @Override + public GUITextureSet getGUITextureSet() { + return new GUITextureSet().setMainBackground(GTPP_UITextures.BACKGROUND_YELLOW) + .setItemSlot(GTPP_UITextures.SLOT_ITEM_YELLOW) + .setTitleTab( + GTPP_UITextures.TAB_TITLE_YELLOW, + GTPP_UITextures.TAB_TITLE_DARK_YELLOW, + GTPP_UITextures.TAB_TITLE_ANGULAR_YELLOW); + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + builder.widget( + new SlotWidget(inventoryHandler, 0).setFilter(stack -> stack.getItem() instanceof ItemAirFilter) + .setBackground(getGUITextureSet().getItemSlot()) + .setPos(79, 34)); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Naquadah.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Naquadah.java new file mode 100644 index 0000000000..ad94907d4c --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Naquadah.java @@ -0,0 +1,203 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; + +import java.lang.reflect.Field; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; + +import gregtech.api.enums.Materials; +import gregtech.api.enums.Textures; +import gregtech.api.enums.Textures.BlockIcons; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.reflect.ReflectionUtils; + +public class GT_MetaTileEntity_Hatch_Naquadah extends GT_MetaTileEntity_Hatch_Input { + + public final FluidStack[] mFluidsToUse = new FluidStack[3]; + public final int mFluidCapacity; + + public GT_MetaTileEntity_Hatch_Naquadah(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional, 6); + mFluidCapacity = 32000; + initHatch(); + } + + public GT_MetaTileEntity_Hatch_Naquadah(final String aName, final String[] aDescription, + final ITexture[][][] aTextures) { + super(aName, 6, aDescription[0], aTextures); + mFluidCapacity = 32000; + initHatch(); + } + + private void initHatch() { + if (mFluidsToUse[0] == null) { + mFluidsToUse[0] = Materials.Naquadah.getMolten(1); + } + if (mFluidsToUse[1] == null) { + mFluidsToUse[1] = Materials.NaquadahEnriched.getMolten(1); + } + if (mFluidsToUse[2] == null) { + mFluidsToUse[2] = Materials.Naquadria.getMolten(1); + } + } + + @Override + public ITexture[] getTexturesActive(final ITexture aBaseTexture) { + return new ITexture[] { aBaseTexture, + new GT_RenderedTexture((IIconContainer) Textures.BlockIcons.NAQUADAH_REACTOR_FLUID_SIDE_ACTIVE) }; + } + + @Override + public ITexture[] getTexturesInactive(final ITexture aBaseTexture) { + return new ITexture[] { aBaseTexture, + new GT_RenderedTexture((IIconContainer) Textures.BlockIcons.NAQUADAH_REACTOR_FLUID_SIDE) }; + } + + public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, + final ForgeDirection side, final ItemStack aStack) { + if (side == aBaseMetaTileEntity.getFrontFacing() && aIndex == 0) { + for (FluidStack f : mFluidsToUse) { + if (f != null) { + if (GT_Utility.getFluidForFilledItem(aStack, true) + .getFluid() == f.getFluid()) { + return true; + } + } + } + } + return false; + } + + @Override + public boolean isFluidInputAllowed(final FluidStack aFluid) { + for (FluidStack f : mFluidsToUse) { + if (f != null) { + if (aFluid.getFluid() == f.getFluid()) { + return true; + } + } + } + return false; + } + + @Override + public int getCapacity() { + return this.mFluidCapacity; + } + + @Override + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Hatch_Naquadah(this.mName, this.mDescriptionArray, this.mTextures); + } + + @Override + public String[] getDescription() { + if (aDescCache[0] == null || aDescCache[0].contains(".name") || aDescCache[0].contains("fluid.")) { + aDescCache[0] = formatFluidString(this.mFluidsToUse[0]); + } + if (aDescCache[1] == null || aDescCache[1].contains(".name") || aDescCache[1].contains("fluid.")) { + aDescCache[1] = formatFluidString(this.mFluidsToUse[1]); + } + if (aDescCache[2] == null || aDescCache[2].contains(".name") || aDescCache[2].contains("fluid.")) { + aDescCache[2] = formatFluidString(this.mFluidsToUse[2]); + } + String aNaq = aDescCache[0]; + String aEnrNaq = aDescCache[1]; + String aNaquad = aDescCache[2]; + String[] s2 = new String[] { "Fluid Input for Multiblocks", "Capacity: " + getCapacity() + "L", + "Accepted Fluid: " + aNaq, "Accepted Fluid: " + aEnrNaq, "Accepted Fluid: " + aNaquad, + CORE.GT_Tooltip.get() }; + return s2; + } + + private static String[] aDescCache = new String[3]; + + private String formatFluidString(FluidStack f) { + FluidStack mLockedStack = f; + Integer mLockedTemp = 0;; + String mTempMod = "" + EnumChatFormatting.RESET; + mLockedTemp = mLockedStack.getFluid() + .getTemperature(); + if (mLockedTemp != null) { + if (mLockedTemp <= -3000) { + mTempMod = "" + EnumChatFormatting.DARK_PURPLE; + } else if (mLockedTemp >= -2999 && mLockedTemp <= -500) { + mTempMod = "" + EnumChatFormatting.DARK_BLUE; + } else if (mLockedTemp >= -499 && mLockedTemp <= -50) { + mTempMod = "" + EnumChatFormatting.BLUE; + } else if (mLockedTemp >= 30 && mLockedTemp <= 300) { + mTempMod = "" + EnumChatFormatting.AQUA; + } else if (mLockedTemp >= 301 && mLockedTemp <= 800) { + mTempMod = "" + EnumChatFormatting.YELLOW; + } else if (mLockedTemp >= 801 && mLockedTemp <= 1500) { + mTempMod = "" + EnumChatFormatting.GOLD; + } else if (mLockedTemp >= 1501) { + mTempMod = "" + EnumChatFormatting.RED; + } + } + return mTempMod + mLockedStack.getLocalizedName(); + } + + @Override + public boolean doesFillContainers() { + return false; + } + + @Override + public ITexture[][][] getTextureSet(ITexture[] aTextures) { + // TODO Auto-generated method stub + return super.getTextureSet(aTextures); + } + + private Field F1, F2; + + @Override + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, ForgeDirection side, ForgeDirection facing, + int aColorIndex, boolean aActive, boolean aRedstone) { + byte a1 = 0, a2 = 0; + try { + if (F1 == null) { + F1 = ReflectionUtils.getField(getClass(), "actualTexture"); + } + if (F2 == null) { + F2 = ReflectionUtils.getField(getClass(), "mTexturePage"); + } + + if (F1 != null) { + a1 = F1.getByte(this); + } + if (F2 != null) { + a2 = F2.getByte(this); + } + } catch (IllegalArgumentException | IllegalAccessException n) {} + + int textureIndex = a1 | a2 << 7; + byte texturePointer = (byte) (a1 & 127); + + if (side == ForgeDirection.UP || side == ForgeDirection.DOWN) { + ITexture g = textureIndex > 0 ? BlockIcons.casingTexturePages[a2][texturePointer] + : BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1]; + + return new ITexture[] { g, + new GT_RenderedTexture((IIconContainer) Textures.BlockIcons.NAQUADAH_REACTOR_FLUID_TOP_ACTIVE) }; + } + + return side != facing + ? (textureIndex > 0 ? new ITexture[] { BlockIcons.casingTexturePages[a2][texturePointer] } + : new ITexture[] { BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1] }) + : (textureIndex > 0 + ? (aActive ? this.getTexturesActive(BlockIcons.casingTexturePages[a2][texturePointer]) + : this.getTexturesInactive(BlockIcons.casingTexturePages[a2][texturePointer])) + : (aActive ? this.getTexturesActive(BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1]) + : this.getTexturesInactive(BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1]))); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBattery.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBattery.java new file mode 100644 index 0000000000..58dc7ec380 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBattery.java @@ -0,0 +1,222 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; + +import static gregtech.api.enums.GT_Values.V; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; + +import org.apache.commons.lang3.ArrayUtils; + +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; + +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.gui.widget.ElectricSlotWidget; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GT_MetaTileEntity_Hatch_OutputBattery extends GT_MetaTileEntity_Hatch { + + public GT_MetaTileEntity_Hatch_OutputBattery(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, getSlots(aTier), "Dischargeable Item Bus for Multiblocks"); + } + + public GT_MetaTileEntity_Hatch_OutputBattery(String aName, int aTier, String[] aDescription, + ITexture[][][] aTextures) { + super(aName, aTier, aTier < 1 ? 1 : aTier == 1 ? 4 : aTier == 2 ? 9 : 16, aDescription, aTextures); + } + + @Override + public String[] getDescription() { + int mSlots = 0; + if (this.mTier == 2) { + mSlots = 4; + } else if (this.mTier == 4) { + mSlots = 16; + } else { + mSlots = 16; + } + return ArrayUtils.addAll(this.mDescriptionArray, "Capacity: " + mSlots + " slots", CORE.GT_Tooltip.get()); + } + + @Override + public boolean isEnetOutput() { + return true; + } + + @Override + public boolean isOutputFacing(ForgeDirection side) { + return side == getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public long getMinimumStoredEU() { + return 0; + } + + @Override + public long maxEUOutput() { + return V[mTier]; + } + + @Override + public long maxEUStore() { + return 512 + V[mTier + 1] * 8; + } + + @Override + public ITexture[] getTexturesActive(ITexture aBaseTexture) { + return new ITexture[] { aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Hatch_Discharger) }; + } + + @Override + public ITexture[] getTexturesInactive(ITexture aBaseTexture) { + return new ITexture[] { aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Hatch_Discharger) }; + } + + @Override + public boolean isSimpleMachine() { + return true; + } + + @Override + public boolean isFacingValid(ForgeDirection facing) { + return true; + } + + @Override + public boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean isValidSlot(int aIndex) { + return true; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Hatch_OutputBattery(mName, mTier, mDescriptionArray, mTextures); + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); + return true; + } + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return side == aBaseMetaTileEntity.getFrontFacing(); + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return side == aBaseMetaTileEntity.getFrontFacing(); + } + + public void updateSlots() { + for (int i = 0; i < mInventory.length; i++) + if (mInventory[i] != null && mInventory[i].stackSize <= 0) mInventory[i] = null; + fillStacksIntoFirstSlots(); + } + + protected void fillStacksIntoFirstSlots() { + for (int i = 0; i < mInventory.length; i++) + for (int j = i + 1; j < mInventory.length; j++) if (mInventory[j] != null + && (mInventory[i] == null || GT_Utility.areStacksEqual(mInventory[i], mInventory[j]))) { + GT_Utility.moveStackFromSlotAToSlotB( + getBaseMetaTileEntity(), + getBaseMetaTileEntity(), + j, + i, + (byte) 64, + (byte) 1, + (byte) 64, + (byte) 1); + } + } + + @Override + public int rechargerSlotStartIndex() { + return 0; + } + + @Override + public int rechargerSlotCount() { + return 0; + } + + @Override + public int dechargerSlotStartIndex() { + return 0; + } + + @Override + public int dechargerSlotCount() { + return mTier == 2 ? 4 : 16; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { + if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.hasInventoryBeenModified()) { + fillStacksIntoFirstSlots(); + } + + if (aBaseMetaTileEntity.isServerSide()) { + if (aBaseMetaTileEntity.getMetaTileEntity() instanceof MetaTileEntity mMetaTileEntity) { + if (mMetaTileEntity.dechargerSlotCount() > 0 + && mMetaTileEntity.getEUVar() < aBaseMetaTileEntity.getEUCapacity()) { + for (int i = mMetaTileEntity.dechargerSlotStartIndex(), + k = mMetaTileEntity.dechargerSlotCount() + i; i < k; i++) { + if (mMetaTileEntity.mInventory[i] != null + && mMetaTileEntity.getEUVar() < aBaseMetaTileEntity.getEUCapacity()) { + aBaseMetaTileEntity.increaseStoredEnergyUnits( + GT_ModHandler.dischargeElectricItem( + mMetaTileEntity.mInventory[i], + (int) Math.min( + V[mTier] * 15, + aBaseMetaTileEntity.getEUCapacity() - aBaseMetaTileEntity.getStoredEU()), + (int) Math.min(Integer.MAX_VALUE, mMetaTileEntity.getInputTier()), + true, + false, + false), + true); + if (mMetaTileEntity.mInventory[i].stackSize <= 0) mMetaTileEntity.mInventory[i] = null; + } + } + } + } + } + super.onPostTick(aBaseMetaTileEntity, aTimer); + } + + @Override + public boolean useModularUI() { + return true; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + if (mTier == 2) { + for (int i = 0; i < 4; i++) { + builder + .widget(new ElectricSlotWidget(inventoryHandler, i).setPos(70 + (i % 2) * 18, 25 + (i / 2) * 18)); + } + } else { + for (int i = 0; i < 16; i++) { + builder.widget(new ElectricSlotWidget(inventoryHandler, i).setPos(52 + (i % 4) * 18, 7 + (i / 4) * 18)); + } + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Reservoir.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Reservoir.java new file mode 100644 index 0000000000..bfe8290240 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Reservoir.java @@ -0,0 +1,75 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; + +import net.minecraft.world.World; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; + +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.objects.GT_RenderedTexture; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GT_MetaTileEntity_Hatch_Reservoir extends GT_MetaTileEntity_Hatch_FluidGenerator { + + public GT_MetaTileEntity_Hatch_Reservoir(final int aID, final String aName, final String aNameRegional, + final int aTier) { + super(aID, aName, aNameRegional, aTier); + } + + public GT_MetaTileEntity_Hatch_Reservoir(final String aName, final int aTier, final String[] aDescription, + final ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } + + @Override + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Hatch_Reservoir(this.mName, this.mTier, this.mDescriptionArray, this.mTextures); + } + + @Override + public String[] getCustomTooltip() { + String[] aTooltip = new String[2]; + aTooltip[0] = "Infinite water supply hatch"; + aTooltip[1] = "Fills to max capacity every 5 seconds"; + return aTooltip; + } + + @Override + public Fluid getFluidToGenerate() { + return FluidRegistry.WATER; + } + + @Override + public int getAmountOfFluidToGenerate() { + return 2_000_000_000; + } + + @Override + public int getMaxTickTime() { + return 100; + } + + @Override + public int getCapacity() { + return 2_000_000_000; + } + + @Override + public boolean doesHatchMeetConditionsToGenerate() { + return true; + } + + @Override + public void generateParticles(World aWorld, String name) {} + + @Override + public ITexture[] getTexturesActive(final ITexture aBaseTexture) { + return new ITexture[] { aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Water) }; + } + + @Override + public ITexture[] getTexturesInactive(final ITexture aBaseTexture) { + return new ITexture[] { aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Water) }; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Solidifier.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Solidifier.java new file mode 100644 index 0000000000..94c28877d8 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Solidifier.java @@ -0,0 +1,72 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; + +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; + +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input; +import gregtech.api.util.GT_Utility; + +public class GT_MetaTileEntity_Hatch_Solidifier extends GT_MetaTileEntity_Hatch_Input { + + static final int moldSlot = 2; + + public GT_MetaTileEntity_Hatch_Solidifier(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier); + } + + @Override + public String[] getDescription() { + return new String[] { + "Fluid Input with Mold for " + EnumChatFormatting.YELLOW + + "Large Processing Factory" + + EnumChatFormatting.RESET, + "#22 Circuit is imprinted in Hatch", "Capacity: " + GT_Utility.formatNumbers(getCapacity()) + "L", + "Added by: " + EnumChatFormatting.AQUA + + "Quetz4l" + + " - " + + EnumChatFormatting.RED + + "[GT++]" + + EnumChatFormatting.RESET }; + } + + public GT_MetaTileEntity_Hatch_Solidifier(String aName, int aTier, String[] aDescription, + ITexture[][][] aTextures) { + super(aName, getSlots(aTier), aTier, aDescription, aTextures); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Hatch_Solidifier(mName, mTier, mDescriptionArray, mTextures); + } + + public ItemStack getMold() { + return this.getStackInSlot(moldSlot); + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + super.addUIWidgets(builder, buildContext); + builder.widget( + new SlotWidget(inventoryHandler, moldSlot).setPos(125, 35) + .setSize(18, 18)); + } + + @Override + public void onBlockDestroyed() { + super.onBlockDestroyed(); + } + + // for a drop-down form when the hatch is destroyed + @Override + public boolean isValidSlot(int aIndex) { + if (aIndex == moldSlot) return true; + else return super.isValidSlot(aIndex); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Steam_BusInput.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Steam_BusInput.java new file mode 100644 index 0000000000..5cc1e64d13 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Steam_BusInput.java @@ -0,0 +1,279 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; + +import static gregtech.api.enums.Textures.BlockIcons.ITEM_IN_SIGN; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPE_IN; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; + +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; + +import gregtech.GT_Mod; +import gregtech.api.enums.Textures; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.render.TextureFactory; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.lib.CORE; + +public class GT_MetaTileEntity_Hatch_Steam_BusInput extends GT_MetaTileEntity_Hatch { + + public RecipeMap<?> mRecipeMap = null; + public boolean disableSort; + + public GT_MetaTileEntity_Hatch_Steam_BusInput(int aID, String aName, String aNameRegional, int aTier) { + super( + aID, + aName, + aNameRegional, + aTier, + getSlots(aTier), + new String[] { "Item Input for Steam Multiblocks", + "Shift + right click with screwdriver to toggle automatic item shuffling", "Capacity: 4 stacks", + "Does not work with non-steam multiblocks", CORE.GT_Tooltip.get() }); + } + + public GT_MetaTileEntity_Hatch_Steam_BusInput(String aName, int aTier, String aDescription, + ITexture[][][] aTextures) { + super(aName, aTier, 4, aDescription, aTextures); + } + + public GT_MetaTileEntity_Hatch_Steam_BusInput(String aName, int aTier, String[] aDescription, + ITexture[][][] aTextures) { + super(aName, aTier, 4, aDescription, aTextures); + } + + @Override + public ITexture[] getTexturesActive(ITexture aBaseTexture) { + return GT_Mod.gregtechproxy.mRenderIndicatorsOnHatch + ? new ITexture[] { aBaseTexture, TextureFactory.of(OVERLAY_PIPE_IN), TextureFactory.of(ITEM_IN_SIGN) } + : new ITexture[] { aBaseTexture, TextureFactory.of(OVERLAY_PIPE_IN) }; + } + + @Override + public ITexture[] getTexturesInactive(ITexture aBaseTexture) { + return GT_Mod.gregtechproxy.mRenderIndicatorsOnHatch + ? new ITexture[] { aBaseTexture, TextureFactory.of(OVERLAY_PIPE_IN), TextureFactory.of(ITEM_IN_SIGN) } + : new ITexture[] { aBaseTexture, TextureFactory.of(OVERLAY_PIPE_IN) }; + } + + @Override + public boolean isSimpleMachine() { + return true; + } + + @Override + public boolean isFacingValid(ForgeDirection facing) { + return true; + } + + @Override + public boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean isValidSlot(int aIndex) { + return true; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Hatch_Steam_BusInput(mName, mTier, mDescriptionArray, mTextures); + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); + return true; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { + if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.hasInventoryBeenModified()) { + fillStacksIntoFirstSlots(); + } + } + + public void updateSlots() { + for (int i = 0; i < mInventory.length; i++) + if (mInventory[i] != null && mInventory[i].stackSize <= 0) mInventory[i] = null; + fillStacksIntoFirstSlots(); + } + + protected void fillStacksIntoFirstSlots() { + if (disableSort) { + for (int i = 0; i < mInventory.length; i++) + if (mInventory[i] != null && mInventory[i].stackSize <= 0) mInventory[i] = null; + } else { + for (int i = 0; i < mInventory.length; i++) + for (int j = i + 1; j < mInventory.length; j++) if (mInventory[j] != null + && (mInventory[i] == null || GT_Utility.areStacksEqual(mInventory[i], mInventory[j]))) + GT_Utility.moveStackFromSlotAToSlotB( + getBaseMetaTileEntity(), + getBaseMetaTileEntity(), + j, + i, + (byte) 64, + (byte) 1, + (byte) 64, + (byte) 1); + } + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setBoolean("disableSort", disableSort); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + disableSort = aNBT.getBoolean("disableSort"); + } + + @Override + public void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (aPlayer.isSneaking()) { + disableSort = !disableSort; + GT_Utility.sendChatToPlayer( + aPlayer, + GT_Utility.trans("200.1", "Automatic Item Shuffling: ") + + (disableSort ? GT_Utility.trans("087", "Disabled") : GT_Utility.trans("088", "Enabled"))); + } + } + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return side == getBaseMetaTileEntity().getFrontFacing() + && (mRecipeMap == null || mRecipeMap.containsInput(aStack)); + } + + @Override + public ITexture[][][] getTextureSet(ITexture[] aTextures) { + ITexture[][][] rTextures = new ITexture[14][17][]; + for (byte c = -1; c < 16; c++) { + if (rTextures[0][c + 1] == null) rTextures[0][c + 1] = getSideFacingActive(c); + if (rTextures[1][c + 1] == null) rTextures[1][c + 1] = getSideFacingInactive(c); + if (rTextures[2][c + 1] == null) rTextures[2][c + 1] = getFrontFacingActive(c); + if (rTextures[3][c + 1] == null) rTextures[3][c + 1] = getFrontFacingInactive(c); + if (rTextures[4][c + 1] == null) rTextures[4][c + 1] = getTopFacingActive(c); + if (rTextures[5][c + 1] == null) rTextures[5][c + 1] = getTopFacingInactive(c); + if (rTextures[6][c + 1] == null) rTextures[6][c + 1] = getBottomFacingActive(c); + if (rTextures[7][c + 1] == null) rTextures[7][c + 1] = getBottomFacingInactive(c); + if (rTextures[8][c + 1] == null) rTextures[8][c + 1] = getBottomFacingPipeActive(c); + if (rTextures[9][c + 1] == null) rTextures[9][c + 1] = getBottomFacingPipeInactive(c); + if (rTextures[10][c + 1] == null) rTextures[10][c + 1] = getTopFacingPipeActive(c); + if (rTextures[11][c + 1] == null) rTextures[11][c + 1] = getTopFacingPipeInactive(c); + if (rTextures[12][c + 1] == null) rTextures[12][c + 1] = getSideFacingPipeActive(c); + if (rTextures[13][c + 1] == null) rTextures[13][c + 1] = getSideFacingPipeInactive(c); + } + return rTextures; + } + + public ITexture[] getSideFacingActive(byte aColor) { + return new ITexture[] { new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE : Textures.BlockIcons.MACHINE_BRONZE_SIDE) }; + } + + public ITexture[] getSideFacingInactive(byte aColor) { + return new ITexture[] { new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE : Textures.BlockIcons.MACHINE_BRONZE_SIDE) }; + } + + public ITexture[] getFrontFacingActive(byte aColor) { + return new ITexture[] { new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE : Textures.BlockIcons.MACHINE_BRONZE_SIDE) }; + } + + public ITexture[] getFrontFacingInactive(byte aColor) { + return new ITexture[] { new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE : Textures.BlockIcons.MACHINE_BRONZE_SIDE) }; + } + + public ITexture[] getTopFacingActive(byte aColor) { + return new ITexture[] { new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_TOP : Textures.BlockIcons.MACHINE_BRONZE_TOP) }; + } + + public ITexture[] getTopFacingInactive(byte aColor) { + return new ITexture[] { new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_TOP : Textures.BlockIcons.MACHINE_BRONZE_TOP) }; + } + + public ITexture[] getBottomFacingActive(byte aColor) { + return new ITexture[] { new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_BOTTOM : Textures.BlockIcons.MACHINE_BRONZE_BOTTOM) }; + } + + public ITexture[] getBottomFacingInactive(byte aColor) { + return new ITexture[] { new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_BOTTOM : Textures.BlockIcons.MACHINE_BRONZE_BOTTOM) }; + } + + public ITexture[] getBottomFacingPipeActive(byte aColor) { + return new ITexture[] { new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_BOTTOM : Textures.BlockIcons.MACHINE_BRONZE_BOTTOM), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) }; + } + + public ITexture[] getBottomFacingPipeInactive(byte aColor) { + return new ITexture[] { new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_BOTTOM : Textures.BlockIcons.MACHINE_BRONZE_BOTTOM), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) }; + } + + public ITexture[] getTopFacingPipeActive(byte aColor) { + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_TOP : Textures.BlockIcons.MACHINE_BRONZE_TOP), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) }; + } + + public ITexture[] getTopFacingPipeInactive(byte aColor) { + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_TOP : Textures.BlockIcons.MACHINE_BRONZE_TOP), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) }; + } + + public ITexture[] getSideFacingPipeActive(byte aColor) { + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE : Textures.BlockIcons.MACHINE_BRONZE_SIDE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) }; + } + + public ITexture[] getSideFacingPipeInactive(byte aColor) { + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE : Textures.BlockIcons.MACHINE_BRONZE_SIDE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) }; + } + + @Override + public boolean useModularUI() { + return true; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + getBaseMetaTileEntity().add2by2Slots(builder); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Steam_BusOutput.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Steam_BusOutput.java new file mode 100644 index 0000000000..1d4dbc8987 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Steam_BusOutput.java @@ -0,0 +1,215 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; + +import static gregtech.api.enums.Textures.BlockIcons.ITEM_OUT_SIGN; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPE_OUT; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; + +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; + +import gregtech.GT_Mod; +import gregtech.api.enums.Textures; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.render.TextureFactory; +import gtPlusPlus.core.lib.CORE; + +public class GT_MetaTileEntity_Hatch_Steam_BusOutput extends GT_MetaTileEntity_Hatch { + + public GT_MetaTileEntity_Hatch_Steam_BusOutput(int aID, String aName, String aNameRegional, int aTier) { + super( + aID, + aName, + aNameRegional, + aTier, + 4, + new String[] { "Item Output for Steam Multiblocks", "Does not automatically export items", + "Capacity: 4 stacks", "Does not work with non-steam multiblocks", CORE.GT_Tooltip.get() }); + } + + public GT_MetaTileEntity_Hatch_Steam_BusOutput(String aName, int aTier, String aDescription, + ITexture[][][] aTextures) { + super(aName, aTier, 4, aDescription, aTextures); + } + + public GT_MetaTileEntity_Hatch_Steam_BusOutput(String aName, int aTier, String[] aDescription, + ITexture[][][] aTextures) { + super(aName, aTier, 4, aDescription, aTextures); + } + + @Override + public ITexture[] getTexturesActive(ITexture aBaseTexture) { + return GT_Mod.gregtechproxy.mRenderIndicatorsOnHatch + ? new ITexture[] { aBaseTexture, TextureFactory.of(OVERLAY_PIPE_OUT), TextureFactory.of(ITEM_OUT_SIGN) } + : new ITexture[] { aBaseTexture, TextureFactory.of(OVERLAY_PIPE_OUT) }; + } + + @Override + public ITexture[] getTexturesInactive(ITexture aBaseTexture) { + return GT_Mod.gregtechproxy.mRenderIndicatorsOnHatch + ? new ITexture[] { aBaseTexture, TextureFactory.of(OVERLAY_PIPE_OUT), TextureFactory.of(ITEM_OUT_SIGN) } + : new ITexture[] { aBaseTexture, TextureFactory.of(OVERLAY_PIPE_OUT) }; + } + + @Override + public boolean isSimpleMachine() { + return true; + } + + @Override + public boolean isFacingValid(ForgeDirection facing) { + return true; + } + + @Override + public boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean isValidSlot(int aIndex) { + return true; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Hatch_Steam_BusOutput(mName, mTier, mDescriptionArray, mTextures); + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); + return true; + } + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return side == aBaseMetaTileEntity.getFrontFacing(); + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return false; + } + + @Override + public ITexture[][][] getTextureSet(ITexture[] aTextures) { + ITexture[][][] rTextures = new ITexture[14][17][]; + for (byte c = -1; c < 16; c++) { + if (rTextures[0][c + 1] == null) rTextures[0][c + 1] = getSideFacingActive(c); + if (rTextures[1][c + 1] == null) rTextures[1][c + 1] = getSideFacingInactive(c); + if (rTextures[2][c + 1] == null) rTextures[2][c + 1] = getFrontFacingActive(c); + if (rTextures[3][c + 1] == null) rTextures[3][c + 1] = getFrontFacingInactive(c); + if (rTextures[4][c + 1] == null) rTextures[4][c + 1] = getTopFacingActive(c); + if (rTextures[5][c + 1] == null) rTextures[5][c + 1] = getTopFacingInactive(c); + if (rTextures[6][c + 1] == null) rTextures[6][c + 1] = getBottomFacingActive(c); + if (rTextures[7][c + 1] == null) rTextures[7][c + 1] = getBottomFacingInactive(c); + if (rTextures[8][c + 1] == null) rTextures[8][c + 1] = getBottomFacingPipeActive(c); + if (rTextures[9][c + 1] == null) rTextures[9][c + 1] = getBottomFacingPipeInactive(c); + if (rTextures[10][c + 1] == null) rTextures[10][c + 1] = getTopFacingPipeActive(c); + if (rTextures[11][c + 1] == null) rTextures[11][c + 1] = getTopFacingPipeInactive(c); + if (rTextures[12][c + 1] == null) rTextures[12][c + 1] = getSideFacingPipeActive(c); + if (rTextures[13][c + 1] == null) rTextures[13][c + 1] = getSideFacingPipeInactive(c); + } + return rTextures; + } + + public ITexture[] getSideFacingActive(byte aColor) { + return new ITexture[] { new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE : Textures.BlockIcons.MACHINE_BRONZE_SIDE) }; + } + + public ITexture[] getSideFacingInactive(byte aColor) { + return new ITexture[] { new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE : Textures.BlockIcons.MACHINE_BRONZE_SIDE) }; + } + + public ITexture[] getFrontFacingActive(byte aColor) { + return new ITexture[] { new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE : Textures.BlockIcons.MACHINE_BRONZE_SIDE) }; + } + + public ITexture[] getFrontFacingInactive(byte aColor) { + return new ITexture[] { new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE : Textures.BlockIcons.MACHINE_BRONZE_SIDE) }; + } + + public ITexture[] getTopFacingActive(byte aColor) { + return new ITexture[] { new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_TOP : Textures.BlockIcons.MACHINE_BRONZE_TOP) }; + } + + public ITexture[] getTopFacingInactive(byte aColor) { + return new ITexture[] { new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_TOP : Textures.BlockIcons.MACHINE_BRONZE_TOP) }; + } + + public ITexture[] getBottomFacingActive(byte aColor) { + return new ITexture[] { new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_BOTTOM : Textures.BlockIcons.MACHINE_BRONZE_BOTTOM) }; + } + + public ITexture[] getBottomFacingInactive(byte aColor) { + return new ITexture[] { new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_BOTTOM : Textures.BlockIcons.MACHINE_BRONZE_BOTTOM) }; + } + + public ITexture[] getBottomFacingPipeActive(byte aColor) { + return new ITexture[] { new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_BOTTOM : Textures.BlockIcons.MACHINE_BRONZE_BOTTOM), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) }; + } + + public ITexture[] getBottomFacingPipeInactive(byte aColor) { + return new ITexture[] { new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_BOTTOM : Textures.BlockIcons.MACHINE_BRONZE_BOTTOM), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) }; + } + + public ITexture[] getTopFacingPipeActive(byte aColor) { + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_TOP : Textures.BlockIcons.MACHINE_BRONZE_TOP), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) }; + } + + public ITexture[] getTopFacingPipeInactive(byte aColor) { + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_TOP : Textures.BlockIcons.MACHINE_BRONZE_TOP), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) }; + } + + public ITexture[] getSideFacingPipeActive(byte aColor) { + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE : Textures.BlockIcons.MACHINE_BRONZE_SIDE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) }; + } + + public ITexture[] getSideFacingPipeInactive(byte aColor) { + return new ITexture[] { + new GT_RenderedTexture( + mTier == 1 ? Textures.BlockIcons.MACHINE_BRONZEBRICKS_SIDE : Textures.BlockIcons.MACHINE_BRONZE_SIDE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT) }; + } + + @Override + public boolean useModularUI() { + return true; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + getBaseMetaTileEntity().add2by2Slots(builder); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Turbine.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Turbine.java new file mode 100644 index 0000000000..ed3101f309 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Turbine.java @@ -0,0 +1,435 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; + +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_ST5; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_ST_ACTIVE5; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; + +import org.apache.commons.lang3.ArrayUtils; + +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.Materials; +import gregtech.api.enums.SoundResource; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.items.GT_MetaGenerated_Tool; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; +import gregtech.api.objects.GT_ItemStack; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.minecraft.BlockPos; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.turbines.GregtechMetaTileEntity_LargerTurbineBase; + +@SuppressWarnings("deprecation") +public class GT_MetaTileEntity_Hatch_Turbine extends GT_MetaTileEntity_Hatch { + + public boolean mHasController = false; + public boolean mUsingAnimation = true; + private String mControllerLocation; + public int mEUt = 0; + + public GT_MetaTileEntity_Hatch_Turbine(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, 16, "Turbine Rotor holder for XL Turbines"); + } + + public GT_MetaTileEntity_Hatch_Turbine(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { + super(aName, aTier, 1, aDescription, aTextures); + } + + public GT_MetaTileEntity_Hatch_Turbine(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { + super(aName, aTier, 1, aDescription[0], aTextures); + } + + @Override + public String[] getDescription() { + return ArrayUtils.addAll( + this.mDescriptionArray, + "Right Click with a soldering iron to reset controller link", + "Right Click with a wrench to remove turbine", + "Right Click with a screwdriver for technical information", + "Sneak + Right Click with a wrench to rotate", + "Sneak + Right Click with a screwdriver to disable animations", + CORE.GT_Tooltip.get()); + } + + @Override + public ITexture[] getTexturesActive(ITexture aBaseTexture) { + return new ITexture[] { aBaseTexture, getFrontFacingTurbineTexture() }; + } + + @Override + public ITexture[] getTexturesInactive(ITexture aBaseTexture) { + return new ITexture[] { aBaseTexture, getFrontFacingTurbineTexture() }; + } + + public int getEU() { + return this.mEUt; + } + + public void setEU(int aEU) { + this.mEUt = aEU; + } + + @Override + public boolean isSimpleMachine() { + return true; + } + + @Override + public boolean isFacingValid(ForgeDirection facing) { + return facing.offsetY == 0; + } + + @Override + public boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean isValidSlot(int aIndex) { + return false; + } + + public boolean hasTurbine() { + ItemStack aStack = this.mInventory[0]; + boolean aIsValid = GregtechMetaTileEntity_LargerTurbineBase.isValidTurbine(aStack); + return aIsValid; + } + + public ItemStack getTurbine() { + if (hasTurbine()) { + return this.mInventory[0]; + } + return null; + } + + public boolean canWork() { + return hasTurbine(); + } + + public boolean insertTurbine(ItemStack aTurbine) { + if (GregtechMetaTileEntity_LargerTurbineBase.isValidTurbine(aTurbine)) { + this.mInventory[0] = aTurbine; + return true; + } + return false; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Hatch_Turbine(mName, mTier, mDescriptionArray, mTextures); + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); + return true; + } + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return false; + } + + @Override + public int getInventoryStackLimit() { + return 1; + } + + public void damageTurbine(int aEUt, int damageFactorLow, float damageFactorHigh) { + damageTurbine((long) aEUt, damageFactorLow, damageFactorHigh); + } + + public void damageTurbine(long aEUt, int damageFactorLow, float damageFactorHigh) { + if (hasTurbine() && MathUtils.randInt(0, 1) == 0) { + ItemStack aTurbine = getTurbine(); + ((GT_MetaGenerated_Tool) aTurbine.getItem()).doDamage( + aTurbine, + (long) getDamageToComponent(aTurbine) + * (long) Math.min((float) aEUt / (float) damageFactorLow, Math.pow(aEUt, damageFactorHigh))); + } + } + + private int getDamageToComponent(ItemStack aStack) { + return 1; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setBoolean("mHasController", mHasController); + aNBT.setBoolean("mUsingAnimation", mUsingAnimation); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + mHasController = aNBT.getBoolean("mHasController"); + mUsingAnimation = aNBT.getBoolean("mUsingAnimation"); + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (this.mHasController) { + if (aTick % 20 == 0) { + if (isControllerActive()) { + this.getBaseMetaTileEntity() + .setActive(true); + } else { + this.getBaseMetaTileEntity() + .setActive(false); + } + } + } else if (!this.mHasController && this.mControllerLocation != null) { + // Weird Invalid State + if (setController(BlockPos.generateBlockPos(mControllerLocation))) { + // Valid + } + } else { + // No Controller + } + if (this.mInventory[0] != null && this.mInventory[0].stackSize <= 0) this.mInventory[0] = null; + } + + public boolean isControllerActive() { + GregtechMetaTileEntity_LargerTurbineBase x = getController(); + if (x != null) { + // Logger.INFO("Checking Status of Controller. Running? "+(x.mEUt > 0)); + return x.lEUt > 0; + } + // Logger.INFO("Status of Controller failed, controller is null."); + return false; + } + + public GregtechMetaTileEntity_LargerTurbineBase getController() { + if (this.mHasController && this.mControllerLocation != null && this.mControllerLocation.length() > 0) { + BlockPos p = BlockPos.generateBlockPos(mControllerLocation); + if (p != null) { + // Logger.INFO(p.getLocationString()); + IGregTechTileEntity tTileEntity = getBaseMetaTileEntity() + .getIGregTechTileEntity(p.xPos, p.yPos, p.zPos); + if (tTileEntity != null + && tTileEntity.getMetaTileEntity() instanceof GregtechMetaTileEntity_LargerTurbineBase) { + return (GregtechMetaTileEntity_LargerTurbineBase) tTileEntity.getMetaTileEntity(); + } else { + if (tTileEntity == null) { + Logger.INFO("Controller MTE is null, somehow?"); + } else { + Logger.INFO("Controller is a different MTE to expected"); + } + } + } + } + // Logger.INFO("Failed to Get Controller."); + return null; + } + + public boolean canSetNewController() { + if ((mControllerLocation != null && mControllerLocation.length() > 0) || this.mHasController) { + return false; + } + return true; + } + + public boolean setController(BlockPos aPos) { + clearController(); + if (canSetNewController()) { + mControllerLocation = aPos.getUniqueIdentifier(); + mHasController = true; + Logger.INFO("Successfully injected controller into this Turbine Assembly Hatch."); + } + return mHasController; + } + + public void clearController() { + this.mControllerLocation = null; + this.mHasController = false; + } + + public boolean usingAnimations() { + return mUsingAnimation; + } + + private ITexture getFrontFacingTurbineTexture() { + if (!mHasController) { + return this.getBaseMetaTileEntity() + .isActive() ? new GT_RenderedTexture(LARGETURBINE_ST_ACTIVE5) + : new GT_RenderedTexture(LARGETURBINE_ST5); + } else { + if (usingAnimations()) { + if (isControllerActive()) { + return getController().frontFaceActive; + } + } + return getController().frontFace; + } + } + + @Override + public long getMinimumStoredEU() { + return 0; + } + + @Override + public boolean isItemValidForSlot(int aIndex, ItemStack aStack) { + return false; + } + + @Override + public int[] getAccessibleSlotsFromSide(int ordinalSide) { + return new int[] {}; + } + + @Override + public boolean canInsertItem(int aIndex, ItemStack aStack, int ordinalSide) { + return false; + } + + public void setActive(boolean b) { + this.getBaseMetaTileEntity() + .setActive(b); + } + + @Override + public boolean allowCoverOnSide(ForgeDirection side, GT_ItemStack aStack) { + return false; + } + + @Override + public void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (!aPlayer.isSneaking()) { + PlayerUtils.messagePlayer(aPlayer, "Using Animations? " + usingAnimations()); + PlayerUtils.messagePlayer(aPlayer, "Has Controller? " + this.mHasController); + if (mHasController) { + PlayerUtils.messagePlayer( + aPlayer, + "Controller Location: " + BlockPos.generateBlockPos(mControllerLocation) + .getLocationString()); + PlayerUtils.messagePlayer(aPlayer, "Controller Active? " + this.isControllerActive()); + } + PlayerUtils.messagePlayer( + aPlayer, + "Active? " + this.getBaseMetaTileEntity() + .isActive()); + PlayerUtils.messagePlayer(aPlayer, "Has Turbine inserted? " + this.hasTurbine()); + if (this.hasTurbine()) { + Materials aMat = GT_MetaGenerated_Tool.getPrimaryMaterial(getTurbine()); + String aSize = GregtechMetaTileEntity_LargerTurbineBase + .getTurbineSizeString(GregtechMetaTileEntity_LargerTurbineBase.getTurbineSize(getTurbine())); + PlayerUtils.messagePlayer(aPlayer, "Using: " + aMat.mLocalizedName + " " + aSize); + } + } else { + this.mUsingAnimation = !mUsingAnimation; + if (this.mUsingAnimation) { + PlayerUtils.messagePlayer(aPlayer, "Using Animated Turbine Texture."); + } else { + PlayerUtils.messagePlayer(aPlayer, "Using Static Turbine Texture."); + } + } + } + + @Override + public boolean onWrenchRightClick(ForgeDirection side, ForgeDirection wrenchingSide, EntityPlayer aPlayer, float aX, + float aY, float aZ) { + if (this.getBaseMetaTileEntity() + .isServerSide() && !aPlayer.isSneaking()) { + ItemStack tCurrentItem = aPlayer.inventory.getCurrentItem(); + if (tCurrentItem != null) { + if (tCurrentItem.getItem() instanceof GT_MetaGenerated_Tool) { + return onToolClick(tCurrentItem, aPlayer, wrenchingSide); + } + } + } + return super.onWrenchRightClick(side, wrenchingSide, aPlayer, aX, aY, aZ); + } + + @Override + public boolean onSolderingToolRightClick(ForgeDirection side, ForgeDirection wrenchingSide, EntityPlayer aPlayer, + float aX, float aY, float aZ) { + if (this.getBaseMetaTileEntity() + .isServerSide()) { + ItemStack tCurrentItem = aPlayer.inventory.getCurrentItem(); + if (tCurrentItem != null) { + if (tCurrentItem.getItem() instanceof GT_MetaGenerated_Tool) { + return onToolClick(tCurrentItem, aPlayer, wrenchingSide); + } + } + } + return false; + } + + public boolean onToolClick(ItemStack tCurrentItem, EntityPlayer aPlayer, ForgeDirection side) { + if (GT_Utility.isStackInList(tCurrentItem, GregTech_API.sWrenchList)) { + boolean aHasTurbine = this.hasTurbine(); + if (aPlayer.inventory.getFirstEmptyStack() >= 0 && aHasTurbine) { + if (PlayerUtils.isCreative(aPlayer) + || GT_ModHandler.damageOrDechargeItem(tCurrentItem, 1, 1000, aPlayer)) { + aPlayer.inventory.addItemStackToInventory((this.getTurbine())); + this.mInventory[0] = null; + GT_Utility.sendChatToPlayer(aPlayer, "Removed turbine with wrench."); + return true; + } + } else { + GT_Utility.sendChatToPlayer( + aPlayer, + aHasTurbine ? "Cannot remove turbine, no free inventory space." : "No turbine to remove."); + } + } else if (GT_Utility.isStackInList(tCurrentItem, GregTech_API.sSolderingToolList)) { + if (mControllerLocation != null && mControllerLocation.length() > 0) { + if (setController(BlockPos.generateBlockPos(mControllerLocation))) { + if (PlayerUtils.isCreative(aPlayer) + || GT_ModHandler.damageOrDechargeItem(tCurrentItem, 1, 1000, aPlayer)) { + String tChat = "Trying to Reset linked Controller"; + IGregTechTileEntity g = this.getBaseMetaTileEntity(); + GT_Utility.sendChatToPlayer(aPlayer, tChat); + GT_Utility.sendSoundToPlayers( + g.getWorld(), + SoundResource.IC2_TOOLS_RUBBER_TRAMPOLINE, + 1.0F, + -1, + g.getXCoord(), + g.getYCoord(), + g.getZCoord()); + return true; + } + } + } + } + return false; + } + + @Override + public boolean useModularUI() { + return true; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + builder.widget( + new SlotWidget(inventoryHandler, 0).setFilter(GregtechMetaTileEntity_LargerTurbineBase::isValidTurbine) + .setAccess(false, true) + .setPos(79, 34)); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_TurbineProvider.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_TurbineProvider.java new file mode 100644 index 0000000000..e9626a310c --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_TurbineProvider.java @@ -0,0 +1,221 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; +import net.minecraftforge.common.util.ForgeDirection; + +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; + +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.items.GT_MetaGenerated_Tool; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBus; +import gregtech.common.tileentities.machines.multi.GT_MetaTileEntity_LargeTurbine; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.core.util.sys.KeyboardUtils; +import gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.turbines.GregtechMetaTileEntity_LargerTurbineBase; + +public class GT_MetaTileEntity_Hatch_TurbineProvider extends GT_MetaTileEntity_Hatch_InputBus { + + public GT_MetaTileEntity_Hatch_TurbineProvider(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier); + } + + public GT_MetaTileEntity_Hatch_TurbineProvider(String aName, int aTier, String[] aDescription, + ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Hatch_TurbineProvider( + this.mName, + this.mTier, + this.mDescriptionArray, + this.mTextures); + } + + @Override + public String[] getDescription() { + return new String[] { "An automation port for Large Turbines", + "Will attempt once per 1200 ticks to fill the turbine slot of it's parent turbine", + "You may adjust this with a screwdriver", "Hold shift to adjust in finer amounts", + "Hold control to adjust direction", "Left Click with Screwdriver to reset", + "This module assumes the entire turbine is in the same Chunk", CORE.GT_Tooltip.get() }; + } + + private GT_MetaTileEntity_LargeTurbine mParent = null; + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { + super.onPostTick(aBaseMetaTileEntity, aTimer); + if (aTimer % mRefreshTime == 0 && this.getBaseMetaTileEntity() + .isServerSide()) { + tryRefillTurbine(); + } + } + + private void tryFindParentTurbine() { + Logger.INFO("This turbine housing has no parent, searching world."); + IGregTechTileEntity T = this.getBaseMetaTileEntity(); + World W = T.getWorld(); + Chunk C = W.getChunkFromBlockCoords(T.getXCoord(), T.getZCoord()); + for (Object o : C.chunkTileEntityMap.values()) { + if (o instanceof IGregTechTileEntity G) { + final IMetaTileEntity aMetaTileEntity = G.getMetaTileEntity(); + if (aMetaTileEntity == null) { + continue; + } + if (aMetaTileEntity instanceof GT_MetaTileEntity_LargeTurbine aTurb) { + for (GT_MetaTileEntity_Hatch_InputBus ee : aTurb.mInputBusses) { + if (ee.equals(this)) { + mParent = aTurb; + Logger.INFO("Found a Parent to attach to this housing."); + return; + } + } + } + } + } + } + + private void tryRefillTurbine() { + if (mParent == null) { + tryFindParentTurbine(); + } + if (mParent != null && mParent.mInventory[1] == null) { + for (ItemStack aStack : this.mInventory) { + if (isItemStackTurbine(aStack)) { + setGUIItemStack(aStack); + } + } + } + } + + protected boolean setGUIItemStack(ItemStack aNewGuiSlotContents) { + boolean result = false; + if (mParent.mInventory[1] == null) { + mParent.mInventory[1] = aNewGuiSlotContents != null ? aNewGuiSlotContents.copy() : null; + mParent.depleteInput(aNewGuiSlotContents); + mParent.updateSlots(); + this.updateSlots(); + result = true; + } + return result; + } + + public boolean isItemStackTurbine(ItemStack aStack) { + if (aStack.getItem() instanceof GT_MetaGenerated_Tool) { + if (aStack.getItemDamage() >= 170 && aStack.getItemDamage() <= 176) { + return true; + } + } + return false; + } + + public boolean isItemStackScrewdriver(ItemStack aStack) { + if (aStack.getItem() instanceof GT_MetaGenerated_Tool) { + if (aStack.getItemDamage() == 22 || aStack.getItemDamage() == 150) { + return true; + } + } + return false; + } + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return isItemStackTurbine(aStack); + } + + private int mRefreshTime = 1200; + private boolean mDescending = true; + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setInteger("mRefreshTime", mRefreshTime); + aNBT.setBoolean("mDescending", mDescending); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + mRefreshTime = aNBT.getInteger("mRefreshTime"); + mDescending = aNBT.getBoolean("mDescending"); + } + + @Override + public void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (aPlayer != null) { + if (KeyboardUtils.isCtrlKeyDown()) { + mDescending = !mDescending; + PlayerUtils.messagePlayer(aPlayer, "Direction: " + (mDescending ? "DOWN" : "UP")); + } else { + int aAmount = 0; + if (KeyboardUtils.isShiftKeyDown()) { + aAmount = 10; + } else { + aAmount = 100; + } + if (mDescending) { + mRefreshTime -= aAmount; + if (mRefreshTime < 0) { + mRefreshTime = 1200; + } + } else { + mRefreshTime += aAmount; + if (mRefreshTime > 1200) { + mRefreshTime = 0; + } + } + PlayerUtils.messagePlayer(aPlayer, "Set check time to be every " + mRefreshTime + " ticks."); + } + } + } + + @Override + public void onLeftclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + boolean aDidScrewdriver = false; + if (aPlayer != null) { + if (aPlayer.getHeldItem() != null) { + if (isItemStackScrewdriver(aPlayer.getHeldItem())) { + aDidScrewdriver = true; + mRefreshTime = 1200; + PlayerUtils.messagePlayer(aPlayer, "Reset check time to " + mRefreshTime + " ticks."); + } + } + } + if (!aDidScrewdriver) { + super.onLeftclick(aBaseMetaTileEntity, aPlayer); + } + } + + @Override + public boolean allowSelectCircuit() { + return false; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + builder.widget( + new SlotWidget(inventoryHandler, 0).setFilter(GregtechMetaTileEntity_LargerTurbineBase::isValidTurbine) + .setAccess(false, true) + .setPos(79, 34)); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SuperBus_Input.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SuperBus_Input.java new file mode 100644 index 0000000000..5794e6adf8 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SuperBus_Input.java @@ -0,0 +1,65 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; + +import com.gtnewhorizons.modularui.api.screen.ModularWindow.Builder; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.Scrollable; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; + +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBus; +import gtPlusPlus.core.lib.CORE; + +public class GT_MetaTileEntity_SuperBus_Input extends GT_MetaTileEntity_Hatch_InputBus { + + public GT_MetaTileEntity_SuperBus_Input(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, getSlots(aTier) + 1); + } + + public GT_MetaTileEntity_SuperBus_Input(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { + super(aName, aTier, getSlots(aTier) + 1, aDescription, aTextures); + } + + /** + * Returns a factor of 16 based on tier. + * + * @param aTier The tier of this bus. + * @return (1 + aTier) * 16 + */ + public static int getSlots(int aTier) { + return (1 + aTier) * 16; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_SuperBus_Input(this.mName, this.mTier, mDescriptionArray, this.mTextures); + } + + @Override + public String[] getDescription() { + return new String[] { "Item Input for Multiblocks", "" + getSlots(this.mTier) + " Slots", + CORE.GT_Tooltip.get() }; + } + + @Override + public int getCircuitSlot() { + return getSlots(mTier); + } + + @Override + public void addUIWidgets(Builder builder, UIBuildContext buildContext) { + final Scrollable scrollable = new Scrollable().setVerticalScroll(); + for (int row = 0; row * 4 < inventoryHandler.getSlots() - 1; row++) { + int columnsToMake = Math.min(inventoryHandler.getSlots() - row * 4, 4); + for (int column = 0; column < columnsToMake; column++) { + scrollable.widget( + new SlotWidget(inventoryHandler, row * 4 + column).setPos(column * 18, row * 18) + .setSize(18, 18)); + } + } + builder.widget( + scrollable.setSize(18 * 4 + 4, 18 * 4) + .setPos(52, 7)); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SuperBus_Output.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SuperBus_Output.java new file mode 100644 index 0000000000..aee6235ab9 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SuperBus_Output.java @@ -0,0 +1,105 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; + +import net.minecraft.inventory.IInventory; + +import com.gtnewhorizons.modularui.api.screen.ModularWindow.Builder; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.Scrollable; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; + +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_OutputBus; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.lib.CORE; + +public class GT_MetaTileEntity_SuperBus_Output extends GT_MetaTileEntity_Hatch_OutputBus { + + public GT_MetaTileEntity_SuperBus_Output(int id, String name, String nameRegional, int tier) { + super(id, name, nameRegional, tier, getSlots(tier)); + } + + public GT_MetaTileEntity_SuperBus_Output(String name, int tier, String[] description, ITexture[][][] textures) { + super(name, tier, getSlots(tier), description, textures); + } + + /** + * Returns a factor of 16 based on tier. + * + * @param aTier The tier of this bus. + * @return (1 + aTier) * 16 + */ + public static int getSlots(int aTier) { + return (1 + aTier) * 16; + } + + @Override + public boolean isValidSlot(int aIndex) { + return true; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_SuperBus_Output(this.mName, this.mTier, mDescriptionArray, this.mTextures); + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { + if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.hasInventoryBeenModified()) { + this.fillStacksIntoFirstSlots(); + } + super.onPostTick(aBaseMetaTileEntity, aTimer); + } + + public void updateSlots() { + for (int i = 0; i < this.mInventory.length; ++i) { + if (this.mInventory[i] != null && this.mInventory[i].stackSize <= 0) { + this.mInventory[i] = null; + } + } + this.fillStacksIntoFirstSlots(); + } + + protected void fillStacksIntoFirstSlots() { + for (int i = 0; i < this.mInventory.length; ++i) { + for (int j = i + 1; j < this.mInventory.length; ++j) { + if (this.mInventory[j] != null && (this.mInventory[i] == null + || GT_Utility.areStacksEqual(this.mInventory[i], this.mInventory[j]))) { + GT_Utility.moveStackFromSlotAToSlotB( + (IInventory) this.getBaseMetaTileEntity(), + (IInventory) this.getBaseMetaTileEntity(), + j, + i, + (byte) 64, + (byte) 1, + (byte) 64, + (byte) 1); + } + } + } + } + + @Override + public String[] getDescription() { + String[] aDesc = new String[] { "Item Output for Multiblocks", "" + getSlots(this.mTier) + " Slots", + CORE.GT_Tooltip.get() }; + return aDesc; + } + + @Override + public void addUIWidgets(Builder builder, UIBuildContext buildContext) { + final Scrollable scrollable = new Scrollable().setVerticalScroll(); + for (int row = 0; row * 4 < inventoryHandler.getSlots() - 1; row++) { + int columnsToMake = Math.min(inventoryHandler.getSlots() - row * 4, 4); + for (int column = 0; column < columnsToMake; column++) { + scrollable.widget( + new SlotWidget(inventoryHandler, row * 4 + column).setPos(column * 18, row * 18) + .setSize(18, 18)); + } + } + builder.widget( + scrollable.setSize(18 * 4 + 4, 18 * 4) + .setPos(52, 7)); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntityFluid.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntityFluid.java new file mode 100644 index 0000000000..e9f9a2dda4 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntityFluid.java @@ -0,0 +1,117 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; + +import net.minecraftforge.common.util.ForgeDirection; + +import gregtech.api.enums.Dyes; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.SubTag; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaPipeEntity_Fluid; +import gregtech.api.render.TextureFactory; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechOrePrefixes.GT_Materials; + +public class GregtechMetaPipeEntityFluid extends GT_MetaPipeEntity_Fluid { + + public final GT_Materials mMaterial; + + public GregtechMetaPipeEntityFluid(int aID, String aName, String aNameRegional, float aThickNess, + GT_Materials aMaterial, int aCapacity, int aHeatResistance, boolean aGasProof) { + this(aID, aName, aNameRegional, aThickNess, aMaterial, aCapacity, aHeatResistance, aGasProof, 1); + } + + public GregtechMetaPipeEntityFluid(final String aName, final float aThickNess, final GT_Materials aMaterial, + final int aCapacity, final int aHeatResistance, final boolean aGasProof) { + this(aName, aThickNess, aMaterial, aCapacity, aHeatResistance, aGasProof, 1); + } + + public GregtechMetaPipeEntityFluid(int aID, String aName, String aNameRegional, float aThickNess, + GT_Materials aMaterial, int aCapacity, int aHeatResistance, boolean aGasProof, int aFluidTypes) { + super(aID, aName, aNameRegional, aThickNess, null, aCapacity, aHeatResistance, aGasProof, aFluidTypes); + this.mLastReceivedFrom = 0; + this.oLastReceivedFrom = 0; + this.mMaterial = aMaterial; + } + + public GregtechMetaPipeEntityFluid(String aName, float aThickNess, GT_Materials aMaterial, int aCapacity, + int aHeatResistance, boolean aGasProof, int aFluidTypes) { + super(aName, aThickNess, null, aCapacity, aHeatResistance, aGasProof, aFluidTypes); + this.mLastReceivedFrom = 0; + this.oLastReceivedFrom = 0; + this.mMaterial = aMaterial; + } + + @Override + public byte getTileEntityBaseType() { + return this.mMaterial == null ? 4 + : (byte) ((this.mMaterial.contains(SubTag.WOOD) ? 12 : 4) + + Math.max(0, Math.min(3, this.mMaterial.mToolQuality))); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaPipeEntityFluid( + this.mName, + this.mThickNess, + this.mMaterial, + this.mCapacity, + this.mHeatResistance, + this.mGasProof); + } + + @Override + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, ForgeDirection side, int aConnections, + int aColorIndex, boolean aConnected, boolean aRedstone) { + float tThickNess = getThickNess(); + if (mDisableInput == 0) + return new ITexture[] { aConnected ? getBaseTexture(tThickNess, mPipeAmount, mMaterial, aColorIndex) + : TextureFactory.of( + mMaterial.mIconSet.mTextures[OrePrefixes.pipe.mTextureIndex], + Dyes.getModulation(aColorIndex, mMaterial.mRGBa)) }; + int tMask = 0; + int[][] sRestrictionArray = { { 2, 3, 5, 4 }, { 2, 3, 5, 4 }, { 1, 0, 5, 4 }, { 1, 0, 4, 5 }, { 1, 0, 2, 3 }, + { 1, 0, 2, 3 } }; + if (side != ForgeDirection.UNKNOWN) { + for (int i = 0; i < 4; i++) + if (isInputDisabledAtSide(ForgeDirection.getOrientation(sRestrictionArray[side.ordinal()][i]))) + tMask |= 1 << i; + // Full block size renderer flips side 5 and 2 textures, flip restrictor textures to compensate + if (side == ForgeDirection.EAST || side == ForgeDirection.UP) + if (tMask > 3 && tMask < 12) tMask = (tMask ^ 12); + } + return new ITexture[] { aConnected ? getBaseTexture(tThickNess, mPipeAmount, mMaterial, aColorIndex) + : TextureFactory.of( + mMaterial.mIconSet.mTextures[OrePrefixes.pipe.mTextureIndex], + Dyes.getModulation(aColorIndex, mMaterial.mRGBa)), + getRestrictorTexture(tMask) }; + } + + protected static ITexture getBaseTexture(float aThickNess, int aPipeAmount, GT_Materials aMaterial, + int aColorIndex) { + if (aPipeAmount >= 9) return TextureFactory.of( + aMaterial.mIconSet.mTextures[OrePrefixes.pipeNonuple.mTextureIndex], + Dyes.getModulation(aColorIndex, aMaterial.mRGBa)); + if (aPipeAmount >= 4) return TextureFactory.of( + aMaterial.mIconSet.mTextures[OrePrefixes.pipeQuadruple.mTextureIndex], + Dyes.getModulation(aColorIndex, aMaterial.mRGBa)); + if (aThickNess < 0.124F) return TextureFactory.of( + aMaterial.mIconSet.mTextures[OrePrefixes.pipe.mTextureIndex], + Dyes.getModulation(aColorIndex, aMaterial.mRGBa)); + if (aThickNess < 0.374F) return TextureFactory.of( + aMaterial.mIconSet.mTextures[OrePrefixes.pipeTiny.mTextureIndex], + Dyes.getModulation(aColorIndex, aMaterial.mRGBa)); + if (aThickNess < 0.499F) return TextureFactory.of( + aMaterial.mIconSet.mTextures[OrePrefixes.pipeSmall.mTextureIndex], + Dyes.getModulation(aColorIndex, aMaterial.mRGBa)); + if (aThickNess < 0.749F) return TextureFactory.of( + aMaterial.mIconSet.mTextures[OrePrefixes.pipeMedium.mTextureIndex], + Dyes.getModulation(aColorIndex, aMaterial.mRGBa)); + if (aThickNess < 0.874F) return TextureFactory.of( + aMaterial.mIconSet.mTextures[OrePrefixes.pipeLarge.mTextureIndex], + Dyes.getModulation(aColorIndex, aMaterial.mRGBa)); + return TextureFactory.of( + aMaterial.mIconSet.mTextures[OrePrefixes.pipeHuge.mTextureIndex], + Dyes.getModulation(aColorIndex, aMaterial.mRGBa)); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntity_Cable.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntity_Cable.java new file mode 100644 index 0000000000..9b1408ba51 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntity_Cable.java @@ -0,0 +1,156 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; + +import net.minecraftforge.common.util.ForgeDirection; + +import gregtech.api.enums.Dyes; +import gregtech.api.enums.Materials; +import gregtech.api.enums.TextureSet; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.metatileentity.IMetaTileEntityCable; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaPipeEntity_Cable; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Utility; + +public class GregtechMetaPipeEntity_Cable extends GT_MetaPipeEntity_Cable implements IMetaTileEntityCable { + + private static Textures.BlockIcons INSULATION_MEDIUM_PLUS; + + static { + try { + INSULATION_MEDIUM_PLUS = (Textures.BlockIcons) GT_Utility + .getField(Textures.BlockIcons.class, "INSULATION_MEDIUM_PLUS") + .get(null); + } catch (IllegalAccessException | NullPointerException e) { + throw new Error(e); + } + } + + private short[] vRGB = null; + + public GregtechMetaPipeEntity_Cable(final int aID, final String aName, final String aNameRegional, + final float aThickNess, final Materials aMaterial, final long aCableLossPerMeter, final long aAmperage, + final long aVoltage, final boolean aInsulated, final boolean aCanShock, final short[] aRGB) { + super( + aID, + aName, + aNameRegional, + aThickNess, + aMaterial, + aCableLossPerMeter, + aAmperage, + aVoltage, + aInsulated, + aCanShock); + this.vRGB = aRGB == null || aRGB.length != 4 ? Materials.Iron.mRGBa : aRGB; + } + + public GregtechMetaPipeEntity_Cable(final String aName, final float aThickNess, final Materials aMaterial, + final long aCableLossPerMeter, final long aAmperage, final long aVoltage, final boolean aInsulated, + final boolean aCanShock, final short[] aRGB) { + super(aName, aThickNess, aMaterial, aCableLossPerMeter, aAmperage, aVoltage, aInsulated, aCanShock); + this.vRGB = aRGB == null || aRGB.length != 4 ? Materials.Iron.mRGBa : aRGB; + } + + public GregtechMetaPipeEntity_Cable(final int aID, final String aName, final String aNameRegional, + final float aThickNess, final long aCableLossPerMeter, final long aAmperage, final long aVoltage, + final boolean aInsulated, final boolean aCanShock, final short[] aRGB) { + this( + aID, + aName, + aNameRegional, + aThickNess, + null, + aCableLossPerMeter, + aAmperage, + aVoltage, + aInsulated, + aCanShock, + aRGB); + } + + public GregtechMetaPipeEntity_Cable(final String aName, final float aThickNess, final long aCableLossPerMeter, + final long aAmperage, final long aVoltage, final boolean aInsulated, final boolean aCanShock, + final short[] aRGB) { + this(aName, aThickNess, null, aCableLossPerMeter, aAmperage, aVoltage, aInsulated, aCanShock, aRGB); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaPipeEntity_Cable( + this.mName, + this.mThickNess, + this.mMaterial, + this.mCableLossPerMeter, + this.mAmperage, + this.mVoltage, + this.mInsulated, + this.mCanShock, + this.vRGB); + } + + @Override + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, ForgeDirection side, int aConnections, + int aColorIndex, boolean aConnected, boolean aRedstone) { + return getTextureGTNH(aBaseMetaTileEntity, side, aConnections, aColorIndex, aConnected, aRedstone); + } + + private ITexture[] getTextureGTNH(IGregTechTileEntity aBaseMetaTileEntity, ForgeDirection aSide, int aConnections, + int aColorIndex, boolean aConnected, boolean aRedstone) { + + Materials wireMaterial = mMaterial; + if (wireMaterial == null) { + wireMaterial = Materials.Iron; + } + + if (!mInsulated) return new ITexture[] { new GT_RenderedTexture( + wireMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], + Dyes.getModulation(aColorIndex, vRGB)) }; + if (aConnected) { + float tThickNess = getThickNess(); + if (tThickNess < 0.124F) return new ITexture[] { new GT_RenderedTexture( + Textures.BlockIcons.INSULATION_FULL, + Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) }; + if (tThickNess < 0.374F) // 0.375 x1 + return new ITexture[] { + new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], vRGB), + new GT_RenderedTexture( + Textures.BlockIcons.INSULATION_TINY, + Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) }; + if (tThickNess < 0.499F) // 0.500 x2 + return new ITexture[] { + new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], vRGB), + new GT_RenderedTexture( + Textures.BlockIcons.INSULATION_SMALL, + Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) }; + if (tThickNess < 0.624F) // 0.625 x4 + return new ITexture[] { + new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], vRGB), + new GT_RenderedTexture( + Textures.BlockIcons.INSULATION_MEDIUM, + Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) }; + if (tThickNess < 0.749F) // 0.750 x8 + return new ITexture[] { + new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], vRGB), + new GT_RenderedTexture( + INSULATION_MEDIUM_PLUS, + Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) }; + if (tThickNess < 0.874F) // 0.825 x12 + return new ITexture[] { + new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], vRGB), + new GT_RenderedTexture( + Textures.BlockIcons.INSULATION_LARGE, + Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) }; + return new ITexture[] { + new GT_RenderedTexture(wireMaterial.mIconSet.mTextures[TextureSet.INDEX_wire], vRGB), + new GT_RenderedTexture( + Textures.BlockIcons.INSULATION_HUGE, + Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) }; + } + return new ITexture[] { new GT_RenderedTexture( + Textures.BlockIcons.INSULATION_FULL, + Dyes.getModulation(aColorIndex, Dyes.CABLE_INSULATION.mRGBa)) }; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaTreeFarmerStructural.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaTreeFarmerStructural.java new file mode 100644 index 0000000000..0aaaa75584 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaTreeFarmerStructural.java @@ -0,0 +1,49 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; + +import net.minecraft.nbt.NBTTagCompound; + +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.objects.GT_RenderedTexture; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.machines.GregtechMetaTreeFarmerBase; + +public class GregtechMetaTreeFarmerStructural extends GregtechMetaTreeFarmerBase { + + public GregtechMetaTreeFarmerStructural(final int aID, final String aName, final String aNameRegional, + final int aTier) { + super(aID, aName, aNameRegional, aTier, 0, "Structural Blocks for the Tree Farmer."); + } + + public GregtechMetaTreeFarmerStructural(final String aName, final int aTier, final int aInvSlotCount, + final String[] aDescription, final ITexture[][][] aTextures) { + super(aName, aTier, aInvSlotCount, aDescription, aTextures); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTreeFarmerStructural( + this.mName, + this.mTier, + this.mInventory.length, + this.mDescriptionArray, + this.mTextures); + } + + @Override + public ITexture getOverlayIcon() { + return new GT_RenderedTexture(Textures.BlockIcons.VOID); + } + + @Override + public boolean isValidSlot(final int aIndex) { + return false; + } + + @Override + public void saveNBTData(final NBTTagCompound paramNBTTagCompound) {} + + @Override + public void loadNBTData(final NBTTagCompound paramNBTTagCompound) {} +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GT_MetaTileEntity_Hatch_CustomFluidBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GT_MetaTileEntity_Hatch_CustomFluidBase.java new file mode 100644 index 0000000000..6a85c06c1b --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GT_MetaTileEntity_Hatch_CustomFluidBase.java @@ -0,0 +1,214 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base; + +import static gregtech.api.enums.Textures.BlockIcons.FLUID_IN_SIGN; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPE_IN; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; + +import com.gtnewhorizons.modularui.common.widget.FluidSlotWidget; + +import gregtech.GT_Mod; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; +import gregtech.api.render.TextureFactory; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.FluidUtils; + +public class GT_MetaTileEntity_Hatch_CustomFluidBase extends GT_MetaTileEntity_Hatch { + + public final Fluid mLockedFluid; + public final int mFluidCapacity; + protected FluidStack mLockedStack = null; + protected String mTempMod = null; + + public GT_MetaTileEntity_Hatch_CustomFluidBase(Fluid aFluid, int aAmount, final int aID, final String aName, + final String aNameRegional) { + super( + aID, + aName, + aNameRegional, + 6, + 3, + new String[] { "Fluid Input for Multiblocks", "Capacity: " + GT_Utility.formatNumbers(aAmount) + "L" }); + this.mLockedFluid = aFluid; + this.mFluidCapacity = aAmount; + } + + public GT_MetaTileEntity_Hatch_CustomFluidBase(Fluid aFluid, int aAmount, final String aName, + final String[] aDescription, final ITexture[][][] aTextures) { + super(aName, 6, 3, aDescription[0], aTextures); + this.mLockedFluid = aFluid; + this.mFluidCapacity = aAmount; + } + + public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, + final ForgeDirection side, final ItemStack aStack) { + if (side == aBaseMetaTileEntity.getFrontFacing() && aIndex == 0) { + FluidStack fs = GT_Utility.getFluidForFilledItem(aStack, true); + return fs != null && fs.getFluid() == this.mLockedFluid; + } + return false; + } + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return side == aBaseMetaTileEntity.getFrontFacing() && aIndex == 1; + } + + @Override + public ITexture[] getTexturesActive(ITexture aBaseTexture) { + return GT_Mod.gregtechproxy.mRenderIndicatorsOnHatch + ? new ITexture[] { aBaseTexture, TextureFactory.of(OVERLAY_PIPE_IN), TextureFactory.of(FLUID_IN_SIGN) } + : new ITexture[] { aBaseTexture, TextureFactory.of(OVERLAY_PIPE_IN) }; + } + + @Override + public ITexture[] getTexturesInactive(ITexture aBaseTexture) { + return GT_Mod.gregtechproxy.mRenderIndicatorsOnHatch + ? new ITexture[] { aBaseTexture, TextureFactory.of(OVERLAY_PIPE_IN), TextureFactory.of(FLUID_IN_SIGN) } + : new ITexture[] { aBaseTexture, TextureFactory.of(OVERLAY_PIPE_IN) }; + } + + @Override + public boolean isSimpleMachine() { + return true; + } + + @Override + public boolean isFacingValid(ForgeDirection facing) { + return true; + } + + @Override + public boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); + return true; + } + + @Override + public boolean doesFillContainers() { + // return true; + return false; + } + + @Override + public boolean doesEmptyContainers() { + return true; + } + + @Override + public boolean canTankBeFilled() { + return true; + } + + @Override + public boolean canTankBeEmptied() { + return true; + } + + @Override + public boolean displaysItemStack() { + return true; + } + + @Override + public boolean displaysStackSize() { + return false; + } + + public void updateSlots() { + if (mInventory[getInputSlot()] != null && mInventory[getInputSlot()].stackSize <= 0) + mInventory[getInputSlot()] = null; + } + + @Override + public int getTankPressure() { + return -100; + } + + @Override + public int getCapacity() { + return this.mFluidCapacity; + } + + @Override + public String[] getDescription() { + if (mLockedStack == null) { + mLockedStack = FluidUtils.getFluidStack(mLockedFluid, 1); + } + int aFluidTemp = 0; + boolean isSteam = false; + if (mLockedFluid != null) { + aFluidTemp = mLockedFluid.getTemperature(); + mTempMod = mLockedFluid.getName(); + } + if (mTempMod.equalsIgnoreCase("steam")) { + isSteam = true; + } + + EnumChatFormatting aColour = EnumChatFormatting.BLUE; + if (aFluidTemp <= -3000) { + aColour = EnumChatFormatting.DARK_PURPLE; + } else if (aFluidTemp >= -2999 && aFluidTemp <= -500) { + aColour = EnumChatFormatting.DARK_BLUE; + } else if (aFluidTemp >= -499 && aFluidTemp <= -50) { + aColour = EnumChatFormatting.BLUE; + } else if (aFluidTemp >= 30 && aFluidTemp <= 300) { + aColour = EnumChatFormatting.AQUA; + } else if (aFluidTemp >= 301 && aFluidTemp <= 800) { + aColour = EnumChatFormatting.YELLOW; + } else if (aFluidTemp >= 801 && aFluidTemp <= 1500) { + aColour = EnumChatFormatting.GOLD; + } else if (aFluidTemp >= 1501) { + aColour = EnumChatFormatting.RED; + } + String aFluidName = "Accepted Fluid: " + aColour + + (mLockedStack != null ? mLockedStack.getLocalizedName() : "Empty") + + EnumChatFormatting.RESET; + return new String[] { "Fluid Input for " + (isSteam ? "Steam " : "") + "Multiblocks", + "Capacity: " + getCapacity() + "L", aFluidName, CORE.GT_Tooltip.get() }; + } + + @Override + public boolean isFluidInputAllowed(final FluidStack aFluid) { + return this.mLockedFluid.getName() + .equals( + aFluid.getFluid() + .getName()); + } + + @Override + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Hatch_CustomFluidBase( + this.mLockedFluid, + this.mFluidCapacity, + this.mName, + this.mDescriptionArray, + this.mTextures); + } + + @Override + public boolean useModularUI() { + return true; + } + + @Override + protected FluidSlotWidget createFluidSlot() { + return super.createFluidSlot().setFilter(f -> f == mLockedFluid); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMetaTileEntity.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMetaTileEntity.java new file mode 100644 index 0000000000..e260347ca5 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMetaTileEntity.java @@ -0,0 +1,74 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base; + +import static gregtech.api.enums.GT_Values.GT; + +import gregtech.api.interfaces.ITexture; +import gregtech.api.metatileentity.MetaTileEntity; + +public abstract class GregtechMetaTileEntity extends MetaTileEntity { + + /** + * Value between [0 - 9] to describe the Tier of this Machine. + */ + protected byte mTier; + + /** + * A simple Description. + */ + protected final String mDescription; + + /** + * Contains all Textures used by this Block. + */ + public final ITexture[][][] mTextures; + + public GregtechMetaTileEntity(final int aID, final String aName, final String aNameRegional, final int aTier, + final int aInvSlotCount, final String aDescription, final ITexture... aTextures) { + super(aID, aName, aNameRegional, aInvSlotCount); + this.mTier = (byte) Math.max(0, Math.min(aTier, 9)); + this.mDescription = aDescription; + + // must always be the last call! + if (GT.isClientSide()) { + this.mTextures = this.getTextureSet(aTextures); + } else { + this.mTextures = null; + } + } + + public GregtechMetaTileEntity(final String aName, final int aTier, final int aInvSlotCount, + final String aDescription, final ITexture[][][] aTextures) { + super(aName, aInvSlotCount); + this.mTier = (byte) aTier; + this.mDescription = aDescription; + this.mTextures = aTextures; + } + + @Override + public byte getTileEntityBaseType() { + return (byte) (Math.min(3, this.mTier <= 0 ? 0 : 1 + ((this.mTier - 1) / 4))); + } + + @Override + public long getInputTier() { + return this.mTier; + } + + @Override + public long getOutputTier() { + return this.mTier; + } + + @Override + public String[] getDescription() { + return new String[] { this.mDescription }; + } + + /** + * Used Client Side to get a Texture Set for this Block. Called after setting the Tier and the Description so that + * those two are accessible. + * + * @param aTextures is the optional Array you can give to the Constructor. + */ + public abstract ITexture[][][] getTextureSet(ITexture[] aTextures); +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMetaTransformerHiAmp.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMetaTransformerHiAmp.java new file mode 100644 index 0000000000..c6a088fb1c --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMetaTransformerHiAmp.java @@ -0,0 +1,117 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; + +import org.apache.commons.lang3.ArrayUtils; + +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Transformer; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.PlayerUtils; + +public class GregtechMetaTransformerHiAmp extends GT_MetaTileEntity_Transformer { + + private boolean mHalfMode = false; + + public GregtechMetaTransformerHiAmp(int aID, String aName, String aNameRegional, int aTier, String aDescription) { + super(aID, aName, aNameRegional, aTier, aDescription); + } + + public GregtechMetaTransformerHiAmp(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } + + @Override + public long maxEUStore() { + return ((512L + gregtech.api.enums.GT_Values.V[(this.mTier + 1)] * 2L) * 8); + } + + @Override + public long maxAmperesOut() { + if (this.mHalfMode) { + return ((getBaseMetaTileEntity().isAllowedToWork()) ? 8L : 2L); + } + return ((getBaseMetaTileEntity().isAllowedToWork()) ? 16L : 4L); + } + + @Override + public long maxAmperesIn() { + if (this.mHalfMode) { + return ((getBaseMetaTileEntity().isAllowedToWork()) ? 2L : 8L); + } + return ((getBaseMetaTileEntity().isAllowedToWork()) ? 4L : 16L); + } + + @Override + public ITexture[][][] getTextureSet(ITexture[] aTextures) { + ITexture[][][] rTextures = new ITexture[12][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], + Textures.BlockIcons.OVERLAYS_ENERGY_OUT[mTier] }; + rTextures[1][i + 1] = new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], + Textures.BlockIcons.OVERLAYS_ENERGY_OUT[mTier] }; + rTextures[2][i + 1] = new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], + Textures.BlockIcons.OVERLAYS_ENERGY_OUT[mTier] }; + rTextures[3][i + 1] = new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], + Textures.BlockIcons.OVERLAYS_ENERGY_IN_MULTI[mTier + 1] }; + rTextures[4][i + 1] = new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], + Textures.BlockIcons.OVERLAYS_ENERGY_IN_MULTI[mTier + 1] }; + rTextures[5][i + 1] = new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], + Textures.BlockIcons.OVERLAYS_ENERGY_IN_MULTI[mTier + 1] }; + rTextures[6][i + 1] = new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], + Textures.BlockIcons.OVERLAYS_ENERGY_IN[mTier] }; + rTextures[7][i + 1] = new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], + Textures.BlockIcons.OVERLAYS_ENERGY_IN[mTier] }; + rTextures[8][i + 1] = new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], + Textures.BlockIcons.OVERLAYS_ENERGY_IN[mTier] }; + rTextures[9][i + 1] = new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], + Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[mTier + 1] }; + rTextures[10][i + 1] = new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], + Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[mTier + 1] }; + rTextures[11][i + 1] = new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], + Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[mTier + 1] }; + } + return rTextures; + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTransformerHiAmp(this.mName, this.mTier, this.mDescriptionArray, this.mTextures); + } + + @Override + public String[] getDescription() { + return ArrayUtils.addAll( + this.mDescriptionArray, + "Accepts 4A and outputs 16A", + "Toggle 2A/8A half-mode with Screwdriver", + CORE.GT_Tooltip.get()); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setBoolean("mHalfMode", this.mHalfMode); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + this.mHalfMode = aNBT.getBoolean("mHalfMode"); + super.loadNBTData(aNBT); + } + + @Override + public void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + this.mHalfMode = !mHalfMode; + if (this.mHalfMode) { + PlayerUtils.messagePlayer(aPlayer, "Transformer is now running at 2A:8A in/out Ratio."); + } else { + PlayerUtils.messagePlayer(aPlayer, "Transformer is now running at 4A:16A in/out Ratio."); + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java new file mode 100644 index 0000000000..e756a92343 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java @@ -0,0 +1,1799 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base; + +import static gregtech.api.enums.Mods.TecTech; +import static gregtech.api.util.GT_Utility.filterValidMTEs; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Map.Entry; +import java.util.Objects; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeUnit; +import java.util.function.BiConsumer; +import java.util.function.BiPredicate; +import java.util.function.Function; +import java.util.stream.Collectors; + +import javax.annotation.Nullable; + +import net.minecraft.block.Block; +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.StatCollector; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.oredict.OreDictionary; + +import com.gtnewhorizon.structurelib.StructureLibAPI; +import com.gtnewhorizon.structurelib.structure.AutoPlaceEnvironment; +import com.gtnewhorizon.structurelib.structure.IStructureElement; +import com.gtnewhorizon.structurelib.structure.StructureUtility; +import com.gtnewhorizons.modularui.api.drawable.ItemDrawable; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.DrawableWidget; +import com.gtnewhorizons.modularui.common.widget.DynamicPositionedColumn; +import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; +import com.gtnewhorizons.modularui.common.widget.TextWidget; + +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.Materials; +import gregtech.api.enums.Textures; +import gregtech.api.enums.VoidingMode; +import gregtech.api.gui.modularui.GT_UITextures; +import gregtech.api.interfaces.IHatchElement; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.items.GT_MetaGenerated_Tool; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_ExtendedPowerMultiBlockBase; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Dynamo; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBus; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Maintenance; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Muffler; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Output; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_OutputBus; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.render.TextureFactory; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.IGT_HatchAdder; +import gregtech.common.items.GT_MetaGenerated_Tool_01; +import gregtech.common.tileentities.machines.IDualInputHatch; +import gtPlusPlus.GTplusplus; +import gtPlusPlus.GTplusplus.INIT_PHASE; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.minecraft.BlockPos; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.core.util.reflect.ReflectionUtils; +import gtPlusPlus.preloader.CORE_Preloader; +import gtPlusPlus.preloader.asm.AsmConfig; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_AirIntake; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBattery; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_OutputBattery; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Steam_BusInput; + +// Glee8e - 11/12/21 - 2:15pm +// Yeah, now I see what's wrong. Someone inherited from GregtechMeta_MultiBlockBase instead of +// GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialDehydrator> as it should have been +// so any method in GregtechMetaTileEntity_IndustrialDehydrator would see generic field declared in +// GregtechMeta_MultiBlockBase without generic parameter + +public abstract class GregtechMeta_MultiBlockBase<T extends GT_MetaTileEntity_ExtendedPowerMultiBlockBase<T>> + extends GT_MetaTileEntity_ExtendedPowerMultiBlockBase<T> { + + public static final boolean DEBUG_DISABLE_CORES_TEMPORARILY = true; + + public GT_Recipe mLastRecipe; + protected long mTotalRunTime = 0; + + /** + * Don't use this for recipe input check, otherwise you'll get duplicated fluids + */ + public ArrayList<GT_MetaTileEntity_Hatch_AirIntake> mAirIntakes = new ArrayList<>(); + + public ArrayList<GT_MetaTileEntity_Hatch_InputBattery> mChargeHatches = new ArrayList<>(); + public ArrayList<GT_MetaTileEntity_Hatch_OutputBattery> mDischargeHatches = new ArrayList<>(); + public ArrayList<GT_MetaTileEntity_Hatch> mAllEnergyHatches = new ArrayList<>(); + public ArrayList<GT_MetaTileEntity_Hatch> mAllDynamoHatches = new ArrayList<>(); + + public GregtechMeta_MultiBlockBase(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMeta_MultiBlockBase(final String aName) { + super(aName); + } + + private static int toStackCount(Entry<ItemStack, Integer> e) { + int tMaxStackSize = e.getKey() + .getMaxStackSize(); + int tStackSize = e.getValue(); + return (tStackSize + tMaxStackSize - 1) / tMaxStackSize; + } + + public long getTotalRuntimeInTicks() { + return this.mTotalRunTime; + } + + public abstract String getMachineType(); + + public String getMachineTooltip() { + return "Machine Type: " + EnumChatFormatting.YELLOW + getMachineType() + EnumChatFormatting.RESET; + } + + public String[] getExtraInfoData() { + return new String[0]; + } + + @Override + public String[] getInfoData() { + ArrayList<String> mInfo = new ArrayList<>(); + if (!this.getMetaName() + .equals("")) { + mInfo.add(this.getMetaName()); + } + + String[] extra = getExtraInfoData(); + + if (extra == null) { + extra = new String[0]; + } + if (extra.length > 0) { + for (String s : extra) { + mInfo.add(s); + } + } + + long seconds = (this.mTotalRunTime / 20); + int weeks = (int) (TimeUnit.SECONDS.toDays(seconds) / 7); + int days = (int) (TimeUnit.SECONDS.toDays(seconds) - 7 * weeks); + long hours = TimeUnit.SECONDS.toHours(seconds) - TimeUnit.DAYS.toHours(days) + - TimeUnit.DAYS.toHours(7L * weeks); + long minutes = TimeUnit.SECONDS.toMinutes(seconds) - (TimeUnit.SECONDS.toHours(seconds) * 60); + long second = TimeUnit.SECONDS.toSeconds(seconds) - (TimeUnit.SECONDS.toMinutes(seconds) * 60); + + mInfo.add(getMachineTooltip()); + + // Lets borrow the GTNH handling + + mInfo.add( + StatCollector.translateToLocal("GTPP.multiblock.progress") + ": " + + EnumChatFormatting.GREEN + + mProgresstime / 20 + + EnumChatFormatting.RESET + + " s / " + + EnumChatFormatting.YELLOW + + mMaxProgresstime / 20 + + EnumChatFormatting.RESET + + " s"); + + if (!this.mAllEnergyHatches.isEmpty()) { + long storedEnergy = getStoredEnergyInAllEnergyHatches(); + long maxEnergy = getMaxEnergyStorageOfAllEnergyHatches(); + mInfo.add(StatCollector.translateToLocal("GTPP.multiblock.energy") + ":"); + mInfo.add( + StatCollector.translateToLocal( + "" + EnumChatFormatting.GREEN + + Long.toString(storedEnergy) + + EnumChatFormatting.RESET + + " EU / " + + EnumChatFormatting.YELLOW + + Long.toString(maxEnergy) + + EnumChatFormatting.RESET + + " EU")); + + mInfo.add(StatCollector.translateToLocal("GTPP.multiblock.mei") + ":"); + mInfo.add( + StatCollector.translateToLocal( + "" + EnumChatFormatting.YELLOW + + Long.toString(getMaxInputVoltage()) + + EnumChatFormatting.RESET + + " EU/t(*2A) " + + StatCollector.translateToLocal("GTPP.machines.tier") + + ": " + + EnumChatFormatting.YELLOW + + GT_Values.VN[GT_Utility.getTier(getMaxInputVoltage())] + + EnumChatFormatting.RESET));; + } + if (!this.mAllDynamoHatches.isEmpty()) { + long storedEnergy = getStoredEnergyInAllDynamoHatches(); + long maxEnergy = getMaxEnergyStorageOfAllDynamoHatches(); + mInfo.add(StatCollector.translateToLocal("GTPP.multiblock.energy") + " In Dynamos:"); + mInfo.add( + StatCollector.translateToLocal( + "" + EnumChatFormatting.GREEN + + Long.toString(storedEnergy) + + EnumChatFormatting.RESET + + " EU / " + + EnumChatFormatting.YELLOW + + Long.toString(maxEnergy) + + EnumChatFormatting.RESET + + " EU")); + } + + if (-lEUt > 0) { + mInfo.add(StatCollector.translateToLocal("GTPP.multiblock.usage") + ":"); + mInfo.add( + StatCollector + .translateToLocal("" + EnumChatFormatting.RED + (-lEUt) + EnumChatFormatting.RESET + " EU/t")); + } else { + mInfo.add(StatCollector.translateToLocal("GTPP.multiblock.generation") + ":"); + mInfo.add( + StatCollector + .translateToLocal("" + EnumChatFormatting.GREEN + lEUt + EnumChatFormatting.RESET + " EU/t")); + } + + mInfo.add( + StatCollector.translateToLocal("GTPP.multiblock.problems") + ": " + + EnumChatFormatting.RED + + (getIdealStatus() - getRepairStatus()) + + EnumChatFormatting.RESET + + " " + + StatCollector.translateToLocal("GTPP.multiblock.efficiency") + + ": " + + EnumChatFormatting.YELLOW + + Float.toString(mEfficiency / 100.0F) + + EnumChatFormatting.RESET + + " %"); + + if (this.getPollutionPerSecond(null) > 0) { + int mPollutionReduction = getPollutionReductionForAllMufflers(); + mInfo.add( + StatCollector.translateToLocal("GTPP.multiblock.pollution") + ": " + + EnumChatFormatting.RED + + this.getPollutionPerSecond(null) + + EnumChatFormatting.RESET + + "/sec"); + mInfo.add( + StatCollector.translateToLocal("GTPP.multiblock.pollutionreduced") + ": " + + EnumChatFormatting.GREEN + + mPollutionReduction + + EnumChatFormatting.RESET + + " %"); + } + + mInfo.add( + StatCollector.translateToLocal("GTPP.CC.parallel") + ": " + + EnumChatFormatting.GREEN + + (getMaxParallelRecipes()) + + EnumChatFormatting.RESET); + + mInfo.add( + "Total Time Since Built: " + EnumChatFormatting.DARK_GREEN + + Integer.toString(weeks) + + EnumChatFormatting.RESET + + " Weeks, " + + EnumChatFormatting.DARK_GREEN + + Integer.toString(days) + + EnumChatFormatting.RESET + + " Days, "); + mInfo.add( + EnumChatFormatting.DARK_GREEN + Long.toString(hours) + + EnumChatFormatting.RESET + + " Hours, " + + EnumChatFormatting.DARK_GREEN + + Long.toString(minutes) + + EnumChatFormatting.RESET + + " Minutes, " + + EnumChatFormatting.DARK_GREEN + + Long.toString(second) + + EnumChatFormatting.RESET + + " Seconds."); + mInfo.add("Total Time in ticks: " + EnumChatFormatting.DARK_GREEN + Long.toString(this.mTotalRunTime)); + + String[] mInfo2 = mInfo.toArray(new String[mInfo.size()]); + return mInfo2; + } + + public int getPollutionReductionForAllMufflers() { + int mPollutionReduction = 0; + for (GT_MetaTileEntity_Hatch_Muffler tHatch : filterValidMTEs(mMufflerHatches)) { + mPollutionReduction = Math.max(calculatePollutionReductionForHatch(tHatch, 100), mPollutionReduction); + } + return mPollutionReduction; + } + + public long getStoredEnergyInAllEnergyHatches() { + long storedEnergy = 0; + for (GT_MetaTileEntity_Hatch tHatch : filterValidMTEs(mAllEnergyHatches)) { + storedEnergy += tHatch.getBaseMetaTileEntity() + .getStoredEU(); + } + return storedEnergy; + } + + public long getMaxEnergyStorageOfAllEnergyHatches() { + long maxEnergy = 0; + for (GT_MetaTileEntity_Hatch tHatch : filterValidMTEs(mAllEnergyHatches)) { + maxEnergy += tHatch.getBaseMetaTileEntity() + .getEUCapacity(); + } + return maxEnergy; + } + + public long getStoredEnergyInAllDynamoHatches() { + long storedEnergy = 0; + for (GT_MetaTileEntity_Hatch tHatch : filterValidMTEs(mAllDynamoHatches)) { + storedEnergy += tHatch.getBaseMetaTileEntity() + .getStoredEU(); + } + return storedEnergy; + } + + public long getMaxEnergyStorageOfAllDynamoHatches() { + long maxEnergy = 0; + for (GT_MetaTileEntity_Hatch tHatch : filterValidMTEs(mAllDynamoHatches)) { + maxEnergy += tHatch.getBaseMetaTileEntity() + .getEUCapacity(); + } + return maxEnergy; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + private String[] aCachedToolTip; + + /* + * private final String aRequiresMuffler = "1x Muffler Hatch"; private final String aRequiresCoreModule = + * "1x Core Module"; private final String aRequiresMaint = "1x Maintanence Hatch"; + */ + + public static final String TAG_HIDE_HATCHES = "TAG_HIDE_HATCHES"; + public static final String TAG_HIDE_MAINT = "TAG_HIDE_MAINT"; + public static final String TAG_HIDE_POLLUTION = "TAG_HIDE_POLLUTION"; + public static final String TAG_HIDE_MACHINE_TYPE = "TAG_HIDE_MACHINE_TYPE"; + + public abstract int getMaxParallelRecipes(); + + @Override + public boolean isCorrectMachinePart(final ItemStack paramItemStack) { + return true; + } + + @Override + public int getDamageToComponent(final ItemStack paramItemStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack p0) { + return false; + } + + /** + * A Static {@link Method} object which holds the current status of logging. + */ + public static Method aLogger = null; + + public void log(String s) { + if (!AsmConfig.disableAllLogging) { + if (CORE_Preloader.DEBUG_MODE) { + Logger.INFO(s); + } else { + Logger.MACHINE_INFO(s); + } + } + } + + @Override + protected void setProcessingLogicPower(ProcessingLogic logic) { + logic.setAvailableVoltage(GT_Utility.roundUpVoltage(this.getMaxInputVoltage())); + logic.setAvailableAmperage(1L); + } + + public long getMaxInputEnergy() { + long rEnergy = 0; + if (mEnergyHatches.size() == 1) // so it only takes 1 amp is only 1 hatch is present so it works like most gt + // multies + return mEnergyHatches.get(0) + .getBaseMetaTileEntity() + .getInputVoltage(); + for (GT_MetaTileEntity_Hatch_Energy tHatch : filterValidMTEs(mEnergyHatches)) + rEnergy += tHatch.getBaseMetaTileEntity() + .getInputVoltage() + * tHatch.getBaseMetaTileEntity() + .getInputAmperage(); + return rEnergy; + } + + public boolean isMachineRunning() { + boolean aRunning = this.getBaseMetaTileEntity() + .isActive(); + // log("Queried Multiblock is currently running: "+aRunning); + return aRunning; + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + + // Time Counter + if (aBaseMetaTileEntity.isServerSide()) { + this.mTotalRunTime++; + } + + if (aBaseMetaTileEntity.isServerSide()) { + if (this.mUpdate == 1 || this.mStartUpCheck == 1) { + this.mChargeHatches.clear(); + this.mDischargeHatches.clear(); + this.mAirIntakes.clear(); + this.mTecTechEnergyHatches.clear(); + this.mTecTechDynamoHatches.clear(); + this.mAllEnergyHatches.clear(); + this.mAllDynamoHatches.clear(); + } + } + + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + @Override + public void explodeMultiblock() { + MetaTileEntity tTileEntity; + for (final Iterator<GT_MetaTileEntity_Hatch_InputBattery> localIterator = this.mChargeHatches + .iterator(); localIterator.hasNext(); tTileEntity.getBaseMetaTileEntity() + .doExplosion(gregtech.api.enums.GT_Values.V[8])) { + tTileEntity = localIterator.next(); + } + tTileEntity = null; + for (final Iterator<GT_MetaTileEntity_Hatch_OutputBattery> localIterator = this.mDischargeHatches + .iterator(); localIterator.hasNext(); tTileEntity.getBaseMetaTileEntity() + .doExplosion(gregtech.api.enums.GT_Values.V[8])) { + tTileEntity = localIterator.next(); + } + tTileEntity = null; + for (final Iterator<GT_MetaTileEntity_Hatch> localIterator = this.mTecTechDynamoHatches + .iterator(); localIterator.hasNext(); tTileEntity.getBaseMetaTileEntity() + .doExplosion(gregtech.api.enums.GT_Values.V[8])) { + tTileEntity = localIterator.next(); + } + tTileEntity = null; + for (final Iterator<GT_MetaTileEntity_Hatch> localIterator = this.mTecTechEnergyHatches + .iterator(); localIterator.hasNext(); tTileEntity.getBaseMetaTileEntity() + .doExplosion(gregtech.api.enums.GT_Values.V[8])) { + tTileEntity = localIterator.next(); + } + + super.explodeMultiblock(); + } + + protected boolean setGUIItemStack(ItemStack aNewGuiSlotContents) { + boolean result = false; + if (this.mInventory[1] == null) { + this.mInventory[1] = aNewGuiSlotContents != null ? aNewGuiSlotContents.copy() : null; + this.depleteInput(aNewGuiSlotContents); + this.updateSlots(); + result = true; + } + return result; + } + + public ItemStack findItemInInventory(Item aSearchStack) { + return findItemInInventory(aSearchStack, 0); + } + + public ItemStack findItemInInventory(Item aSearchStack, int aMeta) { + return findItemInInventory(ItemUtils.simpleMetaStack(aSearchStack, aMeta, 1)); + } + + public ItemStack findItemInInventory(ItemStack aSearchStack) { + if (aSearchStack != null && this.mInputBusses.size() > 0) { + for (GT_MetaTileEntity_Hatch_InputBus bus : this.mInputBusses) { + if (bus != null) { + for (ItemStack uStack : bus.mInventory) { + if (uStack != null) { + if (aSearchStack.getClass() + .isInstance(uStack.getItem())) { + return uStack; + } + } + } + } + } + } + return null; + } + + /** + * Deplete fluid input from a set of restricted hatches. This assumes these hatches can store nothing else but your + * expected fluid + */ + protected boolean depleteInputFromRestrictedHatches(Collection<GT_MetaTileEntity_Hatch_CustomFluidBase> aHatches, + int aAmount) { + for (final GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : filterValidMTEs(aHatches)) { + FluidStack tLiquid = tHatch.getFluid(); + if (tLiquid == null || tLiquid.amount < aAmount) { + continue; + } + tLiquid = tHatch.drain(aAmount, false); + if (tLiquid != null && tLiquid.amount >= aAmount) { + tLiquid = tHatch.drain(aAmount, true); + return tLiquid != null && tLiquid.amount >= aAmount; + } + } + return false; + } + + @Override + public void updateSlots() { + for (final GT_MetaTileEntity_Hatch_InputBattery tHatch : filterValidMTEs(this.mChargeHatches)) { + tHatch.updateSlots(); + } + for (final GT_MetaTileEntity_Hatch_OutputBattery tHatch : filterValidMTEs(this.mDischargeHatches)) { + tHatch.updateSlots(); + } + super.updateSlots(); + } + + /** + * Causes a Random Maint. Issue. + * + * @return {@link boolean} - Returns whether or not an issue was caused, should always be true. + */ + public boolean causeMaintenanceIssue() { + boolean b = false; + switch (this.getBaseMetaTileEntity() + .getRandomNumber(6)) { + case 0 -> { + this.mWrench = false; + b = true; + } + case 1 -> { + this.mScrewdriver = false; + b = true; + } + case 2 -> { + this.mSoftHammer = false; + b = true; + } + case 3 -> { + this.mHardHammer = false; + b = true; + } + case 4 -> { + this.mSolderingTool = false; + b = true; + } + case 5 -> { + this.mCrowbar = false; + b = true; + } + } + return b; + } + + public void fixAllMaintenanceIssue() { + this.mCrowbar = true; + this.mWrench = true; + this.mHardHammer = true; + this.mSoftHammer = true; + this.mSolderingTool = true; + this.mScrewdriver = true; + } + + public boolean checkHatch() { + return mMaintenanceHatches.size() <= 1 + && (this.getPollutionPerSecond(null) > 0 ? !mMufflerHatches.isEmpty() : true); + } + + @Override + public void clearHatches() { + super.clearHatches(); + this.mChargeHatches.clear(); + this.mDischargeHatches.clear(); + this.mAirIntakes.clear(); + this.mTecTechEnergyHatches.clear(); + this.mTecTechDynamoHatches.clear(); + this.mAllEnergyHatches.clear(); + this.mAllDynamoHatches.clear(); + } + + public <E> boolean addToMachineListInternal(ArrayList<E> aList, final IGregTechTileEntity aTileEntity, + final int aBaseCasingIndex) { + return addToMachineListInternal(aList, getMetaTileEntity(aTileEntity), aBaseCasingIndex); + } + + public <E> boolean addToMachineListInternal(ArrayList<E> aList, final IMetaTileEntity aTileEntity, + final int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } + + // Check type + /* + * Class <?> aHatchType = ReflectionUtils.getTypeOfGenericObject(aList); if + * (!aHatchType.isInstance(aTileEntity)) { return false; } + */ + + // Try setRecipeMap + + try { + if (aTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + resetRecipeMapForHatch((GT_MetaTileEntity_Hatch) aTileEntity, getRecipeMap()); + } + if (aTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus) { + resetRecipeMapForHatch((GT_MetaTileEntity_Hatch) aTileEntity, getRecipeMap()); + } + } catch (Throwable t) { + t.printStackTrace(); + } + + if (aList.isEmpty()) { + if (aTileEntity instanceof GT_MetaTileEntity_Hatch) { + if (GTplusplus.CURRENT_LOAD_PHASE == INIT_PHASE.STARTED) { + log( + "Adding " + aTileEntity.getInventoryName() + + " at " + + new BlockPos(aTileEntity.getBaseMetaTileEntity()).getLocationString()); + } + updateTexture(aTileEntity, aBaseCasingIndex); + return aList.add((E) aTileEntity); + } + } else { + IGregTechTileEntity aCur = aTileEntity.getBaseMetaTileEntity(); + if (aList.contains(aTileEntity)) { + log( + "Found Duplicate " + aTileEntity.getInventoryName() + + " @ " + + new BlockPos(aCur).getLocationString()); + return false; + } + BlockPos aCurPos = new BlockPos(aCur); + boolean aExists = false; + for (E m : aList) { + IGregTechTileEntity b = ((IMetaTileEntity) m).getBaseMetaTileEntity(); + if (b != null) { + BlockPos aPos = new BlockPos(b); + if (aPos != null) { + if (aCurPos.equals(aPos)) { + if (GTplusplus.CURRENT_LOAD_PHASE == INIT_PHASE.STARTED) { + log("Found Duplicate " + b.getInventoryName() + " at " + aPos.getLocationString()); + } + return false; + } + } + } + } + if (aTileEntity instanceof GT_MetaTileEntity_Hatch) { + if (GTplusplus.CURRENT_LOAD_PHASE == INIT_PHASE.STARTED) { + log("Adding " + aCur.getInventoryName() + " at " + aCurPos.getLocationString()); + } + updateTexture(aTileEntity, aBaseCasingIndex); + return aList.add((E) aTileEntity); + } + } + return false; + } + + private IMetaTileEntity getMetaTileEntity(final IGregTechTileEntity aTileEntity) { + if (aTileEntity == null) { + return null; + } + final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + return aMetaTileEntity; + } + + @Override + public boolean addToMachineList(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) { + return addToMachineList(getMetaTileEntity(aTileEntity), aBaseCasingIndex); + } + + public boolean addToMachineList(final IMetaTileEntity aMetaTileEntity, final int aBaseCasingIndex) { + if (aMetaTileEntity == null) { + return false; + } + + // Use this to determine the correct value, then update the hatch texture after. + boolean aDidAdd = false; + + // Handle Custom Hatches + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBattery) { + log("Found GT_MetaTileEntity_Hatch_InputBattery"); + aDidAdd = addToMachineListInternal(mChargeHatches, aMetaTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBattery) { + log("Found GT_MetaTileEntity_Hatch_OutputBattery"); + aDidAdd = addToMachineListInternal(mDischargeHatches, aMetaTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_AirIntake) { + aDidAdd = addToMachineListInternal(mAirIntakes, aMetaTileEntity, aBaseCasingIndex) + && addToMachineListInternal(mInputHatches, aMetaTileEntity, aBaseCasingIndex); + } + + // Handle TT Multi-A Energy Hatches + else if (TecTech.isModLoaded() && isThisHatchMultiEnergy(aMetaTileEntity)) { + log("Found isThisHatchMultiEnergy"); + aDidAdd = addToMachineListInternal(mTecTechEnergyHatches, aMetaTileEntity, aBaseCasingIndex); + updateMasterEnergyHatchList(aMetaTileEntity); + } + + // Handle TT Multi-A Dynamos + else if (TecTech.isModLoaded() && isThisHatchMultiDynamo(aMetaTileEntity)) { + log("Found isThisHatchMultiDynamo"); + aDidAdd = addToMachineListInternal(mTecTechDynamoHatches, aMetaTileEntity, aBaseCasingIndex); + updateMasterDynamoHatchList(aMetaTileEntity); + } + + // Handle Fluid Hatches using seperate logic + else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) + aDidAdd = addToMachineListInternal(mInputHatches, aMetaTileEntity, aBaseCasingIndex); + else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output) + aDidAdd = addToMachineListInternal(mOutputHatches, aMetaTileEntity, aBaseCasingIndex); + + // Process Remaining hatches using Vanilla GT Logic + else if (aMetaTileEntity instanceof IDualInputHatch hatch) { + hatch.updateCraftingIcon(this.getMachineCraftingIcon()); + aDidAdd = addToMachineListInternal(mDualInputHatches, aMetaTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus) + aDidAdd = addToMachineListInternal(mInputBusses, aMetaTileEntity, aBaseCasingIndex); + else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) + aDidAdd = addToMachineListInternal(mOutputBusses, aMetaTileEntity, aBaseCasingIndex); + else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy) { + aDidAdd = addToMachineListInternal(mEnergyHatches, aMetaTileEntity, aBaseCasingIndex); + updateMasterEnergyHatchList(aMetaTileEntity); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Dynamo) { + aDidAdd = addToMachineListInternal(mDynamoHatches, aMetaTileEntity, aBaseCasingIndex); + updateMasterDynamoHatchList(aMetaTileEntity); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance) + aDidAdd = addToMachineListInternal(mMaintenanceHatches, aMetaTileEntity, aBaseCasingIndex); + else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) + aDidAdd = addToMachineListInternal(mMufflerHatches, aMetaTileEntity, aBaseCasingIndex); + + // return super.addToMachineList(aTileEntity, aBaseCasingIndex); + return aDidAdd; + } + + @Override + public boolean addMaintenanceToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + IMetaTileEntity aMetaTileEntity = getMetaTileEntity(aTileEntity); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance) { + return addToMachineList(aMetaTileEntity, aBaseCasingIndex); + } + return false; + } + + @Override + public boolean addMufflerToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + IMetaTileEntity aMetaTileEntity = getMetaTileEntity(aTileEntity); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + return addToMachineList(aMetaTileEntity, aBaseCasingIndex); + } + return false; + } + + @Override + public boolean addInputToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + IMetaTileEntity aMetaTileEntity = getMetaTileEntity(aTileEntity); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input + || aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus) { + return addToMachineList(aMetaTileEntity, aBaseCasingIndex); + } + return false; + } + + @Override + public boolean addOutputToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + IMetaTileEntity aMetaTileEntity = getMetaTileEntity(aTileEntity); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output + || aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + return addToMachineList(aMetaTileEntity, aBaseCasingIndex); + } + return false; + } + + public boolean addAirIntakeToMachineList(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) { + IMetaTileEntity aMetaTileEntity = getMetaTileEntity(aTileEntity); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_AirIntake) { + return addToMachineList(aMetaTileEntity, aBaseCasingIndex); + } + return false; + } + + public boolean addFluidInputToMachineList(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) { + return addFluidInputToMachineList(getMetaTileEntity(aTileEntity), aBaseCasingIndex); + } + + public boolean addFluidInputToMachineList(final IMetaTileEntity aMetaTileEntity, final int aBaseCasingIndex) { + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + return addToMachineList(aMetaTileEntity, aBaseCasingIndex); + } + return false; + } + + public boolean clearRecipeMapForAllInputHatches() { + return resetRecipeMapForAllInputHatches(null); + } + + public boolean resetRecipeMapForAllInputHatches() { + return resetRecipeMapForAllInputHatches(this.getRecipeMap()); + } + + public boolean resetRecipeMapForAllInputHatches(RecipeMap<?> aMap) { + int cleared = 0; + for (GT_MetaTileEntity_Hatch_Input g : this.mInputHatches) { + if (resetRecipeMapForHatch(g, aMap)) { + cleared++; + } + } + for (GT_MetaTileEntity_Hatch_InputBus g : this.mInputBusses) { + if (resetRecipeMapForHatch(g, aMap)) { + cleared++; + } + } + return cleared > 0; + } + + public boolean resetRecipeMapForHatch(IGregTechTileEntity aTileEntity, RecipeMap<?> aMap) { + try { + final IMetaTileEntity aMetaTileEntity = getMetaTileEntity(aTileEntity); + if (aMetaTileEntity == null) { + return false; + } + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input + || aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus + || aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Steam_BusInput) { + return resetRecipeMapForHatch((GT_MetaTileEntity_Hatch) aMetaTileEntity, aMap); + } else { + return false; + } + } catch (Throwable t) { + t.printStackTrace(); + return false; + } + } + + public boolean resetRecipeMapForHatch(GT_MetaTileEntity_Hatch aTileEntity, RecipeMap<?> aMap) { + if (aTileEntity == null) { + return false; + } + final IMetaTileEntity aMetaTileEntity = aTileEntity; + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input + || aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus + || aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Steam_BusInput) { + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + ((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity).mRecipeMap = null; + ((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity).mRecipeMap = aMap; + if (aMap != null) { + log("Remapped Input Hatch to " + aMap.unlocalizedName + "."); + } else { + log("Cleared Input Hatch."); + } + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus) { + ((GT_MetaTileEntity_Hatch_InputBus) aMetaTileEntity).mRecipeMap = null; + ((GT_MetaTileEntity_Hatch_InputBus) aMetaTileEntity).mRecipeMap = aMap; + if (aMap != null) { + log("Remapped Input Bus to " + aMap.unlocalizedName + "."); + } else { + log("Cleared Input Bus."); + } + } else { + ((GT_MetaTileEntity_Hatch_Steam_BusInput) aMetaTileEntity).mRecipeMap = null; + ((GT_MetaTileEntity_Hatch_Steam_BusInput) aMetaTileEntity).mRecipeMap = aMap; + if (aMap != null) { + log("Remapped Input Bus to " + aMap.unlocalizedName + "."); + } else { + log("Cleared Input Bus."); + } + } + return true; + } else { + return false; + } + } + + @Override + public final void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + super.onScrewdriverRightClick(side, aPlayer, aX, aY, aZ); + clearRecipeMapForAllInputHatches(); + onModeChangeByScrewdriver(side, aPlayer, aX, aY, aZ); + resetRecipeMapForAllInputHatches(); + } + + public void onModeChangeByScrewdriver(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) {} + + /** + * Enable Texture Casing Support if found in GT 5.09 + */ + public boolean updateTexture(final IGregTechTileEntity aTileEntity, int aCasingID) { + return updateTexture(getMetaTileEntity(aTileEntity), aCasingID); + } + + /** + * Enable Texture Casing Support if found in GT 5.09 + */ + public boolean updateTexture(final IMetaTileEntity aTileEntity, int aCasingID) { + try { // gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch.updateTexture(int) + + final IMetaTileEntity aMetaTileEntity = aTileEntity; + if (aMetaTileEntity == null) { + return false; + } + Method mProper = ReflectionUtils.getMethod(GT_MetaTileEntity_Hatch.class, "updateTexture", int.class); + if (mProper != null) { + if (GT_MetaTileEntity_Hatch.class.isInstance(aMetaTileEntity)) { + mProper.setAccessible(true); + mProper.invoke(aMetaTileEntity, aCasingID); + // log("Good Method Call for updateTexture."); + return true; + } + } else { + log("Bad Method Call for updateTexture."); + if (GT_MetaTileEntity_Hatch.class.isInstance(aMetaTileEntity)) { + if (aCasingID <= Byte.MAX_VALUE) { + ((GT_MetaTileEntity_Hatch) aTileEntity).updateTexture(aCasingID); + log( + "Good Method Call for updateTexture. Used fallback method of setting mMachineBlock as casing id was <= 128."); + return true; + } else { + log("updateTexture returning false. 1.2"); + } + } else { + log("updateTexture returning false. 1.3"); + } + } + log("updateTexture returning false. 1"); + return false; + } catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + log("updateTexture returning false."); + log("updateTexture returning false. 2"); + e.printStackTrace(); + return false; + } + } + + /** + * TecTech Support + */ + + /** + * This is the array Used to Store the Tectech Multi-Amp Dynamo hatches. + */ + public ArrayList<GT_MetaTileEntity_Hatch> mTecTechDynamoHatches = new ArrayList<>(); + + /** + * This is the array Used to Store the Tectech Multi-Amp Energy hatches. + */ + public ArrayList<GT_MetaTileEntity_Hatch> mTecTechEnergyHatches = new ArrayList<>(); + + /** + * TecTech Multi-Amp Dynamo Support + * + * @param aTileEntity - The Dynamo Hatch + * @param aBaseCasingIndex - Casing Texture + * @return + */ + public boolean addMultiAmpDynamoToMachineList(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) { + final IMetaTileEntity aMetaTileEntity = getMetaTileEntity(aTileEntity); + if (aMetaTileEntity == null) { + return false; + } + if (isThisHatchMultiDynamo(aTileEntity)) { + return addToMachineListInternal(mTecTechDynamoHatches, aMetaTileEntity, aBaseCasingIndex); + } + return false; + } + + public boolean isThisHatchMultiDynamo(IGregTechTileEntity aTileEntity) { + return isThisHatchMultiDynamo(getMetaTileEntity(aTileEntity)); + } + + public boolean isThisHatchMultiDynamo(IMetaTileEntity aMetaTileEntity) { + Class<?> mDynamoClass; + mDynamoClass = ReflectionUtils + .getClass("com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_DynamoMulti"); + if (mDynamoClass != null) { + if (mDynamoClass.isInstance(aMetaTileEntity)) { + return true; + } + } + return false; + } + + @Override + public boolean addDynamoToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + IMetaTileEntity aMetaTileEntity = getMetaTileEntity(aTileEntity); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Dynamo || isThisHatchMultiDynamo(aMetaTileEntity)) { + return addToMachineList(aMetaTileEntity, aBaseCasingIndex); + } + return false; + } + + private boolean updateMasterDynamoHatchList(IMetaTileEntity aMetaTileEntity) { + if (aMetaTileEntity == null) { + return false; + } + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch aHatch) { + return mAllDynamoHatches.add(aHatch); + } + return false; + } + + /** + * TecTech Multi-Amp Energy Hatch Support + * + * @param aTileEntity - The Energy Hatch + * @param aBaseCasingIndex - Casing Texture + * @return + */ + public boolean addMultiAmpEnergyToMachineList(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) { + final IMetaTileEntity aMetaTileEntity = getMetaTileEntity(aTileEntity); + if (aMetaTileEntity == null) { + return false; + } + if (isThisHatchMultiEnergy(aMetaTileEntity)) { + return addToMachineListInternal(mTecTechEnergyHatches, aMetaTileEntity, aBaseCasingIndex); + } + return false; + } + + public boolean isThisHatchMultiEnergy(IGregTechTileEntity aTileEntity) { + return isThisHatchMultiEnergy(getMetaTileEntity(aTileEntity)); + } + + public boolean isThisHatchMultiEnergy(IMetaTileEntity aMetaTileEntity) { + Class<?> mDynamoClass; + mDynamoClass = ReflectionUtils + .getClass("com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_EnergyMulti"); + if (mDynamoClass != null) { + if (mDynamoClass.isInstance(aMetaTileEntity)) { + return true; + } + } + return false; + } + + @Override + public boolean addEnergyInputToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + IMetaTileEntity aMetaTileEntity = getMetaTileEntity(aTileEntity); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy || isThisHatchMultiEnergy(aMetaTileEntity)) { + return addToMachineList(aMetaTileEntity, aBaseCasingIndex); + } + return false; + } + + private boolean updateMasterEnergyHatchList(IMetaTileEntity aMetaTileEntity) { + if (aMetaTileEntity == null) { + return false; + } + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch aHatch) { + return mAllEnergyHatches.add(aHatch); + } + return false; + } + + /** + * Pollution Management + */ + public int calculatePollutionReductionForHatch(GT_MetaTileEntity_Hatch_Muffler hatch, int poll) { + return hatch.calculatePollutionReduction(poll); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setLong("mTotalRunTime", this.mTotalRunTime); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + this.mTotalRunTime = aNBT.getLong("mTotalRunTime"); + if (aNBT.hasKey("mVoidExcess")) { + // backward compatibility + voidingMode = aNBT.getBoolean("mVoidExcess") ? VoidingMode.VOID_ALL : VoidingMode.VOID_NONE; + } + if (aNBT.hasKey("mUseMultiparallelMode")) { + // backward compatibility + batchMode = aNBT.getBoolean("mUseMultiparallelMode"); + } + } + + /** + * Custom Tool Handling + */ + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, ForgeDirection side, + float aX, float aY, float aZ) { + // Do Things + if (this.getBaseMetaTileEntity() + .isServerSide()) { + // Logger.INFO("Right Clicked Controller."); + ItemStack tCurrentItem = aPlayer.inventory.getCurrentItem(); + if (tCurrentItem != null) { + // Logger.INFO("Holding Item."); + if (tCurrentItem.getItem() instanceof GT_MetaGenerated_Tool) { + // Logger.INFO("Is GT_MetaGenerated_Tool."); + int[] aOreID = OreDictionary.getOreIDs(tCurrentItem); + for (int id : aOreID) { + // Plunger + if (OreDictionary.getOreName(id) + .equals("craftingToolPlunger")) { + // Logger.INFO("Is Plunger."); + return onPlungerRightClick(aPlayer, side, aX, aY, aZ); + } + } + } + } + } + // Do Super + boolean aSuper = super.onRightclick(aBaseMetaTileEntity, aPlayer, side, aX, aY, aZ); + return aSuper; + } + + public boolean onPlungerRightClick(EntityPlayer aPlayer, ForgeDirection side, float aX, float aY, float aZ) { + int aHatchIndex = 0; + PlayerUtils.messagePlayer(aPlayer, "Trying to clear " + mOutputHatches.size() + " output hatches."); + for (GT_MetaTileEntity_Hatch_Output hatch : this.mOutputHatches) { + if (hatch.mFluid != null) { + PlayerUtils.messagePlayer( + aPlayer, + "Clearing " + hatch.mFluid.amount + + "L of " + + hatch.mFluid.getLocalizedName() + + " from hatch " + + aHatchIndex + + "."); + hatch.mFluid = null; + } + aHatchIndex++; + } + return aHatchIndex > 0; + } + + @Override + public boolean onWireCutterRightClick(ForgeDirection side, ForgeDirection wrenchingSide, EntityPlayer aPlayer, + float aX, float aY, float aZ) { + if (aPlayer.isSneaking()) { + batchMode = !batchMode; + if (batchMode) { + GT_Utility.sendChatToPlayer(aPlayer, StatCollector.translateToLocal("misc.BatchModeTextOn")); + } else { + GT_Utility.sendChatToPlayer(aPlayer, StatCollector.translateToLocal("misc.BatchModeTextOff")); + } + return true; + } + return false; + } + + @Override + public boolean onSolderingToolRightClick(ForgeDirection side, ForgeDirection wrenchingSide, EntityPlayer aPlayer, + float aX, float aY, float aZ) { + if (supportsVoidProtection() && wrenchingSide == getBaseMetaTileEntity().getFrontFacing()) { + Set<VoidingMode> allowed = getAllowedVoidingModes(); + setVoidingMode(getVoidingMode().nextInCollection(allowed)); + GT_Utility.sendChatToPlayer( + aPlayer, + StatCollector.translateToLocal("GT5U.gui.button.voiding_mode") + " " + + StatCollector.translateToLocal(getVoidingMode().getTransKey())); + return true; + } else return super.onSolderingToolRightClick(side, wrenchingSide, aPlayer, aX, aY, aZ); + } + + @Override + public void onServerStart() { + super.onServerStart(); + tryTickWaitTimerDown(); + } + + @Override + public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { + super.onFirstTick(aBaseMetaTileEntity); + tryTickWaitTimerDown(); + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + tryTickWaitTimerDown(); + } + + @Override + public void onCreated(ItemStack aStack, World aWorld, EntityPlayer aPlayer) { + super.onCreated(aStack, aWorld, aPlayer); + tryTickWaitTimerDown(); + } + + private void tryTickWaitTimerDown() { + /* + * if (mStartUpCheck > 10) { mStartUpCheck = 10; } + */ + } + + // Only support to use meta to tier + + /** + * accept meta [0, maxMeta) + * + * @param maxMeta exclusive + */ + public static <T> IStructureElement<T> addTieredBlock(Block aBlock, BiConsumer<T, Integer> aSetTheMeta, + Function<T, Integer> aGetTheMeta, int maxMeta) { + return addTieredBlock(aBlock, (t, i) -> { + aSetTheMeta.accept(t, i); + return true; + }, aGetTheMeta, 0, maxMeta); + } + + /** + * + * @param minMeta inclusive + * @param maxMeta exclusive + */ + public static <T> IStructureElement<T> addTieredBlock(Block aBlock, BiConsumer<T, Integer> aSetTheMeta, + Function<T, Integer> aGetTheMeta, int minMeta, int maxMeta) { + return addTieredBlock(aBlock, (t, i) -> { + aSetTheMeta.accept(t, i); + return true; + }, aGetTheMeta, minMeta, maxMeta); + } + + /** + * + * @param minMeta inclusive + * @param maxMeta exclusive + */ + public static <T> IStructureElement<T> addTieredBlock(Block aBlock, BiPredicate<T, Integer> aSetTheMeta, + Function<T, Integer> aGetTheMeta, int minMeta, int maxMeta) { + + return new IStructureElement<>() { + + @Override + public boolean check(T t, World world, int x, int y, int z) { + Block tBlock = world.getBlock(x, y, z); + if (aBlock == tBlock) { + Integer currentMeta = aGetTheMeta.apply(t); + int newMeta = tBlock.getDamageValue(world, x, y, z) + 1; + if (newMeta > maxMeta || newMeta < minMeta + 1) return false; + if (currentMeta == 0) { + return aSetTheMeta.test(t, newMeta); + } else { + return currentMeta == newMeta; + } + } + return false; + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(world, x, y, z, aBlock, getMeta(trigger)); + return true; + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + return world.setBlock(x, y, z, aBlock, getMeta(trigger), 3); + } + + private int getMeta(ItemStack trigger) { + int meta = trigger.stackSize; + if (meta <= 0) meta = minMeta; + if (meta + minMeta >= maxMeta) meta = maxMeta - 1 - minMeta; + return meta + minMeta; + } + + @Nullable + @Override + public BlocksToPlace getBlocksToPlace(T t, World world, int x, int y, int z, ItemStack trigger, + AutoPlaceEnvironment env) { + return BlocksToPlace.create(aBlock, getMeta(trigger)); + } + + @Override + public PlaceResult survivalPlaceBlock(T t, World world, int x, int y, int z, ItemStack trigger, + AutoPlaceEnvironment env) { + if (world.getBlock(x, y, z) == aBlock) { + if (world.getBlockMetadata(x, y, z) == getMeta(trigger)) { + return PlaceResult.SKIP; + } + return PlaceResult.REJECT; + } + return StructureUtility.survivalPlaceBlock( + aBlock, + getMeta(trigger), + world, + x, + y, + z, + env.getSource(), + env.getActor(), + env.getChatter()); + } + }; + } + + @Override + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, ForgeDirection side, ForgeDirection facing, + int aColorIndex, boolean aActive, boolean aRedstone) { + if (side == facing) { + if (aActive) return new ITexture[] { getCasingTexture(), TextureFactory.builder() + .addIcon(getActiveOverlay()) + .extFacing() + .build() }; + return new ITexture[] { getCasingTexture(), TextureFactory.builder() + .addIcon(getInactiveOverlay()) + .extFacing() + .build() }; + } + return new ITexture[] { getCasingTexture() }; + } + + protected IIconContainer getActiveOverlay() { + return null; + } + + protected IIconContainer getInactiveOverlay() { + return null; + } + + protected ITexture getCasingTexture() { + return Textures.BlockIcons.getCasingTextureForId(getCasingTextureId()); + } + + protected int getCasingTextureId() { + return 0; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + if (doesBindPlayerInventory()) { + super.addUIWidgets(builder, buildContext); + } else { + addNoPlayerInventoryUI(builder, buildContext); + } + } + + private static final Materials GOOD = Materials.Uranium; + private static final Materials BAD = Materials.Plutonium; + private static final ConcurrentHashMap<String, ItemStack> mToolStacks = new ConcurrentHashMap<>(); + + @Override + public boolean supportsVoidProtection() { + return true; + } + + @Override + public boolean supportsBatchMode() { + return true; + } + + protected void addNoPlayerInventoryUI(ModularWindow.Builder builder, UIBuildContext buildContext) { + builder.widget( + new DrawableWidget().setDrawable(GT_UITextures.PICTURE_SCREEN_BLACK) + .setPos(3, 4) + .setSize(152, 159)); + for (int i = 0; i < 9; i++) { + builder.widget( + new DrawableWidget().setDrawable(GT_UITextures.BUTTON_STANDARD) + .setPos(155, 3 + i * 18) + .setSize(18, 18)); + } + + DynamicPositionedColumn screenElements = new DynamicPositionedColumn(); + drawTextsNoPlayerInventory(screenElements); + builder.widget(screenElements); + + setupToolDisplay(); + + builder.widget( + new ItemDrawable(() -> mToolStacks.get(mWrench + "WRENCH")).asWidget() + .setPos(156, 58)) + .widget(new FakeSyncWidget.BooleanSyncer(() -> mWrench, val -> mWrench = val)); + builder.widget( + new ItemDrawable(() -> mToolStacks.get(mCrowbar + "CROWBAR")).asWidget() + .setPos(156, 76)) + .widget(new FakeSyncWidget.BooleanSyncer(() -> mCrowbar, val -> mCrowbar = val)); + builder.widget( + new ItemDrawable(() -> mToolStacks.get(mHardHammer + "HARDHAMMER")).asWidget() + .setPos(156, 94)) + .widget( + new TextWidget("H").setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(167, 103)) + .widget(new FakeSyncWidget.BooleanSyncer(() -> mHardHammer, val -> mHardHammer = val)); + builder.widget( + new ItemDrawable(() -> mToolStacks.get(mSoftHammer + "SOFTHAMMER")).asWidget() + .setPos(156, 112)) + .widget( + new TextWidget("M").setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(167, 121)) + .widget(new FakeSyncWidget.BooleanSyncer(() -> mSoftHammer, val -> mSoftHammer = val)); + builder.widget( + new ItemDrawable(() -> mToolStacks.get(mScrewdriver + "SCREWDRIVER")).asWidget() + .setPos(156, 130)) + .widget(new FakeSyncWidget.BooleanSyncer(() -> mScrewdriver, val -> mScrewdriver = val)); + builder.widget( + new ItemDrawable(() -> mToolStacks.get(mSolderingTool + "SOLDERING_IRON_LV")).asWidget() + .setPos(156, 148)) + .widget(new FakeSyncWidget.BooleanSyncer(() -> mSolderingTool, val -> mSolderingTool = val)); + builder.widget( + new ItemDrawable(() -> mToolStacks.get(getBaseMetaTileEntity().isActive() + "GLASS")).asWidget() + .setPos(156, 22)) + .widget( + TextWidget.dynamicString(() -> getBaseMetaTileEntity().isActive() ? "On" : "Off") + .setSynced(false) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(157, 31)) + .widget( + new FakeSyncWidget.BooleanSyncer( + () -> getBaseMetaTileEntity().isActive(), + val -> getBaseMetaTileEntity().setActive(val))); + } + + protected void drawTextsNoPlayerInventory(DynamicPositionedColumn screenElements) { + screenElements.setSynced(false) + .setSpace(0) + .setPos(6, 7); + + screenElements + .widget( + new TextWidget(GT_Utility.trans("138", "Incomplete Structure.")).setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> !mMachine)) + .widget(new FakeSyncWidget.BooleanSyncer(() -> mMachine, val -> mMachine = val)) + .widget( + TextWidget + .dynamicString( + () -> StatCollector.translateToLocal("GTPP.machines.input") + " " + + StatCollector.translateToLocal("GTPP.machines.tier") + + ": " + + EnumChatFormatting.GREEN + + GT_Values.VOLTAGE_NAMES[(int) getInputTier()]) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> mMachine && getInputTier() > 0)) + .widget( + TextWidget + .dynamicString( + () -> StatCollector.translateToLocal("GTPP.machines.output") + " " + + StatCollector.translateToLocal("GTPP.machines.tier") + + ": " + + EnumChatFormatting.GREEN + + GT_Values.VOLTAGE_NAMES[(int) getOutputTier()]) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> mMachine && getOutputTier() > 0)) + .widget( + TextWidget + .dynamicString( + () -> StatCollector.translateToLocal("GTPP.multiblock.progress") + ": " + + EnumChatFormatting.GREEN + + getBaseMetaTileEntity().getProgress() / 20 + + EnumChatFormatting.RESET + + " s / " + + EnumChatFormatting.YELLOW + + getBaseMetaTileEntity().getMaxProgress() / 20 + + EnumChatFormatting.RESET + + " s") + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> mMachine)) + .widget( + new TextWidget(StatCollector.translateToLocal("GTPP.multiblock.energy") + ":") + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> mMachine)) + .widget( + TextWidget + .dynamicString( + () -> StatCollector.translateToLocal( + "" + EnumChatFormatting.GREEN + + getStoredEnergyInAllEnergyHatches() + + EnumChatFormatting.RESET + + " EU / " + + EnumChatFormatting.YELLOW + + getMaxEnergyStorageOfAllEnergyHatches() + + EnumChatFormatting.RESET + + " EU")) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> mMachine)) + .widget( + new TextWidget(StatCollector.translateToLocal("GTPP.multiblock.usage") + ":") + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> mMachine && getLastRecipeEU() > 0 && getLastRecipeDuration() > 0)) + .widget( + TextWidget.dynamicString( + () -> StatCollector.translateToLocal( + "" + EnumChatFormatting.RED + -getLastRecipeEU() + EnumChatFormatting.RESET + " EU/t/parallel")) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> mMachine && getLastRecipeEU() > 0 && getLastRecipeDuration() > 0)) + .widget( + TextWidget.dynamicString(() -> StatCollector.translateToLocal("GTPP.multiblock.generation") + ":") + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> mMachine && getLastRecipeEU() < 0 && getLastRecipeDuration() > 0)) + .widget( + TextWidget + .dynamicString( + () -> StatCollector.translateToLocal( + "" + EnumChatFormatting.GREEN + + getLastRecipeEU() + + EnumChatFormatting.RESET + + " EU/t/parallel")) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> mMachine && getLastRecipeEU() < 0 && getLastRecipeDuration() > 0)) + .widget( + TextWidget + .dynamicString( + () -> StatCollector.translateToLocal("GTPP.multiblock.duration") + ": " + + EnumChatFormatting.RED + + getLastRecipeDuration() + + EnumChatFormatting.RESET + + " ticks") + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> mMachine && getLastRecipeEU() != 0 && getLastRecipeDuration() > 0)) + .widget( + TextWidget + .dynamicString( + () -> StatCollector.translateToLocal("GTPP.multiblock.specialvalue") + ": " + + EnumChatFormatting.RED + + getLastRecipeEU() + + EnumChatFormatting.RESET + + "") + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled( + widget -> mMachine && getLastRecipeEU() != 0 + && getLastRecipeDuration() > 0 + && (mLastRecipe != null ? mLastRecipe.mSpecialValue : 0) > 0)) + .widget( + new TextWidget(StatCollector.translateToLocal("GTPP.multiblock.mei") + ":") + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> mMachine)) + .widget( + TextWidget + .dynamicString( + () -> StatCollector.translateToLocal( + "" + EnumChatFormatting.YELLOW + + getMaxInputVoltage() + + EnumChatFormatting.RESET + + " EU/t(*2A) " + + StatCollector.translateToLocal("GTPP.machines.tier") + + ": " + + EnumChatFormatting.YELLOW + + GT_Values.VN[GT_Utility.getTier(getMaxInputVoltage())] + + EnumChatFormatting.RESET)) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> mMachine)) + .widget( + TextWidget + .dynamicString( + () -> StatCollector.translateToLocal("GTPP.multiblock.efficiency") + ": " + + EnumChatFormatting.YELLOW + + (mEfficiency / 100.0F) + + EnumChatFormatting.RESET + + " %") + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> mMachine)) + .widget( + TextWidget + .dynamicString( + () -> StatCollector.translateToLocal("GTPP.multiblock.pollution") + ": " + + EnumChatFormatting.RED + + (getPollutionPerTick(null) * 20) + + EnumChatFormatting.RESET + + "/sec") + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> mMachine)) + .widget( + TextWidget + .dynamicString( + () -> StatCollector.translateToLocal("GTPP.multiblock.pollutionreduced") + ": " + + EnumChatFormatting.GREEN + + getPollutionReductionForAllMufflers() + + EnumChatFormatting.RESET + + " %") + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> mMachine)) + .widget( + new TextWidget("Total Time Since Built: ").setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> mMachine)) + .widget( + TextWidget + .dynamicString( + () -> "" + EnumChatFormatting.DARK_GREEN + + getRuntimeWeeksDisplay() + + EnumChatFormatting.RESET + + " Weeks,") + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> mMachine)) + .widget( + TextWidget + .dynamicString( + () -> "" + EnumChatFormatting.DARK_GREEN + + getRuntimeDaysDisplay() + + EnumChatFormatting.RESET + + " Days,") + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> mMachine)) + .widget( + TextWidget + .dynamicString( + () -> "" + EnumChatFormatting.DARK_GREEN + + getRuntimeHoursDisplay() + + EnumChatFormatting.RESET + + " Hours,") + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> mMachine)) + .widget( + TextWidget + .dynamicString( + () -> "" + EnumChatFormatting.DARK_GREEN + + getRuntimeMinutesDisplay() + + EnumChatFormatting.RESET + + " Minutes,") + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> mMachine)) + .widget( + TextWidget + .dynamicString( + () -> "" + EnumChatFormatting.DARK_GREEN + + getRuntimeSecondsDisplay() + + EnumChatFormatting.RESET + + " Seconds") + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> mMachine)); + } + + protected int getLastRecipeEU() { + return mLastRecipe != null ? mLastRecipe.mEUt : 0; + } + + protected int getLastRecipeDuration() { + return mLastRecipe != null ? mLastRecipe.mDuration : 0; + } + + protected long getRuntimeSeconds() { + return getTotalRuntimeInTicks() / 20; + } + + protected long getRuntimeWeeksDisplay() { + return TimeUnit.SECONDS.toDays(getRuntimeSeconds()) / 7; + } + + protected long getRuntimeDaysDisplay() { + return TimeUnit.SECONDS.toDays(getRuntimeSeconds()) - 7 * getRuntimeWeeksDisplay(); + } + + protected long getRuntimeHoursDisplay() { + return TimeUnit.SECONDS.toHours(getRuntimeSeconds()) - TimeUnit.DAYS.toHours(getRuntimeDaysDisplay()) + - TimeUnit.DAYS.toHours(7 * getRuntimeWeeksDisplay()); + } + + protected long getRuntimeMinutesDisplay() { + return TimeUnit.SECONDS.toMinutes(getRuntimeSeconds()) - (TimeUnit.SECONDS.toHours(getRuntimeSeconds()) * 60); + } + + protected long getRuntimeSecondsDisplay() { + return TimeUnit.SECONDS.toSeconds(getRuntimeSeconds()) - (TimeUnit.SECONDS.toMinutes(getRuntimeSeconds()) * 60); + } + + protected void setupToolDisplay() { + if (!mToolStacks.isEmpty()) return; + + mToolStacks.put( + true + "WRENCH", + GT_MetaGenerated_Tool_01.INSTANCE + .getToolWithStats(GT_MetaGenerated_Tool_01.WRENCH, 1, GOOD, Materials.Tungsten, null)); + mToolStacks.put( + true + "CROWBAR", + GT_MetaGenerated_Tool_01.INSTANCE + .getToolWithStats(GT_MetaGenerated_Tool_01.CROWBAR, 1, GOOD, Materials.Tungsten, null)); + mToolStacks.put( + true + "HARDHAMMER", + GT_MetaGenerated_Tool_01.INSTANCE + .getToolWithStats(GT_MetaGenerated_Tool_01.HARDHAMMER, 1, GOOD, Materials.Tungsten, null)); + mToolStacks.put( + true + "SOFTHAMMER", + GT_MetaGenerated_Tool_01.INSTANCE + .getToolWithStats(GT_MetaGenerated_Tool_01.SOFTMALLET, 1, GOOD, Materials.Tungsten, null)); + mToolStacks.put( + true + "SCREWDRIVER", + GT_MetaGenerated_Tool_01.INSTANCE + .getToolWithStats(GT_MetaGenerated_Tool_01.SCREWDRIVER, 1, GOOD, Materials.Tungsten, null)); + mToolStacks.put( + true + "SOLDERING_IRON_LV", + GT_MetaGenerated_Tool_01.INSTANCE + .getToolWithStats(GT_MetaGenerated_Tool_01.SOLDERING_IRON_LV, 1, GOOD, Materials.Tungsten, null)); + + mToolStacks.put( + false + "WRENCH", + GT_MetaGenerated_Tool_01.INSTANCE + .getToolWithStats(GT_MetaGenerated_Tool_01.WRENCH, 1, BAD, Materials.Tungsten, null)); + mToolStacks.put( + false + "CROWBAR", + GT_MetaGenerated_Tool_01.INSTANCE + .getToolWithStats(GT_MetaGenerated_Tool_01.CROWBAR, 1, BAD, Materials.Tungsten, null)); + mToolStacks.put( + false + "HARDHAMMER", + GT_MetaGenerated_Tool_01.INSTANCE + .getToolWithStats(GT_MetaGenerated_Tool_01.HARDHAMMER, 1, BAD, Materials.Tungsten, null)); + mToolStacks.put( + false + "SOFTHAMMER", + GT_MetaGenerated_Tool_01.INSTANCE + .getToolWithStats(GT_MetaGenerated_Tool_01.SOFTMALLET, 1, BAD, Materials.Tungsten, null)); + mToolStacks.put( + false + "SCREWDRIVER", + GT_MetaGenerated_Tool_01.INSTANCE + .getToolWithStats(GT_MetaGenerated_Tool_01.SCREWDRIVER, 1, BAD, Materials.Tungsten, null)); + mToolStacks.put( + false + "SOLDERING_IRON_LV", + GT_MetaGenerated_Tool_01.INSTANCE + .getToolWithStats(GT_MetaGenerated_Tool_01.SOLDERING_IRON_LV, 1, BAD, Materials.Tungsten, null)); + + ItemStack aGlassPane1 = ItemUtils.getItemStackOfAmountFromOreDict("paneGlassRed", 1); + ItemStack aGlassPane2 = ItemUtils.getItemStackOfAmountFromOreDict("paneGlassLime", 1); + mToolStacks.put("falseGLASS", aGlassPane1); + mToolStacks.put("trueGLASS", aGlassPane2); + } + + public enum GTPPHatchElement implements IHatchElement<GregtechMeta_MultiBlockBase<?>> { + + AirIntake(GregtechMeta_MultiBlockBase::addAirIntakeToMachineList, GT_MetaTileEntity_Hatch_AirIntake.class) { + + @Override + public long count(GregtechMeta_MultiBlockBase<?> t) { + return t.mAirIntakes.size(); + } + }, + TTDynamo(GregtechMeta_MultiBlockBase::addMultiAmpDynamoToMachineList, + "com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_DynamoMulti") { + + @Override + public long count(GregtechMeta_MultiBlockBase<?> t) { + return t.mTecTechDynamoHatches.size(); + } + }, + TTEnergy(GregtechMeta_MultiBlockBase::addMultiAmpEnergyToMachineList, + "com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_EnergyMulti") { + + @Override + public long count(GregtechMeta_MultiBlockBase<?> t) { + return t.mTecTechEnergyHatches.size(); + } + },; + + @SuppressWarnings("unchecked") + private static <T> Class<T> retype(Class<?> clazz) { + return (Class<T>) clazz; + } + + private final List<? extends Class<? extends IMetaTileEntity>> mMteClasses; + private final IGT_HatchAdder<? super GregtechMeta_MultiBlockBase<?>> mAdder; + + @SafeVarargs + GTPPHatchElement(IGT_HatchAdder<? super GregtechMeta_MultiBlockBase<?>> aAdder, + Class<? extends IMetaTileEntity>... aMteClasses) { + this.mMteClasses = Arrays.asList(aMteClasses); + this.mAdder = aAdder; + } + + GTPPHatchElement(IGT_HatchAdder<? super GregtechMeta_MultiBlockBase<?>> aAdder, String... aClassNames) { + this.mMteClasses = Arrays.stream(aClassNames) + .map(ReflectionUtils::getClass) + .filter(Objects::nonNull) + .<Class<? extends IMetaTileEntity>>map(GTPPHatchElement::retype) + .collect(Collectors.toList()); + this.mAdder = aAdder; + } + + @Override + public List<? extends Class<? extends IMetaTileEntity>> mteClasses() { + return mMteClasses; + } + + @Override + public IGT_HatchAdder<? super GregtechMeta_MultiBlockBase<?>> adder() { + return mAdder; + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_SteamMultiBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_SteamMultiBase.java new file mode 100644 index 0000000000..6e501815f0 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_SteamMultiBase.java @@ -0,0 +1,428 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base; + +import static gregtech.api.enums.GT_Values.V; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_Utility.filterValidMTEs; +import static gregtech.api.util.GT_Utility.formatNumbers; +import static mcp.mobius.waila.api.SpecialChars.GREEN; +import static mcp.mobius.waila.api.SpecialChars.RED; +import static mcp.mobius.waila.api.SpecialChars.RESET; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.StatCollector; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; + +import gregtech.GT_Mod; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.IHatchElement; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Output; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.util.GT_HatchElementBuilder; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.GT_Waila; +import gregtech.api.util.IGT_HatchAdder; +import gregtech.api.util.shutdown.ShutDownReasonRegistry; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Steam_BusInput; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Steam_BusOutput; +import mcp.mobius.waila.api.IWailaConfigHandler; +import mcp.mobius.waila.api.IWailaDataAccessor; + +public abstract class GregtechMeta_SteamMultiBase<T extends GregtechMeta_SteamMultiBase<T>> + extends GregtechMeta_MultiBlockBase<T> { + + public ArrayList<GT_MetaTileEntity_Hatch_Steam_BusInput> mSteamInputs = new ArrayList<>(); + public ArrayList<GT_MetaTileEntity_Hatch_Steam_BusOutput> mSteamOutputs = new ArrayList<>(); + public ArrayList<GT_MetaTileEntity_Hatch_CustomFluidBase> mSteamInputFluids = new ArrayList<>(); + + protected static final String TT_steaminputbus = StatCollector.translateToLocal("GTPP.MBTT.SteamInputBus"); + protected static final String TT_steamoutputbus = StatCollector.translateToLocal("GTPP.MBTT.SteamOutputBus"); + protected static final String TT_steamhatch = StatCollector.translateToLocal("GTPP.MBTT.SteamHatch"); + + public GregtechMeta_SteamMultiBase(String aName) { + super(aName); + } + + public GregtechMeta_SteamMultiBase(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final ForgeDirection side, + final ForgeDirection facing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { + if (side == facing) { + return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(getCasingTextureIndex()), + aActive ? getFrontOverlayActive() : getFrontOverlay() }; + } + return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(getCasingTextureIndex()) }; + } + + protected abstract GT_RenderedTexture getFrontOverlay(); + + protected abstract GT_RenderedTexture getFrontOverlayActive(); + + private int getCasingTextureIndex() { + return 10; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic().setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + @Override + protected void setProcessingLogicPower(ProcessingLogic logic) { + logic.setAvailableVoltage(V[1]); + // We need to trick the GT_ParallelHelper we have enough amps for all recipe parallels. + logic.setAvailableAmperage(getMaxParallelRecipes()); + logic.setAmperageOC(false); + } + + public ArrayList<FluidStack> getAllSteamStacks() { + ArrayList<FluidStack> aFluids = new ArrayList<>(); + FluidStack aSteam = FluidUtils.getSteam(1); + for (FluidStack aFluid : this.getStoredFluids()) { + if (aFluid.isFluidEqual(aSteam)) { + aFluids.add(aFluid); + } + } + return aFluids; + } + + public int getTotalSteamStored() { + int aSteam = 0; + for (FluidStack aFluid : getAllSteamStacks()) { + aSteam += aFluid.amount; + } + return aSteam; + } + + public boolean tryConsumeSteam(int aAmount) { + if (getTotalSteamStored() <= 0) { + return false; + } else { + return this.depleteInput(FluidUtils.getSteam(aAmount)); + } + } + + @Override + public int getMaxEfficiency(ItemStack arg0) { + return 0; + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + if (aBaseMetaTileEntity.isServerSide()) { + if (this.mUpdate == 1 || this.mStartUpCheck == 1) { + this.mSteamInputs.clear(); + this.mSteamOutputs.clear(); + this.mSteamInputFluids.clear(); + } + } + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + /** + * Called every tick the Machine runs + */ + @Override + public boolean onRunningTick(ItemStack aStack) { + fixAllMaintenanceIssue(); + if (lEUt < 0) { + long aSteamVal = ((-lEUt * 10000) / Math.max(1000, mEfficiency)); + // Logger.INFO("Trying to drain "+aSteamVal+" steam per tick."); + if (!tryConsumeSteam((int) aSteamVal)) { + stopMachine(ShutDownReasonRegistry.POWER_LOSS); + return false; + } + } + return true; + } + + @Override + public boolean addToMachineList(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) { + if (aTileEntity == null) { + log("Invalid IGregTechTileEntity"); + return false; + } + final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) { + log("Invalid IMetaTileEntity"); + return false; + } + + // Use this to determine the correct value, then update the hatch texture after. + boolean aDidAdd = false; + + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_CustomFluidBase) { + log("Adding Steam Input Hatch"); + aDidAdd = addToMachineListInternal(mSteamInputFluids, aMetaTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Steam_BusInput) { + log( + "Trying to set recipe map. Type: " + + (getRecipeMap() != null ? getRecipeMap().unlocalizedName : "Null")); + this.resetRecipeMapForHatch(aTileEntity, getRecipeMap()); + log("Adding Steam Input Bus"); + aDidAdd = addToMachineListInternal(mSteamInputs, aMetaTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Steam_BusOutput) { + log("Adding Steam Output Bus"); + aDidAdd = addToMachineListInternal(mSteamOutputs, aMetaTileEntity, aBaseCasingIndex); + } + + return aDidAdd; + } + + /* + * Handle I/O with custom hatches + */ + + @Override + public boolean depleteInput(FluidStack aLiquid) { + if (aLiquid == null) return false; + for (GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : filterValidMTEs(mSteamInputFluids)) { + FluidStack tLiquid = tHatch.getFluid(); + if (tLiquid != null && tLiquid.isFluidEqual(aLiquid)) { + tLiquid = tHatch.drain(aLiquid.amount, false); + if (tLiquid != null && tLiquid.amount >= aLiquid.amount) { + tLiquid = tHatch.drain(aLiquid.amount, true); + return tLiquid != null && tLiquid.amount >= aLiquid.amount; + } + } + } + return false; + } + + @Override + public boolean depleteInput(ItemStack aStack) { + if (GT_Utility.isStackInvalid(aStack)) return false; + FluidStack aLiquid = GT_Utility.getFluidForFilledItem(aStack, true); + if (aLiquid != null) return depleteInput(aLiquid); + for (GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : filterValidMTEs(mSteamInputFluids)) { + if (GT_Utility.areStacksEqual( + aStack, + tHatch.getBaseMetaTileEntity() + .getStackInSlot(0))) { + if (tHatch.getBaseMetaTileEntity() + .getStackInSlot(0).stackSize >= aStack.stackSize) { + tHatch.getBaseMetaTileEntity() + .decrStackSize(0, aStack.stackSize); + return true; + } + } + } + for (GT_MetaTileEntity_Hatch_Steam_BusInput tHatch : filterValidMTEs(mSteamInputs)) { + tHatch.mRecipeMap = getRecipeMap(); + for (int i = tHatch.getBaseMetaTileEntity() + .getSizeInventory() - 1; i >= 0; i--) { + if (GT_Utility.areStacksEqual( + aStack, + tHatch.getBaseMetaTileEntity() + .getStackInSlot(i))) { + if (tHatch.getBaseMetaTileEntity() + .getStackInSlot(0).stackSize >= aStack.stackSize) { + tHatch.getBaseMetaTileEntity() + .decrStackSize(0, aStack.stackSize); + return true; + } + } + } + } + return false; + } + + @Override + public ArrayList<FluidStack> getStoredFluids() { + ArrayList<FluidStack> rList = new ArrayList<>(); + for (GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : filterValidMTEs(mSteamInputFluids)) { + if (tHatch.getFillableStack() != null) { + rList.add(tHatch.getFillableStack()); + } + } + return rList; + } + + @Override + public ArrayList<ItemStack> getStoredInputs() { + ArrayList<ItemStack> rList = new ArrayList<>(); + for (GT_MetaTileEntity_Hatch_Steam_BusInput tHatch : filterValidMTEs(mSteamInputs)) { + tHatch.mRecipeMap = getRecipeMap(); + for (int i = tHatch.getBaseMetaTileEntity() + .getSizeInventory() - 1; i >= 0; i--) { + if (tHatch.getBaseMetaTileEntity() + .getStackInSlot(i) != null) { + rList.add( + tHatch.getBaseMetaTileEntity() + .getStackInSlot(i)); + } + } + } + return rList; + } + + @Override + public boolean addOutput(ItemStack aStack) { + if (GT_Utility.isStackInvalid(aStack)) return false; + aStack = GT_Utility.copy(aStack); + boolean outputSuccess = true; + while (outputSuccess && aStack.stackSize > 0) { + outputSuccess = false; + ItemStack single = aStack.splitStack(1); + for (GT_MetaTileEntity_Hatch_Steam_BusOutput tHatch : filterValidMTEs(mSteamOutputs)) { + if (!outputSuccess) { + for (int i = tHatch.getSizeInventory() - 1; i >= 0 && !outputSuccess; i--) { + if (tHatch.getBaseMetaTileEntity() + .addStackToSlot(i, single)) outputSuccess = true; + } + } + } + for (GT_MetaTileEntity_Hatch_Output tHatch : filterValidMTEs(mOutputHatches)) { + if (!outputSuccess && tHatch.outputsItems()) { + if (tHatch.getBaseMetaTileEntity() + .addStackToSlot(1, single)) outputSuccess = true; + } + } + } + return outputSuccess; + } + + @Override + public ArrayList<ItemStack> getStoredOutputs() { + ArrayList<ItemStack> rList = new ArrayList<>(); + for (GT_MetaTileEntity_Hatch_Steam_BusOutput tHatch : filterValidMTEs(mSteamOutputs)) { + for (int i = tHatch.getBaseMetaTileEntity() + .getSizeInventory() - 1; i >= 0; i--) { + rList.add( + tHatch.getBaseMetaTileEntity() + .getStackInSlot(i)); + } + } + return rList; + } + + @Override + public List<ItemStack> getItemOutputSlots(ItemStack[] toOutput) { + List<ItemStack> ret = new ArrayList<>(); + for (final GT_MetaTileEntity_Hatch tBus : filterValidMTEs(mSteamOutputs)) { + final IInventory tBusInv = tBus.getBaseMetaTileEntity(); + for (int i = 0; i < tBusInv.getSizeInventory(); i++) { + ret.add(tBus.getStackInSlot(i)); + } + } + return ret; + } + + @Override + public void updateSlots() { + for (GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : filterValidMTEs(mSteamInputFluids)) tHatch.updateSlots(); + for (GT_MetaTileEntity_Hatch_Steam_BusInput tHatch : filterValidMTEs(mSteamInputs)) tHatch.updateSlots(); + } + + @Override + public boolean supportsBatchMode() { + return false; + } + + @Override + public void clearHatches() { + super.clearHatches(); + mSteamInputFluids.clear(); + mSteamInputs.clear(); + mSteamOutputs.clear(); + } + + @Override + public boolean resetRecipeMapForAllInputHatches(RecipeMap<?> aMap) { + boolean ret = super.resetRecipeMapForAllInputHatches(aMap); + for (GT_MetaTileEntity_Hatch_Steam_BusInput hatch : mSteamInputs) { + if (resetRecipeMapForHatch(hatch, aMap)) { + ret = true; + } + } + return ret; + } + + @Override + public void getWailaBody(ItemStack itemStack, List<String> currentTip, IWailaDataAccessor accessor, + IWailaConfigHandler config) { + final NBTTagCompound tag = accessor.getNBTData(); + + if (tag.getBoolean("incompleteStructure")) { + currentTip.add(RED + "** INCOMPLETE STRUCTURE **" + RESET); + } + currentTip.add( + (tag.getBoolean("hasProblems") ? (RED + "** HAS PROBLEMS **") : GREEN + "Running Fine") + RESET + + " Efficiency: " + + tag.getFloat("efficiency") + + "%"); + + boolean isActive = tag.getBoolean("isActive"); + if (isActive) { + long actualEnergyUsage = tag.getLong("energyUsage"); + if (actualEnergyUsage > 0) { + currentTip.add( + StatCollector.translateToLocalFormatted("GTPP.waila.steam.use", formatNumbers(actualEnergyUsage))); + } + } + currentTip.add( + GT_Waila.getMachineProgressString(isActive, tag.getInteger("maxProgress"), tag.getInteger("progress"))); + // Show ns on the tooltip + if (GT_Mod.gregtechproxy.wailaAverageNS && tag.hasKey("averageNS")) { + int tAverageTime = tag.getInteger("averageNS"); + currentTip.add("Average CPU load of ~" + formatNumbers(tAverageTime) + " ns"); + } + super.getMTEWailaBody(itemStack, currentTip, accessor, config); + } + + protected static <T extends GregtechMeta_SteamMultiBase<T>> GT_HatchElementBuilder<T> buildSteamInput( + Class<T> typeToken) { + return buildHatchAdder(typeToken).adder(GregtechMeta_SteamMultiBase::addToMachineList) + .hatchIds(31040) + .shouldReject(t -> !t.mSteamInputFluids.isEmpty()); + } + + protected enum SteamHatchElement implements IHatchElement<GregtechMeta_SteamMultiBase<?>> { + + InputBus_Steam { + + @Override + public List<? extends Class<? extends IMetaTileEntity>> mteClasses() { + return Collections.singletonList(GT_MetaTileEntity_Hatch_Steam_BusInput.class); + } + + @Override + public long count(GregtechMeta_SteamMultiBase<?> t) { + return t.mSteamInputs.size(); + } + }, + OutputBus_Steam { + + @Override + public List<? extends Class<? extends IMetaTileEntity>> mteClasses() { + return Collections.singletonList(GT_MetaTileEntity_Hatch_Steam_BusOutput.class); + } + + @Override + public long count(GregtechMeta_SteamMultiBase<?> t) { + return t.mSteamOutputs.size(); + } + },; + + @Override + public IGT_HatchAdder<? super GregtechMeta_SteamMultiBase<?>> adder() { + return GregtechMeta_SteamMultiBase::addToMachineList; + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/generators/GregtechMetaBoilerBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/generators/GregtechMetaBoilerBase.java new file mode 100644 index 0000000000..3f0d8d1ec1 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/generators/GregtechMetaBoilerBase.java @@ -0,0 +1,361 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.generators; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTankInfo; +import net.minecraftforge.fluids.IFluidHandler; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.SoundResource; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicTank; +import gregtech.api.objects.GT_ItemStack; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_OreDictUnificator; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.util.math.MathUtils; + +public abstract class GregtechMetaBoilerBase extends GT_MetaTileEntity_BasicTank { + + public int mTemperature = 20; + public int mProcessingEnergy = 0; + public int mLossTimer = 0; + public FluidStack mSteam = null; + public boolean mHadNoWater = false; + public long RI = MathUtils.randLong(5L, 30L); + + public GregtechMetaBoilerBase(final int aID, final String aName, final String aNameRegional, + final String aDescription, final ITexture... aTextures) { + super(aID, aName, aNameRegional, 0, 4, aDescription, aTextures); + } + + public GregtechMetaBoilerBase(final String aName, final int aTier, final String[] aDescription, + final ITexture[][][] aTextures) { + super(aName, aTier, 4, aDescription, aTextures); + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final ForgeDirection side, + final ForgeDirection facing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { + ITexture[] tmp = this.mTextures[side.offsetY == 0 ? side != facing ? 2 : ((byte) (aActive ? 4 : 3)) + : side.ordinal()][aColorIndex + 1]; + if ((side != facing) && (tmp.length == 2)) { + tmp = new ITexture[] { tmp[0] }; + } + return tmp; + } + + @Override + public boolean isElectric() { + return false; + } + + @Override + public boolean isPneumatic() { + return false; + } + + @Override + public boolean isSteampowered() { + return false; + } + + @Override + public boolean isSimpleMachine() { + return false; + } + + @Override + public boolean isFacingValid(final ForgeDirection facing) { + return facing.offsetY == 0; + } + + @Override + public boolean isAccessAllowed(final EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean isValidSlot(final int aIndex) { + return true; + } + + @Override + public int getProgresstime() { + return this.mTemperature; + } + + @Override + public int maxProgresstime() { + return 500; + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } + if (aPlayer != null) { + if (GT_Utility.areStacksEqual(aPlayer.getCurrentEquippedItem(), new ItemStack(Items.water_bucket, 1))) { + this.fill(Materials.Water.getFluid(1000 * aPlayer.getCurrentEquippedItem().stackSize), true); + aPlayer.getCurrentEquippedItem() + .func_150996_a(Items.bucket); + } else { + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); + } + } + return true; + } + + @Override + public boolean doesFillContainers() { + return true; + } + + @Override + public boolean doesEmptyContainers() { + return true; + } + + @Override + public boolean canTankBeFilled() { + return true; + } + + @Override + public boolean canTankBeEmptied() { + return true; + } + + @Override + public boolean displaysItemStack() { + return false; + } + + @Override + public boolean displaysStackSize() { + return false; + } + + @Override + public boolean isFluidInputAllowed(final FluidStack aFluid) { + return GT_ModHandler.isWater(aFluid); + } + + @Override + public FluidStack getDrainableStack() { + return this.mSteam; + } + + @Override + public FluidStack setDrainableStack(final FluidStack aFluid) { + this.mSteam = aFluid; + return this.mSteam; + } + + @Override + public boolean isDrainableStackSeparate() { + return true; + } + + @Override + public boolean allowCoverOnSide(final ForgeDirection side, final GT_ItemStack aCover) { + return GregTech_API.getCoverBehaviorNew(aCover.toStack()) + .isSimpleCover(); + } + + @Override + public void saveNBTData(final NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setInteger("mLossTimer", this.mLossTimer); + aNBT.setInteger("mTemperature", this.mTemperature); + aNBT.setInteger("mProcessingEnergy", this.mProcessingEnergy); + if (this.mSteam != null) { + try { + aNBT.setTag("mSteam", this.mSteam.writeToNBT(new NBTTagCompound())); + } catch (final Throwable e) {} + } + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + this.mLossTimer = aNBT.getInteger("mLossTimer"); + this.mTemperature = aNBT.getInteger("mTemperature"); + this.mProcessingEnergy = aNBT.getInteger("mProcessingEnergy"); + this.mSteam = FluidStack.loadFluidStackFromNBT(aNBT.getCompoundTag("mSteam")); + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + if ((aBaseMetaTileEntity.isServerSide()) && (aTick > 20L)) { + if (this.mTemperature <= 20) { + this.mTemperature = 20; + this.mLossTimer = 0; + } + if (++this.mLossTimer > 40) { + this.mTemperature -= 1; + this.mLossTimer = 0; + } + for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { + if (side != aBaseMetaTileEntity.getFrontFacing()) { + final IFluidHandler tTileEntity = aBaseMetaTileEntity.getITankContainerAtSide(side); + if (tTileEntity != null) { + final FluidStack tDrained = aBaseMetaTileEntity + .drain(side, Math.max(1, this.mSteam.amount / 2), false); + if (tDrained != null) { + final int tFilledAmount = tTileEntity.fill(side.getOpposite(), tDrained, false); + if (tFilledAmount > 0) { + tTileEntity.fill( + side.getOpposite(), + aBaseMetaTileEntity.drain(side, tFilledAmount, true), + true); + } + } + } + } + } + if ((aTick % 10L) == 0L) { + if (this.mTemperature > 100) { + if ((this.mFluid == null) || (!GT_ModHandler.isWater(this.mFluid)) || (this.mFluid.amount <= 0)) { + this.mHadNoWater = true; + } else { + if (this.mHadNoWater) { + aBaseMetaTileEntity.doExplosion(2048L); + return; + } + this.mFluid.amount -= 1; + if (this.mSteam == null) { + this.mSteam = GT_ModHandler.getSteam(150L); + } else if (GT_ModHandler.isSteam(this.mSteam)) { + this.mSteam.amount += 150; + } else { + this.mSteam = GT_ModHandler.getSteam(150L); + } + } + } else { + this.mHadNoWater = false; + } + } + if ((this.mSteam != null) && (this.mSteam.amount > getSteamCapacity())) { + this.sendSound((byte) 1); + this.mSteam.amount = getSteamCapacity() * 3 / 4; + } + if ((this.mProcessingEnergy <= 0) && (aBaseMetaTileEntity.isAllowedToWork()) + && (this.mInventory[2] != null)) { + if ((GT_OreDictUnificator + .isItemStackInstanceOf(this.mInventory[2], OrePrefixes.gem.get(Materials.Coal))) + || (GT_OreDictUnificator + .isItemStackInstanceOf(this.mInventory[2], OrePrefixes.dust.get(Materials.Coal))) + || (GT_OreDictUnificator + .isItemStackInstanceOf(this.mInventory[2], OrePrefixes.dustImpure.get(Materials.Coal))) + || (GT_OreDictUnificator + .isItemStackInstanceOf(this.mInventory[2], OrePrefixes.crushed.get(Materials.Coal)))) { + this.mProcessingEnergy += 160; + aBaseMetaTileEntity.decrStackSize(2, 1); + if (aBaseMetaTileEntity.getRandomNumber(3) == 0) { + aBaseMetaTileEntity + .addStackToSlot(3, GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.DarkAsh, 1L)); + } + } else if (GT_OreDictUnificator + .isItemStackInstanceOf(this.mInventory[2], OrePrefixes.gem.get(Materials.Charcoal))) { + this.mProcessingEnergy += 160; + aBaseMetaTileEntity.decrStackSize(2, 1); + if (aBaseMetaTileEntity.getRandomNumber(3) == 0) { + aBaseMetaTileEntity + .addStackToSlot(3, GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.Ash, 1L)); + } + } else if (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[2], "fuelCoke")) { + this.mProcessingEnergy += 640; + aBaseMetaTileEntity.decrStackSize(2, 1); + if (aBaseMetaTileEntity.getRandomNumber(2) == 0) { + aBaseMetaTileEntity + .addStackToSlot(3, GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.Ash, 1L)); + } + } else if ((GT_OreDictUnificator + .isItemStackInstanceOf(this.mInventory[2], OrePrefixes.gem.get(Materials.Lignite))) + || (GT_OreDictUnificator + .isItemStackInstanceOf(this.mInventory[2], OrePrefixes.dust.get(Materials.Lignite))) + || (GT_OreDictUnificator + .isItemStackInstanceOf(this.mInventory[2], OrePrefixes.dustImpure.get(Materials.Lignite))) + || (GT_OreDictUnificator + .isItemStackInstanceOf(this.mInventory[2], OrePrefixes.crushed.get(Materials.Lignite)))) { + this.mProcessingEnergy += 40; + aBaseMetaTileEntity.decrStackSize(2, 1); + if (aBaseMetaTileEntity.getRandomNumber(8) == 0) { + aBaseMetaTileEntity.addStackToSlot( + 3, + GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.DarkAsh, 1L)); + } + } + } + if ((this.mTemperature < 1000) && (this.mProcessingEnergy > 0) && ((aTick % 12L) == 0L)) { + this.mProcessingEnergy -= 2; + this.mTemperature += 1; + } + aBaseMetaTileEntity.setActive(this.mProcessingEnergy > 0); + } + } + + @Override + // Since this type of machine can have different water and steam capacities, we need to override getTankInfo() to + // support returning those different capacities. + public FluidTankInfo[] getTankInfo(ForgeDirection aSide) { + return new FluidTankInfo[] { new FluidTankInfo(this.mFluid, getCapacity()), + new FluidTankInfo(this.mSteam, getSteamCapacity()) }; + } + + @Override + public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, + final ForgeDirection side, final ItemStack aStack) { + return (aIndex == 1) || (aIndex == 3); + } + + @Override + public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, + final ForgeDirection side, final ItemStack aStack) { + return aIndex == 2; + } + + @Override + public void doSound(final byte aIndex, final double aX, final double aY, final double aZ) { + if (aIndex == 1) { + GT_Utility.doSoundAtClient(SoundResource.RANDOM_FIZZ, 2, 1.0F, aX, aY, aZ); + for (int l = 0; l < 8; l++) { + this.getBaseMetaTileEntity() + .getWorld() + .spawnParticle( + "largesmoke", + (aX - 0.5D) + Math.random(), + aY, + (aZ - 0.5D) + Math.random(), + 0.0D, + 0.0D, + 0.0D); + } + } + } + + @Override + public int getCapacity() { + return 16000; + } + + // This type of machine can have different water and steam capacities. + public int getSteamCapacity() { + return 32000; + } + + @Override + public int getTankPressure() { + return 100; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/generators/GregtechMetaSolarGenerator.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/generators/GregtechMetaSolarGenerator.java new file mode 100644 index 0000000000..5e0588acfd --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/generators/GregtechMetaSolarGenerator.java @@ -0,0 +1,241 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.generators; + +import static gregtech.api.enums.GT_Values.V; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.common.util.ForgeDirection; + +import org.apache.commons.lang3.ArrayUtils; + +import gregtech.api.enums.Textures; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicTank; + +public abstract class GregtechMetaSolarGenerator extends GT_MetaTileEntity_BasicTank { + + public int mEfficiency; + public int mProcessingEnergy = 0; + public int mSolarCharge = 20; + public int mLossTimer = 0; + public static int sEnergyPerTick = 16; + + public GregtechMetaSolarGenerator(final int aID, final String aName, final String aNameRegional, final int aTier, + final String aDescription, final ITexture... aTextures) { + super(aID, aName, aNameRegional, aTier, 3, aDescription, aTextures); + } + + public GregtechMetaSolarGenerator(final String aName, final int aTier, final String[] aDescription, + final ITexture[][][] aTextures) { + super(aName, aTier, 3, aDescription, aTextures); + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFrontActive(i); + rTextures[6][i + 1] = this.getBackActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final ForgeDirection side, + final ForgeDirection facing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { + return this.mTextures[(aActive ? 5 : 0) + (side == facing ? 0 + : side == facing.getOpposite() ? 1 + : side == ForgeDirection.DOWN ? 2 : side == ForgeDirection.UP ? 3 : 4)][aColorIndex + 1]; + } + + @Override + public String[] getDescription() { + return ArrayUtils.add(this.mDescriptionArray, "Efficiency: " + this.getEfficiency() + "%"); + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); + return true; + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1] }; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1] }; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1] }; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1] }; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1] }; + } + + public ITexture[] getFrontActive(final byte aColor) { + return this.getFront(aColor); + } + + public ITexture[] getBackActive(final byte aColor) { + return this.getBack(aColor); + } + + public ITexture[] getBottomActive(final byte aColor) { + return this.getBottom(aColor); + } + + public ITexture[] getTopActive(final byte aColor) { + return this.getTop(aColor); + } + + public ITexture[] getSidesActive(final byte aColor) { + return this.getSides(aColor); + } + + @Override + public boolean isFacingValid(final ForgeDirection side) { + return side.offsetY == 0; + } + + @Override + public boolean isSimpleMachine() { + return false; + } + + @Override + public boolean isValidSlot(final int aIndex) { + return aIndex < 2; + } + + @Override + public boolean isEnetOutput() { + return true; + } + + @Override + public boolean isOutputFacing(final ForgeDirection side) { + return true; + } + + @Override + public boolean isAccessAllowed(final EntityPlayer aPlayer) { + return true; + } + + @Override + public long maxEUOutput() { + return this.getBaseMetaTileEntity() + .isAllowedToWork() ? V[this.mTier] : 0; + } + + @Override + public long maxEUStore() { + return Math.max(this.getEUVar(), (V[this.mTier] * 40) + this.getMinimumStoredEU()); + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.isAllowedToWork() + && (aTick > 20L) + && (aBaseMetaTileEntity.getUniversalEnergyStored() + < (this.maxEUOutput() + aBaseMetaTileEntity.getEUCapacity()))) { + + if (this.mSolarCharge <= 20) { + this.mSolarCharge = 20; + this.mLossTimer = 0; + } + if (++this.mLossTimer > 45) { + this.mSolarCharge -= 1; + this.mLossTimer = 0; + } + + if ((aTick % 25L) == 0L) { + if (this.mSolarCharge > 100) { + if ((this.mProcessingEnergy > 0) && (aBaseMetaTileEntity.isAllowedToWork()) + && ((aTick % 256L) == 0L) + && (!aBaseMetaTileEntity.getWorld() + .isThundering() + && (aBaseMetaTileEntity.getUniversalEnergyStored() + < ((this.maxEUOutput() * 20) + this.getMinimumStoredEU())))) { + this.getBaseMetaTileEntity() + .increaseStoredEnergyUnits((sEnergyPerTick * this.getEfficiency()) / 10, false); + } + } + } + + if ((this.mSolarCharge < 500) && (this.mProcessingEnergy > 0) && ((aTick % 12L) == 0L)) { + this.mProcessingEnergy -= 1; + this.mSolarCharge += 1; + } + + if ((this.mProcessingEnergy <= 0) && (aBaseMetaTileEntity.isAllowedToWork()) + && ((aTick % 256L) == 0L) + && (!aBaseMetaTileEntity.getWorld() + .isThundering())) { + final boolean bRain = aBaseMetaTileEntity.getWorld() + .isRaining() && (aBaseMetaTileEntity.getBiome().rainfall > 0.0F); + this.mProcessingEnergy += (bRain && (aBaseMetaTileEntity.getWorld().skylightSubtracted >= 4)) + || !aBaseMetaTileEntity.getSkyAtSide(ForgeDirection.UP) ? 0 + : !bRain && aBaseMetaTileEntity.getWorld() + .isDaytime() ? 8 : 1; + } + + if (aBaseMetaTileEntity.isServerSide()) { + aBaseMetaTileEntity.setActive( + aBaseMetaTileEntity.isAllowedToWork() && (aBaseMetaTileEntity.getUniversalEnergyStored() + >= (this.maxEUOutput() + this.getMinimumStoredEU()))); + } + } + } + + public abstract int getEfficiency(); + + @Override + public boolean doesFillContainers() { + return false; + } + + @Override + public boolean doesEmptyContainers() { + return false; + } + + @Override + public boolean canTankBeFilled() { + return false; + } + + @Override + public boolean canTankBeEmptied() { + return false; + } + + @Override + public boolean displaysItemStack() { + return false; + } + + @Override + public boolean displaysStackSize() { + return false; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/generators/GregtechRocketFuelGeneratorBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/generators/GregtechRocketFuelGeneratorBase.java new file mode 100644 index 0000000000..83745f393a --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/generators/GregtechRocketFuelGeneratorBase.java @@ -0,0 +1,338 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.generators; + +import static gregtech.api.enums.GT_Values.V; + +import java.util.Collection; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; + +import org.apache.commons.lang3.ArrayUtils; + +import gregtech.api.enums.Textures; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.interfaces.tileentity.RecipeMapWorkable; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicTank; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.gregtech.PollutionUtils; + +public abstract class GregtechRocketFuelGeneratorBase extends GT_MetaTileEntity_BasicTank implements RecipeMapWorkable { + + protected int pollMin, pollMax; + + public GregtechRocketFuelGeneratorBase(final int aID, final String aName, final String aNameRegional, + final int aTier, final String aDescription, final ITexture... aTextures) { + super(aID, aName, aNameRegional, aTier, 3, aDescription, aTextures); + pollMin = (int) (CORE.ConfigSwitches.baseMinPollutionPerSecondRocketFuelGenerator + * CORE.ConfigSwitches.pollutionReleasedByTierRocketFuelGenerator[mTier]); + pollMax = (int) (CORE.ConfigSwitches.baseMaxPollutionPerSecondRocketFuelGenerator + * CORE.ConfigSwitches.pollutionReleasedByTierRocketFuelGenerator[mTier]); + } + + public GregtechRocketFuelGeneratorBase(final String aName, final int aTier, final String[] aDescription, + final ITexture[][][] aTextures) { + super(aName, aTier, 3, aDescription, aTextures); + pollMin = (int) (CORE.ConfigSwitches.baseMinPollutionPerSecondRocketFuelGenerator + * CORE.ConfigSwitches.pollutionReleasedByTierRocketFuelGenerator[mTier]); + pollMax = (int) (CORE.ConfigSwitches.baseMaxPollutionPerSecondRocketFuelGenerator + * CORE.ConfigSwitches.pollutionReleasedByTierRocketFuelGenerator[mTier]); + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFrontActive(i); + rTextures[6][i + 1] = this.getBackActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final ForgeDirection side, + final ForgeDirection facing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { + return this.mTextures[(aActive ? 5 : 0) + (side == facing ? 0 + : side == facing.getOpposite() ? 1 + : side == ForgeDirection.DOWN ? 2 : side == ForgeDirection.UP ? 3 : 4)][aColorIndex + 1]; + } + + @Override + public String[] getDescription() { + String aPollution = "Causes between " + pollMin + " and " + pollMax + " Pollution per second"; + return ArrayUtils.addAll( + this.mDescriptionArray, + "Fuel Efficiency: " + this.getEfficiency() + "%", + aPollution, + CORE.GT_Tooltip.get()); + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); + return true; + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1] }; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1] }; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1] }; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1] }; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1] }; + } + + public ITexture[] getFrontActive(final byte aColor) { + return this.getFront(aColor); + } + + public ITexture[] getBackActive(final byte aColor) { + return this.getBack(aColor); + } + + public ITexture[] getBottomActive(final byte aColor) { + return this.getBottom(aColor); + } + + public ITexture[] getTopActive(final byte aColor) { + return this.getTop(aColor); + } + + public ITexture[] getSidesActive(final byte aColor) { + return this.getSides(aColor); + } + + @Override + public boolean isFacingValid(final ForgeDirection side) { + return side.offsetY == 0; + } + + @Override + public boolean isSimpleMachine() { + return false; + } + + @Override + public boolean isValidSlot(final int aIndex) { + return aIndex < 2; + } + + @Override + public boolean isEnetOutput() { + return true; + } + + @Override + public boolean isOutputFacing(final ForgeDirection side) { + return this.getBaseMetaTileEntity() + .getFrontFacing() == side; + } + + @Override + public boolean isAccessAllowed(final EntityPlayer aPlayer) { + return true; + } + + @Override + public long maxEUOutput() { + return V[this.mTier]; + } + + @Override + public long maxEUStore() { + return Math.max(this.getEUVar(), (V[this.mTier] * 500) + this.getMinimumStoredEU()); + } + + @Override + public boolean doesFillContainers() { + return false; + } + + @Override + public boolean doesEmptyContainers() { + return true; + } + + @Override + public boolean canTankBeFilled() { + return true; + } + + @Override + public boolean canTankBeEmptied() { + return false; + } + + @Override + public boolean displaysItemStack() { + return true; + } + + @Override + public boolean displaysStackSize() { + return false; + } + + @Override + public boolean isFluidInputAllowed(final FluidStack aFluid) { + return this.getFuelValue(aFluid) > 0; + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + + if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.isAllowedToWork() && ((aTick % 10) == 0)) { + if (this.mFluid == null) { + if (aBaseMetaTileEntity.getUniversalEnergyStored() < (this.maxEUOutput() + this.getMinimumStoredEU())) { + this.mInventory[this.getStackDisplaySlot()] = null; + } else { + if (this.mInventory[this.getStackDisplaySlot()] == null) { + this.mInventory[this.getStackDisplaySlot()] = new ItemStack(Blocks.fire, 1); + } + this.mInventory[this.getStackDisplaySlot()].setStackDisplayName( + "Generating: " + (aBaseMetaTileEntity.getUniversalEnergyStored() - this.getMinimumStoredEU()) + + " EU"); + } + } else { + final int tFuelValue = this.getFuelValue(this.mFluid), + tConsumed = this.consumedFluidPerOperation(this.mFluid); + if ((tFuelValue > 0) && (tConsumed > 0) && (this.mFluid.amount >= tConsumed)) { + final long tFluidAmountToUse = Math.min( + this.mFluid.amount / tConsumed, + (((this.maxEUOutput() * 20) + this.getMinimumStoredEU()) + - aBaseMetaTileEntity.getUniversalEnergyStored()) / tFuelValue); + if ((tFluidAmountToUse > 0) + && aBaseMetaTileEntity.increaseStoredEnergyUnits(tFluidAmountToUse * tFuelValue, true)) { + int aSafeFloor = (int) Math.max(((tFluidAmountToUse * tConsumed) / 3), 1); + this.mFluid.amount -= (int) aSafeFloor; + PollutionUtils.addPollution(getBaseMetaTileEntity(), 10 * getPollution()); + } + } + } + if ((this.mInventory[this.getInputSlot()] != null) + && (aBaseMetaTileEntity.getUniversalEnergyStored() + < ((this.maxEUOutput() * 20) + this.getMinimumStoredEU())) + && (GT_Utility.getFluidForFilledItem(this.mInventory[this.getInputSlot()], true) == null)) { + final int tFuelValue = this.getFuelValue(this.mInventory[this.getInputSlot()]); + if (tFuelValue > 0) { + final ItemStack tEmptyContainer = this.getEmptyContainer(this.mInventory[this.getInputSlot()]); + if (aBaseMetaTileEntity.addStackToSlot(this.getOutputSlot(), tEmptyContainer)) { + aBaseMetaTileEntity.increaseStoredEnergyUnits(tFuelValue, true); + aBaseMetaTileEntity.decrStackSize(this.getInputSlot(), 1); + PollutionUtils.addPollution(getBaseMetaTileEntity(), getPollution() / 2); + } + } + } + } + + if (aBaseMetaTileEntity.isServerSide()) { + aBaseMetaTileEntity.setActive( + aBaseMetaTileEntity.isAllowedToWork() && (aBaseMetaTileEntity.getUniversalEnergyStored() + >= (this.maxEUOutput() + this.getMinimumStoredEU()))); + } + } + + public int getPollution() { + return MathUtils.randInt(pollMin, pollMax); + } + + @Override + public abstract RecipeMap<?> getRecipeMap(); + + public abstract int getEfficiency(); + + public int consumedFluidPerOperation(final FluidStack aLiquid) { + return 1; + } + + public int getFuelValue(final FluidStack aLiquid) { + if ((aLiquid == null) || (this.getRecipeMap() == null)) { + return 0; + } + FluidStack tLiquid; + final Collection<GT_Recipe> tRecipeList = this.getRecipeMap() + .getAllRecipes(); + for (final GT_Recipe tFuel : tRecipeList) { + if ((tLiquid = tFuel.mFluidInputs[0]) != null) { + if (aLiquid.isFluidEqual(tLiquid)) { + int aperOp = this.consumedFluidPerOperation(tLiquid); + return (int) (((long) tFuel.mSpecialValue * this.getEfficiency() * aperOp) / 100); + } + } + } + return 0; + } + + public int getFuelValue(final ItemStack aStack) { + if (GT_Utility.isStackInvalid(aStack) || (this.getRecipeMap() == null)) { + return 0; + } + final GT_Recipe tFuel = this.getRecipeMap() + .findRecipe(this.getBaseMetaTileEntity(), false, Long.MAX_VALUE, null, aStack); + if (tFuel != null) { + return (int) ((tFuel.mSpecialValue * 1000L * this.getEfficiency()) / 100); + } + return 0; + } + + public ItemStack getEmptyContainer(final ItemStack aStack) { + if (GT_Utility.isStackInvalid(aStack) || (this.getRecipeMap() == null)) { + return null; + } + final GT_Recipe tFuel = this.getRecipeMap() + .findRecipe(this.getBaseMetaTileEntity(), false, Long.MAX_VALUE, null, aStack); + if (tFuel != null) { + return GT_Utility.copy(tFuel.getOutput(0)); + } + return GT_Utility.getContainerItem(aStack, true); + } + + @Override + public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, + final ForgeDirection side, final ItemStack aStack) { + return super.allowPutStack(aBaseMetaTileEntity, aIndex, side, aStack) && ((this.getFuelValue(aStack) > 0) + || (this.getFuelValue(GT_Utility.getFluidForFilledItem(aStack, true)) > 0)); + } + + @Override + public int getCapacity() { + return 32000; + } + + @Override + public int getTankPressure() { + return -100; + } + + @Override + public boolean useModularUI() { + return true; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/machines/GregtechMetaTreeFarmerBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/machines/GregtechMetaTreeFarmerBase.java new file mode 100644 index 0000000000..fe3253244a --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/machines/GregtechMetaTreeFarmerBase.java @@ -0,0 +1,180 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.machines; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; + +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock; +import gregtech.api.objects.GT_RenderedTexture; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public abstract class GregtechMetaTreeFarmerBase extends GT_MetaTileEntity_TieredMachineBlock { + + public GregtechMetaTreeFarmerBase(final int aID, final String aName, final String aNameRegional, final int aTier, + final int aInvSlotCount, final String aDescription) { + super(aID, aName, aNameRegional, aTier, aInvSlotCount, aDescription); + } + + public GregtechMetaTreeFarmerBase(final String aName, final int aTier, final int aInvSlotCount, + final String[] aDescription, final ITexture[][][] aTextures) { + super(aName, aTier, aInvSlotCount, aDescription, aTextures); + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFrontActive(i); + rTextures[6][i + 1] = this.getBackActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final ForgeDirection side, + final ForgeDirection facing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { + return this.mTextures[(aActive ? 5 : 0) + (side == facing ? 0 + : side == facing.getOpposite() ? 1 + : side == ForgeDirection.DOWN ? 2 : side == ForgeDirection.UP ? 3 : 4)][aColorIndex + 1]; + } + + @Override + public boolean isSimpleMachine() { + return false; + } + + @Override + public boolean isValidSlot(final int aIndex) { + return false; + } + + @Override + public boolean isFacingValid(final ForgeDirection facing) { + return true; + } + + @Override + public boolean isEnetInput() { + return false; + } + + @Override + public boolean isEnetOutput() { + return false; + } + + @Override + public boolean isInputFacing(final ForgeDirection side) { + return !this.isOutputFacing(side); + } + + @Override + public boolean isOutputFacing(final ForgeDirection side) { + return this.getBaseMetaTileEntity() + .getBackFacing() == side; + } + + @Override + public boolean isTeleporterCompatible() { + return false; + } + + @Override + public long getMinimumStoredEU() { + return 0; + } + + @Override + public long maxEUStore() { + return 0; + } + + @Override + public long maxEUInput() { + return 0; + } + + @Override + public long maxEUOutput() { + return 0; + } + + @Override + public long maxAmperesIn() { + return 0; + } + + @Override + public long maxAmperesOut() { + return 0; + } + + @Override + public boolean isAccessAllowed(final EntityPlayer aPlayer) { + return false; + } + + public abstract ITexture getOverlayIcon(); + + @Override + public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, + final ForgeDirection side, final ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, + final ForgeDirection side, final ItemStack aStack) { + return false; + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Farm_Manager) }; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Farm_Manager) }; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Acacia_Log) }; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Podzol) }; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Farm_Manager) }; + } + + public ITexture[] getFrontActive(final byte aColor) { + return this.getFront(aColor); + } + + public ITexture[] getBackActive(final byte aColor) { + return this.getBack(aColor); + } + + public ITexture[] getBottomActive(final byte aColor) { + return this.getBottom(aColor); + } + + public ITexture[] getTopActive(final byte aColor) { + return this.getTop(aColor); + } + + public ITexture[] getSidesActive(final byte aColor) { + return this.getSides(aColor); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/nbthandlers/GT_MetaTileEntity_Hatch_Catalysts.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/nbthandlers/GT_MetaTileEntity_Hatch_Catalysts.java new file mode 100644 index 0000000000..b53e540044 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/nbthandlers/GT_MetaTileEntity_Hatch_Catalysts.java @@ -0,0 +1,71 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.nbthandlers; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; + +import org.apache.commons.lang3.ArrayUtils; + +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.objects.GT_RenderedTexture; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GT_MetaTileEntity_Hatch_Catalysts extends GT_MetaTileEntity_Hatch_NbtConsumable { + + public GT_MetaTileEntity_Hatch_Catalysts(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional, 0, 16, "Dedicated Catalyst Storage", false); + } + + public GT_MetaTileEntity_Hatch_Catalysts(String aName, String[] aDescription, ITexture[][][] aTextures) { + super(aName, 0, 16, aDescription, false, aTextures); + } + + @Override + public ITexture[] getTexturesActive(ITexture aBaseTexture) { + return new ITexture[] { aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Bus_Catalyst) }; + } + + @Override + public ITexture[] getTexturesInactive(ITexture aBaseTexture) { + return new ITexture[] { aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Bus_Catalyst) }; + } + + @Override + public String[] getDescription() { + return ArrayUtils.add(this.mDescriptionArray, CORE.GT_Tooltip.get()); + } + + @Override + public boolean isFacingValid(ForgeDirection facing) { + return true; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Hatch_Catalysts(mName, mDescriptionArray, mTextures); + } + + @Override + public String getNameGUI() { + return "Catalyst Container"; + } + + @Override + public AutoMap<ItemStack> getItemsValidForUsageSlots() { + return new AutoMap<>(); + } + + @Override + public boolean isItemValidForUsageSlot(ItemStack aStack) { + return ItemUtils.isCatalyst(aStack); + } + + @Override + public int getInputSlotCount() { + return 16; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/nbthandlers/GT_MetaTileEntity_Hatch_MillingBalls.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/nbthandlers/GT_MetaTileEntity_Hatch_MillingBalls.java new file mode 100644 index 0000000000..e3134f5812 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/nbthandlers/GT_MetaTileEntity_Hatch_MillingBalls.java @@ -0,0 +1,71 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.nbthandlers; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; + +import org.apache.commons.lang3.ArrayUtils; + +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.objects.GT_RenderedTexture; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GT_MetaTileEntity_Hatch_MillingBalls extends GT_MetaTileEntity_Hatch_NbtConsumable { + + public GT_MetaTileEntity_Hatch_MillingBalls(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional, 6, 4, "Dedicated Milling Ball Storage", false); + } + + public GT_MetaTileEntity_Hatch_MillingBalls(String aName, String[] aDescription, ITexture[][][] aTextures) { + super(aName, 6, 4, aDescription, false, aTextures); + } + + @Override + public ITexture[] getTexturesActive(ITexture aBaseTexture) { + return new ITexture[] { aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Bus_Milling_Balls) }; + } + + @Override + public ITexture[] getTexturesInactive(ITexture aBaseTexture) { + return new ITexture[] { aBaseTexture, new GT_RenderedTexture(TexturesGtBlock.Overlay_Bus_Milling_Balls) }; + } + + @Override + public String[] getDescription() { + return ArrayUtils.add(this.mDescriptionArray, CORE.GT_Tooltip.get()); + } + + @Override + public boolean isFacingValid(ForgeDirection facing) { + return true; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Hatch_MillingBalls(mName, mDescriptionArray, mTextures); + } + + @Override + public String getNameGUI() { + return "Ball Housing"; + } + + @Override + public AutoMap<ItemStack> getItemsValidForUsageSlots() { + return new AutoMap<>(); + } + + @Override + public boolean isItemValidForUsageSlot(ItemStack aStack) { + return ItemUtils.isMillingBall(aStack); + } + + @Override + public int getInputSlotCount() { + return 4; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/nbthandlers/GT_MetaTileEntity_Hatch_NbtConsumable.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/nbthandlers/GT_MetaTileEntity_Hatch_NbtConsumable.java new file mode 100644 index 0000000000..e81c9ed554 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/nbthandlers/GT_MetaTileEntity_Hatch_NbtConsumable.java @@ -0,0 +1,353 @@ +package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.nbthandlers; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; + +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.DrawableWidget; +import com.gtnewhorizons.modularui.common.widget.SlotGroup; +import com.gtnewhorizons.modularui.common.widget.TextWidget; + +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.modularui.IAddGregtechLogo; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.core.util.minecraft.ItemUtils; + +public abstract class GT_MetaTileEntity_Hatch_NbtConsumable extends GT_MetaTileEntity_Hatch + implements IAddGregtechLogo { + + private final int mInputslotCount; + private final int mTotalSlotCount; + private final boolean mAllowDuplicateUsageTypes; + + public GT_MetaTileEntity_Hatch_NbtConsumable(int aID, String aName, String aNameRegional, int aTier, + int aInputSlots, String aDescription, boolean aAllowDuplicateTypes) { + super(aID, aName, aNameRegional, aTier, aInputSlots * 2, aDescription); + mInputslotCount = getInputSlotCount(); + mTotalSlotCount = getInputSlotCount() * 2; + mAllowDuplicateUsageTypes = aAllowDuplicateTypes; + } + + public GT_MetaTileEntity_Hatch_NbtConsumable(String aName, int aTier, int aInputSlots, String[] aDescription, + boolean aAllowDuplicateTypes, ITexture[][][] aTextures) { + super(aName, aTier, aInputSlots * 2, aDescription, aTextures); + mInputslotCount = getInputSlotCount(); + mTotalSlotCount = getInputSlotCount() * 2; + mAllowDuplicateUsageTypes = aAllowDuplicateTypes; + } + + @Override + public abstract ITexture[] getTexturesActive(ITexture aBaseTexture); + + @Override + public abstract ITexture[] getTexturesInactive(ITexture aBaseTexture); + + public abstract int getInputSlotCount(); + + @Override + public final boolean isSimpleMachine() { + return true; + } + + @Override + public boolean isFacingValid(ForgeDirection facing) { + return true; + } + + @Override + public final boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + @Override + public final boolean isValidSlot(int aIndex) { + return true; + } + + @Override + public abstract MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity); + + @Override + public final boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); + return true; + } + + public abstract String getNameGUI(); + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { + validateUsageSlots(); + if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.hasInventoryBeenModified()) { + fillStacksIntoFirstSlots(); + tryFillUsageSlots(); + } + } + + public final void updateSlots() { + for (int i = 0; i < mInventory.length; i++) { + if (mInventory[i] != null && mInventory[i].stackSize <= 0) { + mInventory[i] = null; + } + // Only moves items in the first four slots + if (i <= getSlotID_LastInput()) { + fillStacksIntoFirstSlots(); + } + } + } + + protected void validateUsageSlots() { + for (int i = getSlotID_FirstUsage(); i <= getSlotID_LastUsage(); i++) { + if (mInventory[i] != null && mInventory[i].stackSize < 1) { + mInventory[i] = null; + this.markDirty(); + } + } + } + + // Only moves items in the first four slots + protected final void fillStacksIntoFirstSlots() { + for (int i = 0; i <= getSlotID_LastInput(); i++) { + for (int j = i + 1; j <= getSlotID_LastInput(); j++) { + if (mInventory[j] != null + && (mInventory[i] == null || GT_Utility.areStacksEqual(mInventory[i], mInventory[j]))) { + GT_Utility.moveStackFromSlotAToSlotB( + getBaseMetaTileEntity(), + getBaseMetaTileEntity(), + j, + i, + (byte) 64, + (byte) 1, + (byte) 64, + (byte) 1); + } + } + } + } + + public final void tryFillUsageSlots() { + int aSlotSpace = (mInputslotCount - getContentUsageSlots().size()); + if (aSlotSpace > 0) { + Logger.INFO("We have empty usage slots. " + aSlotSpace); + for (int i = getSlotID_FirstInput(); i <= getSlotID_LastInput(); i++) { + ItemStack aStackToTryMove = mInventory[i]; + if (aStackToTryMove != null && isItemValidForUsageSlot(aStackToTryMove)) { + Logger.INFO("Trying to move stack from input slot " + i); + if (moveItemFromStockToUsageSlots(aStackToTryMove)) { + Logger.INFO("Updating Slots."); + updateSlots(); + } + } + } + } + } + + private int getSlotID_FirstInput() { + return 0; + } + + private int getSlotID_LastInput() { + return mInputslotCount - 1; + } + + private int getSlotID_FirstUsage() { + return mInputslotCount; + } + + private int getSlotID_LastUsage() { + return mTotalSlotCount - 1; + } + + public final AutoMap<ItemStack> getContentUsageSlots() { + AutoMap<ItemStack> aItems = new AutoMap<>(); + for (int i = mInputslotCount; i < mTotalSlotCount; i++) { + if (mInventory[i] != null) { + aItems.add(mInventory[i]); + } + } + return aItems; + } + + public final boolean moveItemFromStockToUsageSlots(ItemStack aStack) { + return moveItemFromStockToUsageSlots(aStack, mAllowDuplicateUsageTypes); + } + + public final boolean moveItemFromStockToUsageSlots(ItemStack aStack, boolean aAllowMultiOfSameTypeInUsageSlots) { + if (aStack != null) { + if (aStack.stackSize > 0) { + + if (!isItemValidForUsageSlot(aStack)) { + Logger.INFO("Stack not valid: " + ItemUtils.getItemName(aStack)); + return false; + } + + // Copy the input stack into a new object + ItemStack aStackToMove = aStack.copy(); + // Set stack size of stack to move to 1. + aStackToMove.stackSize = 1; + // Did we set a stack in the usage slots? + boolean aDidSet = false; + // Did we find another of this item already in the usage slots? + boolean aFoundMatching = false; + // Continue processing with our new stack + // First check for duplicates + for (int i = getSlotID_FirstUsage(); i <= getSlotID_LastUsage(); i++) { + if (mInventory[i] != null) { + if (GT_Utility.areStacksEqual(aStackToMove, mInventory[i], true)) { + Logger.INFO("Found matching stack in slot " + i + "."); + aFoundMatching = true; + break; + } + } + } + // Then Move stack to Usage slots + for (int i = getSlotID_FirstUsage(); i <= getSlotID_LastUsage(); i++) { + if (mInventory[i] == null) { + if ((aFoundMatching && aAllowMultiOfSameTypeInUsageSlots) || !aFoundMatching) { + mInventory[i] = aStackToMove; + aDidSet = true; + Logger.INFO("Moving new stack to usage slots."); + break; + } + } + } + if (aDidSet) { + Logger.INFO("Depleting input stack size by 1."); + // Depleted one from the original input stack + aStack.stackSize--; + } + return aDidSet; + } + } + return false; + } + + @Override + public final boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return false; + } + + @Override + public final boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return side == getBaseMetaTileEntity().getFrontFacing() && isItemValidForUsageSlot(aStack) + && aIndex < mInputslotCount; + } + + /** + * Items that get compared when checking for Usage Slot validity. Can return an empty map if + * isItemValidForUsageSlot() is overridden. + * + * @return + */ + public abstract AutoMap<ItemStack> getItemsValidForUsageSlots(); + + /** + * Checks if the given item is valid for Usage Slots. Can be overridden for easier handling if you already have + * methods to check this. + * + * @param aStack + * @return + */ + public boolean isItemValidForUsageSlot(ItemStack aStack) { + if (aStack != null) { + for (ItemStack aValid : getItemsValidForUsageSlots()) { + if (GT_Utility.areStacksEqual(aStack, aValid, true)) { + return true; + } + } + } + return false; + } + + @Override + public boolean useModularUI() { + return true; + } + + @Override + public void addGregTechLogo(ModularWindow.Builder builder) { + switch (mTotalSlotCount) { + case 8, 18 -> builder.widget( + new DrawableWidget().setDrawable(getGUITextureSet().getGregTechLogo()) + .setSize(17, 17) + .setPos(152, 63)); + case 32 -> builder.widget( + new DrawableWidget().setDrawable(getGUITextureSet().getGregTechLogo()) + .setSize(17, 17) + .setPos(79, 35)); + } + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + switch (mTotalSlotCount) { + case 8 -> { + builder.widget( + SlotGroup.ofItemHandler(inventoryHandler, 2) + .startFromSlot(0) + .endAtSlot(3) + .build() + .setPos(25, 25)); + builder.widget( + SlotGroup.ofItemHandler(inventoryHandler, 2) + .startFromSlot(4) + .endAtSlot(7) + .canInsert(false) + .build() + .setPos(115, 25)); + builder.widget( + new TextWidget("Stock").setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(25, 16)) + .widget( + new TextWidget("Active").setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(115, 16)); + } + case 18 -> { + builder.widget( + SlotGroup.ofItemHandler(inventoryHandler, 3) + .startFromSlot(0) + .endAtSlot(8) + .build() + .setPos(25, 19)); + builder.widget( + SlotGroup.ofItemHandler(inventoryHandler, 3) + .startFromSlot(9) + .endAtSlot(17) + .canInsert(false) + .build() + .setPos(97, 19)); + builder.widget( + new TextWidget("Stock").setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(25, 14)) + .widget( + new TextWidget("Active").setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(15, 14)); + } + case 32 -> { + builder.widget( + SlotGroup.ofItemHandler(inventoryHandler, 4) + .startFromSlot(0) + .endAtSlot(15) + .build() + .setPos(7, 7)); + builder.widget( + SlotGroup.ofItemHandler(inventoryHandler, 4) + .startFromSlot(16) + .endAtSlot(31) + .canInsert(false) + .build() + .setPos(96, 7)); + } + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/objects/GTPP_CopiedBlockTexture.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/objects/GTPP_CopiedBlockTexture.java new file mode 100644 index 0000000000..6a780d227c --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/objects/GTPP_CopiedBlockTexture.java @@ -0,0 +1,28 @@ +package gtPlusPlus.xmod.gregtech.api.objects; + +import net.minecraft.block.Block; + +import gregtech.api.enums.Dyes; +import gregtech.api.objects.GT_CopiedBlockTexture; + +/** + * Made this to get rid of deprecation warnings <i>everywhere</i>. + * + * @author Alkalus + * + */ +@SuppressWarnings("deprecation") +public class GTPP_CopiedBlockTexture extends GT_CopiedBlockTexture { + + public GTPP_CopiedBlockTexture(Block aBlock, int aSide, int aMeta, short[] aRGBa, boolean aAllowAlpha) { + super(aBlock, aMeta, aMeta, aRGBa, aAllowAlpha); + } + + public GTPP_CopiedBlockTexture(Block aBlock, int aSide, int aMeta, short[] aRGBa) { + this(aBlock, aSide, aMeta, aRGBa, true); + } + + public GTPP_CopiedBlockTexture(Block aBlock, int aSide, int aMeta) { + this(aBlock, aSide, aMeta, Dyes._NULL.mRGBa); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/objects/GTPP_RenderedTexture.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/objects/GTPP_RenderedTexture.java new file mode 100644 index 0000000000..0da0136193 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/objects/GTPP_RenderedTexture.java @@ -0,0 +1,27 @@ +package gtPlusPlus.xmod.gregtech.api.objects; + +import gregtech.api.enums.Dyes; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.objects.GT_RenderedTexture; + +/** + * Made this to get rid of deprecation warnings <i>everywhere</i>. + * + * @author Alkalus + * + */ +@SuppressWarnings("deprecation") +public class GTPP_RenderedTexture extends GT_RenderedTexture { + + public GTPP_RenderedTexture(IIconContainer aIcon, short[] aRGBa, boolean aAllowAlpha) { + super(aIcon, aRGBa, aAllowAlpha); + } + + public GTPP_RenderedTexture(IIconContainer aIcon, short[] aRGBa) { + this(aIcon, aRGBa, true); + } + + public GTPP_RenderedTexture(IIconContainer aIcon) { + this(aIcon, Dyes._NULL.mRGBa); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/objects/GregtechItemData.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/objects/GregtechItemData.java new file mode 100644 index 0000000000..967d3ae916 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/objects/GregtechItemData.java @@ -0,0 +1,147 @@ +package gtPlusPlus.xmod.gregtech.api.objects; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import net.minecraft.item.ItemStack; + +import gregtech.api.objects.GT_ArrayList; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechOrePrefixes; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechOrePrefixes.GT_Materials; + +public class GregtechItemData { + + private static final GregtechMaterialStack[] EMPTY_GT_MaterialStack_ARRAY = new GregtechMaterialStack[0]; + + public final List<Object> mExtraData = new GT_ArrayList<>(false, 1); + public final GregtechOrePrefixes mPrefix; + public final GregtechMaterialStack mMaterial; + public final GregtechMaterialStack[] mByProducts; + public boolean mBlackListed = false; + public ItemStack mUnificationTarget = null; + + public GregtechItemData(final GregtechOrePrefixes aPrefix, final GT_Materials aMaterial, + final boolean aBlackListed) { + this.mPrefix = aPrefix; + this.mMaterial = aMaterial == null ? null : new GregtechMaterialStack(aMaterial, aPrefix.mMaterialAmount); + this.mBlackListed = aBlackListed; + this.mByProducts = (aPrefix.mSecondaryMaterial == null) || (aPrefix.mSecondaryMaterial.mMaterial == null) + ? EMPTY_GT_MaterialStack_ARRAY + : new GregtechMaterialStack[] { aPrefix.mSecondaryMaterial.clone() }; + } + + public GregtechItemData(final GregtechOrePrefixes aPrefix, final GT_Materials aMaterial) { + this(aPrefix, aMaterial, false); + } + + public GregtechItemData(final GregtechMaterialStack aMaterial, final GregtechMaterialStack... aByProducts) { + this.mPrefix = null; + this.mMaterial = aMaterial.mMaterial == null ? null : aMaterial.clone(); + this.mBlackListed = true; + if (aByProducts == null) { + this.mByProducts = EMPTY_GT_MaterialStack_ARRAY; + } else { + final GregtechMaterialStack[] tByProducts = aByProducts.length < 1 ? EMPTY_GT_MaterialStack_ARRAY + : new GregtechMaterialStack[aByProducts.length]; + int j = 0; + for (GregtechMaterialStack aByProduct : aByProducts) { + if ((aByProduct != null) && (aByProduct.mMaterial != null)) { + tByProducts[j++] = aByProduct.clone(); + } + } + this.mByProducts = j > 0 ? new GregtechMaterialStack[j] : EMPTY_GT_MaterialStack_ARRAY; + for (int i = 0; i < this.mByProducts.length; i++) { + this.mByProducts[i] = tByProducts[i]; + } + } + } + + public GregtechItemData(final GT_Materials aMaterial, final long aAmount, + final GregtechMaterialStack... aByProducts) { + this(new GregtechMaterialStack(aMaterial, aAmount), aByProducts); + } + + public GregtechItemData(final GT_Materials aMaterial, final long aAmount, final GT_Materials aByProduct, + final long aByProductAmount) { + this(new GregtechMaterialStack(aMaterial, aAmount), new GregtechMaterialStack(aByProduct, aByProductAmount)); + } + + public GregtechItemData(final GregtechItemData... aData) { + this.mPrefix = null; + this.mBlackListed = true; + + final ArrayList<GregtechMaterialStack> aList = new ArrayList<>(), rList = new ArrayList<>(); + + for (final GregtechItemData tData : aData) { + if (tData != null) { + if (tData.hasValidMaterialData() && (tData.mMaterial.mAmount > 0)) { + aList.add(tData.mMaterial.clone()); + } + for (final GregtechMaterialStack tMaterial : tData.mByProducts) { + if (tMaterial.mAmount > 0) { + aList.add(tMaterial.clone()); + } + } + } + } + + for (final GregtechMaterialStack aMaterial : aList) { + boolean temp = true; + for (final GregtechMaterialStack tMaterial : rList) { + if (aMaterial.mMaterial == tMaterial.mMaterial) { + tMaterial.mAmount += aMaterial.mAmount; + temp = false; + break; + } + } + if (temp) { + rList.add(aMaterial.clone()); + } + } + + rList.sort((a, b) -> Long.compare(b.mAmount, a.mAmount)); + + if (rList.isEmpty()) { + this.mMaterial = null; + } else { + this.mMaterial = rList.get(0); + rList.remove(0); + } + + this.mByProducts = rList.toArray(new GregtechMaterialStack[0]); + } + + public boolean hasValidPrefixMaterialData() { + return (this.mPrefix != null) && (this.mMaterial != null) && (this.mMaterial.mMaterial != null); + } + + public boolean hasValidPrefixData() { + return this.mPrefix != null; + } + + public boolean hasValidMaterialData() { + return (this.mMaterial != null) && (this.mMaterial.mMaterial != null); + } + + public ArrayList<GregtechMaterialStack> getAllGT_MaterialStacks() { + final ArrayList<GregtechMaterialStack> rList = new ArrayList<>(); + if (this.hasValidMaterialData()) { + rList.add(this.mMaterial); + } + rList.addAll(Arrays.asList(this.mByProducts)); + return rList; + } + + public GregtechMaterialStack getByProduct(final int aIndex) { + return (aIndex >= 0) && (aIndex < this.mByProducts.length) ? this.mByProducts[aIndex] : null; + } + + @Override + public String toString() { + if ((this.mPrefix == null) || (this.mMaterial == null) || (this.mMaterial.mMaterial == null)) { + return ""; + } + return this.mPrefix.name() + this.mMaterial.mMaterial.name(); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/objects/GregtechMaterialStack.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/objects/GregtechMaterialStack.java new file mode 100644 index 0000000000..d1ee02f480 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/objects/GregtechMaterialStack.java @@ -0,0 +1,55 @@ +package gtPlusPlus.xmod.gregtech.api.objects; + +import gtPlusPlus.xmod.gregtech.api.enums.GregtechOrePrefixes.GT_Materials; + +public class GregtechMaterialStack implements Cloneable { + + public long mAmount; + public GT_Materials mMaterial; + + public GregtechMaterialStack(final GT_Materials aMaterial, final long aAmount) { + this.mMaterial = aMaterial == null ? GT_Materials._NULL : aMaterial; + this.mAmount = aAmount; + } + + public GregtechMaterialStack copy(final long aAmount) { + return new GregtechMaterialStack(this.mMaterial, aAmount); + } + + @Override + public GregtechMaterialStack clone() { + return new GregtechMaterialStack(this.mMaterial, this.mAmount); + } + + @Override + public boolean equals(final Object aObject) { + if (aObject == this) { + return true; + } + if (aObject == null) { + return false; + } + if (aObject instanceof GT_Materials) { + return aObject == this.mMaterial; + } + if (aObject instanceof GregtechMaterialStack) { + return (((GregtechMaterialStack) aObject).mMaterial == this.mMaterial) + && ((this.mAmount < 0) || (((GregtechMaterialStack) aObject).mAmount < 0) + || (((GregtechMaterialStack) aObject).mAmount == this.mAmount)); + } + return false; + } + + @Override + public String toString() { + return ((this.mMaterial.mMaterialList.size() > 1) && (this.mAmount > 1) ? "(" : "") + + this.mMaterial.getToolTip(true) + + ((this.mMaterial.mMaterialList.size() > 1) && (this.mAmount > 1) ? ")" : "") + + (this.mAmount > 1 ? this.mAmount : ""); + } + + @Override + public int hashCode() { + return this.mMaterial.hashCode(); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/util/GTPP_Config.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/util/GTPP_Config.java new file mode 100644 index 0000000000..65beea207a --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/util/GTPP_Config.java @@ -0,0 +1,123 @@ +package gtPlusPlus.xmod.gregtech.api.util; + +import static gregtech.api.enums.GT_Values.E; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.common.config.Property; + +import gregtech.api.GregTech_API; +import gregtech.api.util.GT_OreDictUnificator; +import gregtech.api.util.GT_Utility; + +public class GTPP_Config implements Runnable { + + public static boolean troll = false; + + public static Configuration sConfigFileIDs; + public final Configuration mConfig; + + public GTPP_Config(Configuration aConfig) { + mConfig = aConfig; + mConfig.load(); + mConfig.save(); + } + + public static int addIDConfig(Object aCategory, String aName, int aDefault) { + if (GT_Utility.isStringInvalid(aName)) return aDefault; + Property tProperty = sConfigFileIDs.get( + aCategory.toString() + .replaceAll("\\|", "."), + aName.replaceAll("\\|", "."), + aDefault); + int rResult = tProperty.getInt(aDefault); + if (!tProperty.wasRead() && GregTech_API.sPostloadFinished) sConfigFileIDs.save(); + return rResult; + } + + public static String getStackConfigName(ItemStack aStack) { + if (GT_Utility.isStackInvalid(aStack)) return E; + Object rName = GT_OreDictUnificator.getAssociation(aStack); + if (rName != null) return rName.toString(); + try { + if (GT_Utility.isStringValid(rName = aStack.getUnlocalizedName())) return rName.toString(); + } catch (Throwable e) { + /* Do nothing */ + } + String sName = aStack.getItem() + .toString(); + String[] tmp = sName.split("@"); + if (tmp.length > 0) sName = tmp[0]; + return sName + "." + aStack.getItemDamage(); + } + + public boolean get(Object aCategory, ItemStack aStack, boolean aDefault) { + String aName = getStackConfigName(aStack); + return get(aCategory, aName, aDefault); + } + + public boolean get(Object aCategory, String aName, boolean aDefault) { + if (GT_Utility.isStringInvalid(aName)) return aDefault; + Property tProperty = mConfig.get( + aCategory.toString() + .replaceAll("\\|", "_"), + (aName + "_" + aDefault).replaceAll("\\|", "_"), + aDefault); + boolean rResult = tProperty.getBoolean(aDefault); + if (!tProperty.wasRead() && GregTech_API.sPostloadFinished) mConfig.save(); + return rResult; + } + + public int get(Object aCategory, ItemStack aStack, int aDefault) { + return get(aCategory, getStackConfigName(aStack), aDefault); + } + + public int get(Object aCategory, String aName, int aDefault) { + if (GT_Utility.isStringInvalid(aName)) return aDefault; + Property tProperty = mConfig.get( + aCategory.toString() + .replaceAll("\\|", "_"), + (aName + "_" + aDefault).replaceAll("\\|", "_"), + aDefault); + int rResult = tProperty.getInt(aDefault); + if (!tProperty.wasRead() && GregTech_API.sPostloadFinished) mConfig.save(); + return rResult; + } + + public double get(Object aCategory, ItemStack aStack, double aDefault) { + return get(aCategory, getStackConfigName(aStack), aDefault); + } + + public double get(Object aCategory, String aName, double aDefault) { + if (GT_Utility.isStringInvalid(aName)) return aDefault; + Property tProperty = mConfig.get( + aCategory.toString() + .replaceAll("\\|", "_"), + (aName + "_" + aDefault).replaceAll("\\|", "_"), + aDefault); + double rResult = tProperty.getDouble(aDefault); + if (!tProperty.wasRead() && GregTech_API.sPostloadFinished) mConfig.save(); + return rResult; + } + + public String get(Object aCategory, ItemStack aStack, String aDefault) { + return get(aCategory, getStackConfigName(aStack), aDefault); + } + + public String get(Object aCategory, String aName, String aDefault) { + if (GT_Utility.isStringInvalid(aName)) return aDefault; + Property tProperty = mConfig.get( + aCategory.toString() + .replaceAll("\\|", "_"), + (aName + "_" + aDefault).replaceAll("\\|", "_"), + aDefault); + String rResult = tProperty.getString(); + if (!tProperty.wasRead() && GregTech_API.sPostloadFinished) mConfig.save(); + return rResult; + } + + @Override + public void run() { + mConfig.save(); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/util/SpecialBehaviourTooltipHandler.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/util/SpecialBehaviourTooltipHandler.java new file mode 100644 index 0000000000..df95b7de2b --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/util/SpecialBehaviourTooltipHandler.java @@ -0,0 +1,35 @@ +package gtPlusPlus.xmod.gregtech.api.util; + +import java.util.HashMap; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraftforge.event.entity.player.ItemTooltipEvent; + +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import gregtech.api.util.GT_Utility; + +public class SpecialBehaviourTooltipHandler { + + private static final HashMap<ItemStack, String> mTooltipCache = new HashMap<>(); + + public static void addTooltipForItem(ItemStack aStack, String aTooltip) { + mTooltipCache.put(aStack, aTooltip); + } + + @SubscribeEvent + public void onItemTooltip(ItemTooltipEvent event) { + if (event != null) { + if (event.itemStack != null) { + for (ItemStack aKey : mTooltipCache.keySet()) { + if (GT_Utility.areStacksEqual(aKey, event.itemStack, false)) { + String s = mTooltipCache.get(aKey); + if (s != null && s.length() > 0) { + event.toolTip.add(EnumChatFormatting.RED + s); + } + } + } + } + } + } +} |