Skip to content

Commit

Permalink
adapting to gregtech
Browse files Browse the repository at this point in the history
  • Loading branch information
Keriils committed Aug 23, 2024
1 parent f20e620 commit f8d859d
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 10 deletions.
6 changes: 3 additions & 3 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
* For more details, see https://docs.gradle.org/8.0.1/userguide/java_library_plugin.html#sec:java_library_configurations_graph
*/
dependencies {
// api("com.github.GTNewHorizons:GT5-Unofficial:5.09.48.66:dev")
api("com.github.GTNewHorizons:Draconic-Evolution:1.3.5-GTNH:dev")
api("com.github.GTNewHorizons:GT5-Unofficial:5.09.48.66:dev")
implementation("com.github.GTNewHorizons:Draconic-Evolution:1.3.5-GTNH:dev")
implementation("com.github.GTNewHorizons:Botania:1.11.3-GTNH:dev")
implementation('com.github.GTNewHorizons:Avaritia:1.49:dev')
implementation('com.github.GTNewHorizons:Avaritiaddons:1.7.1-GTNH:dev')
Expand All @@ -45,7 +45,7 @@ dependencies {
implementation("com.github.GTNewHorizons:ae2stuff:0.8.2-GTNH:dev")
implementation("com.github.GTNewHorizons:ServerUtilities:2.0.66:dev") // debug info & nbtEdit

compileOnly ('org.jetbrains:annotations:24.1.0')
// compileOnly ('org.jetbrains:annotations:24.1.0')

// libs files
// implementation files("libs/rawinput-1.4.2.jar")
Expand Down
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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ private void tAccelerate() {
long tMaxTime = System.nanoTime() + 1000000;
if (shouldAccelerate(tileEntity)) {
if (tileEntity instanceof ITileEntityTickAcceleration tileEntityITEA) {
tileEntityITEA.tickAcceleration(timeRate);
} else {
accelerateTileEntity(tileEntity, tMaxTime);
if (tileEntityITEA.tickAcceleration(timeRate)) return;
}
accelerateTileEntity(tileEntity, tMaxTime);
} else if (shouldAccelerate(block)) {
accelerateBlock(block, tMaxTime);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/xir/NHUtilities/mixinPlugin/Mixins.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public enum Mixins {

DE_TeleporterMKII_Mixin("TeleporterMKII_Mixin", TargetMods.DraconicEvolution, TargetMods.Baubles),
DE_GUITeleporter_Mixin("GUITeleporter_Mixin", TargetMods.DraconicEvolution),
DE_TeleporterPacket_Mixin("TeleporterPacket_Mixin", TargetMods.DraconicEvolution);
DE_TeleporterPacket_Mixin("TeleporterPacket_Mixin", TargetMods.DraconicEvolution),
GT_MTEAcclerator_Mixin("BaseMetaTileEntity_Mixin", TargetMods.GregTech);

private final String mixinClass;
private final List<String> targetMod = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
public enum MixinsPackage {

EnhanceTeleporterMKII(Config.enableEnhancedTeleporterMKII, "DraconicEvolution", Mixins.DE_TeleporterMKII_Mixin,
Mixins.DE_GUITeleporter_Mixin, Mixins.DE_TeleporterPacket_Mixin);
Mixins.DE_GUITeleporter_Mixin, Mixins.DE_TeleporterPacket_Mixin),
Enable_MTEAcclerator(Config.enableAccelerateGregTechMachine, "GregTech", Mixins.GT_MTEAcclerator_Mixin);

private final Boolean isEnabledModule;
private final Set<String> targetMods = new HashSet<>();
Expand Down
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;
}
}

0 comments on commit f8d859d

Please sign in to comment.