Skip to content

Commit

Permalink
Fix missed phase tracker changes in the Neo module
Browse files Browse the repository at this point in the history
  • Loading branch information
aromaa committed Nov 6, 2024
1 parent 1b07a5e commit e11e9df
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
*/
package org.spongepowered.neoforge.mixin.core.server.level;

import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.common.event.tracking.PhaseContext;
import org.spongepowered.common.event.tracking.PhaseTracker;
Expand All @@ -37,10 +39,14 @@
@Mixin(ServerPlayer.class)
public abstract class ServerPlayerMixin_Neo extends LivingEntityMixin_Neo {

// @formatter:off
@Shadow public abstract ServerLevel shadow$serverLevel();
// @formatter:on

// override from LivingEntityMixin_Neo
@Override
protected void neo$onElytraUse(final CallbackInfo ci) {
final PhaseContext<?> context = PhaseTracker.SERVER.getPhaseContext();
final PhaseContext<?> context = PhaseTracker.getWorldInstance(this.shadow$serverLevel()).getPhaseContext();
final TransactionalCaptureSupplier transactor = context.getTransactor();
final net.minecraft.server.level.ServerPlayer player = (net.minecraft.server.level.ServerPlayer) (Object) this;
try (final EffectTransactor ignored = transactor.logPlayerInventoryChangeWithEffect(player, PlayerInventoryTransaction.EventCreator.STANDARD)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public abstract class ServerGamePacketListenerImplMixin_Neo implements ServerGam
private RecipeBookMenu.PostPlaceAction neo$onPlaceRecipe(
final RecipeBookMenu recipeBookMenu, final boolean shift, final boolean isCreative, final RecipeHolder<?> recipe,
final ServerLevel serverLevel, final net.minecraft.world.entity.player.Inventory inventory) {
final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
final PhaseContext<@NonNull ?> context = PhaseTracker.getWorldInstance(this.player.serverLevel()).getPhaseContext();
final TransactionalCaptureSupplier transactor = context.getTransactor();
final var player = this.player;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@
package org.spongepowered.neoforge.mixin.inventory.event.server.level;

import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
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.Redirect;
Expand All @@ -43,7 +45,12 @@
import java.util.function.Consumer;

@Mixin(ServerPlayer.class)
public class ServerPlayerMixin_Inventory_Neo {
public abstract class ServerPlayerMixin_Inventory_Neo {

// @formatter:off
@Shadow public abstract ServerLevel shadow$serverLevel();
// @formatter:on

@Nullable private Object inventory$menuProvider;

@Inject(
Expand All @@ -56,7 +63,7 @@ public class ServerPlayerMixin_Inventory_Neo {
)
)
private void impl$afterOpenMenu(final CallbackInfoReturnable<OptionalInt> cir) {
PhaseTracker.SERVER.getPhaseContext().getTransactor().logContainerSet((ServerPlayer) (Object) this);
PhaseTracker.getWorldInstance(this.shadow$serverLevel()).getPhaseContext().getTransactor().logContainerSet((ServerPlayer) (Object) this);
}

@Inject(method = "openMenu(Lnet/minecraft/world/MenuProvider;Ljava/util/function/Consumer;)Ljava/util/OptionalInt;", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;initMenu(Lnet/minecraft/world/inventory/AbstractContainerMenu;)V"))
Expand All @@ -75,7 +82,7 @@ public class ServerPlayerMixin_Inventory_Neo {
final MenuProvider menuProvider, final int containerCounter, final net.minecraft.world.entity.player.Inventory inventory,
final Player player
) {
try (final EffectTransactor ignored = PhaseTracker.SERVER.getPhaseContext()
try (final EffectTransactor ignored = PhaseTracker.getWorldInstance(this.shadow$serverLevel()).getPhaseContext()
.getTransactor()
.logOpenInventory((ServerPlayer) (Object) this)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public abstract class ServerPlayerGameModeMixin_Neo_Tracker {
final ItemStack itemStack, final Level level, final BlockState state, final BlockPos pos,
final Player player
) {
final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
final PhaseContext<@NonNull ?> context = PhaseTracker.getWorldInstance(this.player.serverLevel()).getPhaseContext();
final TransactionalCaptureSupplier transactor = context.getTransactor();
// Log the prepare drops here because Forge rewrites
// this method to call mine block before calling destroy block
Expand Down

0 comments on commit e11e9df

Please sign in to comment.