-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for /tick rate on Fabric
- Loading branch information
Showing
10 changed files
with
66 additions
and
11 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
15 changes: 15 additions & 0 deletions
15
fabric/src/main/java/me/caseload/knockbacksync/callback/TickRateChangeEvent.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 me.caseload.knockbacksync.callback; | ||
|
||
import net.fabricmc.fabric.api.event.Event; | ||
import net.fabricmc.fabric.api.event.EventFactory; | ||
|
||
public interface TickRateChangeEvent { | ||
Event<TickRateChangeEvent> EVENT = EventFactory.createArrayBacked(TickRateChangeEvent.class, | ||
(listeners) -> (oldTickRate, newTickRate) -> { | ||
for (TickRateChangeEvent listener : listeners) { | ||
listener.onTickRateChange(oldTickRate, newTickRate); | ||
} | ||
}); | ||
|
||
void onTickRateChange(float oldTickRate, float newTickRate); | ||
} |
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
14 changes: 14 additions & 0 deletions
14
...src/main/java/me/caseload/knockbacksync/listener/fabric/FabricTickRateChangeListener.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,14 @@ | ||
package me.caseload.knockbacksync.listener.fabric; | ||
|
||
import me.caseload.knockbacksync.callback.TickRateChangeEvent; | ||
import me.caseload.knockbacksync.player.PlayerData; | ||
|
||
public class FabricTickRateChangeListener { | ||
public void register() { | ||
TickRateChangeEvent.EVENT.register((oldTickRate, newTickRate) -> { | ||
if (oldTickRate != newTickRate) { | ||
PlayerData.TICK_RATE = newTickRate; | ||
} | ||
}); | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
fabric/src/main/java/me/caseload/knockbacksync/mixin/TickRateManagerMixin.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,22 @@ | ||
package me.caseload.knockbacksync.mixin; | ||
|
||
import me.caseload.knockbacksync.callback.TickRateChangeEvent; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
|
||
import net.minecraft.world.TickRateManager; | ||
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(TickRateManager.class) | ||
public class TickRateManagerMixin { | ||
@Shadow | ||
protected float tickrate; | ||
|
||
@Inject(method = "setTickRate", at = @At("HEAD")) | ||
private void onSetTickRate(float tickRate, CallbackInfo ci) { | ||
float oldTickRate = this.tickrate; | ||
TickRateChangeEvent.EVENT.invoker().onTickRateChange(oldTickRate, tickRate); | ||
} | ||
} |
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