Skip to content

Commit

Permalink
Update to 1.16.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Sep 24, 2020
1 parent e853c36 commit 7123b33
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 68 deletions.
14 changes: 7 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.16.1
yarn_mappings=1.16.1+build.21
loader_version=0.9.0+build.204
fabric_version=0.16.0+build.384-1.16.1
minecraft_version=1.16.3
yarn_mappings=1.16.3+build.12
loader_version=0.9.3+build.207
fabric_version=0.21.0+build.407-1.16

# Minecraft dependencies
cca_version = 2.4.2
cca_version = 2.6.0

# Other Dependencies
jb_annotations_version = 19.0.0
apiguardian_version = 1.0.0

# Mod Properties
mod_version = 2.0.1
mod_version = 2.0.2
maven_group = io.github.ladysnake
archives_base_name = Impersonate

Expand All @@ -25,7 +25,7 @@ owners = Ladysnake
license_header = LGPL
gpl_version = 3
curseforge_id = 360333
curseforge_versions = 1.16; 1.16.1
curseforge_versions = 1.16.3
cf_requirements = fabric-api
cf_embeddeds = cardinal-components
release_type = release
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/io/github/ladysnake/impersonate/Impersonate.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
*/
package io.github.ladysnake.impersonate;

import dev.onyxstudios.cca.api.v3.component.entity.EntityComponentFactoryRegistry;
import dev.onyxstudios.cca.api.v3.component.entity.EntityComponentInitializer;
import dev.onyxstudios.cca.api.v3.component.ComponentKey;
import dev.onyxstudios.cca.api.v3.component.ComponentRegistryV3;
import dev.onyxstudios.cca.api.v3.entity.EntityComponentFactoryRegistry;
import dev.onyxstudios.cca.api.v3.entity.EntityComponentInitializer;
import io.github.ladysnake.impersonate.impl.ImpersonateCommand;
import io.github.ladysnake.impersonate.impl.ImpersonateGamerules;
import io.github.ladysnake.impersonate.impl.PlayerImpersonator;
import nerdhub.cardinal.components.api.ComponentRegistry;
import nerdhub.cardinal.components.api.ComponentType;
import nerdhub.cardinal.components.api.util.RespawnCopyStrategy;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Identifier;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -38,7 +38,7 @@
*/
public final class Impersonate implements ModInitializer, EntityComponentInitializer {
public static final Logger LOGGER = LogManager.getLogger("Impersonate");
public static final ComponentType<Impersonator> IMPERSONATION = ComponentRegistry.INSTANCE.registerStatic(
public static final ComponentKey<Impersonator> IMPERSONATION = ComponentRegistryV3.INSTANCE.getOrCreate(
new Identifier("impersonate", "impersonation"),
Impersonator.class
);
Expand All @@ -51,6 +51,6 @@ public void onInitialize() {

@Override
public void registerEntityComponentFactories(EntityComponentFactoryRegistry registry) {
registry.registerFor(PlayerEntity.class, IMPERSONATION, PlayerImpersonator::new);
registry.registerForPlayers(IMPERSONATION, PlayerImpersonator::new, RespawnCopyStrategy.ALWAYS_COPY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
package io.github.ladysnake.impersonate;

import com.mojang.authlib.GameProfile;
import nerdhub.cardinal.components.api.component.Component;
import dev.onyxstudios.cca.api.v3.component.ComponentV3;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public interface Impersonator extends Component {
public interface Impersonator extends ComponentV3 {

static Impersonator get(@NotNull PlayerEntity player) {
return Impersonate.IMPERSONATION.get(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import io.github.ladysnake.impersonate.Impersonator;
import net.minecraft.command.arguments.EntityArgumentType;
import net.minecraft.command.arguments.GameProfileArgumentType;
import net.minecraft.command.arguments.IdentifierArgumentType;
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.command.argument.GameProfileArgumentType;
import net.minecraft.command.argument.IdentifierArgumentType;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.TranslatableText;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
package io.github.ladysnake.impersonate.impl;

import com.mojang.authlib.GameProfile;
import dev.onyxstudios.cca.api.v3.util.PlayerComponent;
import dev.onyxstudios.cca.api.v3.component.AutoSyncedComponent;
import io.github.ladysnake.impersonate.Impersonate;
import io.github.ladysnake.impersonate.Impersonator;
import nerdhub.cardinal.components.api.ComponentType;
import nerdhub.cardinal.components.api.util.sync.EntitySyncedComponent;
import nerdhub.cardinal.components.api.component.extension.CopyableComponent;
import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundTag;
Expand All @@ -41,7 +41,7 @@
import java.util.Objects;
import java.util.UUID;

public class PlayerImpersonator implements Impersonator, EntitySyncedComponent, PlayerComponent<PlayerImpersonator> {
public class PlayerImpersonator implements Impersonator, AutoSyncedComponent, CopyableComponent<PlayerImpersonator> {

@NotNull
private final PlayerEntity player;
Expand All @@ -55,18 +55,6 @@ public PlayerImpersonator(@NotNull PlayerEntity player) {
this.player = player;
}

@NotNull
@Override
public PlayerEntity getEntity() {
return this.player;
}

@NotNull
@Override
public ComponentType<?> getComponentType() {
return Impersonate.IMPERSONATION;
}

@Override
public void impersonate(@NotNull Identifier key, @NotNull GameProfile profile) {
this.stackedImpersonations.put(key, profile);
Expand Down Expand Up @@ -108,7 +96,7 @@ private void setImpersonatedProfile(@Nullable GameProfile profile) {
ServerPlayerSkins.setSkin(((ServerPlayerEntity) player), this.getEditedProfile().getName());
}
updatePlayerLists(PlayerListS2CPacket.Action.ADD_PLAYER);
this.sync();
Impersonate.IMPERSONATION.sync(this.player);
}
}

Expand Down Expand Up @@ -161,8 +149,8 @@ public GameProfile getImpersonatedProfile() {
}

@Override
public boolean shouldCopyForRespawn(boolean lossless, boolean keepInventory) {
return true;
public @NotNull ComponentType<Impersonator> getComponentType() {
return (ComponentType<Impersonator>) Impersonate.IMPERSONATION;
}

@Override
Expand All @@ -176,14 +164,12 @@ public void copyFrom(PlayerImpersonator other) {
private static final int NAME_PRESENT = 0b10;

@Override
public void syncWith(ServerPlayerEntity player) {
if (player == this.player || player.server.getPlayerManager().isOperator(player.getGameProfile())) {
EntitySyncedComponent.super.syncWith(player);
}
public boolean shouldSyncWith(ServerPlayerEntity player, int syncOp) {
return player == this.player || player.server.getPlayerManager().isOperator(player.getGameProfile());
}

@Override
public void writeToPacket(PacketByteBuf buf) {
public void writeToPacket(PacketByteBuf buf, ServerPlayerEntity recipient, int syncOp) {
GameProfile profile = this.getImpersonatedProfile();
UUID id = profile == null ? null : profile.getId();
String name = profile == null ? null : profile.getName();
Expand Down Expand Up @@ -211,7 +197,7 @@ public void readFromPacket(PacketByteBuf buf) {
}

@Override
public void fromTag(@NotNull CompoundTag tag) {
public void readFromNbt(@NotNull CompoundTag tag) {
if (tag.contains("impersonations", NbtType.LIST)) {
this.stopImpersonations();
ListTag impersonations = tag.getList("impersonations", NbtType.COMPOUND);
Expand All @@ -227,9 +213,8 @@ public void fromTag(@NotNull CompoundTag tag) {
}
}

@NotNull
@Override
public CompoundTag toTag(@NotNull CompoundTag tag) {
public void writeToNbt(@NotNull CompoundTag tag) {
if (this.isImpersonating()) {
ListTag profiles = new ListTag();
for (Map.Entry<Identifier, GameProfile> entry : this.stackedImpersonations.entrySet()) {
Expand All @@ -240,6 +225,5 @@ public CompoundTag toTag(@NotNull CompoundTag tag) {
}
tag.put("impersonations", profiles);
}
return tag;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private static void reloadSkin(ServerPlayerEntity player) {

// need to change the player entity on the client
ServerWorld targetWorld = (ServerWorld) player.world;
player.networkHandler.sendPacket(new PlayerRespawnS2CPacket(targetWorld.getDimensionRegistryKey(), targetWorld.getRegistryKey(), BiomeAccess.hashSeed(targetWorld.getSeed()), player.interactionManager.getGameMode(), player.interactionManager.method_30119(), targetWorld.isDebugWorld(), targetWorld.isFlat(), true));
player.networkHandler.sendPacket(new PlayerRespawnS2CPacket(targetWorld.getDimension(), targetWorld.getRegistryKey(), BiomeAccess.hashSeed(targetWorld.getSeed()), player.interactionManager.getGameMode(), player.interactionManager.getPreviousGameMode(), targetWorld.isDebugWorld(), targetWorld.isFlat(), true));
player.networkHandler.requestTeleport(player.getX(), player.getY(), player.getZ(), player.yaw, player.pitch);
player.server.getPlayerManager().sendCommandTree(player);
player.networkHandler.sendPacket(new ExperienceBarUpdateS2CPacket(player.experienceProgress, player.totalExperience, player.experienceLevel));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.github.ladysnake.impersonate.impl.mixin;

import com.mojang.authlib.GameProfile;
import io.github.ladysnake.impersonate.Impersonate;
import io.github.ladysnake.impersonate.impl.ImpersonateText;
import net.minecraft.server.command.ListCommand;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import org.spongepowered.asm.mixin.Dynamic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.UUID;

@Mixin(ListCommand.class)
public abstract class ListCommandMixin {
@Dynamic("Lambda method in executeUuids(ServerCommandSource), argument to execute(ServerCommandSource, Function)")
@Inject(method = "method_30310", at = @At("RETURN"))
private static void fakeNameAndUuid(ServerPlayerEntity player, CallbackInfoReturnable<Text> cir) {
Text text = cir.getReturnValue();

if (text instanceof TranslatableText) {
Object[] args = ((TranslatableText) text).getArgs();
// Defend against other mods changing the text
if (args.length == 2 && args[0] instanceof Text && args[1] instanceof UUID) {
GameProfile impersonatedProfile = Impersonate.IMPERSONATION.get(player).getImpersonatedProfile();

if (impersonatedProfile != null) {
args[0] = ImpersonateText.get(player);
args[1] = impersonatedProfile.getId();
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package io.github.ladysnake.impersonate.impl.mixin;

import com.mojang.authlib.GameProfile;
import io.github.ladysnake.impersonate.Impersonate;
import io.github.ladysnake.impersonate.Impersonator;
import io.github.ladysnake.impersonate.impl.ImpersonateText;
import io.github.ladysnake.impersonate.impl.PlayerEntityExtensions;
Expand All @@ -35,7 +34,6 @@
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(PlayerEntity.class)
Expand Down Expand Up @@ -87,21 +85,4 @@ private void fakeName(CallbackInfoReturnable<Text> cir) {
cir.setReturnValue(ImpersonateText.get(self, world.isClient));
}
}

@ModifyArg(method = "getNameAndUuid", at = @At(value = "INVOKE", target = "Lnet/minecraft/text/LiteralText;append(Lnet/minecraft/text/Text;)Lnet/minecraft/text/MutableText;", ordinal = 0))
private Text fakeNameAndUuid(Text originalName) {
if (Impersonate.IMPERSONATION.get(this).isImpersonating()) {
return ImpersonateText.get((PlayerEntity) (Object) this);
}
return originalName;
}

@ModifyArg(method = "getNameAndUuid", at = @At(value = "INVOKE", target = "Lnet/minecraft/text/MutableText;append(Ljava/lang/String;)Lnet/minecraft/text/MutableText;", ordinal = 1))
private String fakeNameAndUuid(String originalUuid) {
GameProfile impersonatedProfile = Impersonate.IMPERSONATION.get(this).getImpersonatedProfile();
if (impersonatedProfile != null) {
return impersonatedProfile.getId().toString();
}
return originalUuid;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@

@Mixin(ServerPlayerEntity.class)
public abstract class ServerPlayerEntityMixin extends PlayerEntity implements PlayerEntityExtensions {
public ServerPlayerEntityMixin(World world, BlockPos blockPos, GameProfile gameProfile) {
super(world, blockPos, gameProfile);

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

@Inject(method = "setClientSettings", at = @At("RETURN"))
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/mixins.impersonate.common.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"mixins": [
"EntityTrackerAccessor",
"GameMessageS2CPacketAccessor",
"ListCommandMixin",
"MinecraftServerMixin",
"MutableTextMixin",
"PlayerEntityMixin",
Expand Down

0 comments on commit 7123b33

Please sign in to comment.