Skip to content

Commit

Permalink
Merge pull request #34 from SafariXiu/Water
Browse files Browse the repository at this point in the history
净化水产线Mixin
  • Loading branch information
SafariXiu authored Dec 11, 2024
2 parents 65ced2c + c60857a commit 88a518d
Show file tree
Hide file tree
Showing 12 changed files with 406 additions and 1 deletion.
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ dependencies {
implementation ('org.apache.logging.log4j:log4j-core:2.17.0')
implementation ('com.github.GTNewHorizons:GTNH-Intergalactic:1.4.30:dev')
implementation ('com.github.GTNewHorizons:NewHorizonsCoreMod:2.6.88:dev')
runtimeOnlyNonPublishable("com.github.GTNewHorizons:Chisel:2.15.3-GTNH:dev")
}
46 changes: 46 additions & 0 deletions src/main/java/com/EyeOfHarmonyBuffer/Config/MainConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ public class MainConfig {
public static boolean IndustrialLaserEngraverParallelEnabled = true;
public static boolean IndustrialLaserEngraverOverclockEnabled = false;
public static boolean MaskInfiniteDurability = true;
public static boolean Grade8WaterPurificationEnabled = true;
public static boolean Grade7WaterPurificationEnabled = true;
public static boolean Grade6WaterPurificationEnabled = true;
public static boolean Grade5WaterPurificationEnabled = true;
public static boolean Grade4WaterPurificationEnabled = true;
public static boolean Grade3WaterPurificationEnabled = true;
public static boolean Grade2WaterPurificationEnabled = true;
public static boolean Grade1WaterPurificationEnabled = true;

public static boolean Water = true;

private static Configuration config;

Expand Down Expand Up @@ -245,6 +255,42 @@ public static void loadConfig() {
.get("物品","掩膜板",MaskInfiniteDurability,"开启后全部对应物品变为无限耐久")
.getBoolean(MaskInfiniteDurability);

Water = config
.get("净化水产线机器","提示",Water,"净化水机器修改仅改动了内部处理逻辑,机器多方块结构依然要保证正确!")
.getBoolean(Water);

Grade8WaterPurificationEnabled = config
.get("净化水产线机器","8级水",Grade8WaterPurificationEnabled,"开启后8级水机器输入7级水即可工作并且百分百成功,不需要任何额外自动化")
.getBoolean(Grade8WaterPurificationEnabled);

Grade7WaterPurificationEnabled = config
.get("净化水产线机器","7级水",Grade7WaterPurificationEnabled,"开启后7级水机器输入6级水即可工作并且百分百成功,不需要任何额外自动化")
.getBoolean(Grade7WaterPurificationEnabled);

Grade6WaterPurificationEnabled = config
.get("净化水产线机器","6级水",Grade6WaterPurificationEnabled,"开启后6级水机器输入5级水即可工作并且百分百成功,不需要任何额外自动化")
.getBoolean(Grade6WaterPurificationEnabled);

Grade5WaterPurificationEnabled = config
.get("净化水产线机器","5级水",Grade5WaterPurificationEnabled,"开启后5级水机器输入4级水即可工作并且百分百成功,不需要任何额外自动化")
.getBoolean(Grade5WaterPurificationEnabled);

Grade4WaterPurificationEnabled = config
.get("净化水产线机器","4级水",Grade4WaterPurificationEnabled,"开启后4级水机器输入3级水即可工作并且百分百成功,不需要任何额外自动化")
.getBoolean(Grade4WaterPurificationEnabled);

Grade3WaterPurificationEnabled = config
.get("净化水产线机器","3级水",Grade3WaterPurificationEnabled,"开启后3级水机器输入2级水即可工作并且百分百成功,不需要任何额外自动化")
.getBoolean(Grade3WaterPurificationEnabled);

Grade2WaterPurificationEnabled = config
.get("净化水产线机器","2级水",Grade2WaterPurificationEnabled,"开启后2级水机器百分百成功并且输入臭氧过量也不会爆炸")
.getBoolean(Grade2WaterPurificationEnabled);

Grade1WaterPurificationEnabled = config
.get("净化水产线机器","1级水",Grade1WaterPurificationEnabled,"开启后1级水机器的过滤器永不损坏")
.getBoolean(Grade1WaterPurificationEnabled);

if (config.hasChanged()) {
config.save();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.EyeOfHarmonyBuffer.Mixins.Accessor.TreatedWater;

import gregtech.common.tileentities.machines.multi.purification.MTEPurificationUnitPhAdjustment;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(value = MTEPurificationUnitPhAdjustment.class,remap = false)
public interface Grade4WaterPurificationAccessor {

@Accessor("currentpHValue")
float getCurrentpHValue();

@Accessor("currentpHValue")
void setCurrentpHValue(float value);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.EyeOfHarmonyBuffer.Mixins.TreatedWater;

import com.EyeOfHarmonyBuffer.Config.MainConfig;
import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable;
import gregtech.common.tileentities.machines.multi.purification.MTEPurificationUnitBase;
import gregtech.common.tileentities.machines.multi.purification.MTEPurificationUnitClarifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(value = MTEPurificationUnitClarifier.class, remap = false)
public abstract class Grade1WaterPurificationMixin extends MTEPurificationUnitBase<MTEPurificationUnitClarifier>
implements ISurvivalConstructable {
protected Grade1WaterPurificationMixin(int aID, String aName, String aNameRegional) {
super(aID, aName, aNameRegional);
}

@Inject(method = "depleteRecipeInputs", at = @At("HEAD"), cancellable = true)
public void modifyDepleteRecipeInputs(CallbackInfo ci) {
if(MainConfig.Grade1WaterPurificationEnabled){
ci.cancel();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.EyeOfHarmonyBuffer.Mixins.TreatedWater;

import com.EyeOfHarmonyBuffer.Config.MainConfig;
import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable;
import gregtech.api.recipe.check.CheckRecipeResult;
import gregtech.api.recipe.check.CheckRecipeResultRegistry;
import gregtech.common.tileentities.machines.multi.purification.MTEPurificationUnitBase;
import gregtech.common.tileentities.machines.multi.purification.MTEPurificationUnitOzonation;
import journeymap.shadow.org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;

@Mixin(value = MTEPurificationUnitOzonation.class, remap = false)
public abstract class Grade2WaterPurificationMixin extends MTEPurificationUnitBase<MTEPurificationUnitOzonation>
implements ISurvivalConstructable {
protected Grade2WaterPurificationMixin(int aID, String aName, String aNameRegional) {
super(aID, aName, aNameRegional);
}

/**
* @author EyeOfHarmonyBuffer
* @reason 修改判断逻辑,移除臭氧检查确保每次运行成功
*/
@Overwrite
@NotNull
@Override
public CheckRecipeResult checkProcessing() {
if(MainConfig.Grade2WaterPurificationEnabled){
CheckRecipeResult result = super.checkProcessing();
if (!result.wasSuccessful()) {
return result;
}
return CheckRecipeResultRegistry.SUCCESSFUL;
}
return super.checkProcessing();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.EyeOfHarmonyBuffer.Mixins.TreatedWater;

import com.EyeOfHarmonyBuffer.Config.MainConfig;
import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable;
import gregtech.common.tileentities.machines.multi.purification.MTEPurificationUnitBase;
import gregtech.common.tileentities.machines.multi.purification.MTEPurificationUnitFlocculation;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(value = MTEPurificationUnitFlocculation.class, remap = false)
public abstract class Grade3WaterPurificationMixin extends MTEPurificationUnitBase<MTEPurificationUnitFlocculation>
implements ISurvivalConstructable {
protected Grade3WaterPurificationMixin(int aID, String aName, String aNameRegional) {
super(aID, aName, aNameRegional);
}

@Inject(
method = "calculateFinalSuccessChance",
at = @At("HEAD"),
cancellable = true
)
private void modifyFinalSuccessChance(CallbackInfoReturnable<Float> cir) {
if (MainConfig.Grade3WaterPurificationEnabled) {
cir.setReturnValue(100.0f);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.EyeOfHarmonyBuffer.Mixins.TreatedWater;

import com.EyeOfHarmonyBuffer.Config.MainConfig;
import com.EyeOfHarmonyBuffer.Mixins.Accessor.TreatedWater.Grade4WaterPurificationAccessor;
import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.common.tileentities.machines.multi.purification.MTEPurificationUnitBase;
import gregtech.common.tileentities.machines.multi.purification.MTEPurificationUnitPhAdjustment;
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.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(value = MTEPurificationUnitPhAdjustment.class, remap = false)
public abstract class Grade4WaterPurificationMixin extends MTEPurificationUnitBase<MTEPurificationUnitPhAdjustment>
implements ISurvivalConstructable {

protected Grade4WaterPurificationMixin(int aID, String aName, String aNameRegional) {
super(aID, aName, aNameRegional);
}

private static final float SAFE_PH_MIN = 6.95f; // 安全范围下限
private static final float SAFE_PH_MAX = 7.05f; // 安全范围上限

@Shadow
private float currentpHValue = 0.0f;

@Inject(method = "calculateFinalSuccessChance", at = @At("HEAD"), cancellable = true)
private void forceSuccessChance(CallbackInfoReturnable<Float> cir) {
if(MainConfig.Grade4WaterPurificationEnabled){
cir.setReturnValue(100.0f);
}
}

@Inject(method = "runMachine", at = @At("HEAD"), cancellable = true)
private void forceSafePH(IGregTechTileEntity aBaseMetaTileEntity, long aTick, CallbackInfo ci) {
if(MainConfig.Grade4WaterPurificationEnabled){
MTEPurificationUnitPhAdjustment instance = (MTEPurificationUnitPhAdjustment) (Object) this;
Grade4WaterPurificationAccessor accessor = (Grade4WaterPurificationAccessor) instance;

float currentpHValue = accessor.getCurrentpHValue();

if (currentpHValue < SAFE_PH_MIN) {
accessor.setCurrentpHValue(SAFE_PH_MIN);
} else if (currentpHValue > SAFE_PH_MAX) {
accessor.setCurrentpHValue(SAFE_PH_MAX);
}

ci.cancel();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.EyeOfHarmonyBuffer.Mixins.TreatedWater;

import com.EyeOfHarmonyBuffer.Config.MainConfig;
import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.common.tileentities.machines.multi.purification.MTEPurificationUnitBase;
import gregtech.common.tileentities.machines.multi.purification.MTEPurificationUnitPlasmaHeater;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.lang.reflect.Field;

@Mixin(value = MTEPurificationUnitPlasmaHeater.class, remap = false)
public abstract class Grade5WaterPurificationMixin extends MTEPurificationUnitBase<MTEPurificationUnitPlasmaHeater>
implements ISurvivalConstructable {
protected Grade5WaterPurificationMixin(int aID, String aName, String aNameRegional) {
super(aID, aName, aNameRegional);
}

@Inject(method = "runMachine", at = @At("HEAD"), cancellable = true)
private void injectRunMachine(IGregTechTileEntity aBaseMetaTileEntity, long aTick, CallbackInfo ci) {
if(MainConfig.Grade5WaterPurificationEnabled){
try {
Field stateField = MTEPurificationUnitPlasmaHeater.class.getDeclaredField("state");
stateField.setAccessible(true);

Object state = stateField.get(this);

if (state.toString().equals("Heating")) {
stateField.set(this, Enum.valueOf(
(Class<Enum>) state.getClass(),
"Cooling"
));
}
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.EyeOfHarmonyBuffer.Mixins.TreatedWater;

import com.EyeOfHarmonyBuffer.Config.MainConfig;
import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.common.tileentities.machines.multi.purification.MTEHatchLensHousing;
import gregtech.common.tileentities.machines.multi.purification.MTEPurificationUnitBase;
import gregtech.common.tileentities.machines.multi.purification.MTEPurificationUnitUVTreatment;
import gregtech.common.tileentities.machines.multi.purification.UVTreatmentLensCycle;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;

import static gregtech.common.tileentities.machines.multi.purification.MTEPurificationUnitUVTreatment.LENS_ITEMS;

@Mixin(value = MTEPurificationUnitUVTreatment.class, remap = false)
public abstract class Grade6WaterPurificationMixin extends MTEPurificationUnitBase<MTEPurificationUnitUVTreatment>
implements ISurvivalConstructable {
protected Grade6WaterPurificationMixin(int aID, String aName, String aNameRegional) {
super(aID, aName, aNameRegional);
}

@Shadow
private UVTreatmentLensCycle lensCycle = null;

@Shadow
private int timeUntilNextSwap = 0;

@Shadow
private int numSwapsPerformed = 0;

@Shadow
private MTEHatchLensHousing lensInputBus;

/**
* @author EyeOfHarmonyBuffer
* @reason 修改镜片逻辑
*/
@Overwrite
protected void runMachine(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
if(MainConfig.Grade6WaterPurificationEnabled){
super.runMachine(aBaseMetaTileEntity, aTick);
if (mMaxProgresstime <= 0) return;
if (this.lensCycle == null) {
this.lensCycle = new UVTreatmentLensCycle(LENS_ITEMS);
}
this.timeUntilNextSwap = 0;
this.numSwapsPerformed += 1;
}
}

/**
* @author EyeOfHarmonyBuffer
* @reason 镜片槽为空也可以正常运行
*/
@Overwrite
private ItemStack getCurrentlyInsertedLens() {
if(MainConfig.Grade6WaterPurificationEnabled){
ItemStack actualLens = this.lensInputBus != null ? this.lensInputBus.getStackInSlot(0) : null;
return actualLens != null ? actualLens : (!LENS_ITEMS.isEmpty() ? LENS_ITEMS.get(0) : null);
}
return this.lensInputBus != null ? this.lensInputBus.getStackInSlot(0) : null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.EyeOfHarmonyBuffer.Mixins.TreatedWater;

import com.EyeOfHarmonyBuffer.Config.MainConfig;
import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable;
import gregtech.common.tileentities.machines.multi.purification.MTEPurificationUnitBase;
import gregtech.common.tileentities.machines.multi.purification.MTEPurificationUnitDegasser;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;

@Mixin(value = MTEPurificationUnitDegasser.class, remap = false)
public abstract class Grade7WaterPurificationMixin extends MTEPurificationUnitBase<MTEPurificationUnitDegasser>
implements ISurvivalConstructable {

protected Grade7WaterPurificationMixin(int aID, String aName, String aNameRegional) {
super(aID, aName, aNameRegional);
}

@Inject(method = "startCycle", at = @At("HEAD"))
private void forceControlSignal(int cycleTime, int progressTime, CallbackInfo ci) {
if(MainConfig.Grade7WaterPurificationEnabled){
try {
Field controlSignalField = MTEPurificationUnitDegasser.class.getDeclaredField("controlSignal");
controlSignalField.setAccessible(true);
Class<?> controlSignalClass = Class.forName("gregtech.common.tileentities.machines.multi.purification.MTEPurificationUnitDegasser$ControlSignal");
Constructor<?> constructor = controlSignalClass.getDeclaredConstructor(byte.class);
constructor.setAccessible(true);
Object newControlSignal = constructor.newInstance((byte) 4);

controlSignalField.set(this, newControlSignal);

} catch (Exception e) {
e.printStackTrace();
}
}
}
}
Loading

0 comments on commit 88a518d

Please sign in to comment.