Skip to content
This repository has been archived by the owner on May 25, 2024. It is now read-only.

Commit

Permalink
Add UXV Component Assemblyline functionality (#214)
Browse files Browse the repository at this point in the history
* reduce recipe size for uxv parts

* stop mhdcsm from being compacted

* first attempt at large stacks

* Working mhdcsm conversion

* remove divisor

* add casing recipe

* spotless

* remove wildcard import

* remove unnecessary parentheses

* no need for pairs

* convert 64+ stacksize materials

* spotless

* add comment

* address reviews

* typo

* small uxv casing texture update
  • Loading branch information
GDCloudstrike authored Oct 11, 2023
1 parent 4a204b9 commit 33c59c4
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
import com.github.technus.tectech.recipe.TT_recipeAdder;

import cpw.mods.fml.common.registry.GameRegistry;
import goodgenerator.items.MyMaterial;
import goodgenerator.util.StackUtils;
import gregtech.api.enums.GT_Values;
import gregtech.api.enums.ItemList;
import gregtech.api.enums.Materials;
import gregtech.api.enums.MaterialsUEVplus;
import gregtech.api.enums.OrePrefixes;
import gregtech.api.enums.TierEU;
import gregtech.api.util.GT_OreDictUnificator;
import gregtech.api.util.GT_Utility;
import gtPlusPlus.core.recipe.common.CI;
Expand Down Expand Up @@ -299,6 +301,43 @@ private static void generateCasingRecipes() {
Compassline_Casing_UMV.get(1),
50 * 20,
32000000);
// uxv 13
t++;
TT_recipeAdder.addResearchableAssemblylineRecipe(
Compassline_Casing_UMV.get(1),
375 << (t - 2),
1 << (t - 3),
128_000_000,
1,
new Object[] { GT_OreDictUnificator
.get(OrePrefixes.frameGt, MaterialsUEVplus.MagnetohydrodynamicallyConstrainedStarMatter, 1),
GT_OreDictUnificator.get(
OrePrefixes.plateDense,
MaterialsUEVplus.MagnetohydrodynamicallyConstrainedStarMatter,
3),
MyMaterial.shirabon.get(OrePrefixes.plateDense, 3),
ComponentType.Robot_Arm.getComponent(t).get(8),
ComponentType.Electric_Piston.getComponent(t).get(10),
ComponentType.Electric_Motor.getComponent(t).get(16),
GT_OreDictUnificator.get(
OrePrefixes.gearGt,
MaterialsUEVplus.MagnetohydrodynamicallyConstrainedStarMatter,
2),
MyMaterial.shirabon.get(OrePrefixes.gearGt, 2),
GT_OreDictUnificator.get(
OrePrefixes.gearGtSmall,
MaterialsUEVplus.MagnetohydrodynamicallyConstrainedStarMatter,
8),
MyMaterial.shirabon.get(OrePrefixes.gearGtSmall, 8),
GT_OreDictUnificator.get(OrePrefixes.wireGt04, Materials.Infinity, 4),
GT_OreDictUnificator.get(OrePrefixes.wireGt04, MaterialsUEVplus.SpaceTime, 4),
getALCircuit(t, 8), getALCircuit(t - 1, 16) },
new FluidStack[] { new FluidStack(sold, 144 * t * 4),
MaterialsUEVplus.BlackDwarfMatter.getMolten(144 * t * 2),
MaterialsUEVplus.Eternity.getMolten(144 * t), Materials.Lubricant.getFluid(1000 * (t - 2)) },
Compassline_Casing_UXV.get(1),
50 * 20,
(int) TierEU.RECIPE_UMV);
}

private static int getV(int tier) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package goodgenerator.loader;

