Skip to content

Commit

Permalink
🐞 Fixed bug of RailwaySignWallDouble
Browse files Browse the repository at this point in the history
The game exits to main menu when `selectedIds` are not zero.
  • Loading branch information
ZiYueCommentary committed Feb 12, 2024
1 parent 3c390e0 commit 6c5de63
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void writeCompoundTag(CompoundTag compoundTag) {
}

public void setData(List<Set<Long>> selectedIds, String[][] signTypes) {
this.selectedIds.forEach(Set::clear);
this.selectedIds.clear();
this.selectedIds.addAll(selectedIds);
if (signIds[0].length == signTypes[0].length) { // Both lines have the same length
System.arraycopy(signTypes, 0, signIds, 0, signTypes.length);
Expand Down
4 changes: 2 additions & 2 deletions common/src/main/java/ziyue/tjmetro/packet/IPacket.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public interface IPacket
ResourceLocation PACKET_UPDATE_CUSTOM_COLOR = new ResourceLocation(Reference.MOD_ID, "packet_update_custom_color_screen");
ResourceLocation PACKET_OPEN_RAILWAY_SIGN_SCREEN = new ResourceLocation(Reference.MOD_ID, "packet_open_railway_sign_screen");
ResourceLocation PACKET_OPEN_RAILWAY_SIGN_WALL_DOUBLE_SCREEN = new ResourceLocation(Reference.MOD_ID, "packet_open_railway_sign_wall_double_screen");
ResourceLocation PACKET_SIGN_TYPES = new ResourceLocation(MTR.MOD_ID, "packet_sign_types");
ResourceLocation PACKET_SIGN_TYPES_DOUBLE = new ResourceLocation(MTR.MOD_ID, "packet_sign_types_double");
ResourceLocation PACKET_SIGN_TYPES = new ResourceLocation(Reference.MOD_ID, "packet_sign_types");
ResourceLocation PACKET_SIGN_TYPES_DOUBLE = new ResourceLocation(Reference.MOD_ID, "packet_sign_types_double");
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,10 @@ public static void openRailwaySignWallDoubleScreenS2C(ServerPlayer player, Block
public static void sendSignIdsDoubleC2S(BlockPos signPos, List<Set<Long>> selectedIds, String[][] signIds) {
final FriendlyByteBuf packet = new FriendlyByteBuf(Unpooled.buffer());
packet.writeBlockPos(signPos);
packet.writeInt(selectedIds.get(0).size());
selectedIds.forEach(line -> line.forEach(packet::writeLong));
selectedIds.forEach(line -> {
packet.writeInt(line.size());
line.forEach(packet::writeLong);
});
packet.writeInt(signIds[0].length);
for (int i = 0; i < 2; i++) {
for (final String signType : signIds[i]) {
Expand All @@ -137,11 +139,11 @@ public static void sendSignIdsDoubleC2S(BlockPos signPos, List<Set<Long>> select

public static void receiveSignIdsDoubleC2S(MinecraftServer minecraftServer, ServerPlayer player, FriendlyByteBuf packet) {
final BlockPos signPos = packet.readBlockPos();
final int selectedIdsLength = packet.readInt();
final List<Set<Long>> selectedIds = new ArrayList<>();
selectedIds.add(new HashSet<>());
selectedIds.add(new HashSet<>());
for (int i = 0; i < 2; i++) {
final int selectedIdsLength = packet.readInt();
for (int j = 0; j < selectedIdsLength; j++) {
selectedIds.get(i).add(packet.readLong());
}
Expand Down

0 comments on commit 6c5de63

Please sign in to comment.