its a doozie
This commit is contained in:
1 parent
365892b9ca
commit
ab553187c5
43 files changed
+356
-351
No files matched your search
@@ -4,9 +4,9 @@ import carpet.CarpetServer;
|
||||
import carpet.CarpetSettings;
|
||||
import carpet.script.utils.ShapesRenderer;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtList;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
@@ -64,16 +64,16 @@ public class CarpetClient
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void onClientCommand(Tag t)
|
||||
public static void onClientCommand(NbtElement t)
|
||||
{
|
||||
CarpetSettings.LOG.info("Server Response:");
|
||||
CompoundTag tag = (CompoundTag)t;
|
||||
NbtCompound tag = (NbtCompound)t;
|
||||
CarpetSettings.LOG.info(" - id: "+tag.getString("id"));
|
||||
CarpetSettings.LOG.info(" - code: "+tag.getInt("code"));
|
||||
if (tag.contains("error")) CarpetSettings.LOG.warn(" - error: "+tag.getString("error"));
|
||||
if (tag.contains("output"))
|
||||
{
|
||||
ListTag outputTag = (ListTag) tag.get("output");
|
||||
NbtList outputTag = (NbtList) tag.get("output");
|
||||
for (int i = 0; i < outputTag.size(); i++)
|
||||
CarpetSettings.LOG.info(" - response: " + Text.Serializer.fromJson(outputTag.getString(i)).getString());
|
||||
}
|
||||
|
||||
@@ -8,11 +8,11 @@ import carpet.settings.ParsedRule;
|
||||
import carpet.settings.SettingsManager;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.nbt.AbstractNumberTag;
|
||||
import net.minecraft.nbt.ByteTag;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
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;
|
||||
|
||||
@@ -22,14 +22,14 @@ import java.util.function.BiConsumer;
|
||||
|
||||
public class ClientNetworkHandler
|
||||
{
|
||||
private static Map<String, BiConsumer<ClientPlayerEntity, Tag>> dataHandlers = new HashMap<String, BiConsumer<ClientPlayerEntity, Tag>>();
|
||||
private static Map<String, BiConsumer<ClientPlayerEntity, NbtElement>> dataHandlers = new HashMap<String, BiConsumer<ClientPlayerEntity, NbtElement>>();
|
||||
static
|
||||
{
|
||||
dataHandlers.put("Rules", (p, t) -> {
|
||||
CompoundTag ruleset = (CompoundTag)t;
|
||||
NbtCompound ruleset = (NbtCompound)t;
|
||||
for (String ruleKey: ruleset.getKeys())
|
||||
{
|
||||
CompoundTag ruleNBT = (CompoundTag) ruleset.get(ruleKey);
|
||||
NbtCompound ruleNBT = (NbtCompound) ruleset.get(ruleKey);
|
||||
SettingsManager manager = null;
|
||||
String ruleName;
|
||||
if (ruleNBT.contains("Manager"))
|
||||
@@ -65,22 +65,22 @@ public class ClientNetworkHandler
|
||||
}
|
||||
}
|
||||
});
|
||||
dataHandlers.put("TickRate", (p, t) -> TickSpeed.tickrate(((AbstractNumberTag)t).getFloat(), false));
|
||||
dataHandlers.put("TickRate", (p, t) -> TickSpeed.tickrate(((AbstractNbtNumber)t).floatValue(), false));
|
||||
dataHandlers.put("TickingState", (p, t) -> {
|
||||
CompoundTag tickingState = (CompoundTag)t;
|
||||
NbtCompound tickingState = (NbtCompound)t;
|
||||
TickSpeed.setFrozenState(tickingState.getBoolean("is_paused"), tickingState.getBoolean("deepFreeze"));
|
||||
});
|
||||
dataHandlers.put("SuperHotState", (p, t) -> {
|
||||
TickSpeed.is_superHot = ((ByteTag) t).equals(ByteTag.ONE);
|
||||
TickSpeed.is_superHot = ((NbtByte) t).equals(NbtByte.ONE);
|
||||
});
|
||||
dataHandlers.put("TickPlayerActiveTimeout", (p, t) -> TickSpeed.player_active_timeout = ((AbstractNumberTag)t).getInt());
|
||||
dataHandlers.put("TickPlayerActiveTimeout", (p, t) -> TickSpeed.player_active_timeout = ((AbstractNbtNumber)t).intValue());
|
||||
dataHandlers.put("scShape", (p, t) -> { // deprecated
|
||||
if (CarpetClient.shapes != null)
|
||||
CarpetClient.shapes.addShape((CompoundTag)t);
|
||||
CarpetClient.shapes.addShape((NbtCompound)t);
|
||||
});
|
||||
dataHandlers.put("scShapes", (p, t) -> {
|
||||
if (CarpetClient.shapes != null)
|
||||
CarpetClient.shapes.addShapes((ListTag) t);
|
||||
CarpetClient.shapes.addShapes((NbtList) t);
|
||||
});
|
||||
dataHandlers.put("clientCommand", (p, t) -> {
|
||||
CarpetClient.onClientCommand(t);
|
||||
@@ -129,7 +129,7 @@ public class ClientNetworkHandler
|
||||
|
||||
private static void onSyncData(PacketByteBuf data, ClientPlayerEntity player)
|
||||
{
|
||||
CompoundTag compound = data.readCompoundTag();
|
||||
NbtCompound compound = data.readCompoundTag();
|
||||
if (compound == null) return;
|
||||
for (String key: compound.getKeys())
|
||||
{
|
||||
@@ -142,10 +142,10 @@ public class ClientNetworkHandler
|
||||
|
||||
public static void clientCommand(String command)
|
||||
{
|
||||
CompoundTag tag = new CompoundTag();
|
||||
NbtCompound tag = new NbtCompound();
|
||||
tag.putString("id", command);
|
||||
tag.putString("command", command);
|
||||
CompoundTag outer = new CompoundTag();
|
||||
NbtCompound outer = new NbtCompound();
|
||||
outer.put("clientCommand", tag);
|
||||
CarpetClient.getPlayer().networkHandler.sendPacket(new CustomPayloadC2SPacket(
|
||||
CarpetClient.CARPET_CHANNEL,
|
||||
|
||||
@@ -6,10 +6,10 @@ import carpet.helpers.TickSpeed;
|
||||
import carpet.settings.ParsedRule;
|
||||
import carpet.settings.SettingsManager;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtList;
|
||||
import net.minecraft.nbt.NbtString;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
@@ -31,9 +31,9 @@ public class ServerNetworkHandler
|
||||
private static Map<ServerPlayerEntity, String> remoteCarpetPlayers = new HashMap<>();
|
||||
private static Set<ServerPlayerEntity> validCarpetPlayers = new HashSet<>();
|
||||
|
||||
private static Map<String, BiConsumer<ServerPlayerEntity, Tag>> dataHandlers = new HashMap<String, BiConsumer<ServerPlayerEntity, Tag>>(){{
|
||||
private static Map<String, BiConsumer<ServerPlayerEntity, NbtElement>> dataHandlers = new HashMap<String, BiConsumer<ServerPlayerEntity, NbtElement>>(){{
|
||||
put("clientCommand", (p, t) -> {
|
||||
handleClientCommand(p, (CompoundTag)t);
|
||||
handleClientCommand(p, (NbtCompound)t);
|
||||
});
|
||||
}};
|
||||
|
||||
@@ -88,7 +88,7 @@ public class ServerNetworkHandler
|
||||
playerEntity.networkHandler.sendPacket(new CustomPayloadS2CPacket(CarpetClient.CARPET_CHANNEL, data.build() ));
|
||||
}
|
||||
|
||||
private static void handleClientCommand(ServerPlayerEntity player, CompoundTag commandData)
|
||||
private static void handleClientCommand(ServerPlayerEntity player, NbtCompound commandData)
|
||||
{
|
||||
String command = commandData.getString("command");
|
||||
String id = commandData.getString("id");
|
||||
@@ -121,12 +121,12 @@ public class ServerNetworkHandler
|
||||
command
|
||||
);
|
||||
};
|
||||
CompoundTag result = new CompoundTag();
|
||||
NbtCompound result = new NbtCompound();
|
||||
result.putString("id", id);
|
||||
result.putInt("code", resultCode);
|
||||
if (error[0] != null) result.putString("error", error[0]);
|
||||
ListTag outputResult = new ListTag();
|
||||
for (Text line: output) outputResult.add(StringTag.of(Text.Serializer.toJson(line)));
|
||||
NbtList outputResult = new NbtList();
|
||||
for (Text line: output) outputResult.add(NbtString.of(Text.Serializer.toJson(line)));
|
||||
if (!output.isEmpty()) result.put("output", outputResult);
|
||||
player.networkHandler.sendPacket(new CustomPayloadS2CPacket(
|
||||
CarpetClient.CARPET_CHANNEL,
|
||||
@@ -138,7 +138,7 @@ public class ServerNetworkHandler
|
||||
|
||||
private static void onClientData(ServerPlayerEntity player, PacketByteBuf data)
|
||||
{
|
||||
CompoundTag compound = data.readCompoundTag();
|
||||
NbtCompound compound = data.readCompoundTag();
|
||||
if (compound == null) return;
|
||||
for (String key: compound.getKeys())
|
||||
{
|
||||
@@ -209,7 +209,7 @@ public class ServerNetworkHandler
|
||||
}
|
||||
}
|
||||
|
||||
public static void broadcastCustomCommand(String command, Tag data)
|
||||
public static void broadcastCustomCommand(String command, NbtElement data)
|
||||
{
|
||||
if (CarpetSettings.superSecretSetting) return;
|
||||
for (ServerPlayerEntity player : validCarpetPlayers)
|
||||
@@ -221,7 +221,7 @@ public class ServerNetworkHandler
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendCustomCommand(ServerPlayerEntity player, String command, Tag data)
|
||||
public static void sendCustomCommand(ServerPlayerEntity player, String command, NbtElement data)
|
||||
{
|
||||
if (isValidCarpetPlayer(player))
|
||||
{
|
||||
@@ -262,14 +262,14 @@ public class ServerNetworkHandler
|
||||
|
||||
private static class DataBuilder
|
||||
{
|
||||
private CompoundTag tag;
|
||||
private NbtCompound tag;
|
||||
private static DataBuilder create()
|
||||
{
|
||||
return new DataBuilder();
|
||||
}
|
||||
private DataBuilder()
|
||||
{
|
||||
tag = new CompoundTag();
|
||||
tag = new NbtCompound();
|
||||
}
|
||||
private DataBuilder withTickRate()
|
||||
{
|
||||
@@ -278,7 +278,7 @@ public class ServerNetworkHandler
|
||||
}
|
||||
private DataBuilder withFrozenState()
|
||||
{
|
||||
CompoundTag tickingState = new CompoundTag();
|
||||
NbtCompound tickingState = new NbtCompound();
|
||||
tickingState.putBoolean("is_paused", TickSpeed.isPaused());
|
||||
tickingState.putBoolean("deepFreeze", TickSpeed.deeplyFrozen());
|
||||
tag.put("TickingState", tickingState);
|
||||
@@ -296,16 +296,16 @@ public class ServerNetworkHandler
|
||||
}
|
||||
private DataBuilder withRule(ParsedRule<?> rule)
|
||||
{
|
||||
CompoundTag rules = (CompoundTag) tag.get("Rules");
|
||||
NbtCompound rules = (NbtCompound) tag.get("Rules");
|
||||
if (rules == null)
|
||||
{
|
||||
rules = new CompoundTag();
|
||||
rules = new NbtCompound();
|
||||
tag.put("Rules", rules);
|
||||
}
|
||||
String identifier = rule.settingsManager.getIdentifier();
|
||||
String key = rule.name;
|
||||
while (rules.contains(key)) { key = key+"2";}
|
||||
CompoundTag ruleNBT = new CompoundTag();
|
||||
NbtCompound ruleNBT = new NbtCompound();
|
||||
ruleNBT.putString("Value", rule.getAsString());
|
||||
ruleNBT.putString("Manager",identifier);
|
||||
ruleNBT.putString("Rule",rule.name);
|
||||
@@ -313,7 +313,7 @@ public class ServerNetworkHandler
|
||||
return this;
|
||||
}
|
||||
|
||||
public DataBuilder withCustomNbt(String key, Tag value)
|
||||
public DataBuilder withCustomNbt(String key, NbtElement value)
|
||||
{
|
||||
tag.put(key, value);
|
||||
return this;
|
||||
|
||||
Reference in new issue
Block a user