-
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.
Make Schematicannon fire rate depend on the avg MSPT
- Loading branch information
1 parent
f113218
commit 57abcfe
Showing
6 changed files
with
90 additions
and
2 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
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
28 changes: 28 additions & 0 deletions
28
.../java/dev/ithundxr/railwaystweaks/mixin/compat/create/SchematicannonBlockEntityMixin.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,28 @@ | ||
package dev.ithundxr.railwaystweaks.mixin.compat.create; | ||
|
||
import com.simibubi.create.content.schematics.cannon.SchematicannonBlockEntity; | ||
import dev.ithundxr.railwaystweaks.RailwaysTweaks; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
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; | ||
|
||
@Mixin(SchematicannonBlockEntity.class) | ||
public class SchematicannonBlockEntityMixin { | ||
|
||
@Shadow private int printerCooldown; | ||
|
||
@Inject(method = "tickPrinter", at = @At("TAIL"), remap = false) | ||
private void railwaytweaks$tickPrinter(CallbackInfo ci) { | ||
double mspt = RailwaysTweaks.MSPT_TRACKER.getAverageMSPT(); | ||
|
||
if (mspt > 55) | ||
this.printerCooldown = 60; | ||
else if (mspt > 45) | ||
this.printerCooldown = 20; | ||
else | ||
this.printerCooldown = 10; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/dev/ithundxr/railwaystweaks/utils/MSPTTracker.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,44 @@ | ||
package dev.ithundxr.railwaystweaks.utils; | ||
|
||
import dev.ithundxr.railwaystweaks.RailwaysTweaks; | ||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.server.level.ServerLevel; | ||
|
||
public class MSPTTracker { | ||
private final int averageIntervalTicks; | ||
private long lastTickTime = System.nanoTime(); | ||
private double totalMSPT = 0; | ||
private double averageMSPT = 30; | ||
private int tickCount = 0; | ||
|
||
public MSPTTracker(int averageIntervalTicks) { | ||
this.averageIntervalTicks = averageIntervalTicks; | ||
ServerTickEvents.END_SERVER_TICK.register(this::endServerTick); | ||
} | ||
|
||
private void endServerTick(MinecraftServer server) { | ||
long now = System.nanoTime(); | ||
long tickDuration = now - lastTickTime; | ||
double mspt = tickDuration / 1_000_000.0; | ||
lastTickTime = now; | ||
|
||
// Accumulate the MSPT and increment the tick counter | ||
totalMSPT += mspt; | ||
tickCount++; | ||
|
||
// Calculate the average MSPT every AVERAGE_INTERVAL_TICKS | ||
if (tickCount >= averageIntervalTicks) { | ||
averageMSPT = totalMSPT / tickCount; | ||
RailwaysTweaks.LOGGER.info("MSPT: " + averageMSPT); | ||
|
||
// Reset for the next interval | ||
totalMSPT = 0; | ||
tickCount = 0; | ||
} | ||
} | ||
|
||
public double getAverageMSPT() { | ||
return averageMSPT; | ||
} | ||
} |
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