Fix BattleSign in world text (#314)

This commit is contained in:
Jason Mitchell authored and GitHub committed 2026-08-15 15:40:42 -07:00
1 parent cdbd90be5f
commit 37744c8385
4 files changed
+33 -51

No files matched your search

@@ -7,75 +7,70 @@ import cpw.mods.fml.common.network.ByteBufUtils;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import mantle.common.network.AbstractPacket;
import tconstruct.TConstruct;
import tconstruct.tools.logic.BattlesignLogic;
public class SignDataPacket extends AbstractPacket {
private int dimension, x, y, z, length;
private static final int MAX_LINE_LENGTH = 256;
private static final double MAX_EDIT_DISTANCE_SQ = 64D;
private int x, y, z;
private String[] text;
public SignDataPacket() {}
public SignDataPacket(int dimension, int x, int y, int z, String[] text) {
public SignDataPacket(int x, int y, int z, String[] text) {
this.text = text;
this.dimension = dimension;
this.x = x;
this.y = y;
this.z = z;
this.length = text.length;
}
@Override
public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
buffer.writeInt(dimension);
buffer.writeInt(x);
buffer.writeInt(y);
buffer.writeInt(z);
buffer.writeInt(length);
for (int i = 0; i < length; i++) {
ByteBufUtils.writeUTF8String(buffer, text[i]);
buffer.writeInt(text.length);
for (String line : text) {
ByteBufUtils.writeUTF8String(buffer, line);
}
}
@Override
public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
dimension = buffer.readInt();
x = buffer.readInt();
y = buffer.readInt();
z = buffer.readInt();
length = buffer.readInt();
text = new String[length];
for (int i = 0; i < length; i++) {
text[i] = ByteBufUtils.readUTF8String(buffer);
int lineCount = Math.max(0, Math.min(buffer.readInt(), BattlesignLogic.LINE_COUNT));
text = new String[lineCount];
for (int i = 0; i < lineCount; i++) {
String line = ByteBufUtils.readUTF8String(buffer);
text[i] = line.length() > MAX_LINE_LENGTH ? line.substring(0, MAX_LINE_LENGTH) : line;
}
}
@Override
public void handleClientSide(EntityPlayer player) {
TileEntity te = player.worldObj.getTileEntity(x, y, z);
if (te instanceof BattlesignLogic) {
BattlesignLogic logic = (BattlesignLogic) te;
logic.setText(text);
}
}
public void handleClientSide(EntityPlayer player) {}
@Override
public void handleServerSide(EntityPlayer player) {
if (player.worldObj.blockExists(x, y, z)) {
if (!player.worldObj.blockExists(x, y, z)) {
return;
}
if (player.getDistanceSq(x + 0.5D, y + 0.5D, z + 0.5D) > MAX_EDIT_DISTANCE_SQ) {
return;
}
TileEntity te = player.worldObj.getTileEntity(x, y, z);
if (te instanceof BattlesignLogic) {
BattlesignLogic logic = (BattlesignLogic) te;
logic.setText(text);
if (!(te instanceof BattlesignLogic)) {
return;
}
TConstruct.packetPipeline.sendToDimension(new SignDataPacket(dimension, x, y, z, text), dimension);
((BattlesignLogic) te).setText(text);
te.markDirty();
player.worldObj.markBlockForUpdate(x, y, z);
}
}