-
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.
- Loading branch information
Showing
11 changed files
with
158 additions
and
20 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
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
34 changes: 34 additions & 0 deletions
34
src/main/java/me/drex/vanish/mixin/MapItemSavedDataMixin.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,34 @@ | ||
package me.drex.vanish.mixin; | ||
|
||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import com.llamalad7.mixinextras.sugar.Local; | ||
import me.drex.vanish.api.VanishAPI; | ||
import net.minecraft.world.level.saveddata.maps.MapItemSavedData; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
@Mixin(MapItemSavedData.class) | ||
public abstract class MapItemSavedDataMixin { | ||
|
||
@Shadow | ||
protected abstract void removeDecoration(String string); | ||
|
||
@WrapOperation( | ||
method = "tickCarriedBy", | ||
at = @At( | ||
value = "FIELD", | ||
target = "Lnet/minecraft/world/level/saveddata/maps/MapItemSavedData;trackingPosition:Z" | ||
) | ||
) | ||
private boolean vanish_hideFromMap(MapItemSavedData instance, Operation<Boolean> original, @Local MapItemSavedData.HoldingPlayer holdingPlayer) { | ||
if (VanishAPI.isVanished(holdingPlayer.player)) { | ||
removeDecoration(holdingPlayer.player.getName().getString()); | ||
return false; | ||
} else { | ||
return original.call(instance); | ||
} | ||
} | ||
|
||
} |
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
50 changes: 50 additions & 0 deletions
50
src/main/java/me/drex/vanish/mixin/VanishedServerPlayerMixin.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,50 @@ | ||
package me.drex.vanish.mixin; | ||
|
||
import com.mojang.authlib.GameProfile; | ||
import eu.pb4.playerdata.api.PlayerDataApi; | ||
import me.drex.vanish.util.VanishData; | ||
import me.drex.vanish.util.VanishedEntity; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.level.Level; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
|
||
import static me.drex.vanish.util.VanishManager.VANISH_DATA_STORAGE; | ||
|
||
@Mixin(ServerPlayer.class) | ||
public abstract class VanishedServerPlayerMixin extends Player implements VanishedEntity { | ||
|
||
@Shadow | ||
@Final | ||
public MinecraftServer server; | ||
@Unique | ||
private boolean vanished$dirty = true; | ||
|
||
@Unique | ||
private boolean vanished$vanished; | ||
|
||
public VanishedServerPlayerMixin(Level level, BlockPos blockPos, float f, GameProfile gameProfile) { | ||
super(level, blockPos, f, gameProfile); | ||
} | ||
|
||
@Override | ||
public boolean vanish$isVanished() { | ||
if (vanished$dirty) { | ||
VanishData data = PlayerDataApi.getCustomDataFor(server, uuid, VANISH_DATA_STORAGE); | ||
vanished$vanished = data != null && data.vanished; | ||
vanished$dirty = false; | ||
} | ||
return vanished$vanished; | ||
} | ||
|
||
@Override | ||
public void vanish$setDirty() { | ||
vanished$dirty = true; | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package me.drex.vanish.util; | ||
|
||
public interface VanishedEntity { | ||
|
||
boolean vanish$isVanished(); | ||
|
||
void vanish$setDirty(); | ||
|
||
} |
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