1.4.113 on 23w31a, many regressions including modded networking, fake players, scoreboard api and more.
This commit is contained in:
1 parent
8416a2f28b
commit
55a88c6cdc
25 files changed
+356
-109
No files matched your search
@@ -0,0 +1,11 @@
|
||||
package carpet.fakes;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.network.protocol.common.custom.DiscardedPayload;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public interface CarpetPacketPayload extends CustomPacketPayload
|
||||
{
|
||||
FriendlyByteBuf data();
|
||||
}
|
||||
@@ -33,7 +33,7 @@ public interface FertilizableCoral extends BonemealableBlock {
|
||||
boolean isEnabled();
|
||||
|
||||
@Override
|
||||
public default boolean isValidBonemealTarget(LevelReader world, BlockPos pos, BlockState state, boolean var4)
|
||||
public default boolean isValidBonemealTarget(LevelReader world, BlockPos pos, BlockState state)
|
||||
{
|
||||
return isEnabled()
|
||||
&& state.getValue(BaseCoralPlantTypeBlock.WATERLOGGED)
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.network.CarpetClient;
|
||||
import net.minecraft.client.multiplayer.ClientCommonPacketListenerImpl;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
|
||||
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.CallbackInfo;
|
||||
|
||||
@Mixin(ClientCommonPacketListenerImpl.class)
|
||||
public class ClientCommonPacketListenerImpl_customPacketMixin
|
||||
{
|
||||
@Inject(method = "onDisconnect", at = @At("HEAD"))
|
||||
private void onCMDisconnected(Component reason, CallbackInfo ci)
|
||||
{
|
||||
CarpetClient.disconnect();
|
||||
}
|
||||
|
||||
@Inject(method = "handleCustomPayload(Lnet/minecraft/network/protocol/common/ClientboundCustomPayloadPacket;)V",
|
||||
at = @At("HEAD"))
|
||||
private void onOnCustomPayload(ClientboundCustomPayloadPacket packet, CallbackInfo ci)
|
||||
{
|
||||
//System.out.println("CustomPayload of : " + packet.payload());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,8 +3,11 @@ package carpet.mixins;
|
||||
import carpet.CarpetServer;
|
||||
import carpet.network.CarpetClient;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ClientCommonPacketListenerImpl;
|
||||
import net.minecraft.client.multiplayer.ClientPacketListener;
|
||||
import net.minecraft.client.multiplayer.CommonListenerCookie;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.network.Connection;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
@@ -13,9 +16,13 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(ClientPacketListener.class)
|
||||
public class ClientPacketListener_clientCommandMixin
|
||||
public abstract class ClientPacketListener_clientCommandMixin extends ClientCommonPacketListenerImpl
|
||||
{
|
||||
@Shadow @Final private Minecraft minecraft;
|
||||
|
||||
protected ClientPacketListener_clientCommandMixin(final Minecraft minecraft, final Connection connection, final CommonListenerCookie commonListenerCookie)
|
||||
{
|
||||
super(minecraft, connection, commonListenerCookie);
|
||||
}
|
||||
|
||||
@Inject(method = "sendCommand", at = @At("HEAD"))
|
||||
private void inspectMessage(String string, CallbackInfo ci)
|
||||
|
||||
@@ -3,41 +3,39 @@ package carpet.mixins;
|
||||
import carpet.network.CarpetClient;
|
||||
import carpet.network.ClientNetworkHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ClientCommonPacketListenerImpl;
|
||||
import net.minecraft.client.multiplayer.ClientPacketListener;
|
||||
import net.minecraft.client.multiplayer.CommonListenerCookie;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket;
|
||||
import net.minecraft.network.protocol.common.ClientCommonPacketListener;
|
||||
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.network.protocol.common.custom.DiscardedPayload;
|
||||
import net.minecraft.network.protocol.game.ClientboundLoginPacket;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
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.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(ClientPacketListener.class)
|
||||
public abstract class ClientPacketListener_customPacketsMixin
|
||||
public abstract class ClientPacketListener_customPacketsMixin extends ClientCommonPacketListenerImpl
|
||||
{
|
||||
@Final @Shadow private Minecraft minecraft;
|
||||
|
||||
@Inject(method = "handleCustomPayload", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/game/ClientboundCustomPayloadPacket;getIdentifier()Lnet/minecraft/resources/ResourceLocation;"), cancellable = true)
|
||||
private void onOnCustomPayload(ClientboundCustomPayloadPacket packet, CallbackInfo ci)
|
||||
protected ClientPacketListener_customPacketsMixin(final Minecraft minecraft, final Connection connection, final CommonListenerCookie commonListenerCookie)
|
||||
{
|
||||
if (CarpetClient.CARPET_CHANNEL.equals(packet.getIdentifier()))
|
||||
{
|
||||
ClientNetworkHandler.handleData(packet.getData(), minecraft.player);
|
||||
ci.cancel();
|
||||
}
|
||||
super(minecraft, connection, commonListenerCookie);
|
||||
}
|
||||
|
||||
@Inject(method = "handleLogin", at = @At("RETURN"))
|
||||
private void onGameJoined(ClientboundLoginPacket packet, CallbackInfo info)
|
||||
{
|
||||
CarpetClient.gameJoined(minecraft.player);
|
||||
CarpetClient.gameJoined( minecraft.player);
|
||||
}
|
||||
|
||||
@Inject(method = "onDisconnect", at = @At("HEAD"))
|
||||
private void onCMDisconnected(Component reason, CallbackInfo ci)
|
||||
{
|
||||
CarpetClient.disconnect();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package carpet.mixins;
|
||||
|
||||
|
||||
import carpet.network.CarpetClient;
|
||||
import carpet.network.ClientNetworkHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.network.protocol.common.custom.DiscardedPayload;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
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;
|
||||
|
||||
@Mixin(ClientboundCustomPayloadPacket.class)
|
||||
public class ClientboundCustomPayloadPacket_customPacketMixin
|
||||
{
|
||||
@Inject(method = "readPayload", at = @At("HEAD"))
|
||||
private static void onOnCustomPayloadR(final ResourceLocation resourceLocation, final FriendlyByteBuf friendlyByteBuf, final CallbackInfoReturnable<CustomPacketPayload> cir)
|
||||
{
|
||||
}
|
||||
|
||||
@Inject(method = "readUnknownPayload", at = @At(value = "HEAD"), cancellable = true)
|
||||
private static void onOnCustomPayload(ResourceLocation resourceLocation, FriendlyByteBuf friendlyByteBuf, CallbackInfoReturnable<DiscardedPayload> cir)
|
||||
{
|
||||
if (true) return;
|
||||
if (CarpetClient.CARPET_CHANNEL.equals(resourceLocation) && Minecraft.getInstance().isSameThread())
|
||||
{
|
||||
ClientNetworkHandler.handleData(friendlyByteBuf, Minecraft.getInstance().player);
|
||||
cir.setReturnValue(new DiscardedPayload(resourceLocation));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ public abstract class Connection_packetCounterMixin implements ClientConnectionI
|
||||
|
||||
// Add to the packet counter whenever a packet is sent.
|
||||
@Inject(method = "sendPacket", at = @At("HEAD"))
|
||||
private void packetOutCount(Packet<?> packet, @Nullable PacketSendListener packetSendListener, CallbackInfo ci)
|
||||
private void packetOutCount(final Packet<?> packet, final PacketSendListener packetSendListener, final boolean bl, final CallbackInfo ci)
|
||||
{
|
||||
PacketCounter.totalOut++;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public class MinecraftMixin implements MinecraftInterface
|
||||
{
|
||||
@Shadow public ClientLevel level;
|
||||
|
||||
@Inject(method = "clearLevel(Lnet/minecraft/client/gui/screens/Screen;)V", at = @At("HEAD"))
|
||||
@Inject(method = "disconnect(Lnet/minecraft/client/gui/screens/Screen;)V", at = @At("HEAD"))
|
||||
private void onCloseGame(Screen screen, CallbackInfo ci)
|
||||
{
|
||||
CarpetClient.disconnect();
|
||||
|
||||
@@ -16,7 +16,7 @@ public class PlayerList_coreMixin
|
||||
{
|
||||
|
||||
@Inject(method = "placeNewPlayer", at = @At("RETURN"))
|
||||
private void onPlayerConnected(Connection connection, ServerPlayer player, CallbackInfo ci)
|
||||
private void onPlayerConnected(Connection connection, ServerPlayer player, int i, CallbackInfo ci)
|
||||
{
|
||||
CarpetServer.onPlayerLoggedIn(player);
|
||||
}
|
||||
|
||||
@@ -34,21 +34,21 @@ public abstract class PlayerList_fakePlayersMixin
|
||||
}
|
||||
}
|
||||
|
||||
@Redirect(method = "placeNewPlayer", at = @At(value = "NEW", target = "net/minecraft/server/network/ServerGamePacketListenerImpl"))
|
||||
private ServerGamePacketListenerImpl replaceNetworkHandler(MinecraftServer server, Connection clientConnection, ServerPlayer playerIn)
|
||||
@Redirect(method = "placeNewPlayer", at = @At(value = "NEW", target = "(Lnet/minecraft/server/MinecraftServer;Lnet/minecraft/network/Connection;Lnet/minecraft/server/level/ServerPlayer;I)Lnet/minecraft/server/network/ServerGamePacketListenerImpl;"))
|
||||
private ServerGamePacketListenerImpl replaceNetworkHandler( MinecraftServer server, Connection clientConnection, ServerPlayer playerIn, int i)
|
||||
{
|
||||
if (playerIn instanceof EntityPlayerMPFake fake)
|
||||
{
|
||||
return new NetHandlerPlayServerFake(this.server, clientConnection, fake);
|
||||
return new NetHandlerPlayServerFake(this.server, clientConnection, fake, i);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new ServerGamePacketListenerImpl(this.server, clientConnection, playerIn);
|
||||
return new ServerGamePacketListenerImpl(this.server, clientConnection, playerIn, i);
|
||||
}
|
||||
}
|
||||
|
||||
@Redirect(method = "respawn", at = @At(value = "NEW", target = "net/minecraft/server/level/ServerPlayer"))
|
||||
public ServerPlayer makePlayerForRespawn(MinecraftServer minecraftServer, ServerLevel serverLevel, GameProfile gameProfile, ServerPlayer serverPlayer, boolean bl)
|
||||
@Redirect(method = "respawn", at = @At(value = "NEW", target = "(Lnet/minecraft/server/MinecraftServer;Lnet/minecraft/server/level/ServerLevel;Lcom/mojang/authlib/GameProfile;)Lnet/minecraft/server/level/ServerPlayer;"))
|
||||
public ServerPlayer makePlayerForRespawn(MinecraftServer minecraftServer, ServerLevel serverLevel, GameProfile gameProfile, ServerPlayer serverPlayer, boolean i)
|
||||
{
|
||||
if (serverPlayer instanceof EntityPlayerMPFake) {
|
||||
return EntityPlayerMPFake.respawnFake(minecraftServer, serverLevel, gameProfile);
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.CarpetPacketPayload;
|
||||
import carpet.network.ServerNetworkHandler;
|
||||
import net.minecraft.network.protocol.PacketUtils;
|
||||
import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
|
||||
import net.minecraft.network.protocol.game.ServerGamePacketListener;
|
||||
import net.minecraft.server.network.ServerCommonPacketListenerImpl;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
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.CallbackInfo;
|
||||
|
||||
@Mixin(ServerCommonPacketListenerImpl.class)
|
||||
public class ServerCommonPacketListenerimpl_connectionMixin
|
||||
{
|
||||
@Inject(method = "handleCustomPayload", at = @At("HEAD"), cancellable = true)
|
||||
private void onCustomCarpetPayload(ServerboundCustomPayloadPacket serverboundCustomPayloadPacket, CallbackInfo ci)
|
||||
{
|
||||
if (true) return;
|
||||
Object thiss = this;
|
||||
if (thiss instanceof ServerGamePacketListenerImpl impl && serverboundCustomPayloadPacket.payload() instanceof CarpetPacketPayload cpp) {
|
||||
// We should force onto the main thread here
|
||||
// ServerNetworkHandler.handleData can possibly mutate data that isn't
|
||||
// thread safe, and also allows for client commands to be executed
|
||||
PacketUtils.ensureRunningOnSameThread(serverboundCustomPayloadPacket, (ServerGamePacketListener) this, impl.player.serverLevel());
|
||||
ServerNetworkHandler.handleData(cpp.data(), impl.player);
|
||||
ci.cancel();
|
||||
}
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,8 @@ package carpet.mixins;
|
||||
import carpet.network.CarpetClient;
|
||||
import carpet.network.ServerNetworkHandler;
|
||||
import net.minecraft.network.protocol.PacketUtils;
|
||||
import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
|
||||
import net.minecraft.network.protocol.game.ServerGamePacketListener;
|
||||
import net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
@@ -19,18 +19,5 @@ public class ServerGamePacketListenerImplMixin
|
||||
{
|
||||
@Shadow public ServerPlayer player;
|
||||
|
||||
@Inject(method = "handleCustomPayload", at = @At("HEAD"), cancellable = true)
|
||||
private void onCustomCarpetPayload(ServerboundCustomPayloadPacket packet, CallbackInfo ci)
|
||||
{
|
||||
ResourceLocation channel = packet.getIdentifier();
|
||||
if (CarpetClient.CARPET_CHANNEL.equals(channel))
|
||||
{
|
||||
// We should force onto the main thread here
|
||||
// ServerNetworkHandler.handleData can possibly mutate data that isn't
|
||||
// thread safe, and also allows for client commands to be executed
|
||||
PacketUtils.ensureRunningOnSameThread(packet, (ServerGamePacketListener) this, player.serverLevel());
|
||||
ServerNetworkHandler.handleData(packet.getData(), player);
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+10
-2
@@ -1,7 +1,10 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.CarpetSettings;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerCommonPacketListenerImpl;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
@@ -11,13 +14,18 @@ import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(ServerGamePacketListenerImpl.class)
|
||||
public abstract class ServerGamePacketListenerImpl_antiCheatDisabledMixin
|
||||
public abstract class ServerGamePacketListenerImpl_antiCheatDisabledMixin extends ServerCommonPacketListenerImpl
|
||||
{
|
||||
@Shadow private int aboveGroundTickCount;
|
||||
|
||||
@Shadow private int aboveGroundVehicleTickCount;
|
||||
|
||||
@Shadow protected abstract boolean isSingleplayerOwner();
|
||||
public ServerGamePacketListenerImpl_antiCheatDisabledMixin(final MinecraftServer minecraftServer, final Connection connection, final int i)
|
||||
{
|
||||
super(minecraftServer, connection, i);
|
||||
}
|
||||
|
||||
//@Shadow protected abstract boolean isSingleplayerOwner();
|
||||
|
||||
@Inject(method = "tick", at = @At("HEAD"))
|
||||
private void restrictFloatingBits(CallbackInfo ci)
|
||||
|
||||
@@ -4,7 +4,9 @@ import carpet.CarpetServer;
|
||||
import carpet.fakes.ServerGamePacketListenerImplInterface;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerCommonPacketListenerImpl;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@@ -14,11 +16,14 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(ServerGamePacketListenerImpl.class)
|
||||
public class ServerGamePacketListenerImpl_coreMixin implements ServerGamePacketListenerImplInterface {
|
||||
public abstract class ServerGamePacketListenerImpl_coreMixin extends ServerCommonPacketListenerImpl implements ServerGamePacketListenerImplInterface {
|
||||
@Shadow
|
||||
public ServerPlayer player;
|
||||
|
||||
@Shadow @Final private Connection connection;
|
||||
public ServerGamePacketListenerImpl_coreMixin(final MinecraftServer minecraftServer, final Connection connection, final int i)
|
||||
{
|
||||
super(minecraftServer, connection, i);
|
||||
}
|
||||
|
||||
@Inject(method = "onDisconnect", at = @At("HEAD"))
|
||||
private void onPlayerDisconnect(Component reason, CallbackInfo ci) {
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.CarpetPacketPayload;
|
||||
import carpet.network.CarpetClient;
|
||||
import carpet.network.ClientNetworkHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.network.protocol.common.custom.DiscardedPayload;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
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;
|
||||
|
||||
@Mixin(ServerboundCustomPayloadPacket.class)
|
||||
public class ServerboundCustomPayloadPacket_mixin
|
||||
{
|
||||
@Inject(method = "readPayload", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/network/protocol/common/ServerboundCustomPayloadPacket;readUnknownPayload(Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/network/FriendlyByteBuf;)Lnet/minecraft/network/protocol/common/custom/DiscardedPayload;"
|
||||
), cancellable = true)
|
||||
private static void onOnCustomPayload(ResourceLocation resourceLocation, FriendlyByteBuf friendlyByteBuf, CallbackInfoReturnable<CustomPacketPayload> cir)
|
||||
{
|
||||
if (true) return;
|
||||
if (CarpetClient.CARPET_CHANNEL.equals(resourceLocation))
|
||||
{
|
||||
//ClientNetworkHandler.handleData(friendlyByteBuf, Minecraft.getInstance().player);
|
||||
cir.setReturnValue(new CarpetPacketPayload()
|
||||
{
|
||||
@Override
|
||||
public FriendlyByteBuf data()
|
||||
{
|
||||
return friendlyByteBuf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final FriendlyByteBuf friendlyByteBuf)
|
||||
{
|
||||
// noop - its a client side and we handle it server side only
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation id()
|
||||
{
|
||||
return resourceLocation;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,11 +7,32 @@ import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public class CarpetClient
|
||||
{
|
||||
public record CarpetPayload(CompoundTag data) implements CustomPacketPayload
|
||||
{
|
||||
public static final ResourceLocation ID = CARPET_CHANNEL;
|
||||
|
||||
public CarpetPayload(final FriendlyByteBuf input) {
|
||||
this(input.readNbt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final FriendlyByteBuf output) {
|
||||
output.writeNbt(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation id() {
|
||||
return ID;
|
||||
}
|
||||
}
|
||||
|
||||
public static final int HI = 69;
|
||||
public static final int HELLO = 420;
|
||||
public static final int DATA = 1;
|
||||
|
||||
@@ -19,7 +19,9 @@ import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.NumericTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket;
|
||||
import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public class ClientNetworkHandler
|
||||
{
|
||||
@@ -129,8 +131,20 @@ public class ClientNetworkHandler
|
||||
public static void respondHello()
|
||||
{
|
||||
CarpetClient.getPlayer().connection.send(new ServerboundCustomPayloadPacket(
|
||||
CarpetClient.CARPET_CHANNEL,
|
||||
(new FriendlyByteBuf(Unpooled.buffer())).writeVarInt(CarpetClient.HELLO).writeUtf(CarpetSettings.carpetVersion)
|
||||
new CustomPacketPayload()
|
||||
{
|
||||
@Override
|
||||
public void write(final FriendlyByteBuf friendlyByteBuf)
|
||||
{
|
||||
friendlyByteBuf.writeVarInt(CarpetClient.HELLO).writeUtf(CarpetSettings.carpetVersion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation id()
|
||||
{
|
||||
return CarpetClient.CARPET_CHANNEL;
|
||||
}
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
@@ -162,8 +176,20 @@ public class ClientNetworkHandler
|
||||
CompoundTag outer = new CompoundTag();
|
||||
outer.put("clientCommand", tag);
|
||||
CarpetClient.getPlayer().connection.send(new ServerboundCustomPayloadPacket(
|
||||
CarpetClient.CARPET_CHANNEL,
|
||||
(new FriendlyByteBuf(Unpooled.buffer())).writeVarInt(CarpetClient.DATA).writeNbt(outer)
|
||||
new CustomPacketPayload()
|
||||
{
|
||||
@Override
|
||||
public void write( FriendlyByteBuf friendlyByteBuf)
|
||||
{
|
||||
friendlyByteBuf.writeVarInt(CarpetClient.DATA).writeNbt(outer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation id()
|
||||
{
|
||||
return CarpetClient.CARPET_CHANNEL;
|
||||
}
|
||||
}
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import carpet.CarpetServer;
|
||||
import carpet.CarpetSettings;
|
||||
import carpet.api.settings.CarpetRule;
|
||||
import carpet.api.settings.RuleHelper;
|
||||
import carpet.fakes.CarpetPacketPayload;
|
||||
import carpet.fakes.MinecraftServerInterface;
|
||||
import carpet.fakes.ServerGamePacketListenerImplInterface;
|
||||
import carpet.helpers.ServerTickRateManager;
|
||||
@@ -16,19 +17,39 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket;
|
||||
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class ServerNetworkHandler
|
||||
{
|
||||
@FunctionalInterface
|
||||
public interface CarpetCustomPayload extends CustomPacketPayload
|
||||
{
|
||||
void writeData(FriendlyByteBuf output);
|
||||
|
||||
@Override
|
||||
default void write(FriendlyByteBuf output) {
|
||||
writeData(output);
|
||||
}
|
||||
|
||||
@Override
|
||||
default ResourceLocation id()
|
||||
{
|
||||
return CarpetClient.CARPET_CHANNEL;
|
||||
}
|
||||
}
|
||||
private static final Map<ServerPlayer, String> remoteCarpetPlayers = new HashMap<>();
|
||||
private static final Set<ServerPlayer> validCarpetPlayers = new HashSet<>();
|
||||
|
||||
@@ -52,24 +73,39 @@ public class ServerNetworkHandler
|
||||
|
||||
|
||||
|
||||
private static ClientboundCustomPayloadPacket make(Consumer<FriendlyByteBuf> accepter) {
|
||||
return new ClientboundCustomPayloadPacket(
|
||||
new CarpetCustomPayload()
|
||||
{
|
||||
@Override
|
||||
public void writeData(final FriendlyByteBuf t)
|
||||
{
|
||||
accepter.accept(t);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public static void onPlayerJoin(ServerPlayer playerEntity)
|
||||
{
|
||||
if (true) return;
|
||||
if (!((ServerGamePacketListenerImplInterface)playerEntity.connection).getConnection().isMemoryConnection())
|
||||
{
|
||||
playerEntity.connection.send(new ClientboundCustomPayloadPacket(
|
||||
CarpetClient.CARPET_CHANNEL,
|
||||
(new FriendlyByteBuf(Unpooled.buffer())).writeVarInt(CarpetClient.HI).writeUtf(CarpetSettings.carpetVersion)
|
||||
playerEntity.connection.send( make( output -> {
|
||||
output.writeVarInt(CarpetClient.HI);
|
||||
output.writeUtf(CarpetSettings.carpetVersion);
|
||||
}
|
||||
));
|
||||
}
|
||||
else
|
||||
{
|
||||
validCarpetPlayers.add(playerEntity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void onHello(ServerPlayer playerEntity, FriendlyByteBuf packetData)
|
||||
{
|
||||
if (true) return;
|
||||
validCarpetPlayers.add(playerEntity);
|
||||
String clientVersion = packetData.readUtf(64);
|
||||
remoteCarpetPlayers.put(playerEntity, clientVersion);
|
||||
@@ -79,13 +115,13 @@ public class ServerNetworkHandler
|
||||
CarpetSettings.LOG.warn("Player "+playerEntity.getName().getString()+" joined with another carpet version: "+clientVersion);
|
||||
DataBuilder data = DataBuilder.create(playerEntity.server); // tickrate related settings are sent on world change
|
||||
CarpetServer.forEachManager(sm -> sm.getCarpetRules().forEach(data::withRule));
|
||||
playerEntity.connection.send(new ClientboundCustomPayloadPacket(CarpetClient.CARPET_CHANNEL, data.build() ));
|
||||
playerEntity.connection.send(make(data::build));
|
||||
}
|
||||
|
||||
public static void sendPlayerLevelData(ServerPlayer player, ServerLevel level) {
|
||||
if (CarpetSettings.superSecretSetting || !validCarpetPlayers.contains(player)) return;
|
||||
DataBuilder data = DataBuilder.create(player.server).withTickRate().withFrozenState().withTickPlayerActiveTimeout(); // .withSuperHotState()
|
||||
player.connection.send(new ClientboundCustomPayloadPacket(CarpetClient.CARPET_CHANNEL, data.build() ));
|
||||
player.connection.send(make(data::build));
|
||||
|
||||
}
|
||||
|
||||
@@ -113,9 +149,8 @@ public class ServerNetworkHandler
|
||||
ListTag outputResult = new ListTag();
|
||||
for (Component line: output) outputResult.add(StringTag.valueOf(Component.Serializer.toJson(line)));
|
||||
if (!output.isEmpty()) result.put("output", outputResult);
|
||||
player.connection.send(new ClientboundCustomPayloadPacket(
|
||||
CarpetClient.CARPET_CHANNEL,
|
||||
DataBuilder.create(player.server).withCustomNbt("clientCommand", result).build()
|
||||
player.connection.send(make( butebuf ->
|
||||
DataBuilder.create(player.server).withCustomNbt("clientCommand", result).build(butebuf)
|
||||
));
|
||||
// run command plug to command output,
|
||||
}
|
||||
@@ -139,9 +174,8 @@ public class ServerNetworkHandler
|
||||
if (CarpetSettings.superSecretSetting) return;
|
||||
for (ServerPlayer player : remoteCarpetPlayers.keySet())
|
||||
{
|
||||
player.connection.send(new ClientboundCustomPayloadPacket(
|
||||
CarpetClient.CARPET_CHANNEL,
|
||||
DataBuilder.create(player.server).withRule(rule).build()
|
||||
player.connection.send(make( output ->
|
||||
DataBuilder.create(player.server).withRule(rule).build(output)
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -151,9 +185,8 @@ public class ServerNetworkHandler
|
||||
if (CarpetSettings.superSecretSetting) return;
|
||||
for (ServerPlayer player : validCarpetPlayers)
|
||||
{
|
||||
player.connection.send(new ClientboundCustomPayloadPacket(
|
||||
CarpetClient.CARPET_CHANNEL,
|
||||
DataBuilder.create(player.server).withTickRate().build()
|
||||
player.connection.send(make( output ->
|
||||
DataBuilder.create(player.server).withTickRate().build(output)
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -163,9 +196,8 @@ public class ServerNetworkHandler
|
||||
if (CarpetSettings.superSecretSetting) return;
|
||||
for (ServerPlayer player : validCarpetPlayers)
|
||||
{
|
||||
player.connection.send(new ClientboundCustomPayloadPacket(
|
||||
CarpetClient.CARPET_CHANNEL,
|
||||
DataBuilder.create(player.server).withFrozenState().build()
|
||||
player.connection.send(make( output ->
|
||||
DataBuilder.create(player.server).withFrozenState().build(output)
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -175,9 +207,8 @@ public class ServerNetworkHandler
|
||||
if(CarpetSettings.superSecretSetting) return;
|
||||
for (ServerPlayer player : validCarpetPlayers)
|
||||
{
|
||||
player.connection.send(new ClientboundCustomPayloadPacket(
|
||||
CarpetClient.CARPET_CHANNEL,
|
||||
DataBuilder.create(player.server).withSuperHotState().build()
|
||||
player.connection.send(make(output ->
|
||||
DataBuilder.create(player.server).withSuperHotState().build(output)
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -187,9 +218,8 @@ public class ServerNetworkHandler
|
||||
if (CarpetSettings.superSecretSetting) return;
|
||||
for (ServerPlayer player : validCarpetPlayers)
|
||||
{
|
||||
player.connection.send(new ClientboundCustomPayloadPacket(
|
||||
CarpetClient.CARPET_CHANNEL,
|
||||
DataBuilder.create(player.server).withTickPlayerActiveTimeout().build()
|
||||
player.connection.send(make(output ->
|
||||
DataBuilder.create(player.server).withTickPlayerActiveTimeout().build(output)
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -199,9 +229,8 @@ public class ServerNetworkHandler
|
||||
if (CarpetSettings.superSecretSetting) return;
|
||||
for (ServerPlayer player : validCarpetPlayers)
|
||||
{
|
||||
player.connection.send(new ClientboundCustomPayloadPacket(
|
||||
CarpetClient.CARPET_CHANNEL,
|
||||
DataBuilder.create(player.server).withCustomNbt(command, data).build()
|
||||
player.connection.send(make(output ->
|
||||
DataBuilder.create(player.server).withCustomNbt(command, data).build(output)
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -210,9 +239,8 @@ public class ServerNetworkHandler
|
||||
{
|
||||
if (isValidCarpetPlayer(player))
|
||||
{
|
||||
player.connection.send(new ClientboundCustomPayloadPacket(
|
||||
CarpetClient.CARPET_CHANNEL,
|
||||
DataBuilder.create(player.server).withCustomNbt(command, data).build()
|
||||
player.connection.send(make(output ->
|
||||
DataBuilder.create(player.server).withCustomNbt(command, data).build(output)
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -310,12 +338,10 @@ public class ServerNetworkHandler
|
||||
return this;
|
||||
}
|
||||
|
||||
private FriendlyByteBuf build()
|
||||
private void build(FriendlyByteBuf packetBuf)
|
||||
{
|
||||
FriendlyByteBuf packetBuf = new FriendlyByteBuf(Unpooled.buffer());
|
||||
packetBuf.writeVarInt(CarpetClient.DATA);
|
||||
packetBuf.writeNbt(tag);
|
||||
return packetBuf;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -63,12 +63,12 @@ public class EntityPlayerMPFake extends ServerPlayer
|
||||
if (gameprofile.getProperties().containsKey("textures"))
|
||||
{
|
||||
AtomicReference<GameProfile> result = new AtomicReference<>();
|
||||
SkullBlockEntity.updateGameprofile(gameprofile, result::set);
|
||||
gameprofile = result.get();
|
||||
//SkullBlockEntity.updateGameprofile(gameprofile, result::set);
|
||||
//gameprofile = result.get();
|
||||
}
|
||||
EntityPlayerMPFake instance = new EntityPlayerMPFake(server, worldIn, gameprofile, false);
|
||||
instance.fixStartingPosition = () -> instance.moveTo(pos.x, pos.y, pos.z, (float) yaw, (float) pitch);
|
||||
server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), instance);
|
||||
server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), instance, 0);
|
||||
instance.teleportTo(worldIn, pos.x, pos.y, pos.z, (float) yaw, (float) pitch);
|
||||
instance.setHealth(20.0F);
|
||||
instance.unsetRemoved();
|
||||
@@ -90,7 +90,7 @@ public class EntityPlayerMPFake extends ServerPlayer
|
||||
GameProfile gameprofile = player.getGameProfile();
|
||||
EntityPlayerMPFake playerShadow = new EntityPlayerMPFake(server, worldIn, gameprofile, true);
|
||||
playerShadow.setChatSession(player.getChatSession());
|
||||
server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), playerShadow);
|
||||
server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), playerShadow, 0);
|
||||
|
||||
playerShadow.setHealth(player.getHealth());
|
||||
playerShadow.connection.teleport(player.getX(), player.getY(), player.getZ(), player.getYRot(), player.getXRot());
|
||||
|
||||
@@ -5,15 +5,16 @@ import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.contents.TranslatableContents;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.world.entity.RelativeMovement;
|
||||
import java.util.Set;
|
||||
|
||||
public class NetHandlerPlayServerFake extends ServerGamePacketListenerImpl
|
||||
{
|
||||
public NetHandlerPlayServerFake(MinecraftServer server, Connection cc, EntityPlayerMPFake playerIn)
|
||||
public NetHandlerPlayServerFake(final MinecraftServer minecraftServer, final Connection connection, final ServerPlayer serverPlayer, final int i)
|
||||
{
|
||||
super(server, cc, playerIn);
|
||||
super(minecraftServer, connection, serverPlayer, i);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -61,7 +61,7 @@ public class Scoreboards
|
||||
return ListValue.wrap(scoreboard.getObjectiveNames().stream().map(StringValue::new));
|
||||
}
|
||||
String objectiveName = lv.get(0).getString();
|
||||
Objective objective = scoreboard.getOrCreateObjective(objectiveName);
|
||||
Objective objective = scoreboard.getObjective(objectiveName);
|
||||
if (objective == null)
|
||||
{
|
||||
return Value.NULL;
|
||||
@@ -103,7 +103,7 @@ public class Scoreboards
|
||||
CarpetContext cc = (CarpetContext) c;
|
||||
Scoreboard scoreboard = cc.server().getScoreboard();
|
||||
String objectiveName = lv.get(0).getString();
|
||||
Objective objective = scoreboard.getOrCreateObjective(objectiveName);
|
||||
Objective objective = scoreboard.getObjective(objectiveName);
|
||||
if (objective == null)
|
||||
{
|
||||
return Value.FALSE;
|
||||
@@ -151,7 +151,7 @@ public class Scoreboards
|
||||
}
|
||||
}
|
||||
|
||||
Objective objective = scoreboard.getOrCreateObjective(objectiveName);
|
||||
Objective objective = scoreboard.getObjective(objectiveName);
|
||||
if (objective != null)
|
||||
{
|
||||
c.host.issueDeprecation("reading or modifying an objective's criterion with scoreboard_add");
|
||||
@@ -181,7 +181,7 @@ public class Scoreboards
|
||||
}
|
||||
CarpetContext cc = (CarpetContext) c;
|
||||
Scoreboard scoreboard = cc.server().getScoreboard();
|
||||
Objective objective = scoreboard.getOrCreateObjective(lv.get(0).getString());
|
||||
Objective objective = scoreboard.getObjective(lv.get(0).getString());
|
||||
if (objective == null)
|
||||
{
|
||||
return Value.NULL;
|
||||
@@ -225,7 +225,7 @@ public class Scoreboards
|
||||
}
|
||||
return new FormattedTextValue(objective.getDisplayName());
|
||||
}
|
||||
case "display_slot" -> {
|
||||
case "display_slot" -> { /*
|
||||
if (modify)
|
||||
{
|
||||
int slotId = Scoreboard.getDisplaySlotByName(setValue.getString());
|
||||
@@ -249,7 +249,8 @@ public class Scoreboards
|
||||
slots.add(StringValue.of(slotName));
|
||||
}
|
||||
}
|
||||
return ListValue.wrap(slots);
|
||||
return ListValue.wrap(slots); */
|
||||
return Value.NULL;
|
||||
}
|
||||
case "render_type" -> {
|
||||
if (modify)
|
||||
@@ -269,7 +270,7 @@ public class Scoreboards
|
||||
});
|
||||
|
||||
expression.addContextFunction("scoreboard_display", 2, (c, t, lv) ->
|
||||
{
|
||||
{ /*
|
||||
CarpetContext cc = (CarpetContext) c;
|
||||
Scoreboard scoreboard = cc.server().getScoreboard();
|
||||
String location = lv.get(0).getString();
|
||||
@@ -291,7 +292,8 @@ public class Scoreboards
|
||||
return Value.NULL;
|
||||
}
|
||||
scoreboard.setDisplayObjective(slot, objective);
|
||||
return new NumericValue(slot);
|
||||
return new NumericValue(slot); */
|
||||
return Value.NULL;
|
||||
});
|
||||
|
||||
expression.addContextFunction("team_list", -1, (c, t, lv) ->
|
||||
|
||||
@@ -258,9 +258,9 @@ public abstract class CommandArgument
|
||||
true
|
||||
),
|
||||
new ScoreholderArgument(),
|
||||
new VanillaUnconfigurableArgument("scoreboardslot", ScoreboardSlotArgument::displaySlot,
|
||||
(c, p) -> StringValue.of(Scoreboard.getDisplaySlotName(ScoreboardSlotArgument.getDisplaySlot(c, p))), false
|
||||
),
|
||||
//new VanillaUnconfigurableArgument("scoreboardslot", ScoreboardSlotArgument::displaySlot,
|
||||
// (c, p) -> StringValue.of(Scoreboard.getDisplaySlotName(ScoreboardSlotArgument.getDisplaySlot(c, p))), false
|
||||
//),
|
||||
new VanillaUnconfigurableArgument("swizzle", SwizzleArgument::swizzle,
|
||||
(c, p) -> StringValue.of(SwizzleArgument.getSwizzle(c, p).stream().map(Direction.Axis::getSerializedName).collect(Collectors.joining())), true
|
||||
),
|
||||
|
||||
@@ -633,7 +633,7 @@ public class EntityValue extends Value
|
||||
|
||||
put("client_brand", (e, a) -> e instanceof final ServerPlayer sp ? StringValue.of(Carpet.getPlayerStatus(sp)) : Value.NULL);
|
||||
put("team", (e, a) -> e.getTeam() == null ? Value.NULL : new StringValue(e.getTeam().getName()));
|
||||
put("ping", (e, a) -> e instanceof final ServerPlayer sp ? new NumericValue(sp.latency) : Value.NULL);
|
||||
put("ping", (e, a) -> e instanceof final ServerPlayer sp ? new NumericValue(sp.connection.latency()) : Value.NULL);
|
||||
|
||||
//spectating_entity
|
||||
// isGlowing
|
||||
|
||||
@@ -181,7 +181,11 @@
|
||||
"BlockBehaviourBlockStateBase_mixin",
|
||||
"ChainBlock_customStickyMixin",
|
||||
"ChestBlock_customStickyMixin",
|
||||
"PistonStructureResolver_customStickyMixin"
|
||||
"PistonStructureResolver_customStickyMixin",
|
||||
|
||||
"ServerboundCustomPayloadPacket_mixin",
|
||||
"ServerCommonPacketListenerimpl_connectionMixin",
|
||||
"ClientboundCustomPayloadPacket_customPacketMixin"
|
||||
|
||||
],
|
||||
"client": [
|
||||
@@ -200,7 +204,10 @@
|
||||
"LevelRenderer_creativeNoClipMixin",
|
||||
"ClientPacketListener_customPacketsMixin",
|
||||
"DebugRenderer_scarpetRenderMixin",
|
||||
"LevelRenderer_scarpetRenderMixin"
|
||||
"LevelRenderer_scarpetRenderMixin",
|
||||
|
||||
|
||||
"ClientCommonPacketListenerImpl_customPacketMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
||||
Reference in new issue
Block a user