Skip to content

Commit

Permalink
Fix GT 4A Hatches Max Input Voltage Not Being Correct
Browse files Browse the repository at this point in the history
  • Loading branch information
IntegerLimit committed Mar 10, 2024
1 parent 41577b8 commit 81da13f
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.nomiceu.nomilabs.gregtech.mixinhelper;

public interface AccessibleEnergyContainerList {
/**
* The total amperage of all the containers with the highest input voltage.
*/
long getTotalHighestInputAmperage();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.nomiceu.nomilabs.mixin.gregtech;

import com.nomiceu.nomilabs.gregtech.mixinhelper.AccessibleEnergyContainerList;
import gregtech.api.capability.IEnergyContainer;
import gregtech.api.capability.impl.EnergyContainerList;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.List;

@Mixin(value = EnergyContainerList.class, remap = false)
public class EnergyContainerListMixin implements AccessibleEnergyContainerList {
@Shadow
@Final
private long highestInputVoltage;

/**
* The total amperage of all the containers with the highest input voltage.
*/
@Unique
private long totalHighestInputAmperage = 0;

@Inject(method = "<init>", at = @At("TAIL"))
public void initTotalHighestInputAmp(List<IEnergyContainer> energyContainerList, CallbackInfo ci) {
for (IEnergyContainer container : energyContainerList) {
if (container.getInputVoltage() == highestInputVoltage) {
totalHighestInputAmperage += container.getInputAmperage();
}
}
}

@Override
public long getTotalHighestInputAmperage() {
return totalHighestInputAmperage;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.nomiceu.nomilabs.mixin.gregtech;

import com.nomiceu.nomilabs.gregtech.mixinhelper.AccessibleEnergyContainerList;
import gregtech.api.GTValues;
import gregtech.api.capability.IEnergyContainer;
import gregtech.api.capability.impl.AbstractRecipeLogic;
import gregtech.api.capability.impl.EnergyContainerList;
import gregtech.api.capability.impl.MultiblockRecipeLogic;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.recipes.RecipeMap;
import gregtech.api.util.GTUtility;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(value = MultiblockRecipeLogic.class, remap = false)
public abstract class MultiblockRecipeLogicMixin extends AbstractRecipeLogic {
@Shadow public abstract IEnergyContainer getEnergyContainer();

/**
* Default Ignored Constructor
*/
public MultiblockRecipeLogicMixin(MetaTileEntity tileEntity, RecipeMap<?> recipeMap) {
super(tileEntity, recipeMap);
}

@Inject(method = "getMaxVoltage", at = @At("HEAD"), cancellable = true)
public void getCorrectMaxVoltage(CallbackInfoReturnable<Long> cir) {
if (!consumesEnergy()) return;

IEnergyContainer energyContainer = getEnergyContainer();
if (energyContainer instanceof EnergyContainerList energyList) {
long highestVoltage = energyList.getHighestInputVoltage();
if (energyList.getNumHighestInputContainers() > 1) {
// allow tier + 1 if there are multiple hatches present at the highest tier
int tier = GTUtility.getTierByVoltage(highestVoltage);
cir.setReturnValue(GTValues.V[Math.min(tier + 1, GTValues.MAX)]);
} else {
var amp = ((AccessibleEnergyContainerList) energyList).getTotalHighestInputAmperage();
if (amp >= 4) highestVoltage = highestVoltage * 4;
cir.setReturnValue(highestVoltage);
}
} else {
var amp = energyContainer.getInputAmperage();
var voltage = energyContainer.getInputVoltage();
if (amp >= 4) voltage = voltage * 4;
cir.setReturnValue(voltage);
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/mixins.nomilabs.gregtech.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
"mixins": [
"AccessibleDecompositionRecipeHandler",
"AccessibleMaterialInfo",
"EnergyContainerListMixin",
"FluidStorageKeyMixin",
"GTRecipeWrapperMixin",
"MaterialFlagsMixin",
"MaterialMixin",
"MaterialStackMixin",
"MetaItemsMixin",
"MultiblockRecipeLogicMixin",
"RecipeBuilderMixin",
"RecipeMapMixin",
"VirtualizedRecipeMapMixin"
Expand Down

0 comments on commit 81da13f

Please sign in to comment.