Skip to content

Commit

Permalink
Merge branch '1.19.2' into 1.19
Browse files Browse the repository at this point in the history
# Conflicts:
#	changelog.md
#	gradle.properties
  • Loading branch information
Pyrofab committed Mar 4, 2023
2 parents 74fdae7 + 7695ad2 commit 078fbcb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ Version 0.10.0
------------------------------------------------------
Updated to 1.19.3

------------------------------------------------------
Version 0.9.1
------------------------------------------------------
**Fixes**
- Fixed fake players' UUID resetting with each world reload

------------------------------------------------------
Version 0.9.0
------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,31 @@

import baritone.api.fakeplayer.AutomatoneFakePlayer;
import baritone.api.fakeplayer.FakeServerPlayerEntity;
import com.mojang.authlib.GameProfile;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
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.ModifyVariable;
import org.spongepowered.asm.mixin.injection.Slice;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(PlayerEntity.class)
public abstract class PlayerEntityMixin extends LivingEntity {

@Shadow @Final @Mutable
private GameProfile gameProfile;

protected PlayerEntityMixin(EntityType<? extends LivingEntity> entityType, World world) {
super(entityType, world);
}
Expand All @@ -62,6 +72,16 @@ private void allowFakePlayerSave(CallbackInfoReturnable<Boolean> cir) {
}
}

/**
* @reason minecraft overwrites the uuid when reading data, which breaks anything that tries to find this entity after a reload
*/
@Inject(method = "readCustomDataFromNbt", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;readCustomDataFromNbt(Lnet/minecraft/nbt/NbtCompound;)V"))
private void bringBackUuid(NbtCompound nbt, CallbackInfo ci) {
if (this instanceof AutomatoneFakePlayer) {
this.gameProfile = new GameProfile(this.getUuid(), this.gameProfile.getName());
}
}

/**
* Minecraft cancels knockback for players and instead relies entirely on the client for handling the velocity change.
* This injection cancels the cancellation for fake players, as they do not have an associated client.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.NetworkSide;
import net.minecraft.network.packet.s2c.play.SystemMessageS2CPacket;
import net.minecraft.server.network.ServerPlayNetworkHandler;
Expand Down Expand Up @@ -82,6 +83,17 @@ public void shellsDoNotPreventSleeping(TestContext ctx) {
ctx.complete();
}


@GameTest(structureName = EMPTY_STRUCTURE)
public void shellsKeepUuidOnReload(TestContext ctx) {
ServerPlayerEntity fakePlayer = new FakeServerPlayerEntity(Otomaton.FAKE_PLAYER, ctx.getWorld());
ServerPlayerEntity fakePlayer2 = new FakeServerPlayerEntity(Otomaton.FAKE_PLAYER, ctx.getWorld());
NbtCompound nbtCompound = fakePlayer.writeNbt(new NbtCompound());
fakePlayer2.readNbt(nbtCompound);
GameTestUtil.assertTrue("Fake players should keep UUID after reload", fakePlayer2.getUuid().equals(fakePlayer.getUuid()));
ctx.complete();
}

@GameTest(structureName = EMPTY_STRUCTURE)
public void realPlayersDoBroadcastAdvancements(TestContext ctx) {
ServerPlayerEntity player = ((ElmendorfTestContext) ctx).spawnServerPlayer(1, 0, 1);
Expand Down

0 comments on commit 078fbcb

Please sign in to comment.