-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9efd044
commit 0055f16
Showing
8 changed files
with
189 additions
and
43 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
src/main/java/redstone/multimeter/interfaces/mixin/BlockEventListener.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,11 @@ | ||
package redstone.multimeter.interfaces.mixin; | ||
|
||
public interface BlockEventListener { | ||
|
||
void rsmm$startBlockEvents(); | ||
|
||
void rsmm$nextBlockEvent(); | ||
|
||
void rsmm$endBlockEvents(); | ||
|
||
} |
8 changes: 2 additions & 6 deletions
8
src/main/java/redstone/multimeter/interfaces/mixin/ILevelTicks.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 |
---|---|---|
@@ -1,13 +1,9 @@ | ||
package redstone.multimeter.interfaces.mixin; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import net.minecraft.world.ticks.ScheduledTick; | ||
|
||
public interface ILevelTicks { | ||
|
||
public void rsmm$setScheduleListener(Consumer<ScheduledTick<?>> listener); | ||
void rsmm$setListener(ScheduledTickListener listener); | ||
|
||
public void rsmm$setTickListener(Consumer<ScheduledTick<?>> listener); | ||
ScheduledTickListener rsmm$getListener(); | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/redstone/multimeter/interfaces/mixin/ScheduledTickListener.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,11 @@ | ||
package redstone.multimeter.interfaces.mixin; | ||
|
||
import net.minecraft.world.ticks.ScheduledTick; | ||
|
||
public interface ScheduledTickListener { | ||
|
||
void rsmm$scheduleTick(ScheduledTick<?> scheduledTick); | ||
|
||
void rsmm$runTick(ScheduledTick<?> scheduledTick); | ||
|
||
} |
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
68 changes: 68 additions & 0 deletions
68
src/main/java/redstone/multimeter/mixin/common/compat/subtick/BlockEventQueueMixin.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,68 @@ | ||
package redstone.multimeter.mixin.common.compat.subtick; | ||
|
||
import org.apache.commons.lang3.tuple.Pair; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Pseudo; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.server.level.ServerLevel; | ||
|
||
import redstone.multimeter.interfaces.mixin.BlockEventListener; | ||
|
||
@Pseudo | ||
@Mixin(targets = "subtick.queues.BlockEventQueue") | ||
public class BlockEventQueueMixin { | ||
|
||
private BlockEventListener rsmm$listener; | ||
|
||
@Inject( | ||
method = "<init>", | ||
at = @At( | ||
value = "TAIL" | ||
) | ||
) | ||
private void init(ServerLevel level, CallbackInfo ci) { | ||
this.rsmm$listener = (BlockEventListener)level; | ||
} | ||
|
||
@Inject( | ||
method = "start", | ||
at = @At( | ||
value = "HEAD" | ||
) | ||
) | ||
private void start(CallbackInfo ci) { | ||
if (rsmm$listener != null) { | ||
rsmm$listener.rsmm$startBlockEvents(); | ||
} | ||
} | ||
|
||
@Inject( | ||
method = "step", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lit/unimi/dsi/fastutil/objects/ObjectLinkedOpenHashSet;removeFirst()Ljava/lang/Object;" | ||
) | ||
) | ||
private void next(int count, BlockPos pos, int range, CallbackInfoReturnable<Pair<Integer, Boolean>> cir) { | ||
if (rsmm$listener != null) { | ||
rsmm$listener.rsmm$nextBlockEvent(); | ||
} | ||
} | ||
|
||
@Inject( | ||
method = "end", | ||
at = @At( | ||
value = "HEAD" | ||
) | ||
) | ||
private void end(CallbackInfo ci) { | ||
if (rsmm$listener != null) { | ||
rsmm$listener.rsmm$endBlockEvents(); | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/redstone/multimeter/mixin/common/compat/subtick/ScheduledTickQueueMixin.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,41 @@ | ||
package redstone.multimeter.mixin.common.compat.subtick; | ||
|
||
import org.apache.commons.lang3.tuple.Pair; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Pseudo; | ||
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.CallbackInfoReturnable; | ||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.ticks.LevelTicks; | ||
import net.minecraft.world.ticks.ScheduledTick; | ||
|
||
import redstone.multimeter.interfaces.mixin.ILevelTicks; | ||
import redstone.multimeter.interfaces.mixin.ScheduledTickListener; | ||
|
||
@Pseudo | ||
@Mixin(targets = "subtick.queues.ScheduledTickQueue") | ||
public class ScheduledTickQueueMixin { | ||
|
||
@Shadow @Final private LevelTicks<?> levelTicks; | ||
|
||
@Inject( | ||
method = "step", | ||
locals = LocalCapture.CAPTURE_FAILHARD, | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Ljava/util/function/BiConsumer;accept(Ljava/lang/Object;Ljava/lang/Object;)V" | ||
) | ||
) | ||
private void logTick(int count, BlockPos pos, int range, CallbackInfoReturnable<Pair<Integer, Boolean>> cir, int executed_steps, ScheduledTick<?> scheduledTick) { | ||
ScheduledTickListener listener = ((ILevelTicks)levelTicks).rsmm$getListener(); | ||
|
||
if (listener != null) { | ||
listener.rsmm$runTick(scheduledTick); | ||
} | ||
} | ||
} |
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