-
-
Save PTOM76/14b9ec07497a8035c0d6d9c3636b3490 to your computer and use it in GitHub Desktop.
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
package com.github.ptom76.tutorialfabricmod.mixin; | |
import com.github.ptom76.tutorialfabricmod.timer.StuffTimerAccess; | |
import com.github.ptom76.tutorialfabricmod.timer.TickTimer; | |
import net.minecraft.server.MinecraftServer; | |
import org.spongepowered.asm.mixin.Mixin; | |
import org.spongepowered.asm.mixin.Unique; | |
import org.spongepowered.asm.mixin.injection.At; | |
import org.spongepowered.asm.mixin.injection.Inject; | |
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.function.Supplier; | |
@Mixin(MinecraftServer.class) | |
public class StuffTimer implements StuffTimerAccess { | |
@Unique | |
private final List<TickTimer> tickTimers = new ArrayList<>(); | |
@Inject(method = "tick", at = @At("TAIL")) | |
private void onTick(CallbackInfo ci) { | |
if (tickTimers.isEmpty()) return; | |
for (TickTimer tickTimer : tickTimers) { | |
if (--tickTimer.ticksUntilSomething == 0) { | |
tickTimer.supplier.get(); | |
} | |
} | |
} | |
@Override | |
public void tutorialFabricMod_addTimer(long ticksUntilSomething, Supplier<Boolean> supplier) { | |
tickTimers.add(new TickTimer(ticksUntilSomething, supplier)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment