Skip to content

Commit

Permalink
Fixed #38
Browse files Browse the repository at this point in the history
  • Loading branch information
Chailotl committed Aug 29, 2024
1 parent bc9f387 commit fffe219
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;

public record C2SEditHyperlinkBlock(BlockPos pos, String url) implements C2SEditBlockEntity {
public record C2SEditHyperlinkBlock(BlockPos pos, String title, String url) implements C2SEditBlockEntity {
public static final Id<C2SEditHyperlinkBlock> ID = new Id<>(Glowcase.id("channel.hyperlink.save"));
public static final PacketCodec<RegistryByteBuf, C2SEditHyperlinkBlock> PACKET_CODEC = PacketCodec.tuple(
BlockPos.PACKET_CODEC, C2SEditHyperlinkBlock::pos,
PacketCodecs.STRING, C2SEditHyperlinkBlock::title,
PacketCodecs.STRING, C2SEditHyperlinkBlock::url,
C2SEditHyperlinkBlock::new
);

public static C2SEditHyperlinkBlock of(HyperlinkBlockEntity be) {
return new C2SEditHyperlinkBlock(be.getPos(), be.getUrl());
return new C2SEditHyperlinkBlock(be.getPos(), be.getTitle(), be.getUrl());
}

@Override
Expand All @@ -30,6 +31,9 @@ public Id<? extends CustomPayload> getId() {
@Override
public void receive(ServerWorld world, BlockEntity blockEntity) {
if (!(blockEntity instanceof HyperlinkBlockEntity be)) return;
if (this.title().length() <= HyperlinkBlockEntity.TITLE_MAX_LENGTH) {
be.setTitle(this.title());
}
if (this.url().length() <= HyperlinkBlockEntity.URL_MAX_LENGTH) {
be.setUrl(this.url());
}
Expand Down

0 comments on commit fffe219

Please sign in to comment.