This repository has been archived by the owner on Sep 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix some bug and add DynamicDuration
- Loading branch information
Showing
13 changed files
with
194 additions
and
44 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
31 changes: 31 additions & 0 deletions
31
src/main/java/com/github/wohaopa/GTNHModify/EventHandler.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,31 @@ | ||
package com.github.wohaopa.GTNHModify; | ||
|
||
import com.github.wohaopa.GTNHModify.tweakers.Tweakers; | ||
import com.github.wohaopa.GTNHModify.tweakers.gt.DynamicDuration; | ||
|
||
import cpw.mods.fml.common.eventhandler.SubscribeEvent; | ||
import cpw.mods.fml.common.gameevent.TickEvent; | ||
|
||
public class EventHandler { | ||
|
||
long lastUpdateTime = 0; | ||
long ticks = 0; | ||
|
||
@SubscribeEvent | ||
public void onTickPost(TickEvent.ServerTickEvent event) { | ||
if (Tweakers.Dynamic_Duration.enabled) if (event.phase == TickEvent.Phase.END) { | ||
ticks++; | ||
long now = System.currentTimeMillis(); | ||
if (now - lastUpdateTime > 10000) { // 10秒 | ||
if (lastUpdateTime != 0) { | ||
if (ticks < 195) { | ||
DynamicDuration.instance.setF((float) (ticks * 50.0) / (now - lastUpdateTime)); | ||
DynamicDuration.update(); | ||
} | ||
ticks = 0; | ||
} | ||
lastUpdateTime = now; | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,6 @@ void exportRecipe() {} | |
public Object getSettings() { | ||
return null; | ||
} | ||
|
||
public void setSetting(Object setting) {} | ||
} |
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
71 changes: 71 additions & 0 deletions
71
src/main/java/com/github/wohaopa/GTNHModify/tweakers/gt/DynamicDuration.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,71 @@ | ||
package com.github.wohaopa.GTNHModify.tweakers.gt; | ||
|
||
import com.github.wohaopa.GTNHModify.GTNHModifyMod; | ||
|
||
import gregtech.api.util.GT_Recipe; | ||
|
||
public class DynamicDuration extends GT_RecipeTweaker { | ||
|
||
public static DynamicDuration instance = new DynamicDuration(); | ||
private static final Thread updateThread = new Thread(() -> { | ||
while (true) { | ||
if (DynamicDuration.needsUpdate) { | ||
GTNHModifyMod.LOG.info("Updating DynamicDuration: f = {}", instance.aFloat); | ||
long a = System.currentTimeMillis(); | ||
instance.apply(); | ||
DynamicDuration.needsUpdate = false; | ||
GTNHModifyMod.LOG.info("Updating DynamicDuration: use time {}ms", System.currentTimeMillis() - a); | ||
} | ||
Thread.yield(); | ||
try { | ||
Thread.sleep(100); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
}); | ||
private static boolean running = false; | ||
private static boolean needsUpdate = false; | ||
|
||
static { | ||
updateThread.setDaemon(true); | ||
updateThread.setName("GTNHModify DynamicDuration UpdateThread"); | ||
} | ||
|
||
public static void update() { | ||
needsUpdate = true; | ||
if (!running) { | ||
running = true; | ||
updateThread.start(); | ||
} | ||
} | ||
|
||
public void setF(float f) { | ||
f0 = f / f0 * aFloat; | ||
} | ||
|
||
private float aFloat = 0.9f; | ||
private float f0 = 1f; | ||
|
||
@Override | ||
protected void modifyGT_Recipe(GT_Recipe aRecipe) { | ||
aRecipe.mDuration *= (int) f0; | ||
if (aRecipe.mDuration < 1) aRecipe.mDuration = 1; | ||
} | ||
|
||
@Override | ||
protected void modifyGT_Recipe_AssemblyLine(GT_Recipe.GT_Recipe_AssemblyLine aRecipe) { | ||
aRecipe.mDuration *= (int) f0; | ||
if (aRecipe.mDuration < 1) aRecipe.mDuration = 1; | ||
} | ||
|
||
@Override | ||
public Object getSettings() { | ||
return aFloat; | ||
} | ||
|
||
@Override | ||
public void setSetting(Object s) { | ||
aFloat = (float) s; | ||
} | ||
} |
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
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