import static goodgenerator.util.StackUtils.*;
import static goodgenerator.util.StackUtils.getTotalItems;
import static goodgenerator.util.StackUtils.mergeStacks;
import static goodgenerator.util.StackUtils.multiplyAndSplitIntoStacks;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -22,6 +24,7 @@
import gregtech.api.enums.GT_Values;
import gregtech.api.enums.ItemList;
import gregtech.api.enums.Materials;
import gregtech.api.enums.MaterialsUEVplus;
import gregtech.api.enums.OrePrefixes;
import gregtech.api.objects.ItemData;
import gregtech.api.util.GT_OreDictUnificator;
Expand All @@ -34,15 +37,18 @@ public class ComponentAssemblyLineRecipeLoader {
private static final String[] compPrefixes = { "Electric_Motor_", "Electric_Piston_", "Electric_Pump_",
"Robot_Arm_", "Conveyor_Module_", "Emitter_", "Sensor_", "Field_Generator_", };
private static final String[] blacklistedDictPrefixes = { "circuit" };
private static final String[] softBlacklistedDictPrefixes = { "Any", "crafting" };
private static final String[] softBlacklistedDictPrefixes = { "Any", "crafting", "nanite" };
private static final String moltenMHDCSM = "molten.magnetohydrodynamicallyconstrainedstarmatter";

private static LinkedHashMap<List<GT_Recipe>, Pair<ItemList, Integer>> allAssemblerRecipes;
private static LinkedHashMap<List<GT_Recipe.GT_Recipe_AssemblyLine>, Pair<ItemList, Integer>> allAsslineRecipes;

private static final HashMap<OrePrefixes, Double> magnetoConversionMultipliers = new HashMap<>();
private static final HashMap<OrePrefixes, OrePrefixes> conversion = new HashMap<>();

private static final int INPUT_MULTIPLIER = 48;
private static final int OUTPUT_MULTIPLIER = 64;
private static final int FLUID_CONVERSION_STACKSIZE_THRESHOLD = 64;

public static void run() {
ComponentAssemblyLineMiscRecipes.run();
Expand All @@ -58,6 +64,20 @@ public static void run() {
conversion.put(OrePrefixes.foil, OrePrefixes.plate);
conversion.put(OrePrefixes.stick, OrePrefixes.stickLong);
conversion.put(OrePrefixes.gearGtSmall, OrePrefixes.gearGt);
magnetoConversionMultipliers.put(OrePrefixes.frameGt, 1.0);
magnetoConversionMultipliers.put(OrePrefixes.plate, 1.0);
magnetoConversionMultipliers.put(OrePrefixes.plateDense, 3.0);
magnetoConversionMultipliers.put(OrePrefixes.stick, 1.0 / 2.0);
magnetoConversionMultipliers.put(OrePrefixes.round, 1.0 / 8.0);
magnetoConversionMultipliers.put(OrePrefixes.bolt, 1.0 / 8.0);
magnetoConversionMultipliers.put(OrePrefixes.screw, 1.0 / 8.0);
magnetoConversionMultipliers.put(OrePrefixes.ring, 1.0 / 4.0);
magnetoConversionMultipliers.put(OrePrefixes.foil, 1.0 / 8.0);
magnetoConversionMultipliers.put(OrePrefixes.gearGtSmall, 1.0);
magnetoConversionMultipliers.put(OrePrefixes.rotor, 2.0);
magnetoConversionMultipliers.put(OrePrefixes.stickLong, 1.0);
magnetoConversionMultipliers.put(OrePrefixes.gearGt, 2.0);
magnetoConversionMultipliers.put(OrePrefixes.wireFine, 1.0 / 8.0);
findAllRecipes();
generateAssemblerRecipes();
generateAsslineRecipes();
Expand All @@ -82,10 +102,12 @@ private static void generateAssemblerRecipes() {
fixedFluids.add(currFluid);
}

fixedInputs = compactItems(fixedInputs, info.getRight());
replaceIntoFluids(fixedInputs, fixedFluids, 64);
int tier = info.getRight();
int energy = (int) Math.min(Integer.MAX_VALUE - 7, GT_Values.VP[tier - 1]);
MyRecipeAdder.instance.addComponentAssemblyLineRecipe(
compactItems(fixedInputs, info.getRight()).toArray(new ItemStack[0]),
fixedInputs.toArray(new ItemStack[0]),
fixedFluids.toArray(new FluidStack[0]),
info.getLeft().get(OUTPUT_MULTIPLIER),
recipe.mDuration * INPUT_MULTIPLIER,
Expand Down Expand Up @@ -116,7 +138,7 @@ private static void generateAsslineRecipes() {
// Multiplies the original fluid inputs
for (int j = 0; j < recipe.mFluidInputs.length; j++) {
FluidStack currFluid = recipe.mFluidInputs[j].copy();
currFluid.amount *= INPUT_MULTIPLIER;
currFluid.amount *= (double) INPUT_MULTIPLIER;
fixedFluids.add(currFluid);
}

Expand All @@ -139,11 +161,13 @@ private static void generateAsslineRecipes() {
}
}
fixedInputs = compactItems(fixedInputs, info.getRight());
replaceIntoFluids(fixedInputs, fixedFluids, 128);
replaceIntoFluids(fixedInputs, fixedFluids, FLUID_CONVERSION_STACKSIZE_THRESHOLD);
// If it overflows then it tries REALLY HARD to cram as much stuff into there.
if (fixedInputs.size() > (addProgrammedCircuit ? 8 : 9))
replaceIntoFluids(fixedInputs, fixedFluids, 32);
replaceIntoFluids(fixedInputs, fixedFluids, FLUID_CONVERSION_STACKSIZE_THRESHOLD / 2);
if (addProgrammedCircuit) fixedInputs.add(GT_Utility.getIntegratedCircuit(componentCircuit));

addEternityForMHDCSM(fixedFluids);
MyRecipeAdder.instance.addComponentAssemblyLineRecipe(
fixedInputs.toArray(new ItemStack[0]),
fixedFluids.toArray(new FluidStack[0]),
Expand Down Expand Up @@ -198,7 +222,7 @@ private static void replaceIntoFluids(List<ItemStack> inputs, List<FluidStack> f
}
}
if (!isConverted) {
newInputs.addAll(multiplyAndSplitIntoStacks(input, count));
newInputs.add(GT_Utility.copyAmountUnsafe(count, input));
}
}
inputs.clear();
Expand Down Expand Up @@ -274,8 +298,8 @@ private static String findBestPrefix(String oreDict) {

/**
* Transforms each {@code ItemStack}, if possible, into a more compact form. For example, a stack of 16 1x cables,
* when passed into the {@code items} array, will be converted into a single 16x cable. Also handles GraviStar
* conversion.
* when passed into the {@code items} array, will be converted into a single 16x cable. Also handles GraviStar and
* neutronium nanite conversion.
*/
private static ArrayList<ItemStack> compactItems(List<ItemStack> items, int tier) {
ArrayList<ItemStack> stacks = new ArrayList<>();
Expand All @@ -290,6 +314,12 @@ private static ArrayList<ItemStack> compactItems(List<ItemStack> items, int tier
if (dict.startsWith("circuit")) {
stacks.addAll(getWrappedCircuits(itemstack, totalItems, dict));
isCompacted = true;
break;
}
if (dict.contains("Magneto")) {
stacks.addAll(getMagnetoConversion(itemstack, totalItems));
isCompacted = true;
break;
}
}

Expand All @@ -304,6 +334,14 @@ private static ArrayList<ItemStack> compactItems(List<ItemStack> items, int tier
stacks.addAll(multiplyAndSplitIntoStacks(ItemList.NuclearStar.get(1), totalItems / 16));
isCompacted = true;
}
if (GT_Utility
.areStacksEqual(itemstack, GT_OreDictUnificator.get(OrePrefixes.nanite, Materials.Neutronium, 1))) {
stacks.addAll(
multiplyAndSplitIntoStacks(
GT_OreDictUnificator.get(OrePrefixes.nanite, Materials.Gold, 1),
totalItems / 16));
isCompacted = true;
}
if (!isCompacted) stacks.addAll(multiplyAndSplitIntoStacks(itemstack, totalItems));
}
stacks = mergeStacks(stacks);
Expand All @@ -327,7 +365,7 @@ private static void findAllRecipes() {
allAssemblerRecipes = new LinkedHashMap<>();
allAsslineRecipes = new LinkedHashMap<>();
for (String compPrefix : compPrefixes) {
for (int t = 1; t <= 12; t++) {
for (int t = 1; t <= 13; t++) {
String vName = GT_Values.VN[t];
ItemList currentComponent = ItemList.valueOf(compPrefix + vName);
if (currentComponent.hasBeenSet()) {
Expand Down Expand Up @@ -363,4 +401,44 @@ private static List<ItemStack> getWrappedCircuits(ItemStack item, int total, Str

return stacks;
}

private static List<ItemStack> getMagnetoConversion(ItemStack item, int total) {
ArrayList<ItemStack> stacks = new ArrayList<>();
ItemData data = GT_OreDictUnificator.getAssociation(item);
if (data == null) {
return stacks;
}
if (total >= FLUID_CONVERSION_STACKSIZE_THRESHOLD) {
double multiplier = magnetoConversionMultipliers.get(data.mPrefix);
stacks.addAll(
getWrappedCircuits(
GT_OreDictUnificator.get(OrePrefixes.circuit, Materials.Infinite, 1),
(int) (total * multiplier),
"circuitInfinite"));
}
stacks.addAll(multiplyAndSplitIntoStacks(item, total));
return stacks;
}

private static void addEternityForMHDCSM(ArrayList<FluidStack> fluidInputs) {
boolean eternity = false;
boolean mhdcsm = false;
int mhdcsmAmount = 0;

for (FluidStack fluidstack : fluidInputs) {
if (fluidstack.getFluid().equals(FluidRegistry.getFluid(moltenMHDCSM))) {
mhdcsm = true;
mhdcsmAmount = fluidstack.amount;
}
if (fluidstack.getFluid().equals(FluidRegistry.getFluid("molten.eternity"))) {
eternity = true;
}
}

if (mhdcsm && !eternity) {
// 576 * 48 is substracted because uxv parts have 576L mhdcsm fluid (not solid, so no EIC conversion needed)
// in their assline recipes and each CoAl recipe has 48x recipe inputs
fluidInputs.add(MaterialsUEVplus.Eternity.getMolten(mhdcsmAmount - 576 * 48));
}
}
}
13 changes: 1 addition & 12 deletions src/main/java/goodgenerator/util/StackUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,16 @@ public static ArrayList<ItemStack> mergeStacks(List<ItemStack> stacks) {
ArrayList<ItemStack> output = new ArrayList<>();
for (int index = 0; index < stacks.size(); index++) {
ItemStack i = stacks.get(index);
boolean hasDupe = false;
int newSize = i.stackSize;
for (int j = index + 1; j < stacks.size(); j++) {
ItemStack is2 = stacks.get(j);
if (GT_Utility.areStacksEqual(i, is2)) {
hasDupe = true;
newSize += is2.stackSize;
stacks.remove(j);
j--;
}
}
if (hasDupe) {
if (newSize >= 64) {
for (int k = 0; k < newSize / 64; k++) {
output.add(GT_Utility.copyAmount(64, i));
}
}
if (newSize % 64 > 0) {
output.add(GT_Utility.copyAmount(newSize > 64 ? newSize % 64 : newSize, i));
}
} else output.add(i);
output.add(GT_Utility.copyAmountUnsafe(newSize, i));
}
return output;
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 33c59c4

Please sign in to comment.