Skip to content

Commit

Permalink
Update mod litematica-server-paster to v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Fallen-Breath committed Nov 5, 2023
1 parent 9b332f9 commit 652c394
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.fallenbreath.lmspaster;

import carpet.settings.CarpetSettings;
import me.fallenbreath.lmspaster.network.LmsPasterPayload;
import me.fallenbreath.lmspaster.network.Network;
import me.fallenbreath.lmspaster.network.ServerNetworkHandler;
import net.minecraft.entity.player.EntityPlayerMP;
Expand All @@ -22,7 +23,8 @@ public static void onPacket(CPacketCustomPayload packetIn, EntityPlayerMP player
ResourceLocation channel = packetIn.getChannel();
if (Network.CHANNEL.equals(channel))
{
ServerNetworkHandler.handleClientPacket(packetIn.getData(), player);
LmsPasterPayload payload = new LmsPasterPayload(packetIn.getData());
ServerNetworkHandler.handleClientPacket(payload, player);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
/*
* This file is part of the Litematica Server Paster project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2023 Fallen_Breath and contributors
*
* Litematica Server Paster is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Litematica Server Paster is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Litematica Server Paster. If not, see <https://www.gnu.org/licenses/>.
*/

package me.fallenbreath.lmspaster;

import org.apache.logging.log4j.LogManager;
Expand All @@ -9,5 +29,5 @@ public class LitematicaServerPasterMod

public static final String MOD_NAME = "Litematica Server Paster";
public static final String MOD_ID = "litematica-server-paster";
public static final String VERSION = "1.1.0";
public static final String VERSION = "1.2.0";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* This file is part of the Litematica Server Paster project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2023 Fallen_Breath and contributors
*
* Litematica Server Paster is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Litematica Server Paster is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Litematica Server Paster. If not, see <https://www.gnu.org/licenses/>.
*/

package me.fallenbreath.lmspaster.network;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.ResourceLocation;

public class LmsPasterPayload
{
public static final ResourceLocation ID = Network.CHANNEL;

private final int id;
private final NBTTagCompound nbt;

public LmsPasterPayload(int id, NBTTagCompound nbt)
{
this.id = id;
this.nbt = nbt;
}

public LmsPasterPayload(PacketBuffer buf)
{
this(buf.readVarInt(), buf.readCompoundTag());
}

public int getPacketId()
{
return this.id;
}

public NBTTagCompound getNbt()
{
return this.nbt;
}
}
38 changes: 27 additions & 11 deletions src/main/java/me/fallenbreath/lmspaster/network/Network.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
/*
* This file is part of the Litematica Server Paster project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2023 Fallen_Breath and contributors
*
* Litematica Server Paster is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Litematica Server Paster is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Litematica Server Paster. If not, see <https://www.gnu.org/licenses/>.
*/

package me.fallenbreath.lmspaster.network;

import com.google.common.collect.Sets;
import io.netty.buffer.Unpooled;
import me.fallenbreath.lmspaster.LitematicaServerPasterMod;
import me.fallenbreath.lmspaster.util.RegistryUtil;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.play.client.CPacketCustomPayload;
import net.minecraft.network.play.server.SPacketCustomPayload;
import net.minecraft.util.ResourceLocation;

Expand All @@ -16,7 +36,7 @@

public class Network
{
public static final ResourceLocation CHANNEL = RegistryUtil.id("network");
public static final ResourceLocation CHANNEL = RegistryUtil.id("network_v2");

public static class C2S
{
Expand Down Expand Up @@ -57,24 +77,20 @@ public static class C2S
ALL_PACKET_IDS[i++] = id;
}
}

public static CPacketCustomPayload packet(Consumer<PacketBuffer> byteBufBuilder)
{
PacketBuffer packetByteBuf = new PacketBuffer(Unpooled.buffer());
byteBufBuilder.accept(packetByteBuf);
return new CPacketCustomPayload(CHANNEL, packetByteBuf);
}
}

public static class S2C
{
public static final int HI = 0;
public static final int ACCEPT_PACKETS = 1;

public static SPacketCustomPayload packet(Consumer<PacketBuffer> byteBufBuilder)
public static SPacketCustomPayload packet(int packetId, Consumer<NBTTagCompound> payloadBuilder)
{
NBTTagCompound nbt = new NBTTagCompound();
payloadBuilder.accept(nbt);
PacketBuffer packetByteBuf = new PacketBuffer(Unpooled.buffer());
byteBufBuilder.accept(packetByteBuf);
packetByteBuf.writeVarInt(packetId);
packetByteBuf.writeCompoundTag(nbt);
return new SPacketCustomPayload(CHANNEL, packetByteBuf);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
/*
* This file is part of the Litematica Server Paster project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2023 Fallen_Breath and contributors
*
* Litematica Server Paster is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Litematica Server Paster is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Litematica Server Paster. If not, see <https://www.gnu.org/licenses/>.
*/

package me.fallenbreath.lmspaster.network;

import me.fallenbreath.lmspaster.LitematicaServerPasterMod;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.network.PacketBuffer;

import java.util.Map;
import java.util.Objects;
Expand All @@ -19,28 +39,27 @@ private static Optional<StringBuilder> getVeryLongChatBuilder(EntityPlayerMP pla
return Optional.ofNullable(VERY_LONG_CHATS.get(player.connection));
}

public static void handleClientPacket(PacketBuffer data, EntityPlayerMP player)
public static void handleClientPacket(LmsPasterPayload payload, EntityPlayerMP player)
{
String playerName = player.getName().getString();
int id = data.readVarInt();
int id = payload.getPacketId();
NBTTagCompound nbt = payload.getNbt();
switch (id)
{
case Network.C2S.HI:
String clientModVersion = data.readString(Short.MAX_VALUE);
String clientModVersion = nbt.getString("mod_version");
LitematicaServerPasterMod.LOGGER.info("Player {} connected with {} @ {}", playerName, LitematicaServerPasterMod.MOD_NAME, clientModVersion);
player.connection.sendPacket(Network.S2C.packet(buf -> buf.
writeVarInt(Network.S2C.HI).
writeString(LitematicaServerPasterMod.VERSION)
));
player.connection.sendPacket(Network.S2C.packet(buf -> buf.
writeVarInt(Network.S2C.ACCEPT_PACKETS).
writeVarIntArray(Network.C2S.ALL_PACKET_IDS))
);
player.connection.sendPacket(Network.S2C.packet(Network.S2C.HI, nbt2 -> {
nbt2.putString("mod_version", LitematicaServerPasterMod.VERSION);
}));
player.connection.sendPacket(Network.S2C.packet(Network.S2C.ACCEPT_PACKETS, nbt2 -> {
nbt2.putIntArray("ids", Network.C2S.ALL_PACKET_IDS);
}));
break;

case Network.C2S.CHAT:
LitematicaServerPasterMod.LOGGER.debug("Received chat from player {}", playerName);
String message = data.readString(Short.MAX_VALUE);
String message = nbt.getString("chat");
triggerCommand(player, playerName, message);
break;

Expand All @@ -50,9 +69,9 @@ public static void handleClientPacket(PacketBuffer data, EntityPlayerMP player)
break;

case Network.C2S.VERY_LONG_CHAT_CONTENT:
String content = data.readString(Short.MAX_VALUE);
LitematicaServerPasterMod.LOGGER.debug("Received VERY_LONG_CHAT_CONTENT from player {} with length {}", playerName, content.length());
getVeryLongChatBuilder(player).ifPresent(builder -> builder.append(content));
String segment = nbt.getString("segment");
LitematicaServerPasterMod.LOGGER.debug("Received VERY_LONG_CHAT_CONTENT from player {} with length {}", playerName, segment.length());
getVeryLongChatBuilder(player).ifPresent(builder -> builder.append(segment));
break;

case Network.C2S.VERY_LONG_CHAT_END:
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/me/fallenbreath/lmspaster/util/RegistryUtil.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
/*
* This file is part of the Litematica Server Paster project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2023 Fallen_Breath and contributors
*
* Litematica Server Paster is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Litematica Server Paster is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Litematica Server Paster. If not, see <https://www.gnu.org/licenses/>.
*/

package me.fallenbreath.lmspaster.util;

import me.fallenbreath.lmspaster.LitematicaServerPasterMod;
Expand Down

0 comments on commit 652c394

Please sign in to comment.