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

@@ -1,5 +1,7 @@
package tconstruct.tools.gui;
import java.util.Arrays;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.Tessellator;
@@ -25,11 +27,12 @@ public class BattlesignGui extends GuiScreen {
private float bgColG = 1F;
private float bgColB = 1F;
private static final ResourceLocation background = new ResourceLocation("tinker:textures/gui/battlesignText.png");
private final String[] text = { "", "", "", "", "" };
private final String[] text = new String[BattlesignLogic.LINE_COUNT];
int currentLine = 0;
public BattlesignGui(BattlesignLogic logic) {
this.battlesign = logic;
Arrays.fill(text, "");
ItemStack stack = logic.getEquipmentItem();
if (stack != null) {
@@ -146,13 +149,8 @@ public class BattlesignGui extends GuiScreen {
Keyboard.enableRepeatEvents(false);
TConstruct.packetPipeline.sendToServer(
new SignDataPacket(
battlesign.getWorldObj().provider.dimensionId,
battlesign.xCoord,
battlesign.yCoord,
battlesign.zCoord,
text));
TConstruct.packetPipeline
.sendToServer(new SignDataPacket(battlesign.xCoord, battlesign.yCoord, battlesign.zCoord, text));
}
private float calcLuminance(float r, float g, float b) {
@@ -3,8 +3,6 @@ package tconstruct.tools.logic;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.world.World;
/*
@@ -13,6 +11,8 @@ import net.minecraft.world.World;
public class BattlesignLogic extends EquipLogic {
public static final int LINE_COUNT = 5;
protected String[] text;
public BattlesignLogic() {
@@ -72,16 +72,4 @@ public class BattlesignLogic extends EquipLogic {
public String[] getText() {
return text;
}
@Override
public S35PacketUpdateTileEntity getDescriptionPacket() {
NBTTagCompound compound = new NBTTagCompound();
this.writeToNBT(compound);
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, compound);
}
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
this.readFromNBT(pkt.func_148857_g());
}
}
@@ -56,5 +56,6 @@ public abstract class EquipLogic extends InventoryLogic {
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
this.readFromNBT(pkt.func_148857_g());
worldObj.func_147479_m(xCoord, yCoord, zCoord);
}
}
@@ -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);
}
}