-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Vanished players can no longer block merchant trading
The trading system in vanilla is implemented with just one trading player in mind. Because of that the trade screen of vanished players is simply closed when another player attempts to trade with the villager to make it seem like nobody else is trading with the villager to non vanished players. These changes have low priority and may be removed at any time, because it is easy to not allow this case to happen as a vanished player. resolves #46
- Loading branch information
Showing
3 changed files
with
37 additions
and
0 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
35 changes: 35 additions & 0 deletions
35
src/main/java/me/drex/vanish/mixin/AbstractVillagerMixin.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,35 @@ | ||
package me.drex.vanish.mixin; | ||
|
||
import com.llamalad7.mixinextras.injector.ModifyReturnValue; | ||
import me.drex.vanish.api.VanishAPI; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.world.entity.npc.AbstractVillager; | ||
import net.minecraft.world.entity.player.Player; | ||
import org.jetbrains.annotations.Nullable; | ||
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.callback.CallbackInfo; | ||
|
||
@Mixin(AbstractVillager.class) | ||
public class AbstractVillagerMixin { | ||
@Shadow | ||
private @Nullable Player tradingPlayer; | ||
|
||
@ModifyReturnValue(method = "isTrading", at = @At("RETURN")) | ||
private boolean vanish_allowTradingIfVanished(boolean original) { | ||
if (original) { | ||
assert this.tradingPlayer != null; | ||
return !VanishAPI.isVanished(this.tradingPlayer); | ||
} | ||
return false; | ||
} | ||
|
||
@Inject(method = "setTradingPlayer", at = @At("HEAD")) | ||
private void vanish_closeVanishedPlayerTradeScreen(Player player, CallbackInfo ci) { | ||
if (player != null && this.tradingPlayer instanceof ServerPlayer serverPlayer) { | ||
serverPlayer.closeContainer(); | ||
} | ||
} | ||
} |
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