Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/main/java/gregtech/api/GTValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class GTValues {
/**
* The Voltage Tiers adjusted for cable loss, divided by 2.
*/
public static final int[] VHA = { 7, 16, 60, 240, 960, 3840, 15360, 61440, 245760, 983040, 3932160, 15728640,
public static final int[] VHA = { 4, 16, 60, 240, 960, 3840, 15360, 61440, 245760, 983040, 3932160, 15728640,
62914560, 251658240, 1006632960 };

/**
Expand All @@ -83,6 +83,13 @@ public class GTValues {
9007199254740992L, 36028797018963968L, 144115188075855872L, 576460752303423488L, 2305843009213693952L,
Long.MAX_VALUE };

public static final long[] VAOC = { 7, 30, 120, 480, 1920, 7680, 30720, 123880, 491520, 1966080, 7864320,
31457280, 125829120, 503316480, 2013265920, 8053063680L, 32212254720L, 128849018880L, 515396075520L,
2061584302080L, 8246337208320L, 32985348833280L, 131948427333120L, 527865581332480L, 2111062325297920L,
8444249301319680L, 33777097205278720L, 135108988821415880L, 540431751284459520L, 2161727821137838080L,
8646911284550352320L
};

public static final int ULV = 0;
public static final int LV = 1;
public static final int MV = 2;
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/gregtech/api/unification/material/Material.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gregtech.api.unification.material;

import gregtech.api.GTValues;
import gregtech.api.GregTechAPI;
import gregtech.api.fluids.FluidBuilder;
import gregtech.api.fluids.FluidState;
Expand Down Expand Up @@ -370,6 +371,26 @@ public int getBlastTemperature() {
return prop == null ? 0 : prop.getBlastTemperature();
}

@ZenGetter("workingTier")
public int getWorkingTier() {
return materialInfo.workingTier;
}

@ZenMethod
public void setWorkingTier(int workingTier) {
if (workingTier < 0) {
throw new IllegalArgumentException(
"Cannot set working tier for material " + materialInfo.resourceLocation + "to less than 0 (ULV)!");
}
if (workingTier > GTValues.MAX) {
throw new IllegalArgumentException(
"Cannot set working tier for material " + materialInfo.resourceLocation +
"to greater than 14 (MAX)!");

}
materialInfo.workingTier = workingTier;
}

public FluidStack getPlasma(int amount) {
return getFluid(FluidStorageKeys.PLASMA, amount);
}
Expand Down Expand Up @@ -1110,6 +1131,28 @@ public Builder addDefaultEnchant(Enchantment enchant, int level) {
return this;
}

/**
* Sets the tier for "working" recipes to require, such as extruding, bending, etc.
*
* @param tier The tier. Defaults to {@link GTValues#LV} if unset,
* though some recipes may still vary (such as Extruder recipes or Dense Plates).
*/
public Builder workingTier(int tier) {
if (tier < 0) {
throw new IllegalArgumentException(
"Cannot set working tier for material " + materialInfo.resourceLocation +
"to less than 0 (ULV)!");
}
if (tier > GTValues.MAX) {
throw new IllegalArgumentException(
"Cannot set working tier for material " + materialInfo.resourceLocation +
"to greater than 14 (MAX)!");

}
materialInfo.workingTier = tier;
return this;
}

public Material build() {
materialInfo.componentList = ImmutableList.copyOf(composition);
materialInfo.verifyInfo(properties, averageRGB);
Expand Down Expand Up @@ -1168,6 +1211,13 @@ private static class MaterialInfo {
*/
private Element element;

/**
* The tier for "working" recipes to require, such as extruding, bending, etc.
* <p>
* Default: {@link GTValues#LV}, though some recipes may still vary (such as Dense Plates being MV).
*/
private int workingTier = GTValues.LV;

private MaterialInfo(int metaItemSubId, @NotNull ResourceLocation resourceLocation) {
this.metaItemSubId = metaItemSubId;
String name = resourceLocation.getPath();
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/gregtech/api/util/GTUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -920,4 +920,43 @@ public double getAsDouble() {
public static int safeCastLongToInt(long v) {
return v > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) v;
}

/**
* Scales a proposed recipe voltage according to a provided Material working tier.
*
* @param voltage The suggested base voltage for the recipe.
* @param workingTier The voltage tier ({@link GTValues#V}) to conform this recipe to.
*
* @return The new recipe voltage.
*/
public static long scaleVoltage(long voltage, int workingTier) {
if (workingTier == GTValues.LV) {
// no action needed, as this is the default.
return voltage;
}

int tierLower = Math.max(0, workingTier - 1);
if (voltage > GTValues.V[tierLower]) {
// no action needed, this recipe is already scaled accordingly.
return voltage;
}

// Multiplying very low voltages (less than 16 EU/t) with a formula like below can cause undesirably high
// EU/t. For example, 2 EU/t scaled to MV would multiply all the way to 128 EU/t before being above LV voltage.
// For this reason, recipes below 16 EU/t simply get set to their tier's VHA[tier] (half voltage adjusted).
if (voltage <= 16) {
return GTValues.VHA[workingTier];
}

// Instead of blindly increasing the voltage to something like VA[workingTier], try to scale the
// voltage up by a "0/4 overclock". The goal here is to retain recipes with EU/t such as 24 staying
// below a full amp but still increasing the tier. For instance, 24 EU/t with working tier of MV would become
// 96 EU/t rather than 120 EU/t with this logic.
while (voltage <= GTValues.V[workingTier - 1]) {
voltage *= 4;
}

// Sanity check to make sure we don't accidentally create full-amp recipes.
return Math.min(voltage, GTValues.VA[workingTier]);
}
}
Loading