2424 */
2525package org .spongepowered .common .mixin .tracker .world .level .block ;
2626
27+ import com .llamalad7 .mixinextras .injector .wrapmethod .WrapMethod ;
28+ import com .llamalad7 .mixinextras .injector .wrapoperation .Operation ;
2729import net .minecraft .core .BlockPos ;
2830import net .minecraft .core .Registry ;
2931import net .minecraft .core .registries .BuiltInRegistries ;
3739import org .checkerframework .checker .nullness .qual .NonNull ;
3840import org .checkerframework .checker .nullness .qual .Nullable ;
3941import org .spongepowered .asm .mixin .Mixin ;
40- import org .spongepowered .asm .mixin .injection .At ;
41- import org .spongepowered .asm .mixin .injection .Inject ;
42- import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
4342import org .spongepowered .common .bridge .RegistryBackedTrackableBridge ;
4443import org .spongepowered .common .bridge .world .level .block .TrackableBlockBridge ;
4544import org .spongepowered .common .config .SpongeGameConfigs ;
@@ -55,8 +54,6 @@ public abstract class BlockMixin_Tracker implements TrackableBlockBridge, Regist
5554 private final boolean tracker$hasNeighborLogicOverridden = ReflectionUtil .isNeighborChangedDeclared (this .getClass ());
5655 private final boolean tracker$hasEntityInsideLogicOverridden = ReflectionUtil .isEntityInsideDeclared (this .getClass ());
5756
58- @ Nullable private static EffectTransactor tracker$effectTransactorForDrops = null ;
59-
6057 @ Override
6158 public boolean bridge$overridesNeighborNotificationLogic () {
6259 return this .tracker$hasNeighborLogicOverridden ;
@@ -67,99 +64,46 @@ public abstract class BlockMixin_Tracker implements TrackableBlockBridge, Regist
6764 return this .tracker$hasEntityInsideLogicOverridden ;
6865 }
6966
70- /**
71- * This is a scattering approach to checking that all block spawns being
72- * attempted are going to be prevented if the block changes are currently
73- * restoring.
74- *
75- * @author gabizou - August 16th, 2020 - Minecraft 1.14.4
76- * @param ci The callback info
77- */
78- @ Inject (
79- method = {
80- "dropResources(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)V" ,
81- "dropResources(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/entity/BlockEntity;)V" ,
82- "dropResources(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/entity/BlockEntity;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/item/ItemStack;)V"
83- },
84- at = @ At ("HEAD" ),
85- cancellable = true
86- )
87- private static void tracker$cancelOnBlockRestoration (final CallbackInfo ci ) {
88- if (Thread .currentThread () == PhaseTracker .SERVER .getSidedThread ()) {
89- if (PhaseTracker .SERVER .getPhaseContext ().isRestoring ()) {
90- ci .cancel ();
91- }
92- }
93- }
94-
95- @ Inject (
96- method = "dropResources(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)V" ,
97- at = @ At ("HEAD" )
98- )
67+ @ WrapMethod (method = "dropResources(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)V" )
9968 private static void tracker$captureBlockProposedToBeSpawningDrops (final BlockState state , final Level worldIn ,
100- final BlockPos pos , final CallbackInfo ci ) {
101- final PhaseTracker server = PhaseTracker .SERVER ;
102- if (server .getSidedThread () != Thread .currentThread ()) {
103- return ;
104- }
105- final PhaseContext <@ NonNull ?> context = server .getPhaseContext ();
106- BlockMixin_Tracker .tracker$effectTransactorForDrops = context .getTransactor ()
107- .logBlockDrops (worldIn , pos , state , null );
69+ final BlockPos pos , final Operation <Void > original ) {
70+ BlockMixin_Tracker .tracker$logBlockDrops (worldIn , pos , state , null , () -> original .call (state , worldIn , pos ));
10871 }
10972
110- @ Inject (
111- method = "dropResources(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/entity/BlockEntity;)V" ,
112- at = @ At ("HEAD" )
113- )
73+ @ WrapMethod (method = "dropResources(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/entity/BlockEntity;)V" )
11474 private static void tracker$captureBlockProposedToBeSpawningDrops (
11575 final BlockState state , final LevelAccessor worldIn ,
116- final BlockPos pos , final @ Nullable BlockEntity tileEntity , final CallbackInfo ci
76+ final BlockPos pos , final @ Nullable BlockEntity tileEntity , final Operation < Void > original
11777 ) {
118- if (!(worldIn instanceof Level )) {
78+ if (!(worldIn instanceof final Level level )) {
11979 return ; // In the name of my father, and his father before him, I cast you out!
12080 }
121- final PhaseTracker server = PhaseTracker .SERVER ;
122- if (server .getSidedThread () != Thread .currentThread ()) {
123- return ;
124- }
125- final PhaseContext <@ NonNull ?> context = server .getPhaseContext ();
126- BlockMixin_Tracker .tracker$effectTransactorForDrops = context .getTransactor ()
127- .logBlockDrops ((Level ) worldIn , pos , state , tileEntity );
81+
82+ BlockMixin_Tracker .tracker$logBlockDrops (level , pos , state , tileEntity , () -> original .call (state , worldIn , pos , tileEntity ));
12883 }
12984
130- @ Inject (
131- method = "dropResources(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/entity/BlockEntity;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/item/ItemStack;)V" ,
132- at = @ At ("HEAD" )
133- )
85+ @ WrapMethod (method = "dropResources(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/entity/BlockEntity;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/item/ItemStack;)V" )
13486 private static void tracker$captureBlockProposedToBeSpawningDrops (final BlockState state , final Level worldIn ,
13587 final BlockPos pos , final @ Nullable BlockEntity tileEntity , final Entity entity , final ItemStack itemStack ,
136- final CallbackInfo ci ) {
137- final PhaseTracker server = PhaseTracker .SERVER ;
138- if (server .getSidedThread () != Thread .currentThread ()) {
139- return ;
140- }
141- final PhaseContext <@ NonNull ?> context = server .getPhaseContext ();
142- BlockMixin_Tracker .tracker$effectTransactorForDrops = context .getTransactor ()
143- .logBlockDrops (worldIn , pos , state , tileEntity );
88+ final Operation <Void > original ) {
89+ BlockMixin_Tracker .tracker$logBlockDrops (worldIn , pos , state , tileEntity , () -> original .call (state , worldIn , pos , tileEntity , entity , itemStack ));
14490 }
14591
92+ private static void tracker$logBlockDrops (final Level worldIn , final BlockPos pos , final BlockState state ,
93+ final @ Nullable BlockEntity tileEntity , final Runnable runnable ) {
94+ final PhaseTracker tracker = PhaseTracker .SERVER ;
95+ if (tracker .onSidedThread ()) {
96+ if (tracker .getPhaseContext ().isRestoring ()) {
97+ return ;
98+ }
14699
147- @ Inject (
148- method = {
149- "dropResources(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)V" ,
150- "dropResources(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/entity/BlockEntity;)V" ,
151- "dropResources(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/entity/BlockEntity;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/item/ItemStack;)V"
152- },
153- at = @ At ("TAIL" )
154- )
155- private static void tracker$closeEffectIfCapturing (final CallbackInfo ci ) {
156- final PhaseTracker server = PhaseTracker .SERVER ;
157- if (server .getSidedThread () != Thread .currentThread ()) {
158- return ;
100+ final PhaseContext <@ NonNull ?> context = tracker .getPhaseContext ();
101+ try (final EffectTransactor ignored = context .getTransactor ().logBlockDrops (worldIn , pos , state , tileEntity )) {
102+ runnable .run ();
103+ }
104+ } else {
105+ runnable .run ();
159106 }
160- final PhaseContext <@ NonNull ?> context = server .getPhaseContext ();
161- context .getTransactor ().completeBlockDrops (BlockMixin_Tracker .tracker$effectTransactorForDrops );
162- BlockMixin_Tracker .tracker$effectTransactorForDrops = null ;
163107 }
164108
165109 @ Override
0 commit comments