diff options
Diffstat (limited to 'src/main/java')
4 files changed, 643 insertions, 695 deletions
diff --git a/src/main/java/com/github/technus/tectech/recipe/EyeOfHarmonyRecipe.java b/src/main/java/com/github/technus/tectech/recipe/EyeOfHarmonyRecipe.java index 3cf0974278..1a6ba57bf2 100644 --- a/src/main/java/com/github/technus/tectech/recipe/EyeOfHarmonyRecipe.java +++ b/src/main/java/com/github/technus/tectech/recipe/EyeOfHarmonyRecipe.java @@ -1,89 +1,222 @@ package com.github.technus.tectech.recipe; +import gregtech.api.enums.Materials; import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; import org.apache.commons.lang3.tuple.Pair; +import org.lwjgl.Sys; +import pers.gwyog.gtneioreplugin.util.GT5OreLayerHelper; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; public class EyeOfHarmonyRecipe { - private final List<Pair<ItemStack, Long>> output_items; - private final FluidStack[] output_fluids; + private static final double maxPlasmaEfficiency = 3; - private long hydrogen_requirement; - private long helium_requirement; + private final List<Pair<ItemStack, Long>> outputItems; + private final FluidStack[] outputFluids; - private long eu_output; - private long eu_start_cost; + private final long hydrogenRequirement; + private final long heliumRequirement; - private long recipe_processing_time_in_ticks; + private final long euOutput; + private final long euStartCost; - private double base_success_chance; + private final double baseSuccessChance; - private long spacetime_casing_tier_required; + private final long spacetimeCasingTierRequired; - public EyeOfHarmonyRecipe(List<Pair<ItemStack, Long>> _output_items, - FluidStack[] _output_fluids, - long _hydrogen_requirement, - long _helium_requirement, - long _eu_output, - long _eu_start_cost, - long _recipe_processing_time_in_ticks, - double _base_success_chance, - long _spacetime_casing_tier_required) { + private final long miningTime; - output_items = _output_items; - output_fluids = _output_fluids; - hydrogen_requirement = _hydrogen_requirement; - helium_requirement = _helium_requirement; + public EyeOfHarmonyRecipe(GT5OreLayerHelper.OreDimensionWrapper dimensionWrapper, + double recipeEnergyEfficiency, + long hydrogenRequirement, + long heliumRequirement, + long miningTime, + long spacetimeCasingTierRequired, + long euOutput, + double baseSuccessChance + ) { + System.out.println("TEST12345MKFWA"); - eu_output = _eu_output; - eu_start_cost = _eu_start_cost; + ArrayList<Pair<Materials, Long>> materialList = processDimension(dimensionWrapper, miningTime, 6); - recipe_processing_time_in_ticks = _recipe_processing_time_in_ticks; + this.outputItems = validDustGenerator(materialList); + this.outputFluids = validPlasmaGenerator(materialList, 0.1); - base_success_chance = _base_success_chance; + this.spacetimeCasingTierRequired = spacetimeCasingTierRequired; + + this.euStartCost = (long) (plasmaCostCalculator(this.outputFluids) * recipeEnergyEfficiency); + this.euOutput = euOutput; + + this.hydrogenRequirement = hydrogenRequirement; + this.heliumRequirement = heliumRequirement; + + this.baseSuccessChance = baseSuccessChance; + + this.miningTime = miningTime; - // 0 - 7; - spacetime_casing_tier_required = _spacetime_casing_tier_required; } public List<Pair<ItemStack, Long>> getOutputItems() { - return output_items; + return outputItems; } public FluidStack[] getOutputFluids() { - return output_fluids.clone(); + return outputFluids.clone(); } public long getHydrogenRequirement() { - return hydrogen_requirement; + return hydrogenRequirement; } public long getHeliumRequirement() { - return helium_requirement; + return heliumRequirement; } public long getEUOutput() { - return eu_output; + return euOutput; } public long getEUStartCost() { - return eu_start_cost; + return euStartCost; } public long getRecipeTime() { - return recipe_processing_time_in_ticks; + return miningTime; } public double getBaseRecipeSuccessChance() { - return base_success_chance; + return baseSuccessChance; } public long getSpacetimeCasingTierRequired() { - return spacetime_casing_tier_required; + return spacetimeCasingTierRequired; + } + + static final double primaryMultiplier = (0.1 + 1.0/9.0); + static final double secondaryMultiplier = (1.0/9.0); + static final double tertiaryMultiplier = (0.1); + + static final double[] oreMultiplier = {primaryMultiplier, secondaryMultiplier, tertiaryMultiplier}; + + private static class HashMapHelper extends HashMap<Materials, Double> { + + void add(Materials material, double value) { + + // If key already exists. + if (this.containsKey(material)) { + this.put(material, value + this.get(material)); + return; + } + + // Otherwise, add value to hashmap entry. + this.put(material, value); + } + } + + static void processHelper(HashMapHelper outputMap, Materials material, double mainMultiplier, double probability) { + outputMap.add(material, material.mOreMultiplier * mainMultiplier * probability); + + int index = 0; + for (Materials byProductMaterial : material.mOreByProducts) { + outputMap.add(byProductMaterial, mainMultiplier * oreMultiplier[index++]); + } + } + + static ArrayList<Pair<Materials, Long>> processDimension(GT5OreLayerHelper.OreDimensionWrapper dimWrapper, long timeInSeconds, long miningMultiplier) { + HashMapHelper outputMap = new HashMapHelper(); + + double mainMultiplier = timeInSeconds * miningMultiplier; + + dimWrapper.oreVeinToProbabilityInDimension.forEach((veinInfo, probability) -> { + processHelper(outputMap, veinInfo.mPrimaryVeinMaterial, mainMultiplier, probability); + processHelper(outputMap, veinInfo.mSecondaryMaterial, mainMultiplier, probability); + processHelper(outputMap, veinInfo.mBetweenMaterial, mainMultiplier, probability); + processHelper(outputMap, veinInfo.mSporadicMaterial, mainMultiplier, probability); + }); + + ArrayList<Pair<Materials, Long>> outputList = new ArrayList<>(); + + outputMap.forEach((material, quantity) -> outputList.add(Pair.of(material, (long) Math.floor(quantity)))); + + return outputList; } + + static FluidStack[] validPlasmaGenerator(final List<Pair<Materials, Long>> planetList, final double percentageOfPlasma) { + + List<FluidStack> plasma_list = new ArrayList<>(); + + for (Pair<Materials, Long> pair : planetList) { + if (validPlasmas.contains(pair.getLeft())) { + plasma_list.add(pair.getLeft().getPlasma((int) (pair.getRight() * percentageOfPlasma))); + } + } + return plasma_list.toArray(new FluidStack[0]); + } + + static List<Pair<ItemStack, Long>> validDustGenerator(final List<Pair<Materials, Long>> planetList) { + + List<Pair<ItemStack, Long>> dust_list = new ArrayList<>(); + + for (Pair<Materials, Long> pair : planetList) { + dust_list.add(Pair.of(pair.getLeft().getDust(1), pair.getRight())); + } + return dust_list; + } + + static long plasmaCostCalculator(FluidStack[] plasmas) { + long total = 0; + + for (FluidStack plasma : plasmas) { + total += (plasmaEnergyMap.get(plasma.getFluid()) * plasma.amount); + } + + return (long) (total * maxPlasmaEfficiency); + } + + static final List<Materials> validPlasmas = Stream.of( + Materials.Helium, + Materials.Boron, + Materials.Nitrogen, + Materials.Oxygen, + Materials.Sulfur, + Materials.Calcium, + Materials.Titanium, + Materials.Iron, + Materials.Nickel, + Materials.Zinc, + Materials.Niobium, + Materials.Silver, + Materials.Tin, + Materials.Bismuth, + Materials.Americium, + Materials.Niobium + ).collect(Collectors.toList()); + + static HashMap<Fluid, Long> plasmaEnergyMap = new HashMap<Fluid, Long>() {{ + put(Materials.Helium.getPlasma(1).getFluid(), 81_920L); + put(Materials.Boron.getPlasma(1).getFluid(), 112_640L); + put(Materials.Nitrogen.getPlasma(1).getFluid(), 129_024L); + put(Materials.Oxygen.getPlasma(1).getFluid(), 131_072L); + put(Materials.Sulfur.getPlasma(1).getFluid(), 170_393L); + put(Materials.Calcium.getPlasma(1).getFluid(), 188_416L); + put(Materials.Titanium.getPlasma(1).getFluid(), 196_608L); + put(Materials.Iron.getPlasma(1).getFluid(), 206_438L); + put(Materials.Nickel.getPlasma(1).getFluid(), 213_811L); + put(Materials.Zinc.getPlasma(1).getFluid(), 226_304L); + put(Materials.Niobium.getPlasma(1).getFluid(), 269_516L); + put(Materials.Silver.getPlasma(1).getFluid(), 282_685L); + put(Materials.Tin.getPlasma(1).getFluid(), 304_496L); + put(Materials.Americium.getPlasma(1).getFluid(), 501_760L); + put(Materials.Radon.getPlasma(1).getFluid(), 450_560L); + put(Materials.Bismuth.getPlasma(1).getFluid(), 425_984L); + }}; } diff --git a/src/main/java/com/github/technus/tectech/recipe/EyeOfHarmonyRecipeStorage.java b/src/main/java/com/github/technus/tectech/recipe/EyeOfHarmonyRecipeStorage.java index c6f192e467..de27967ce3 100644 --- a/src/main/java/com/github/technus/tectech/recipe/EyeOfHarmonyRecipeStorage.java +++ b/src/main/java/com/github/technus/tectech/recipe/EyeOfHarmonyRecipeStorage.java @@ -1,199 +1,24 @@ package com.github.technus.tectech.recipe; -import gregtech.api.enums.Materials; -import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidStack; -import org.apache.commons.lang3.tuple.Pair; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; - import static com.google.common.math.IntMath.pow; +import static pers.gwyog.gtneioreplugin.util.GT5OreLayerHelper.dimToOreWrapper; public abstract class EyeOfHarmonyRecipeStorage { - static final long MILLION = pow(10, 6); - static final long BILLION = pow(10, 9); - static final long TRILLION = pow(10, 12); - static final long QUADRILLION = pow(10, 15); - static final long QUINTILLION = pow(10, 18); +// static final long MILLION = pow(10, 6); // Fix, these take int, not long, overflow occurring. +// static final long BILLION = pow(10, 9); +// static final long TRILLION = pow(10, 12); +// static final long QUADRILLION = pow(10, 15); +// static final long QUINTILLION = pow(10, 18); static final long SEXTILLION = pow(10, 21); - // VEGA B (approx), 36000 seconds, 3x multiplier on output (excluding 2x already from ore output): - // iron:490_898_412L - // gold:91_781_220L - // copper:156_028_074L - // antimony:24_912_048L - // lead:105_941_754L - // silver:26_223_204L - // naquadah:68_180_334L - // enriched naquadah:3_933_480L - // tungsten:22_289_724L - // lithium:1_311_162L - // uranium:94_403_538L - // arsenic:62_935_692L - // bismuth:71_327_118L - // infused gold:3_933_480L - // platinum:3_933_480L - // chrome:7_866_960L - // neutronium:18_880_710L - // adamantium:10_489_284L - // titanium:1_311_162L - // niobium:62_935_692L - // yttrium:62_935_692L - // gallium:15_733_926L - // thorium:62_935_692L - // uranium 238:62_935_692L - // plutonium 241:7_866_960L - // uranium 235:7_866_960L - // cadmium:41_957_130L - // caesium:41_957_130L - // lanthanum:5_244_642L - // cerium:5_244_642L - // awakened_draconium:2_097_858L - // black_plutonium:6_293_568L - // infinity_catalyst:6_293_568L - - static HashMap<Fluid, Long> plasma_energy_map = new HashMap<Fluid, Long>() {{ - put(Materials.Helium.getPlasma(1).getFluid(), 81_920L); - put(Materials.Boron.getPlasma(1).getFluid(), 112_640L); - put(Materials.Nitrogen.getPlasma(1).getFluid(), 129_024L); - put(Materials.Oxygen.getPlasma(1).getFluid(), 131_072L); - put(Materials.Sulfur.getPlasma(1).getFluid(), 170_393L); - put(Materials.Calcium.getPlasma(1).getFluid(), 188_416L); - put(Materials.Titanium.getPlasma(1).getFluid(), 196_608L); - put(Materials.Iron.getPlasma(1).getFluid(), 206_438L); - put(Materials.Nickel.getPlasma(1).getFluid(), 213_811L); - put(Materials.Zinc.getPlasma(1).getFluid(), 226_304L); - put(Materials.Niobium.getPlasma(1).getFluid(), 269_516L); - put(Materials.Silver.getPlasma(1).getFluid(), 282_685L); - put(Materials.Tin.getPlasma(1).getFluid(), 304_496L); - put(Materials.Americium.getPlasma(1).getFluid(), 501_760L); - put(Materials.Radon.getPlasma(1).getFluid(), 450_560L); - put(Materials.Bismuth.getPlasma(1).getFluid(), 425_984L); - }}; - - static long plasma_cost_calculator(FluidStack[] plasmas, double efficiency) { - long total = 0; - - for (FluidStack plasma : plasmas) { - total += (plasma_energy_map.get(plasma.getFluid()) * plasma.amount); - } - - return (long) (total * efficiency); - } - - static FluidStack[] valid_plasma_generator(final List<Pair<Materials, Long>> planet_list, final double multiplier) { - - List<FluidStack> plasma_list = new ArrayList<>(); - - for (Pair<Materials, Long> pair : planet_list) { - if (valid_plasmas.contains(pair.getLeft())) { - plasma_list.add(pair.getLeft().getPlasma((int) (pair.getRight() * multiplier))); - } - } - return plasma_list.toArray(new FluidStack[0]); - } - - static List<Pair<ItemStack, Long>> valid_dust_generator(final List<Pair<Materials, Long>> planet_list, final double multiplier) { - - List<Pair<ItemStack, Long>> dust_list = new ArrayList<>(); - - for (Pair<Materials, Long> pair : planet_list) { - if (valid_plasmas.contains(pair.getLeft())) { - dust_list.add(Pair.of(pair.getLeft().getDust(1), (long) (pair.getRight() * multiplier))); - } - } - return dust_list; - } - - static final List<Materials> valid_plasmas = Stream.of( - Materials.Copper, - Materials.Silver, - Materials.Helium, - Materials.Boron, - Materials.Nitrogen, - Materials.Oxygen, - Materials.Sulfur, - Materials.Calcium, - Materials.Titanium, - Materials.Iron, - Materials.Nickel, - Materials.Zinc, - Materials.Niobium, - Materials.Silver, - Materials.Tin, - Materials.Bismuth, - Materials.Americium, - Materials.Niobium - ).collect(Collectors.toList()); - - // Vega B weights (approximately). 36000 seconds, Og, UV VM, 2x for ore processing and a final 3x output bonus. - static final List<Pair<Materials, Long>> vega_b = Stream.of( - Pair.of(Materials.Iron, 490_898_412L), - Pair.of(Materials.Gold, 91_781_220L), - Pair.of(Materials.Copper, 156_028_074L), - Pair.of(Materials.Antimony, 24_912_048L), - Pair.of(Materials.Lead, 105_941_754L), - Pair.of(Materials.Silver, 26_223_204L), - Pair.of(Materials.Naquadah, 68_180_334L), - Pair.of(Materials.NaquadahEnriched, 3_933_480L), - Pair.of(Materials.Tungsten, 22_289_724L), - Pair.of(Materials.Lithium, 1_311_162L), - Pair.of(Materials.Uranium235, 94_403_538L + 156_028_074L), - Pair.of(Materials.Arsenic, 62_935_692L), - Pair.of(Materials.Bismuth, 71_327_118L), - Pair.of(Materials.InfusedGold, 3_933_480L), - Pair.of(Materials.Platinum, 3_933_480L), - Pair.of(Materials.Chrome, 7_866_960L), - Pair.of(Materials.Neutronium, 18_880_710L), - Pair.of(Materials.Adamantium, 10_489_284L), - Pair.of(Materials.Titanium, 1_311_162L), - Pair.of(Materials.Niobium, 62_935_692L), - Pair.of(Materials.Yttrium, 62_935_692L), - Pair.of(Materials.Gallium, 15_733_926L), - Pair.of(Materials.Thorium, 62_935_692L), - Pair.of(Materials.Uranium, 62_935_692L), - Pair.of(Materials.Plutonium241, 7_866_960L), - Pair.of(Materials.Cadmium, 41_957_130L), - Pair.of(Materials.Caesium, 41_957_130L), - Pair.of(Materials.Lanthanum, 5_244_642L), - Pair.of(Materials.Cerium, 5_244_642L), - Pair.of(Materials.DraconiumAwakened, 2_097_858L), - Pair.of(Materials.BlackPlutonium, 6_293_568L), - Pair.of(Materials.InfinityCatalyst, 6_293_568L) - ).collect(Collectors.toList()); - - static final FluidStack[] vega_b_plasmas = valid_plasma_generator(vega_b, 0.1); - - static final long vega_b_seconds = 36_000L; - - public static final EyeOfHarmonyRecipe recipe_0 = new EyeOfHarmonyRecipe( - valid_dust_generator(vega_b, 1), - vega_b_plasmas, +// + public static EyeOfHarmonyRecipe overworld = new EyeOfHarmonyRecipe(dimToOreWrapper.get("Ow"), + 1.0, 100, 100, - 1800 * TRILLION, - 524_288L * vega_b_seconds * 20 + 600 * TRILLION + plasma_cost_calculator(vega_b_plasmas, 1), - vega_b_seconds * 20, - 0.40, - 1 - ); - - static final EyeOfHarmonyRecipe recipe_1 = new EyeOfHarmonyRecipe( - valid_dust_generator(vega_b, 1), - vega_b_plasmas, - 100 * BILLION, - 100 * BILLION, - 1800 * TRILLION, - 524_288L * vega_b_seconds * 20 + 600 * TRILLION + plasma_cost_calculator(vega_b_plasmas, 1), - vega_b_seconds * 20, - 0.40, - 1 - ); - + 36_000L, + 0, + 100 * 10, + 0.4); } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_EyeOfHarmony.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_EyeOfHarmony.java index 9e740719f7..93f56e64f5 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_EyeOfHarmony.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_EyeOfHarmony.java @@ -18,20 +18,23 @@ import gregtech.api.interfaces.IGlobalWirelessEnergy; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Output; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_OutputBus; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Utility; +import gregtech.common.tileentities.machines.GT_MetaTileEntity_Hatch_OutputBus_ME; +import gregtech.common.tileentities.machines.GT_MetaTileEntity_Hatch_Output_ME; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.fluids.FluidStack; import org.apache.commons.lang3.tuple.Pair; import java.util.*; -import static com.github.technus.tectech.recipe.EyeOfHarmonyRecipeStorage.recipe_0; +import static com.github.technus.tectech.recipe.EyeOfHarmonyRecipeStorage.overworld; import static com.github.technus.tectech.thing.casing.GT_Block_CasingsTT.textureOffset; import static com.github.technus.tectech.thing.casing.GT_Block_CasingsTT.texturePage; import static com.github.technus.tectech.thing.casing.TT_Container_Casings.sBlockCasingsTT; @@ -151,6 +154,7 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl private double hydrogen_overflow_probability_adjustment; private double helium_overflow_probability_adjustment; + // Maximum additional chance of recipe success that can be obtained from adding computation. private static final double max_percentage_chance_gain_from_computation_per_second = 0.3; private static final long ticks_between_hatch_drain = 20; @@ -177,13 +181,11 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl - helium_overflow_probability_adjustment + max_percentage_chance_gain_from_computation_per_second * (1 - exp(-10e-5 * getComputation()))); - return clamp_probability(chance); + return clamp(chance, 0.0, 1.0); } - // Restrict number between 0 and 1. MathHelper.clamp was giving NoClassDefFoundError, so I wrote this. - private double clamp_probability(double number) { - if (number > (double) 1) { return 1; } - return Math.max(number, 0); + public static double clamp(double amount, double min, double max) { + return Math.max(min, Math.min(amount, max)); } private double recipeYieldCalculator() { @@ -192,8 +194,7 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl - helium_overflow_probability_adjustment - StabilisationFieldMetadata * 0.05; - // Restrict value between 0 and 1 given it is a probability. - return clamp_probability(yield); + return clamp(yield, 0.0, 1.0); } private long recipeProcessTimeCalculator(long recipe_time, long recipe_spacetime_casing_required) { @@ -224,7 +225,61 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl @Override public boolean checkMachine_EM(IGregTechTileEntity iGregTechTileEntity, ItemStack itemStack) { - return structureCheck_EM("main", 16, 16, 0); + + // Check structure of multi. + if (!structureCheck_EM("main", 16, 16, 0)) { + return false; + } + + // Check if there is 1+ output bus, and they are ME output busses. + { + if (mOutputBusses.size() == 0) { + return false; + } + + for (GT_MetaTileEntity_Hatch_OutputBus hatch : mOutputBusses) { + if (!(hatch instanceof GT_MetaTileEntity_Hatch_OutputBus_ME)) { + return false; + } + } + } + + // Check if there is 1+ output hatch, and they are ME output hatches. + { + if (mOutputHatches.size() == 0) { + return false; + } + + for (GT_MetaTileEntity_Hatch_Output hatch : mOutputHatches) { + if (!(hatch instanceof GT_MetaTileEntity_Hatch_Output_ME)) { + return false; + } + } + } + + // Make sure there are no energy hatches. + { + if (mEnergyHatches.size() > 0) { + return false; + } + + if (mExoticEnergyHatches.size() > 0) { + return false; + } + } + + // Make sure there is 2 input hatches. + if (mInputHatches.size() != 2) { + return false; + } + + // Make sure there is 1 input bus. + if (mInputBusses.size() != 1) { + return false; + } + + // 1 Maintenance hatch, as usual. + return (mMaintenanceHatches.size() == 1); } @Override @@ -266,19 +321,27 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl .addInfo("starts at 1 and subtracts depending on penalities. All fluid/item outputs are multiplied") .addInfo("by the yield calculated.") .addInfo(GOLD + "--------------------------------------------------------------------------------") - .addInfo("This multiblock requires a quantum chest to be placed in front each output bus for") - .addInfo("items to output properly. Items will be instantly deposited into them when the recipe") - .addInfo("finishes. If a quantum chest is full it will void any items over the max it can hold.") - .addInfo("If a quantum chest is occupied by another item it will be passed over. If no chest is") - .addInfo("avaliable the items will be " + UNDERLINE + DARK_RED + "voided" + RESET + GRAY + ".") + .addInfo("This multiblock can only output to ME output busses/hatches. If no space in the network") + .addInfo("is avaliable the items/fluids will be " + UNDERLINE + DARK_RED + "voided" + RESET + GRAY + ".") .addInfo(GOLD + "--------------------------------------------------------------------------------") .addInfo("Recipes that fail will return a random amount of the fluid back from the recipe and some") - .addInfo("exotic materials that reject conventional physics.") - + .addInfo("exotic material that rejects conventional physics.") .addSeparator() - + .addStructureInfo("Eye of Harmony structure is too complex! See schematic for details.") + .addStructureInfo(EnumChatFormatting.GOLD + "888" + EnumChatFormatting.GRAY + " Ultimate Molecular Casing.") + .addStructureInfo(EnumChatFormatting.GOLD + "534" + EnumChatFormatting.GRAY + " Ultimate Advanced Molecular Casing.") + .addStructureInfo(EnumChatFormatting.GOLD + "680" + EnumChatFormatting.GRAY + " Time Dilation Field Generator.") + .addStructureInfo(EnumChatFormatting.GOLD + "48" + EnumChatFormatting.GRAY + " Stabilisation Field Generator.") + .addStructureInfo(EnumChatFormatting.GOLD + "138" + EnumChatFormatting.GRAY + " Spacetime Compression Field Generator.") + .addStructureInfo("--------------------------------------------") + .addStructureInfo("Requires " + EnumChatFormatting.GOLD + 1 + EnumChatFormatting.GRAY + " maintenance hatch.") + .addStructureInfo("Requires " + EnumChatFormatting.GOLD + 2 + EnumChatFormatting.GRAY + " input hatches.") + .addStructureInfo("Requires " + EnumChatFormatting.GOLD + 1 + EnumChatFormatting.GRAY + "+ ME output hatch.") + .addStructureInfo("Requires " + EnumChatFormatting.GOLD + 1 + EnumChatFormatting.GRAY + " input busses.") + .addStructureInfo("Requires " + EnumChatFormatting.GOLD + 1 + EnumChatFormatting.GRAY + " ME output bus.") + .addStructureInfo("--------------------------------------------") .beginStructureBlock(33, 33, 33, false) - .toolTipFinisher(CommonValues.TEC_MARK_EM + " & " + AuthorColen.substring(8)); + .toolTipFinisher( AuthorColen.substring(8) + EnumChatFormatting.GRAY + "&" + CommonValues.TEC_MARK_EM); return tt; } @@ -335,10 +398,8 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl long hydrogen_stored = validFluidMap.get(Materials.Hydrogen.getGas(1)); long helium_stored = validFluidMap.get(Materials.Helium.getGas(1)); - System.out.println("TEST123VC" + recipe_0.getEUOutput()); - - if ((hydrogen_stored >= recipe_0.getHydrogenRequirement()) & (helium_stored >= recipe_0.getHeliumRequirement())) { - return processRecipe(recipe_0); + if ((hydrogen_stored >= overworld.getHydrogenRequirement()) & (helium_stored >= overworld.getHeliumRequirement())) { + return processRecipe(overworld); } return false; @@ -377,14 +438,12 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl double yield = recipeYieldCalculator(); - List<Pair<ItemStack, Long>> tmp_items_output = recipeObject.getOutputItems(); + List<Pair<ItemStack, Long>> tmp_items_output = new ArrayList<>(); FluidStack[] tmp_fluids_output = recipeObject.getOutputFluids().clone(); // Iterate over item output list and apply yield values. - for (int i = 0; i < tmp_items_output.size(); i++) { - Pair<ItemStack, Long> tmp_0 = tmp_items_output.get(i); - Pair<ItemStack, Long> tmp_1 = Pair.of(tmp_0.getLeft(), (long) (tmp_0.getRight() * yield)); - tmp_items_output.set(i, tmp_1); + for (Pair<ItemStack, Long> pair : recipeObject.getOutputItems()) { + tmp_items_output.add(Pair.of(pair.getLeft(), (long) (pair.getRight() * yield))); } // Iterate over fluid output list and apply yield values. @@ -402,9 +461,7 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl private double success_chance; - private void outputFailedChance() { - - } + private void outputFailedChance() {} @Override public void stopMachine() { @@ -424,14 +481,8 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl addEUToGlobalEnergyMap(user_uuid, euOutput); euOutput = 0; - int index = 0; - for (Pair<ItemStack, Long> item : output_items) { - // If you can output the item, increment the input hatch index. - try { - if (outputItemToQuantumChest(mOutputBusses.get(index), item.getLeft(), item.getRight())) { - index++; - } - } catch(Exception ignored) { break; } + for (Pair<ItemStack, Long> itemPair : output_items) { + outputItemToAENetwork(itemPair.getLeft(), itemPair.getRight()); } super.outputAfterRecipe_EM(); @@ -450,10 +501,8 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl super.onPreTick(aBaseMetaTileEntity, aTick); if (aTick == 1) { - user_uuid = String.valueOf(getBaseMetaTileEntity().getOwnerUuid()); user_name = getBaseMetaTileEntity().getOwnerName(); - strongCheckOrAddUser(user_uuid, user_name); } @@ -461,7 +510,7 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl pushComputation(); if (!recipeRunning) { - if (aTick % ticks_between_hatch_drain == 0) { + if ((aTick % ticks_between_hatch_drain) == 0) { drainFluidFromHatchesAndStoreInternally(); } } @@ -477,93 +526,36 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl private long max(long[] array) { long max = array[0]; - for (int i = 1; i < array.length; i++) { - if (array[i] > max) { - max = array[i]; - } + for (long i : array) { + if (i > max) { max = i; } } return max; } - private void addItemsToQuantumChest(IGregTechTileEntity quantum_chest, long amount) { - long stored_quantity = quantum_chest.getProgress(); - int max_inventory_size = quantum_chest.getMaxItemCount(); + // Will void if AE network is full. + private void outputItemToAENetwork(ItemStack item, long amount) { - if ((stored_quantity + amount) > max_inventory_size) { - quantum_chest.setItemCount(max_inventory_size); - } else { - quantum_chest.setItemCount((int) (amount + stored_quantity)); - } - } - - private int[] coordinate_calculator(GT_MetaTileEntity_Hatch output_bus) { - - IGregTechTileEntity tile_entity = output_bus.getBaseMetaTileEntity(); - - int x = tile_entity.getXCoord(); - int y = tile_entity.getYCoord(); - int z = tile_entity.getZCoord(); - - // Get direction that the output bus is currently facing. - switch (tile_entity.getFrontFacing()) { - case 0: - y -= 1; - case 1: - y += 1; - case 2: - z -= 1; - case 3: - z += 1; - case 4: - x -= 1; - case 5: - x += 1; + if ((item == null) || (amount <= 0)) { + return; } - int[] coordinates = new int[3]; - - coordinates[0] = x; - coordinates[1] = y; - coordinates[2] = z; - - return coordinates; - } - - private boolean outputItemToQuantumChest(GT_MetaTileEntity_Hatch_OutputBus output_bus, ItemStack item, long amount) { - - int[] coords = coordinate_calculator(output_bus); - int x = coords[0]; - int y = coords[1]; - int z = coords[2]; - - try { - // Get block in front of output bus. - IGregTechTileEntity quantum_chest = (IGregTechTileEntity) getBaseMetaTileEntity().getTileEntity(x, y, z); - - // Slot 0 = Top input slot of quantum chest. - // Slot 1 = Bottom output slot of quantum chest. - // Slot 2 = Stored item slot. - ItemStack quantum_chest_stored_item = quantum_chest.getStackInSlot(2); - - // Adjust sizes so no extra items from quantum chest nonsense. - amount = amount - 64; - item.stackSize = 64; - - // Check if chest contains item already. If not, add it. - if (quantum_chest_stored_item == null) { - quantum_chest.setInventorySlotContents(0, item); - addItemsToQuantumChest(quantum_chest, amount); - return true; - } else if (quantum_chest_stored_item.isItemEqual(item)) { - addItemsToQuantumChest(quantum_chest, amount); - return true; + if (amount < Integer.MAX_VALUE) { + ItemStack tmpItem = item.copy(); + tmpItem.stackSize = (int) amount; + ((GT_MetaTileEntity_Hatch_OutputBus_ME) mOutputBusses.get(0)).store(tmpItem); + } else { + // For item stacks > Int max. + while (amount >= Integer.MAX_VALUE) { + ItemStack tmpItem = item.copy(); + tmpItem.stackSize = Integer.MAX_VALUE; + ((GT_MetaTileEntity_Hatch_OutputBus_ME) mOutputBusses.get(0)).store(tmpItem); + amount -= Integer.MAX_VALUE; } - } catch (Exception e) { - e.printStackTrace(); + ItemStack tmpItem = item.copy(); + tmpItem.stackSize = (int) amount; + ((GT_MetaTileEntity_Hatch_OutputBus_ME) mOutputBusses.get(0)).store(tmpItem); } - - return false; } @Override @@ -587,7 +579,6 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl @Override public void saveNBTData(NBTTagCompound aNBT) { - // Save the quantity of fluid stored inside the controller. validFluidMap.forEach((key, value) -> aNBT.setLong("stored." + key.getUnlocalizedName(), value)); @@ -601,7 +592,6 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl // Load the quantity of fluid stored inside the controller. validFluidMap.forEach((key, value) -> validFluidMap.put(key, aNBT.getLong("stored." + key.getUnlocalizedName()))); - recipeRunning = aNBT.getBoolean("eye_of_harmony_recipeRunning"); super.loadNBTData(aNBT); diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java index 8ca4844043..2cd77008fa 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java @@ -1,349 +1,349 @@ -package com.github.technus.tectech.thing.metaTileEntity.single;
-
-import com.github.technus.tectech.TecTech;
-import com.github.technus.tectech.loader.NetworkDispatcher;
-import com.github.technus.tectech.mechanics.spark.RendererMessage;
-import com.github.technus.tectech.mechanics.spark.ThaumSpark;
-import com.github.technus.tectech.mechanics.tesla.ITeslaConnectable;
-import com.github.technus.tectech.mechanics.tesla.ITeslaConnectableSimple;
-import com.github.technus.tectech.util.CommonValues;
-import com.github.technus.tectech.util.TT_Utility;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.MultimapBuilder;
-import com.gtnewhorizon.structurelib.util.Vec3Impl;
-import eu.usrv.yamcore.auxiliary.PlayerChatHelper;
-import gregtech.api.interfaces.ITexture;
-import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
-import gregtech.api.metatileentity.MetaTileEntity;
-import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicBatteryBuffer;
-import net.minecraft.entity.player.EntityPlayer;
-import net.minecraft.entity.player.EntityPlayerMP;
-import net.minecraft.nbt.NBTTagCompound;
-import net.minecraft.util.EnumChatFormatting;
-import org.apache.commons.lang3.ArrayUtils;
-import org.apache.commons.lang3.reflect.FieldUtils;
-
-import java.util.Arrays;
-import java.util.HashSet;
-
-import static com.github.technus.tectech.mechanics.tesla.ITeslaConnectable.TeslaUtil.*;
-import static com.github.technus.tectech.thing.metaTileEntity.Textures.*;
-import static com.github.technus.tectech.util.CommonValues.V;
-import static java.lang.Math.round;
-import static net.minecraft.util.StatCollector.translateToLocal;
-import static net.minecraft.util.StatCollector.translateToLocalFormatted;
-
-public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryBuffer implements ITeslaConnectable {
- //Interface fields
- private final Multimap<Integer, ITeslaConnectableSimple> teslaNodeMap = MultimapBuilder.treeKeys().linkedListValues().build();
- private final HashSet<ThaumSpark> sparkList = new HashSet<>();
- private int sparkCount = 10;
-
- private final static int transferRadiusMax = TecTech.configTecTech.TESLA_SINGLE_RANGE;//Default is 20
- private final static int perBlockLoss = TecTech.configTecTech.TESLA_SINGLE_LOSS_PER_BLOCK;//Default is 1
- private final static float overDriveLoss = TecTech.configTecTech.TESLA_SINGLE_LOSS_FACTOR_OVERDRIVE;//Default is 0.25F
- private final static int transferRadiusMin = 4;//Minimum user configurable
- private int transferRadius = transferRadiusMax;//Default transferRadius setting
-
- public boolean powerPassToggle = false;//Power Pass for public viewing
- private final static int histSteps = 20;//Hysteresis Resolution
- private int histSettingLow = 3;//Hysteresis Low Limit
- private int histSettingHigh = 15;//Hysteresis High Limit
- private final static int histLowLimit = 1;//How low can you configure it?
- private final static int histHighLimit = 19;//How high can you configure it?
- private float histLow = (float) histSettingLow / histSteps;//Power pass is disabled if power is under this fraction
- private float histHigh = (float) histSettingHigh / histSteps;//Power pass is enabled if power is over this fraction
-
- private final long outputVoltage = V[mTier];
- private boolean overdriveToggle = false;
-
- private String clientLocale = "en_US";
-
- public GT_MetaTileEntity_TeslaCoil(int aID, String aName, String aNameRegional, int aTier, int aSlotCount) {
- super(aID, aName, aNameRegional, aTier, "", aSlotCount);
- TT_Utility.setTier(aTier, this);
- }
-
- public GT_MetaTileEntity_TeslaCoil(String aName, int aTier, String aDescription, ITexture[][][] aTextures, int aSlotCount) {
- super(aName, aTier, aDescription, aTextures, aSlotCount);
- }
-
- @Override
- public String[] getDescription() {
- String[] jargon = new String[]{
- CommonValues.BASS_MARK,
- translateToLocal("gt.blockmachines.machine.tt.tesla.desc.0"),//Your Tesla I/O machine of choice
- EnumChatFormatting.AQUA + translateToLocal("gt.blockmachines.machine.tt.tesla.desc.1")//Lightning stoves for the rich
- };
- String[] sDesc = super.getDescription();
- sDesc = Arrays.copyOfRange(sDesc, 1, sDesc.length);//Removes first element from array
- return ArrayUtils.addAll(jargon, sDesc);
- }
-
- @Override
- public boolean onSolderingToolRightClick(byte aSide, byte aWrenchingSide, EntityPlayer aPlayer, float aX, float aY, float aZ) {
- if (overdriveToggle) {
- overdriveToggle = false;
- PlayerChatHelper.SendInfo(aPlayer, translateToLocalFormatted("tt.keyphrase.Overdrive_disengaged", clientLocale));
- } else {
- overdriveToggle = true;
- PlayerChatHelper.SendInfo(aPlayer, translateToLocalFormatted("tt.keyphrase.Overdrive_engaged", clientLocale));
- }
- return true;
- }
-
- @Override
- public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) {
- if (aPlayer.isSneaking()) {
- if (histSettingHigh < histHighLimit) {
- histSettingHigh++;
- } else {
- histSettingHigh = histSettingLow + 1;
- }
- histHigh = (float) histSettingHigh / histSteps;
- PlayerChatHelper.SendInfo(aPlayer, translateToLocalFormatted("tt.keyphrase.Hysteresis_high_set_to", clientLocale) + " " + round(histHigh * 100F) + "%");
- } else {
- if (histSettingLow > histLowLimit) {
- histSettingLow--;
- } else {
- histSettingLow = histSettingHigh - 1;
- }
- histLow = (float) histSettingLow / histSteps;
- PlayerChatHelper.SendInfo(aPlayer, translateToLocalFormatted("tt.keyphrase.Hysteresis_low_set_to", clientLocale) + " " + round(histLow * 100F) + "%");
- }
- }
-
- @Override
- public boolean onWireCutterRightClick(byte aSide, byte aWrenchingSide, EntityPlayer aPlayer, float aX, float aY, float aZ) {
- if (aPlayer.isSneaking()) {
- if (transferRadius > transferRadiusMin) {
- transferRadius--;
- }
- } else {
- if (transferRadius < transferRadiusMax) {
- transferRadius++;
- }
- }
- PlayerChatHelper.SendInfo(aPlayer, translateToLocalFormatted("tt.keyphrase.Tesla_radius_set_to", clientLocale) + " " + transferRadius + "m");
- return false;
- }
-
- // Cheeky skrub stuff to get machine to switch powerPass on soft mallet
- @Override
- public boolean hasAlternativeModeText() {
- return true;
- }
-
- @Override
- public String getAlternativeModeText() {
- //Hysteresis based ePowerPass Config
- long energyMax = getStoredEnergy()[1];
- long energyStored = getStoredEnergy()[0];
- float energyFrac = (float) energyStored / energyMax;
-
- //ePowerPass hist toggle
- if (energyFrac > histHigh) {
- powerPassToggle = true;
- } else if (energyFrac < histLow) {
- powerPassToggle = false;
- } else {
- powerPassToggle = !powerPassToggle;
- }
-
- //And after this cheeky-ness, toss the string XD
- return powerPassToggle ? translateToLocalFormatted("tt.keyphrase.Sending_power", clientLocale) + "!" : translateToLocalFormatted("tt.keyphrase.Receiving_power", clientLocale) + "!";
- }
-
- @Override
- public boolean isFacingValid(byte aSide) {
- return aSide != 1;
- }//Prevents output at the top side
-
- @Override
- public ITexture[][][] getTextureSet(ITexture[] aTextures) {
- ITexture[][][] rTextures = new ITexture[3][17][];
- for (byte i = -1; i < 16; ++i) {
- rTextures[0][i + 1] = new ITexture[]{MACHINE_CASINGS_TT[this.mTier][i + 1]};
- rTextures[1][i + 1] = new ITexture[]{MACHINE_CASINGS_TT[this.mTier][i + 1], TESLA_TRANSCEIVER_TOP_BA};
- rTextures[2][i + 1] = new ITexture[]{MACHINE_CASINGS_TT[this.mTier][i + 1], this.mInventory.length == 16 ? OVERLAYS_ENERGY_OUT_POWER_TT[this.mTier] : (this.mInventory.length > 4 ? OVERLAYS_ENERGY_OUT_MULTI_TT[this.mTier] : OVERLAYS_ENERGY_OUT_TT[this.mTier])};
- }
- return rTextures;
- }
-
- @Override
- public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) {
- return this.mTextures[aSide == aFacing ? 2 : aSide == 1 ? 1 : 0][aColorIndex + 1];
- }
-
- @Override
- public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {
- return new GT_MetaTileEntity_TeslaCoil(mName, mTier, mDescription, mTextures, mInventory.length);
- }
-
- @Override
- public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) {
- super.onFirstTick(aBaseMetaTileEntity);
- if (!aBaseMetaTileEntity.isClientSide()) {
- teslaSimpleNodeSetAdd(this);
- generateTeslaNodeMap(this);
- }
- }
-
- @Override
- public void onRemoval() {
- super.onRemoval();
- if (!this.getBaseMetaTileEntity().isClientSide()) {
- teslaSimpleNodeSetRemove(this);
- }
- }
-
- @Override
- public void loadNBTData(NBTTagCompound aNBT) {
- super.loadNBTData(aNBT);
- teslaSimpleNodeSetAdd(this);
- }
-
- @Override
- public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
- super.onPostTick(aBaseMetaTileEntity, aTick);
- if (aBaseMetaTileEntity.isClientSide()) {
- return;
- }
-
- //Hysteresis based ePowerPass Config
- long energyMax = getStoredEnergy()[1];
- long energyStored = getStoredEnergy()[0];
- float energyFrac = (float) energyStored / energyMax;
-
- //ePowerPass hist toggle
- if (!powerPassToggle && energyFrac > histHigh) {
- powerPassToggle = true;
- } else if (powerPassToggle && energyFrac < histLow) {
- powerPassToggle = false;
- }
-
- //Send Power
- powerTeslaNodeMap(this);
-
- //TODO Encapsulate the spark sender
- sparkCount--;
- if (sparkCount == 0){
- sparkCount = 10;
- if(!sparkList.isEmpty()){
- NetworkDispatcher.INSTANCE.sendToAllAround(new RendererMessage.RendererData(sparkList),
- aBaseMetaTileEntity.getWorld().provider.dimensionId,
- aBaseMetaTileEntity.getXCoord(),
- aBaseMetaTileEntity.getYCoord(),
- aBaseMetaTileEntity.getZCoord(),
- 256);
- sparkList.clear();
- }
- }
- }
-
- @Override
- public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) {
- if (aBaseMetaTileEntity.isServerSide()) {
- try {
- EntityPlayerMP player = (EntityPlayerMP) aPlayer;
- clientLocale = (String) FieldUtils.readField(player, "translator", true);
- } catch (Exception e) {
- clientLocale = "en_US";
- }
- aBaseMetaTileEntity.openGUI(aPlayer);
- }
- return true;
- }
-
- @Override
- public byte getTeslaReceptionCapability() {
- return 1;
- }
-
- @Override
- public float getTeslaReceptionCoefficient() {
- return 1;
- }
-
- @Override
- public Multimap<Integer, ITeslaConnectableSimple> getTeslaNodeMap() {
- return teslaNodeMap;
- }
-
- @Override
- public HashSet<ThaumSpark> getSparkList() {
- return sparkList;
- }
-
- @Override
- public byte getTeslaTransmissionCapability() {
- return 2;
- }
-
- @Override
- public int getTeslaTransmissionRange() {
- return transferRadius;
- }
-
- @Override
- public boolean isOverdriveEnabled() {
- return overdriveToggle;
- }
-
- @Override
- public int getTeslaEnergyLossPerBlock() {
- return perBlockLoss;
- }
-
- @Override
- public float getTeslaOverdriveLossCoefficient() {
- return overDriveLoss;
- }
-
- @Override
- public long getTeslaOutputVoltage() {
- return outputVoltage;
- }
-
- @Override
- public long getTeslaOutputCurrent() {
- return mBatteryCount;
- }
-
- @Override
- public boolean teslaDrainEnergy(long teslaVoltageDrained) {
- if (getEUVar() < teslaVoltageDrained) {
- return false;
- }
-
- setEUVar(getEUVar() - teslaVoltageDrained);
- return true;
- }
-
- @Override
- public boolean isTeslaReadyToReceive() {
- return !this.powerPassToggle;
- }
-
- @Override
- public long getTeslaStoredEnergy() {
- return getEUVar();
- }
-
- @Override
- public Vec3Impl getTeslaPosition() {
- return new Vec3Impl(this.getBaseMetaTileEntity().getXCoord(),
- this.getBaseMetaTileEntity().getYCoord(),
- this.getBaseMetaTileEntity().getZCoord());
- }
-
- @Override
- public Integer getTeslaDimension() {
- return this.getBaseMetaTileEntity().getWorld().provider.dimensionId;
- }
-
- @Override
- public boolean teslaInjectEnergy(long teslaVoltageInjected) {
- return this.getBaseMetaTileEntity().injectEnergyUnits((byte) 1, teslaVoltageInjected, 1L) > 0L;
- }
-}
+package com.github.technus.tectech.thing.metaTileEntity.single; + +import com.github.technus.tectech.TecTech; +import com.github.technus.tectech.loader.NetworkDispatcher; +import com.github.technus.tectech.mechanics.spark.RendererMessage; +import com.github.technus.tectech.mechanics.spark.ThaumSpark; +import com.github.technus.tectech.mechanics.tesla.ITeslaConnectable; +import com.github.technus.tectech.mechanics.tesla.ITeslaConnectableSimple; +import com.github.technus.tectech.util.CommonValues; +import com.github.technus.tectech.util.TT_Utility; +import com.google.common.collect.Multimap; +import com.google.common.collect.MultimapBuilder; +import com.gtnewhorizon.structurelib.util.Vec3Impl; +import eu.usrv.yamcore.auxiliary.PlayerChatHelper; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicBatteryBuffer; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.reflect.FieldUtils; + +import java.util.Arrays; +import java.util.HashSet; + +import static com.github.technus.tectech.mechanics.tesla.ITeslaConnectable.TeslaUtil.*; +import static com.github.technus.tectech.thing.metaTileEntity.Textures.*; +import static com.github.technus.tectech.util.CommonValues.V; +import static java.lang.Math.round; +import static net.minecraft.util.StatCollector.translateToLocal; +import static net.minecraft.util.StatCollector.translateToLocalFormatted; + +public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryBuffer implements ITeslaConnectable { + //Interface fields + private final Multimap<Integer, ITeslaConnectableSimple> teslaNodeMap = MultimapBuilder.treeKeys().linkedListValues().build(); + private final HashSet<ThaumSpark> sparkList = new HashSet<>(); + private int sparkCount = 10; + + private final static int transferRadiusMax = TecTech.configTecTech.TESLA_SINGLE_RANGE;//Default is 20 + private final static int perBlockLoss = TecTech.configTecTech.TESLA_SINGLE_LOSS_PER_BLOCK;//Default is 1 + private final static float overDriveLoss = TecTech.configTecTech.TESLA_SINGLE_LOSS_FACTOR_OVERDRIVE;//Default is 0.25F + private final static int transferRadiusMin = 4;//Minimum user configurable + private int transferRadius = transferRadiusMax;//Default transferRadius setting + + public boolean powerPassToggle = false;//Power Pass for public viewing + private final static int histSteps = 20;//Hysteresis Resolution + private int histSettingLow = 3;//Hysteresis Low Limit + private int histSettingHigh = 15;//Hysteresis High Limit + private final static int histLowLimit = 1;//How low can you configure it? + private final static int histHighLimit = 19;//How high can you configure it? + private float histLow = (float) histSettingLow / histSteps;//Power pass is disabled if power is under this fraction + private float histHigh = (float) histSettingHigh / histSteps;//Power pass is enabled if power is over this fraction + + private final long outputVoltage = V[mTier]; + private boolean overdriveToggle = false; + + private String clientLocale = "en_US"; + + public GT_MetaTileEntity_TeslaCoil(int aID, String aName, String aNameRegional, int aTier, int aSlotCount) { + super(aID, aName, aNameRegional, aTier, "", aSlotCount); + TT_Utility.setTier(aTier, this); + } + + public GT_MetaTileEntity_TeslaCoil(String aName, int aTier, String aDescription, ITexture[][][] aTextures, int aSlotCount) { + super(aName, aTier, aDescription, aTextures, aSlotCount); + } + + @Override + public String[] getDescription() { + String[] jargon = new String[]{ + CommonValues.BASS_MARK, + translateToLocal("gt.blockmachines.machine.tt.tesla.desc.0"),//Your Tesla I/O machine of choice + EnumChatFormatting.AQUA + translateToLocal("gt.blockmachines.machine.tt.tesla.desc.1")//Lightning stoves for the rich + }; + String[] sDesc = super.getDescription(); + sDesc = Arrays.copyOfRange(sDesc, 1, sDesc.length);//Removes first element from array + return ArrayUtils.addAll(jargon, sDesc); + } + + @Override + public boolean onSolderingToolRightClick(byte aSide, byte aWrenchingSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (overdriveToggle) { + overdriveToggle = false; + PlayerChatHelper.SendInfo(aPlayer, translateToLocalFormatted("tt.keyphrase.Overdrive_disengaged", clientLocale)); + } else { + overdriveToggle = true; + PlayerChatHelper.SendInfo(aPlayer, translateToLocalFormatted("tt.keyphrase.Overdrive_engaged", clientLocale)); + } + return true; + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (aPlayer.isSneaking()) { + if (histSettingHigh < histHighLimit) { + histSettingHigh++; + } else { + histSettingHigh = histSettingLow + 1; + } + histHigh = (float) histSettingHigh / histSteps; + PlayerChatHelper.SendInfo(aPlayer, translateToLocalFormatted("tt.keyphrase.Hysteresis_high_set_to", clientLocale) + " " + round(histHigh * 100F) + "%"); + } else { + if (histSettingLow > histLowLimit) { + histSettingLow--; + } else { + histSettingLow = histSettingHigh - 1; + } + histLow = (float) histSettingLow / histSteps; + PlayerChatHelper.SendInfo(aPlayer, translateToLocalFormatted("tt.keyphrase.Hysteresis_low_set_to", clientLocale) + " " + round(histLow * 100F) + "%"); + } + } + + @Override + public boolean onWireCutterRightClick(byte aSide, byte aWrenchingSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (aPlayer.isSneaking()) { + if (transferRadius > transferRadiusMin) { + transferRadius--; + } + } else { + if (transferRadius < transferRadiusMax) { + transferRadius++; + } + } + PlayerChatHelper.SendInfo(aPlayer, translateToLocalFormatted("tt.keyphrase.Tesla_radius_set_to", clientLocale) + " " + transferRadius + "m"); + return false; + } + + // Cheeky skrub stuff to get machine to switch powerPass on soft mallet + @Override + public boolean hasAlternativeModeText() { + return true; + } + + @Override + public String getAlternativeModeText() { + //Hysteresis based ePowerPass Config + long energyMax = getStoredEnergy()[1]; + long energyStored = getStoredEnergy()[0]; + float energyFrac = (float) energyStored / energyMax; + + //ePowerPass hist toggle + if (energyFrac > histHigh) { + powerPassToggle = true; + } else if (energyFrac < histLow) { + powerPassToggle = false; + } else { + powerPassToggle = !powerPassToggle; + } + + //And after this cheeky-ness, toss the string XD + return powerPassToggle ? translateToLocalFormatted("tt.keyphrase.Sending_power", clientLocale) + "!" : translateToLocalFormatted("tt.keyphrase.Receiving_power", clientLocale) + "!"; + } + + @Override + public boolean isFacingValid(byte aSide) { + return aSide != 1; + }//Prevents output at the top side + + @Override + public ITexture[][][] getTextureSet(ITexture[] aTextures) { + ITexture[][][] rTextures = new ITexture[3][17][]; + for (byte i = -1; i < 16; ++i) { + rTextures[0][i + 1] = new ITexture[]{MACHINE_CASINGS_TT[this.mTier][i + 1]}; + rTextures[1][i + 1] = new ITexture[]{MACHINE_CASINGS_TT[this.mTier][i + 1], TESLA_TRANSCEIVER_TOP_BA}; + rTextures[2][i + 1] = new ITexture[]{MACHINE_CASINGS_TT[this.mTier][i + 1], this.mInventory.length == 16 ? OVERLAYS_ENERGY_OUT_POWER_TT[this.mTier] : (this.mInventory.length > 4 ? OVERLAYS_ENERGY_OUT_MULTI_TT[this.mTier] : OVERLAYS_ENERGY_OUT_TT[this.mTier])}; + } + return rTextures; + } + + @Override + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { + return this.mTextures[aSide == aFacing ? 2 : aSide == 1 ? 1 : 0][aColorIndex + 1]; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_TeslaCoil(mName, mTier, mDescription, mTextures, mInventory.length); + } + + @Override + public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { + super.onFirstTick(aBaseMetaTileEntity); + if (!aBaseMetaTileEntity.isClientSide()) { + teslaSimpleNodeSetAdd(this); + generateTeslaNodeMap(this); + } + } + + @Override + public void onRemoval() { + super.onRemoval(); + if (!this.getBaseMetaTileEntity().isClientSide()) { + teslaSimpleNodeSetRemove(this); + } + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + teslaSimpleNodeSetAdd(this); + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (aBaseMetaTileEntity.isClientSide()) { + return; + } + + //Hysteresis based ePowerPass Config + long energyMax = getStoredEnergy()[1]; + long energyStored = getStoredEnergy()[0]; + float energyFrac = (float) energyStored / energyMax; + + //ePowerPass hist toggle + if (!powerPassToggle && energyFrac > histHigh) { + powerPassToggle = true; + } else if (powerPassToggle && energyFrac < histLow) { + powerPassToggle = false; + } + + //Send Power + powerTeslaNodeMap(this); + + //TODO Encapsulate the spark sender + sparkCount--; + if (sparkCount == 0){ + sparkCount = 10; + if(!sparkList.isEmpty()){ + NetworkDispatcher.INSTANCE.sendToAllAround(new RendererMessage.RendererData(sparkList), + aBaseMetaTileEntity.getWorld().provider.dimensionId, + aBaseMetaTileEntity.getXCoord(), + aBaseMetaTileEntity.getYCoord(), + aBaseMetaTileEntity.getZCoord(), + 256); + sparkList.clear(); + } + } + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isServerSide()) { + try { + EntityPlayerMP player = (EntityPlayerMP) aPlayer; + clientLocale = (String) FieldUtils.readField(player, "translator", true); + } catch (Exception e) { + clientLocale = "en_US"; + } + aBaseMetaTileEntity.openGUI(aPlayer); + } + return true; + } + + @Override + public byte getTeslaReceptionCapability() { + return 1; + } + + @Override + public float getTeslaReceptionCoefficient() { + return 1; + } + + @Override + public Multimap<Integer, ITeslaConnectableSimple> getTeslaNodeMap() { + return teslaNodeMap; + } + + @Override + public HashSet<ThaumSpark> getSparkList() { + return sparkList; + } + + @Override + public byte getTeslaTransmissionCapability() { + return 2; + } + + @Override + public int getTeslaTransmissionRange() { + return transferRadius; + } + + @Override + public boolean isOverdriveEnabled() { + return overdriveToggle; + } + + @Override + public int getTeslaEnergyLossPerBlock() { + return perBlockLoss; + } + + @Override + public float getTeslaOverdriveLossCoefficient() { + return overDriveLoss; + } + + @Override + public long getTeslaOutputVoltage() { + return outputVoltage; + } + + @Override + public long getTeslaOutputCurrent() { + return mBatteryCount; + } + + @Override + public boolean teslaDrainEnergy(long teslaVoltageDrained) { + if (getEUVar() < teslaVoltageDrained) { + return false; + } + + setEUVar(getEUVar() - teslaVoltageDrained); + return true; + } + + @Override + public boolean isTeslaReadyToReceive() { + return !this.powerPassToggle; + } + + @Override + public long getTeslaStoredEnergy() { + return getEUVar(); + } + + @Override + public Vec3Impl getTeslaPosition() { + return new Vec3Impl(this.getBaseMetaTileEntity().getXCoord(), + this.getBaseMetaTileEntity().getYCoord(), + this.getBaseMetaTileEntity().getZCoord()); + } + + @Override + public Integer getTeslaDimension() { + return this.getBaseMetaTileEntity().getWorld().provider.dimensionId; + } + + @Override + public boolean teslaInjectEnergy(long teslaVoltageInjected) { + return this.getBaseMetaTileEntity().injectEnergyUnits((byte) 1, teslaVoltageInjected, 1L) > 0L; + } +} |