3838import org .spongepowered .api .event .SpongeEventFactory ;
3939import org .spongepowered .api .event .block .entity .BrewingEvent ;
4040import org .spongepowered .api .item .inventory .ItemStackSnapshot ;
41+ import org .spongepowered .api .item .inventory .Slot ;
4142import org .spongepowered .api .item .inventory .transaction .SlotTransaction ;
4243import org .spongepowered .asm .mixin .Mixin ;
4344import org .spongepowered .asm .mixin .Shadow ;
4647import org .spongepowered .asm .mixin .injection .Slice ;
4748import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
4849import org .spongepowered .asm .mixin .injection .callback .LocalCapture ;
50+ import org .spongepowered .common .inventory .adapter .InventoryAdapter ;
4951import org .spongepowered .common .inventory .adapter .impl .slots .SlotAdapter ;
52+ import org .spongepowered .common .inventory .lens .Lens ;
5053import org .spongepowered .common .item .util .ItemStackUtil ;
5154
5255import java .util .ArrayList ;
@@ -75,7 +78,12 @@ public class BrewingStandBlockEntityMixin {
7578 fuelStack .grow (1 );
7679 final ItemStackSnapshot originalStack = ItemStackUtil .snapshotOf (fuelStack );
7780 fuelStack .shrink (1 );
78- final SlotTransaction fuelTransaction = new SlotTransaction (((BrewingStand ) param3 ).inventory ().slot (4 ).get (), originalStack , ItemStackUtil .snapshotOf (fuelStack ));
81+ final Lens lens = ((InventoryAdapter ) param3 ).inventoryAdapter$getRootLens ();
82+ final SlotTransaction fuelTransaction = new SlotTransaction (
83+ (Slot ) lens .getLens (4 ).getAdapter (((InventoryAdapter ) param3 ).inventoryAdapter$getFabric (), ((BrewingStand ) param3 ).inventory ()),
84+ originalStack ,
85+ ItemStackUtil .snapshotOf (fuelStack )
86+ );
7987 final ItemStackSnapshot ingredientStack = ItemStackUtil .snapshotOf (((BrewingStandBlockEntityMixin ) (Object ) param3 ).items .get (3 ));
8088 final BrewingEvent .ConsumeFuel
8189 event = SpongeEventFactory .createBrewingEventConsumeFuel (currentCause , (BrewingStand ) param3 , ingredientStack , Collections .singletonList (fuelTransaction ));
@@ -104,17 +112,20 @@ public class BrewingStandBlockEntityMixin {
104112 private static void impl$callBrewEvents (final Level param0 , final BlockPos param1 , final BlockState param2 , final BrewingStandBlockEntity param3 ,
105113 final CallbackInfo ci , final ItemStack fuelStack , final boolean isBrewable , final boolean isBrewing , final ItemStack ingredientStack ) {
106114 final Cause currentCause = Sponge .server ().causeStackManager ().currentCause ();
115+ final BrewingStandBlockEntityMixin mixinSelf = (BrewingStandBlockEntityMixin ) (Object ) param3 ;
107116 if (isBrewing ) {
108- if ((( BrewingStandBlockEntityMixin ) ( Object ) param3 ) .brewTime == 0 && isBrewable ) {
117+ if (mixinSelf .brewTime == 0 && isBrewable ) {
109118 final List <SlotTransaction > transactions = new ArrayList <>();
119+ final Lens lens = ((InventoryAdapter ) param3 ).inventoryAdapter$getRootLens ();
110120 for (int i = 0 ; i < 4 ; ++i ) {
111- final ItemStack original = (( BrewingStandBlockEntityMixin ) ( Object ) param3 ) .impl$originalSlots [i ];
112- final ItemStack replace = (( BrewingStandBlockEntityMixin ) ( Object ) param3 ) .items .get (i );
113- (( BrewingStandBlockEntityMixin ) ( Object ) param3 ) .impl$originalSlots [i ] = null ;
121+ final ItemStack original = mixinSelf .impl$originalSlots [i ];
122+ final ItemStack replace = mixinSelf .items .get (i );
123+ mixinSelf .impl$originalSlots [i ] = null ;
114124 if (original == replace ) {
115125 continue ;
116126 }
117- transactions .add (new SlotTransaction (((BrewingStand ) param3 ).inventory ().slot (i ).get (),
127+ transactions .add (new SlotTransaction (
128+ (Slot ) lens .getLens (i ).getAdapter (((InventoryAdapter ) param3 ).inventoryAdapter$getFabric (), ((BrewingStand ) param3 ).inventory ()),
118129 ItemStackUtil .snapshotOf (original ),
119130 ItemStackUtil .snapshotOf (replace )
120131 ));
@@ -123,18 +134,18 @@ public class BrewingStandBlockEntityMixin {
123134 Sponge .eventManager ().post (event );
124135 for (final SlotTransaction transaction : transactions ) {
125136 transaction .custom ().ifPresent (item ->
126- (( BrewingStandBlockEntityMixin ) ( Object ) param3 ) .items .set (((SlotAdapter ) transaction .slot ()).getOrdinal (), ItemStackUtil .fromSnapshotToNative (item )));
137+ mixinSelf .items .set (((SlotAdapter ) transaction .slot ()).getOrdinal (), ItemStackUtil .fromSnapshotToNative (item )));
127138 }
128- } else if (!isBrewable || (( BrewingStandBlockEntityMixin ) ( Object ) param3 ) .ingredient != ingredientStack .getItem ()) {
139+ } else if (!isBrewable || mixinSelf .ingredient != ingredientStack .getItem ()) {
129140 final BrewingEvent .Interrupt event = SpongeEventFactory .createBrewingEventInterrupt (currentCause , (BrewingStand ) param3 , ItemStackUtil .snapshotOf (ingredientStack ));
130141 Sponge .eventManager ().post (event );
131142 }
132- } else if (isBrewable && (( BrewingStandBlockEntityMixin ) ( Object ) param3 ) .fuel > 0 ) {
143+ } else if (isBrewable && mixinSelf .fuel > 0 ) {
133144 final BrewingEvent .Start event = SpongeEventFactory .createBrewingEventStart (currentCause , (BrewingStand ) param3 , ItemStackUtil .snapshotOf (ingredientStack ));
134145 if (Sponge .eventManager ().post (event )) {
135- (( BrewingStandBlockEntityMixin ) ( Object ) param3 ) .brewTime = 0 ;
136- (( BrewingStandBlockEntityMixin ) ( Object ) param3 ) .ingredient = Items .AIR ;
137- (( BrewingStandBlockEntityMixin ) ( Object ) param3 ) .fuel ++;
146+ mixinSelf .brewTime = 0 ;
147+ mixinSelf .ingredient = Items .AIR ;
148+ mixinSelf .fuel ++;
138149 }
139150 }
140151 }
0 commit comments