-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
84 additions
and
10 deletions.
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
12 changes: 10 additions & 2 deletions
12
src/main/java/com/xir/NHUtilities/common/api/ITileEntityTickAcceleration.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 |
---|---|---|
@@ -1,8 +1,16 @@ | ||
package com.xir.NHUtilities.common.api; | ||
|
||
@SuppressWarnings("unused") | ||
import com.xir.NHUtilities.common.entity.EntityTimeAccelerator; | ||
|
||
/** | ||
* only used for EntityTimeAccelerator {@link EntityTimeAccelerator#onEntityUpdate()} | ||
*/ | ||
public interface ITileEntityTickAcceleration { | ||
|
||
default void tickAcceleration(int tickAcceleratedRate) {} | ||
/** | ||
* <li>true if the tickAcceleration logic should be executed.</li> | ||
* <li>false if the default TileEntity update method should proceed.</li> | ||
*/ | ||
boolean tickAcceleration(int tickAcceleratedRate); | ||
|
||
} |
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
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
65 changes: 65 additions & 0 deletions
65
src/main/java/com/xir/NHUtilities/mixins/late/GregTech/BaseMetaTileEntity_Mixin.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,65 @@ | ||
package com.xir.NHUtilities.mixins.late.GregTech; | ||
|
||
import static com.xir.NHUtilities.config.Config.enableLogInfo; | ||
import static com.xir.NHUtilities.main.NHUtilities.LOG; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
import com.xir.NHUtilities.common.api.ITileEntityTickAcceleration; | ||
|
||
import gregtech.api.interfaces.metatileentity.IMetaTileEntity; | ||
import gregtech.api.metatileentity.BaseMetaTileEntity; | ||
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine; | ||
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; | ||
import gregtech.common.tileentities.machines.multi.GT_MetaTileEntity_PrimitiveBlastFurnace; | ||
|
||
@Mixin(BaseMetaTileEntity.class) | ||
public abstract class BaseMetaTileEntity_Mixin implements ITileEntityTickAcceleration { | ||
|
||
@Shadow(remap = false) | ||
public abstract int getProgress(); | ||
|
||
@Shadow(remap = false) | ||
public abstract int getMaxProgress(); | ||
|
||
@Shadow(remap = false) | ||
public abstract IMetaTileEntity getMetaTileEntity(); | ||
|
||
@Override | ||
public boolean tickAcceleration(int tickAcceleratedRate) { | ||
// safely calling | ||
int currentProgress = this.getProgress(); | ||
int maxProgress = this.getMaxProgress(); | ||
|
||
if (maxProgress >= 2) { // obviously | ||
tickAcceleratedRate = (int) (tickAcceleratedRate * 0.8f); // discount for accelerating gregtech machines | ||
int newProgress = currentProgress + tickAcceleratedRate; | ||
int NHUtilities$modify = Math.min(maxProgress, newProgress); | ||
if (enableLogInfo) LOG.info("modifyArg {}", NHUtilities$modify); | ||
|
||
IMetaTileEntity metaTileEntity = this.getMetaTileEntity(); | ||
|
||
// for accelerating basic machine | ||
if (metaTileEntity instanceof GT_MetaTileEntity_BasicMachine basicMachine) { | ||
basicMachine.mProgresstime = NHUtilities$modify; | ||
if (enableLogInfo) LOG.info("success accelerating basicMachine"); | ||
} | ||
|
||
// for accelerating multi machine | ||
if (metaTileEntity instanceof GT_MetaTileEntity_MultiBlockBase multiBlockBase) { | ||
multiBlockBase.mProgresstime = NHUtilities$modify; | ||
if (enableLogInfo) LOG.info("success accelerating multiBlockBase"); | ||
} | ||
|
||
// for accelerating primitive blast furnace | ||
if (metaTileEntity instanceof GT_MetaTileEntity_PrimitiveBlastFurnace primitiveBlastFurnace) { | ||
primitiveBlastFurnace.mProgresstime = NHUtilities$modify; | ||
if (enableLogInfo) LOG.info("success accelerating primitiveBlastFurnace"); | ||
} | ||
} else { | ||
return false; // this for accelerating gt machine by executing TE update method | ||
} | ||
return true; | ||
} | ||
} |