Migrate the Carpet codebase to Mojang Mappings
This commit is contained in:
346 files changed
+8353
-8492
No files matched your search
@@ -7,29 +7,28 @@ import carpet.helpers.TickSpeed;
|
||||
import carpet.settings.ParsedRule;
|
||||
import carpet.settings.SettingsManager;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.nbt.AbstractNbtNumber;
|
||||
import net.minecraft.nbt.NbtByte;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtList;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.nbt.ByteTag;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
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;
|
||||
|
||||
public class ClientNetworkHandler
|
||||
{
|
||||
private static final Map<String, BiConsumer<ClientPlayerEntity, NbtElement>> dataHandlers = new HashMap<String, BiConsumer<ClientPlayerEntity, NbtElement>>();
|
||||
private static final Map<String, BiConsumer<LocalPlayer, Tag>> dataHandlers = new HashMap<String, BiConsumer<LocalPlayer, Tag>>();
|
||||
static
|
||||
{
|
||||
dataHandlers.put("Rules", (p, t) -> {
|
||||
NbtCompound ruleset = (NbtCompound)t;
|
||||
for (String ruleKey: ruleset.getKeys())
|
||||
CompoundTag ruleset = (CompoundTag)t;
|
||||
for (String ruleKey: ruleset.getAllKeys())
|
||||
{
|
||||
NbtCompound ruleNBT = (NbtCompound) ruleset.get(ruleKey);
|
||||
CompoundTag ruleNBT = (CompoundTag) ruleset.get(ruleKey);
|
||||
SettingsManager manager = null;
|
||||
String ruleName;
|
||||
if (ruleNBT.contains("Manager"))
|
||||
@@ -65,29 +64,29 @@ public class ClientNetworkHandler
|
||||
}
|
||||
}
|
||||
});
|
||||
dataHandlers.put("TickRate", (p, t) -> TickSpeed.tickrate(((AbstractNbtNumber)t).floatValue(), false));
|
||||
dataHandlers.put("TickRate", (p, t) -> TickSpeed.tickrate(((NumericTag)t).getAsFloat(), false));
|
||||
dataHandlers.put("TickingState", (p, t) -> {
|
||||
NbtCompound tickingState = (NbtCompound)t;
|
||||
CompoundTag tickingState = (CompoundTag)t;
|
||||
TickSpeed.setFrozenState(tickingState.getBoolean("is_paused"), tickingState.getBoolean("deepFreeze"));
|
||||
});
|
||||
dataHandlers.put("SuperHotState", (p, t) -> {
|
||||
TickSpeed.is_superHot = ((NbtByte) t).equals(NbtByte.ONE);
|
||||
TickSpeed.is_superHot = ((ByteTag) t).equals(ByteTag.ONE);
|
||||
});
|
||||
dataHandlers.put("TickPlayerActiveTimeout", (p, t) -> TickSpeed.player_active_timeout = ((AbstractNbtNumber)t).intValue());
|
||||
dataHandlers.put("TickPlayerActiveTimeout", (p, t) -> TickSpeed.player_active_timeout = ((NumericTag)t).getAsInt());
|
||||
dataHandlers.put("scShape", (p, t) -> { // deprecated // and unused // should remove for 1.17
|
||||
if (CarpetClient.shapes != null)
|
||||
CarpetClient.shapes.addShape((NbtCompound)t);
|
||||
CarpetClient.shapes.addShape((CompoundTag)t);
|
||||
});
|
||||
dataHandlers.put("scShapes", (p, t) -> {
|
||||
if (CarpetClient.shapes != null)
|
||||
CarpetClient.shapes.addShapes((NbtList) t);
|
||||
CarpetClient.shapes.addShapes((ListTag) t);
|
||||
});
|
||||
dataHandlers.put("clientCommand", (p, t) -> {
|
||||
CarpetClient.onClientCommand(t);
|
||||
});
|
||||
};
|
||||
|
||||
public static void handleData(PacketByteBuf data, ClientPlayerEntity player)
|
||||
public static void handleData(FriendlyByteBuf data, LocalPlayer player)
|
||||
{
|
||||
if (data != null)
|
||||
{
|
||||
@@ -99,12 +98,12 @@ public class ClientNetworkHandler
|
||||
}
|
||||
}
|
||||
|
||||
private static void onHi(PacketByteBuf data)
|
||||
private static void onHi(FriendlyByteBuf data)
|
||||
{
|
||||
synchronized (CarpetClient.sync)
|
||||
{
|
||||
CarpetClient.setCarpet();
|
||||
CarpetClient.serverCarpetVersion = data.readString(64);
|
||||
CarpetClient.serverCarpetVersion = data.readUtf(64);
|
||||
if (CarpetSettings.carpetVersion.equals(CarpetClient.serverCarpetVersion))
|
||||
{
|
||||
CarpetSettings.LOG.info("Joined carpet server with matching carpet version");
|
||||
@@ -121,17 +120,17 @@ public class ClientNetworkHandler
|
||||
|
||||
public static void respondHello()
|
||||
{
|
||||
CarpetClient.getPlayer().networkHandler.sendPacket(new CustomPayloadC2SPacket(
|
||||
CarpetClient.getPlayer().connection.send(new ServerboundCustomPayloadPacket(
|
||||
CarpetClient.CARPET_CHANNEL,
|
||||
(new PacketByteBuf(Unpooled.buffer())).writeVarInt(CarpetClient.HELLO).writeString(CarpetSettings.carpetVersion)
|
||||
(new FriendlyByteBuf(Unpooled.buffer())).writeVarInt(CarpetClient.HELLO).writeUtf(CarpetSettings.carpetVersion)
|
||||
));
|
||||
}
|
||||
|
||||
private static void onSyncData(PacketByteBuf data, ClientPlayerEntity player)
|
||||
private static void onSyncData(FriendlyByteBuf data, LocalPlayer player)
|
||||
{
|
||||
NbtCompound compound = data.readNbt();
|
||||
CompoundTag compound = data.readNbt();
|
||||
if (compound == null) return;
|
||||
for (String key: compound.getKeys())
|
||||
for (String key: compound.getAllKeys())
|
||||
{
|
||||
if (dataHandlers.containsKey(key)) {
|
||||
try {
|
||||
@@ -149,14 +148,14 @@ public class ClientNetworkHandler
|
||||
|
||||
public static void clientCommand(String command)
|
||||
{
|
||||
NbtCompound tag = new NbtCompound();
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.putString("id", command);
|
||||
tag.putString("command", command);
|
||||
NbtCompound outer = new NbtCompound();
|
||||
CompoundTag outer = new CompoundTag();
|
||||
outer.put("clientCommand", tag);
|
||||
CarpetClient.getPlayer().networkHandler.sendPacket(new CustomPayloadC2SPacket(
|
||||
CarpetClient.getPlayer().connection.send(new ServerboundCustomPayloadPacket(
|
||||
CarpetClient.CARPET_CHANNEL,
|
||||
(new PacketByteBuf(Unpooled.buffer())).writeVarInt(CarpetClient.DATA).writeNbt(outer)
|
||||
(new FriendlyByteBuf(Unpooled.buffer())).writeVarInt(CarpetClient.DATA).writeNbt(outer)
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user