lots of code

This commit is contained in:
skippyall
2024-04-13 22:04:49 +02:00
commit 60fd7f0891
71 changed files with 3667 additions and 0 deletions
@@ -0,0 +1,14 @@
package io.github.skippyall.minions.mixins;
import io.github.skippyall.minions.fakeplayer.ClientConnectionInterface;
import io.netty.channel.Channel;
import net.minecraft.network.Connection;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(Connection.class)
public abstract class ConnectionMixin implements ClientConnectionInterface {
@Override
@Accessor //Compat with adventure-platform-fabric
public abstract void setChannel(Channel channel);
}
@@ -0,0 +1,56 @@
package io.github.skippyall.minions.mixins;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.mojang.authlib.GameProfile;
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
import io.github.skippyall.minions.fakeplayer.NetHandlerPlayServerFake;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.Connection;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ClientInformation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.CommonListenerCookie;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
import net.minecraft.server.players.PlayerList;
import org.spongepowered.asm.mixin.Final;
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.CallbackInfoReturnable;
@Mixin(PlayerList.class)
public class PlayerListMixin {
@Shadow
@Final
private MinecraftServer server;
@Inject(method = "load", at = @At(value = "RETURN", shift = At.Shift.BEFORE))
private void fixStartingPos(ServerPlayer serverPlayerEntity_1, CallbackInfoReturnable<CompoundTag> cir)
{
if (serverPlayerEntity_1 instanceof MinionFakePlayer)
{
((MinionFakePlayer) serverPlayerEntity_1).fixStartingPosition.run();
}
}
@WrapOperation(method = "placeNewPlayer", at = @At(value = "NEW", target = "(Lnet/minecraft/server/MinecraftServer;Lnet/minecraft/network/Connection;Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/server/network/CommonListenerCookie;)Lnet/minecraft/server/network/ServerGamePacketListenerImpl;"))
private ServerGamePacketListenerImpl replaceNetworkHandler(MinecraftServer minecraftServer, Connection connection, ServerPlayer serverPlayer, CommonListenerCookie commonListenerCookie, Operation<ServerGamePacketListenerImpl> original)
{
if (serverPlayer instanceof MinionFakePlayer fake) {
return new NetHandlerPlayServerFake(this.server, connection, fake, commonListenerCookie);
} else {
return original.call(minecraftServer, connection, serverPlayer, commonListenerCookie);
}
}
@WrapOperation(method = "respawn", at = @At(value = "NEW", target = "(Lnet/minecraft/server/MinecraftServer;Lnet/minecraft/server/level/ServerLevel;Lcom/mojang/authlib/GameProfile;Lnet/minecraft/server/level/ClientInformation;)Lnet/minecraft/server/level/ServerPlayer;"))
public ServerPlayer makePlayerForRespawn(MinecraftServer minecraftServer, ServerLevel serverLevel, GameProfile gameProfile, ClientInformation clientInformation, Operation<ServerPlayer> original, ServerPlayer serverPlayer, boolean bl) {
if (serverPlayer instanceof MinionFakePlayer) {
return MinionFakePlayer.respawnFake(minecraftServer, serverLevel, gameProfile, clientInformation);
}
return original.call(minecraftServer, serverLevel, gameProfile, clientInformation);
}
}
@@ -0,0 +1,37 @@
package io.github.skippyall.minions.mixins;
import com.mojang.authlib.GameProfile;
import io.github.skippyall.minions.fakeplayer.EntityPlayerActionPack;
import io.github.skippyall.minions.fakeplayer.ServerPlayerInterface;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ClientInformation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import org.spongepowered.asm.mixin.Mixin;
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.callback.CallbackInfo;
@Mixin(ServerPlayer.class)
public abstract class ServerPlayerMixin implements ServerPlayerInterface {
@Unique
public EntityPlayerActionPack actionPack;
@Override
public EntityPlayerActionPack getActionPack()
{
return actionPack;
}
@Inject(method = "<init>", at = @At(value = "RETURN"))
private void onServerPlayerEntityContructor(MinecraftServer minecraftServer, ServerLevel serverLevel, GameProfile gameProfile, ClientInformation clientInformation, CallbackInfo ci)
{
this.actionPack = new EntityPlayerActionPack((ServerPlayer) (Object) this);
}
@Inject(method = "tick", at = @At(value = "HEAD"))
private void onTick(CallbackInfo ci)
{
actionPack.onUpdate();
}
}