generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 23
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
Showing
11 changed files
with
115 additions
and
4 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
23 changes: 23 additions & 0 deletions
23
src/main/java/com/github/zly2006/reden/mixin/undo/MixinBlockEvent.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,23 @@ | ||
package com.github.zly2006.reden.mixin.undo; | ||
|
||
import com.github.zly2006.reden.access.ScheduledTickAccess; | ||
import net.minecraft.server.world.BlockEvent; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
|
||
@SuppressWarnings("AddedMixinMembersNamePattern") | ||
@Mixin(BlockEvent.class) | ||
public class MixinBlockEvent implements ScheduledTickAccess { | ||
@Unique | ||
long undoId; | ||
|
||
@Override | ||
public long getUndoId() { | ||
return undoId; | ||
} | ||
|
||
@Override | ||
public void setUndoId(long l) { | ||
undoId = l; | ||
} | ||
} |
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
58 changes: 58 additions & 0 deletions
58
src/main/java/com/github/zly2006/reden/mixin/undo/MixinServerWorld.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,58 @@ | ||
package com.github.zly2006.reden.mixin.undo; | ||
|
||
import com.github.zly2006.reden.access.PlayerData; | ||
import com.github.zly2006.reden.access.ScheduledTickAccess; | ||
import com.github.zly2006.reden.mixinhelper.UpdateMonitorHelper; | ||
import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet; | ||
import net.minecraft.server.world.BlockEvent; | ||
import net.minecraft.server.world.ServerWorld; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(ServerWorld.class) | ||
public class MixinServerWorld { | ||
@Redirect( | ||
method = "addSyncedBlockEvent", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lit/unimi/dsi/fastutil/objects/ObjectLinkedOpenHashSet;add(Ljava/lang/Object;)Z", | ||
remap = false | ||
) | ||
) | ||
private boolean onAddBlockEvent(ObjectLinkedOpenHashSet<BlockEvent> instance, Object curr) { | ||
if (curr instanceof ScheduledTickAccess access) { | ||
PlayerData.UndoRecord recording = UpdateMonitorHelper.INSTANCE.getRecording(); | ||
if (recording != null) { | ||
access.setUndoId(recording.getId()); | ||
} | ||
} | ||
return instance.add((BlockEvent) curr); | ||
} | ||
@Inject( | ||
method = "processBlockEvent", | ||
at = @At( | ||
value = "INVOKE", | ||
shift = At.Shift.BEFORE, | ||
target = "Lnet/minecraft/block/BlockState;onSyncedBlockEvent(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;II)Z" | ||
) | ||
) | ||
private void beforeProcessBlockEvent(BlockEvent event, CallbackInfoReturnable<Boolean> cir) { | ||
UpdateMonitorHelper.INSTANCE.setRecording( | ||
UpdateMonitorHelper.INSTANCE.getUndoRecordsMap().get(((ScheduledTickAccess) event).getUndoId()) | ||
); | ||
} | ||
@Inject( | ||
method = "processBlockEvent", | ||
at = @At( | ||
value = "INVOKE", | ||
shift = At.Shift.AFTER, | ||
target = "Lnet/minecraft/block/BlockState;onSyncedBlockEvent(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;II)Z" | ||
) | ||
) | ||
private void afterProcessBlockEvent(BlockEvent event, CallbackInfoReturnable<Boolean> cir) { | ||
UpdateMonitorHelper.INSTANCE.setRecording(null); | ||
} | ||
} |
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