Skip to content

Commit

Permalink
Merge branch 'master' into littlecube-soft-tool-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
littlecube8152 authored Feb 4, 2025
2 parents 5e98391 + 68f6e52 commit b7c6027
Show file tree
Hide file tree
Showing 168 changed files with 3,803 additions and 1,535 deletions.
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
dependencies {
// Published dependencies
api("codechicken:codechickenlib:3.2.3.358")
api("com.cleanroommc:modularui:2.5.0-rc2") { transitive = false }
api("com.cleanroommc:modularui:2.5.0-rc3") { transitive = false }
api("com.cleanroommc:groovyscript:1.2.0-hotfix1") { transitive = false }
api("CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.1.20.700")
api("appeng:ae2-uel:v0.56.4") { transitive = false }
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/gregtech/GregTechMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
acceptedMinecraftVersions = "[1.12.2,1.13)",
version = GTInternalTags.VERSION,
dependencies = "required:forge@[14.23.5.2847,);" + "required-after:codechickenlib@[3.2.3,);" +
"required-after:modularui@[2.3,);" + "required-after:mixinbooter@[8.0,);" + "after:appliedenergistics2;" +
"required-after:modularui@[2.5.0-rc,);" + "required-after:mixinbooter@[8.0,);" +
"after:appliedenergistics2;" +
"after:forestry;" + "after:extrabees;" + "after:extratrees;" + "after:genetics;" + "after:magicbees;" +
"after:jei@[4.15.0,);" + "after:crafttweaker@[4.1.20,);" + "after:groovyscript@[1.2.0,);" +
"after:theoneprobe;" + "after:hwyla;")
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/gregtech/api/GTValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,12 @@ public class GTValues {
* The short names for the voltages, formatted for text
*/
public static final String[] VNF = new String[] {
DARK_GRAY + "ULV", GRAY + "LV", AQUA + "MV",
GOLD + "HV", DARK_PURPLE + "EV", DARK_BLUE + "IV",
LIGHT_PURPLE + "LuV", RED + "ZPM", DARK_AQUA + "UV",
DARK_RED + "UHV", GREEN + "UEV", DARK_GREEN + "UIV",
YELLOW + "UXV", BLUE + "OpV", RED.toString() + BOLD + "MAX" };
RED + "ULV", GRAY + "LV", GOLD + "MV",
YELLOW + "HV", DARK_GRAY + "EV", WHITE + "IV",
LIGHT_PURPLE + "LuV", AQUA + "ZPM", DARK_GREEN + "UV",
DARK_RED + "UHV", DARK_BLUE + "UEV", DARK_GREEN.toString() + BOLD + "UIV",
DARK_PURPLE.toString() + BOLD + "UXV", DARK_RED.toString() + BOLD + "OpV",
RED.toString() + BOLD + "MAX" };

/**
* The short names for the voltages, up to max Long, formatted for text
Expand All @@ -146,7 +147,7 @@ public class GTValues {
* Color values for the voltages
*/
public static final int[] VC = new int[] { 0xC80000, 0xDCDCDC, 0xFF6400, 0xFFFF1E, 0x808080, 0xF0F0F5, 0xE99797,
0x7EC3C4, 0x7EB07E, 0xBF74C0, 0x0B5CFE, 0x914E91, 0x488748, 0x8C0000, 0x2828F5 };
0x7EC3C4, 0x7EB07E, 0xBF74C0, 0x0B5CFE, 0x488748, 0x914E91, 0x8C0000, 0x2828F5 };

