-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix GT 4A Hatches Max Input Voltage Not Being Correct
- Loading branch information
1 parent
41577b8
commit 81da13f
Showing
4 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
src/main/java/com/nomiceu/nomilabs/gregtech/mixinhelper/AccessibleEnergyContainerList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/nomiceu/nomilabs/mixin/gregtech/EnergyContainerListMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/com/nomiceu/nomilabs/mixin/gregtech/MultiblockRecipeLogicMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters