Skip to content

Commit

Permalink
Update to 1.21.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Dec 22, 2024
1 parent 56280f6 commit ecb8759
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 40 deletions.
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ org.gradle.jvmargs=-Xmx2G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.21
yarn_mappings=1.21+build.9
loader_version=0.15.11
fabric_version=0.100.7+1.21
minecraft_version=1.21.4
yarn_mappings=1.21.4+build.2
loader_version=0.16.9
fabric_version=0.112.2+1.21.4

# Other Dependencies
jb_annotations_version = 23.0.0
apiguardian_version = 1.1.2

# Mod Properties
mod_version = 3.2.1
mod_version = 3.3.0
maven_group = org.ladysnake
archives_base_name = impersonate

Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
cca = "6.1.1"
cca = "6.1.2"
fpa = "0.2-SNAPSHOT"
elmendorf = "0.13.0"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.ladysnake.impersonate.impl;

import net.minecraft.server.command.CommandOutput;

public interface ImpersonateCommandOutput extends CommandOutput {
boolean impersonate$shouldRevealName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@
import net.minecraft.server.command.CommandOutput;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.MutableText;
import net.minecraft.text.StringVisitable;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.text.TextContent;
import net.minecraft.text.*;
import org.jetbrains.annotations.Nullable;
import org.ladysnake.impersonate.Impersonator;

Expand Down Expand Up @@ -66,17 +62,17 @@ private ImpersonateTextContent(String trueText, String fakedText, boolean reveal

@Override
public void impersonateResolve(CommandOutput recipient) {
revealed = !(recipient instanceof PlayerEntity player) || shouldBeRevealedBy(player);
revealed = !(recipient instanceof ImpersonateCommandOutput impersonateOutput) || impersonateOutput.impersonate$shouldRevealName();
}

public boolean isRevealed() {
return revealed;
}

public static boolean shouldBeRevealedBy(PlayerEntity player) {
return player instanceof ServerPlayerEntity
&& player.getWorld().getGameRules().getBoolean(ImpersonateGamerules.OP_REVEAL_IMPERSONATIONS)
&& ((ServerPlayerEntity) player).server.getPlayerManager().isOperator(player.getGameProfile());
return player instanceof ServerPlayerEntity serverPlayer
&& serverPlayer.getServerWorld().getGameRules().getBoolean(ImpersonateGamerules.OP_REVEAL_IMPERSONATIONS)
&& serverPlayer.server.getPlayerManager().isOperator(player.getGameProfile());
}

@Override
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/org/ladysnake/impersonate/impl/PacketMeddling.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,24 @@
*/
package org.ladysnake.impersonate.impl;

import io.netty.buffer.ByteBuf;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.codec.PacketCodecs;
import net.minecraft.network.message.MessageType;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.s2c.play.ChatMessageS2CPacket;
import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.server.command.CommandOutput;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import org.jetbrains.annotations.Nullable;
import org.ladysnake.impersonate.Impersonate;
import org.ladysnake.impersonate.Impersonator;
import org.ladysnake.impersonate.impl.mixin.PlayerListS2CPacketEntryAccessor;

import java.util.Optional;
import java.util.function.Function;

public final class PacketMeddling {

Expand Down Expand Up @@ -72,12 +68,14 @@ public static <P extends Packet<?>> P copyPacket(P packet, PacketCodec<? super R
}

public static ChatMessageS2CPacket resolveChatMessage(ChatMessageS2CPacket chatPacket, ServerPlayerEntity player) {
@Nullable Text unsignedContent = Optional.ofNullable(chatPacket.unsignedContent()).map(t -> ((RecipientAwareText) t).impersonateResolveAll(player)).orElse(null);
Text name = ((RecipientAwareText) chatPacket.serializedParameters().name()).impersonateResolveAll(player);
CommandOutput commandOutput = player.getCommandOutput();
@Nullable Text unsignedContent = Optional.ofNullable(chatPacket.unsignedContent()).map(t -> ((RecipientAwareText) t).impersonateResolveAll(commandOutput)).orElse(null);
Text name = ((RecipientAwareText) chatPacket.serializedParameters().name()).impersonateResolveAll(commandOutput);
Optional<Text> targetName = chatPacket.serializedParameters().targetName().map(text -> text instanceof RecipientAwareText t
? t.impersonateResolveAll(player)
? t.impersonateResolveAll(commandOutput)
: null);


// God, I wish we had a Record#copy method in this language
// And yes we need to do a deep copy at the end, to avoid sharing text references
return copyPacket(new ChatMessageS2CPacket(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void syncChanges(@Nullable GameProfile profile) {
}

private void applyCapeGamerule(ServerPlayerEntity player, GameProfile impersonatedProfile) {
if (!player.getWorld().getGameRules().getBoolean(ImpersonateGamerules.FAKE_CAPES)) {
if (!player.getServerWorld().getGameRules().getBoolean(ImpersonateGamerules.FAKE_CAPES)) {
if (impersonatedProfile == null) {
((PlayerEntityExtensions) player).impersonate_resetCape();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,7 @@
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.entity.Entity;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.network.packet.s2c.play.CommonPlayerSpawnInfo;
import net.minecraft.network.packet.s2c.play.EntityPassengersSetS2CPacket;
import net.minecraft.network.packet.s2c.play.EntityStatusEffectS2CPacket;
import net.minecraft.network.packet.s2c.play.ExperienceBarUpdateS2CPacket;
import net.minecraft.network.packet.s2c.play.HealthUpdateS2CPacket;
import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket;
import net.minecraft.network.packet.s2c.play.PlayerRemoveS2CPacket;
import net.minecraft.network.packet.s2c.play.PlayerRespawnS2CPacket;
import net.minecraft.network.packet.s2c.play.*;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerChunkLoadingManager;
import net.minecraft.server.world.ServerChunkManager;
Expand Down Expand Up @@ -172,7 +165,8 @@ private static void reloadSkinVanilla(ServerPlayerEntity player) {
targetWorld.isDebugWorld(),
targetWorld.isFlat(),
player.getLastDeathPos(),
player.getPortalCooldown()
player.getPortalCooldown(),
targetWorld.getSeaLevel()
),
PlayerRespawnS2CPacket.KEEP_ATTRIBUTES
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private Packet<?> resolveFakeTextsInPackets(Packet<?> packet) {
}
} else if (packet instanceof GameMessageS2CPacket gamePacket) {
if (this.existsImpersonator()) {
Text resolvedText = ((RecipientAwareText) gamePacket.content()).impersonateResolveAll(player);
Text resolvedText = ((RecipientAwareText) gamePacket.content()).impersonateResolveAll(player.getCommandOutput());
return new GameMessageS2CPacket(resolvedText, gamePacket.overlay());
}
} else if (packet instanceof PlayerListS2CPacket listPacket) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.ladysnake.impersonate.impl.mixin;

import net.minecraft.server.network.ServerPlayerEntity;
import org.ladysnake.impersonate.impl.ImpersonateCommandOutput;
import org.ladysnake.impersonate.impl.ImpersonateTextContent;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(targets = "net.minecraft.server.network.ServerPlayerEntity$3")
public abstract class ServerPlayerEntity$CommandOutput implements ImpersonateCommandOutput {
@Shadow
@Final
ServerPlayerEntity field_54403;

@Override
public boolean impersonate$shouldRevealName() {
return ImpersonateTextContent.shouldBeRevealedBy(this.field_54403);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,31 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.packet.c2s.common.SyncedClientOptions;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.ladysnake.impersonate.Impersonator;
import org.ladysnake.impersonate.impl.ImpersonateGamerules;
import org.ladysnake.impersonate.impl.PlayerEntityExtensions;
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(ServerPlayerEntity.class)
public abstract class ServerPlayerEntityMixin extends PlayerEntity implements PlayerEntityExtensions {

@Shadow
public abstract ServerWorld getServerWorld();

public ServerPlayerEntityMixin(World world, BlockPos pos, float yaw, GameProfile profile) {
super(world, pos, yaw, profile);
}

@Inject(method = "setClientOptions", at = @At("RETURN"))
private void removeCapeIfDisallowed(SyncedClientOptions clientOptions, CallbackInfo ci) {
if (Impersonator.get(this).isImpersonating() && !this.getWorld().getGameRules().getBoolean(ImpersonateGamerules.FAKE_CAPES)) {
if (Impersonator.get(this).isImpersonating() && !this.getServerWorld().getGameRules().getBoolean(ImpersonateGamerules.FAKE_CAPES)) {
this.impersonate_disableCape();
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/mixins.impersonate.common.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
"PlayerListS2CPacketEntryAccessor",
"PlayerListS2CPacketEntryMixin",
"PlayerManagerMixin",
"ServerChunkLoadingManagerAccessor",
"ServerCommonNetworkHandlerMixin",
"ServerPlayerEntity$CommandOutput",
"ServerPlayerEntityMixin",
"TextMixin",
"ServerChunkLoadingManagerAccessor",
"TranslatableTextContentMixin"
],
"injectors": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.TypedActionResult;
import net.minecraft.world.World;
import org.ladysnake.impersonate.Impersonator;

Expand All @@ -37,9 +36,9 @@ public ImpersonItem(Settings settings) {
}

@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
public ActionResult use(World world, PlayerEntity user, Hand hand) {
if (Impersonator.get(user).stopImpersonation(IMPERSONATION_KEY) != null) {
return TypedActionResult.success(user.getStackInHand(hand));
return ActionResult.SUCCESS;
}
return super.use(world, user, hand);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import net.minecraft.item.Item;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;

public final class Impersonatest implements ModInitializer {
Expand All @@ -31,7 +33,8 @@ public static Identifier id(String path) {

@Override
public void onInitialize() {
Registry.register(Registries.ITEM, id("impersonitem"), new ImpersonItem(new Item.Settings()));
Identifier impersonitemId = id("impersonitem");
Registry.register(Registries.ITEM, impersonitemId, new ImpersonItem(new Item.Settings().registryKey(RegistryKey.of(RegistryKeys.ITEM, impersonitemId))));
}

}

0 comments on commit ecb8759

Please sign in to comment.