-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from SafariXiu/Water
净化水产线Mixin
- Loading branch information
Showing
12 changed files
with
406 additions
and
1 deletion.
There are no files selected for viewing
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
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
15 changes: 15 additions & 0 deletions
15
.../com/EyeOfHarmonyBuffer/Mixins/Accessor/TreatedWater/Grade4WaterPurificationAccessor.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,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); | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/EyeOfHarmonyBuffer/Mixins/TreatedWater/Grade1WaterPurificationMixin.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,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(); | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/EyeOfHarmonyBuffer/Mixins/TreatedWater/Grade2WaterPurificationMixin.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,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(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/EyeOfHarmonyBuffer/Mixins/TreatedWater/Grade3WaterPurificationMixin.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,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); | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/com/EyeOfHarmonyBuffer/Mixins/TreatedWater/Grade4WaterPurificationMixin.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,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(); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/com/EyeOfHarmonyBuffer/Mixins/TreatedWater/Grade5WaterPurificationMixin.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,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(); | ||
} | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
src/main/java/com/EyeOfHarmonyBuffer/Mixins/TreatedWater/Grade6WaterPurificationMixin.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,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; | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/EyeOfHarmonyBuffer/Mixins/TreatedWater/Grade7WaterPurificationMixin.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.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(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.