/**
* The long names for the voltages
Expand Down
43 changes: 43 additions & 0 deletions src/main/java/gregtech/api/capability/GregtechDataCodes.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package gregtech.api.capability;

import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import org.apache.commons.lang3.ArrayUtils;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

public class GregtechDataCodes {

private static int nextId = 0;
Expand Down Expand Up @@ -88,6 +95,7 @@ public static int assignId() {
public static final int MAINTENANCE_MULTIPLIER = assignId();
public static final int UPDATE_UPWARDS_FACING = assignId();
public static final int UPDATE_FLIP = assignId();
public static final int LOCK_FILL = assignId();

// Item Bus Item Stack Auto Collapsing
public static final int TOGGLE_COLLAPSE_ITEMS = assignId();
Expand Down Expand Up @@ -148,6 +156,9 @@ public static int assignId() {
// Detector Covers
public static final int UPDATE_INVERTED = assignId();

// Ender Covers
public static final int UPDATE_PRIVATE = assignId();

// HPCA / Research Station
public static final int DAMAGE_STATE = assignId();
public static final int LOCK_OBJECT_HOLDER = assignId();
Expand Down Expand Up @@ -180,4 +191,36 @@ public static int assignId() {
// ME Parts
public static final int UPDATE_AUTO_PULL = assignId();
public static final int UPDATE_ONLINE_STATUS = assignId();

// Everything below MUST be last in the class!
public static final Int2ObjectMap<String> NAMES = new Int2ObjectArrayMap<>();

static {
registerFields(GregtechDataCodes.class);
}

public static String getNameFor(int id) {
return NAMES.getOrDefault(id, "Unknown_DataCode:" + id);
}

/**
* Registers all fields from the passed in class to the name registry.
* Optionally, you can pass in a list of valid ids to check against so that errant ids are not added
*
* @param clazz Class to iterate fields
* @param validIds optional array of valid ids to check against class fields
*/
public static void registerFields(Class<?> clazz, int... validIds) {
try {
for (Field field : clazz.getDeclaredFields()) {
if (field.getType() != Integer.TYPE) continue;
if (!Modifier.isStatic(field.getModifiers())) continue;
if (!Modifier.isFinal(field.getModifiers())) continue;
int id = field.getInt(null);
if (!ArrayUtils.isEmpty(validIds) && !ArrayUtils.contains(validIds, id))
continue;
NAMES.put(id, field.getName() + ":" + id);
}
} catch (IllegalAccessException ignored) {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import gregtech.api.GTValues;
import gregtech.api.capability.GregtechDataCodes;
import gregtech.api.capability.GregtechTileCapabilities;
import gregtech.api.capability.IEnergyContainer;
import gregtech.api.capability.IMultiblockController;
import gregtech.api.capability.IMultipleTankHandler;
import gregtech.api.capability.IWorkable;
Expand Down Expand Up @@ -101,17 +102,27 @@ public AbstractRecipeLogic(MetaTileEntity tileEntity, RecipeMap<?> recipeMap, bo
/**
* @return the energy container's energy input per second
*/
protected abstract long getEnergyInputPerSecond();
protected long getEnergyInputPerSecond() {
return getEnergyContainer().getInputPerSec();
}

/**
* @return the energy container's current stored energy
*/
protected abstract long getEnergyStored();
protected long getEnergyStored() {
return getEnergyContainer().getEnergyStored();
}

/**
* @return the energy container's maximum energy capacity
*/
protected abstract long getEnergyCapacity();
protected long getEnergyCapacity() {
return getEnergyContainer().getEnergyCapacity();
}

protected IEnergyContainer getEnergyContainer() {
return IEnergyContainer.DEFAULT;
}

/**
* Draw energy from the energy container
Expand All @@ -120,12 +131,22 @@ public AbstractRecipeLogic(MetaTileEntity tileEntity, RecipeMap<?> recipeMap, bo
* @param simulate whether to simulate energy extraction or not
* @return true if the energy can/was drained, otherwise false
*/
protected abstract boolean drawEnergy(long recipeEUt, boolean simulate);
protected boolean drawEnergy(long recipeEUt, boolean simulate) {
// this should be the ONLY time eut is negative!
if (consumesEnergy()) recipeEUt = -recipeEUt;
long resultEnergy = getEnergyStored() + recipeEUt;
if (resultEnergy >= 0L && resultEnergy <= getEnergyCapacity()) {
if (!simulate) getEnergyContainer().changeEnergy(recipeEUt);
return true;
} else return false;
}

/**
* @return the maximum voltage the machine can use/handle for recipe searching
*/
public abstract long getMaxVoltage();
public long getMaxVoltage() {
return Math.max(getEnergyContainer().getInputVoltage(), getEnergyContainer().getOutputVoltage());
}

/**
*
Expand Down Expand Up @@ -941,7 +962,7 @@ public String[] getAvailableOverclockingTiers() {
protected void setupRecipe(@NotNull Recipe recipe) {
this.progressTime = 1;
setMaxProgress(ocResult.duration());
this.recipeEUt = consumesEnergy() ? ocResult.eut() : -ocResult.eut();
this.recipeEUt = ocResult.eut();

int recipeTier = GTUtility.getTierByVoltage(recipe.getEUt());
int machineTier = getOverclockForTier(getMaximumOverclockVoltage());
Expand Down Expand Up @@ -1226,7 +1247,7 @@ public void deserializeNBT(@NotNull NBTTagCompound compound) {
if (progressTime > 0) {
this.isActive = true;
this.maxProgressTime = compound.getInteger("MaxProgress");
this.recipeEUt = compound.getLong("RecipeEUt");
this.recipeEUt = Math.abs(compound.getLong("RecipeEUt"));
NBTTagList itemOutputsList = compound.getTagList("ItemOutputs", Constants.NBT.TAG_COMPOUND);
this.itemOutputs = new ArrayList<>(itemOutputsList.tagCount());
for (int i = 0; i < itemOutputsList.tagCount(); i++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gregtech.api.capability.impl;

import gregtech.api.GTValues;
import gregtech.api.capability.IEnergyContainer;
import gregtech.api.capability.IMultiblockController;
import gregtech.api.capability.IMultipleTankHandler;
import gregtech.api.recipes.Recipe;
Expand Down Expand Up @@ -330,6 +331,12 @@ public long getMaxVoltage() {
return 0;
}

@Override
protected IEnergyContainer getEnergyContainer() {
GTLog.logger.error("Large Boiler called getEnergyContainer(), this should not be possible!");
return super.getEnergyContainer();
}

/**
* @param fluidHandler the handler to drain from
* @param amount the amount to drain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,9 @@ protected long boostProduction(long production) {
}

@Override
protected boolean drawEnergy(long recipeEUt, boolean simulate) {
long euToDraw = boostProduction(recipeEUt);
long resultEnergy = getEnergyStored() - euToDraw;
if (resultEnergy >= 0L && resultEnergy <= getEnergyCapacity()) {
if (!simulate) getEnergyContainer().changeEnergy(-euToDraw);
return true;
}
return false;
}

@Override
public long getInfoProviderEUt() {
return boostProduction(super.getInfoProviderEUt());
protected void setupRecipe(@NotNull Recipe recipe) {
super.setupRecipe(recipe);
this.recipeEUt = boostProduction(this.recipeEUt);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,35 +384,11 @@ protected void performMufflerOperations() {
}
}

@Override
protected long getEnergyInputPerSecond() {
return getEnergyContainer().getInputPerSec();
}

@Override
protected long getEnergyStored() {
return getEnergyContainer().getEnergyStored();
}

@Override
protected long getEnergyCapacity() {
return getEnergyContainer().getEnergyCapacity();
}

@Override
protected boolean drawEnergy(long recipeEUt, boolean simulate) {
long resultEnergy = getEnergyStored() - recipeEUt;
if (resultEnergy >= 0L && resultEnergy <= getEnergyCapacity()) {
if (!simulate) getEnergyContainer().changeEnergy(-recipeEUt);
return true;
} else return false;
}

@Override
public long getMaxVoltage() {
IEnergyContainer energyContainer = getEnergyContainer();
if (!consumesEnergy()) {
// Generators
// Generator Multiblocks
long voltage = energyContainer.getOutputVoltage();
long amperage = energyContainer.getOutputAmperage();
if (energyContainer instanceof EnergyContainerList && amperage == 1) {
Expand All @@ -424,7 +400,7 @@ public long getMaxVoltage() {
}
return voltage;
} else {
// Machines
// Machine Multiblocks
if (energyContainer instanceof EnergyContainerList energyList) {
long highestVoltage = energyList.getHighestInputVoltage();
if (energyList.getNumHighestInputContainers() > 1) {
Expand Down
29 changes: 2 additions & 27 deletions src/main/java/gregtech/api/capability/impl/RecipeLogicEnergy.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,8 @@ public RecipeLogicEnergy(MetaTileEntity tileEntity, RecipeMap<?> recipeMap,
}

@Override
protected long getEnergyInputPerSecond() {
return energyContainer.get().getInputPerSec();
}

@Override
protected long getEnergyStored() {
return energyContainer.get().getEnergyStored();
}

@Override
protected long getEnergyCapacity() {
return energyContainer.get().getEnergyCapacity();
}

@Override
protected boolean drawEnergy(long recipeEUt, boolean simulate) {
long resultEnergy = getEnergyStored() - recipeEUt;
if (resultEnergy >= 0L && resultEnergy <= getEnergyCapacity()) {
if (!simulate) energyContainer.get().changeEnergy(-recipeEUt);
return true;
}
return false;
}

@Override
public long getMaxVoltage() {
return Math.max(energyContainer.get().getInputVoltage(), energyContainer.get().getOutputVoltage());
protected IEnergyContainer getEnergyContainer() {
return energyContainer.get();
}

@Override
Expand Down
Loading

0 comments on commit b7c6027

Please sign in to comment.