From 2c0b0e99464a55c49bf62e855a9c3529b0188079 Mon Sep 17 00:00:00 2001 From: Chai <7232280+Chailotl@users.noreply.github.com> Date: Sat, 13 Jul 2024 19:03:53 -0400 Subject: [PATCH 01/14] Fixed #23 by moving setMaxLength to before setText --- .../client/gui/screen/ingame/HyperlinkBlockEditScreen.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/HyperlinkBlockEditScreen.java b/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/HyperlinkBlockEditScreen.java index db8fd90..e76dd6c 100644 --- a/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/HyperlinkBlockEditScreen.java +++ b/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/HyperlinkBlockEditScreen.java @@ -25,8 +25,8 @@ public void init() { if (this.client == null) return; this.urlEntryWidget = new TextFieldWidget(this.client.textRenderer, width / 10, height / 2 - 10, 8 * width / 10, 20, Text.empty()); - this.urlEntryWidget.setText(this.hyperlinkBlockEntity.getUrl()); this.urlEntryWidget.setMaxLength(Integer.MAX_VALUE); + this.urlEntryWidget.setText(this.hyperlinkBlockEntity.getUrl()); this.addDrawableChild(this.urlEntryWidget); } From 31f84723e8bff8fa5208cbc0ec9e9ecbb5e6ea02 Mon Sep 17 00:00:00 2001 From: Chai <7232280+Chailotl@users.noreply.github.com> Date: Sat, 13 Jul 2024 19:21:41 -0400 Subject: [PATCH 02/14] Closed #25 title masks for hyperlink blocks --- .../glowcase/block/HyperlinkBlock.java | 7 +++++-- .../block/entity/HyperlinkBlockEntity.java | 17 +++++++++++++++++ .../screen/ingame/HyperlinkBlockEditScreen.java | 14 ++++++++++++-- .../entity/HyperlinkBlockEntityRenderer.java | 4 ++-- .../networking/GlowcaseClientNetworking.java | 4 ++-- .../networking/GlowcaseCommonNetworking.java | 8 +++++--- .../resources/assets/glowcase/lang/en_us.json | 4 +++- 7 files changed, 46 insertions(+), 12 deletions(-) diff --git a/src/main/java/dev/hephaestus/glowcase/block/HyperlinkBlock.java b/src/main/java/dev/hephaestus/glowcase/block/HyperlinkBlock.java index 9b9adea..fd11e03 100644 --- a/src/main/java/dev/hephaestus/glowcase/block/HyperlinkBlock.java +++ b/src/main/java/dev/hephaestus/glowcase/block/HyperlinkBlock.java @@ -6,6 +6,8 @@ import net.minecraft.block.BlockState; import net.minecraft.block.ShapeContext; import net.minecraft.block.entity.BlockEntity; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.ConfirmLinkScreen; import net.minecraft.component.DataComponentTypes; import net.minecraft.component.type.NbtComponent; import net.minecraft.entity.LivingEntity; @@ -61,8 +63,9 @@ protected ActionResult onUse(BlockState state, World world, BlockPos pos, Player @Override protected ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { if (!(world.getBlockEntity(pos) instanceof HyperlinkBlockEntity be)) return ItemActionResult.CONSUME; - if (world.isClient && player.getStackInHand(hand).isIn(Glowcase.ITEM_TAG) && canEditGlowcase(player, pos)) { - Glowcase.proxy.openHyperlinkBlockEditScreen(pos); + if (player.getStackInHand(hand).isIn(Glowcase.ITEM_TAG) && canEditGlowcase(player, pos)) { + if (world.isClient) { Glowcase.proxy.openHyperlinkBlockEditScreen(pos); } + return ItemActionResult.SUCCESS; } return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; } diff --git a/src/main/java/dev/hephaestus/glowcase/block/entity/HyperlinkBlockEntity.java b/src/main/java/dev/hephaestus/glowcase/block/entity/HyperlinkBlockEntity.java index 05bfd6d..b5bd7b3 100644 --- a/src/main/java/dev/hephaestus/glowcase/block/entity/HyperlinkBlockEntity.java +++ b/src/main/java/dev/hephaestus/glowcase/block/entity/HyperlinkBlockEntity.java @@ -13,12 +13,27 @@ import org.jetbrains.annotations.Nullable; public class HyperlinkBlockEntity extends BlockEntity { + private String title = ""; private String url = ""; public HyperlinkBlockEntity(BlockPos pos, BlockState state) { super(Glowcase.HYPERLINK_BLOCK_ENTITY, pos, state); } + public String getText() { + return !title.isEmpty() ? title : url; + } + + public String getTitle() { + return title; + } + + public void setTitle(String newTitle) { + title = newTitle; + markDirty(); + dispatch(); + } + public String getUrl() { return url; } @@ -32,12 +47,14 @@ public void setUrl(String newUrl) { @Override public void writeNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) { super.writeNbt(tag, registryLookup); + tag.putString("title", this.title); tag.putString("url", this.url); } @Override public void readNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) { super.readNbt(tag, registryLookup); + this.title = tag.getString("title"); this.url = tag.getString("url"); } diff --git a/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/HyperlinkBlockEditScreen.java b/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/HyperlinkBlockEditScreen.java index e76dd6c..cd59401 100644 --- a/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/HyperlinkBlockEditScreen.java +++ b/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/HyperlinkBlockEditScreen.java @@ -12,6 +12,7 @@ public class HyperlinkBlockEditScreen extends GlowcaseScreen { private final HyperlinkBlockEntity hyperlinkBlockEntity; + private TextFieldWidget titleEntryWidget; private TextFieldWidget urlEntryWidget; public HyperlinkBlockEditScreen(HyperlinkBlockEntity hyperlinkBlockEntity) { @@ -24,10 +25,17 @@ public void init() { if (this.client == null) return; - this.urlEntryWidget = new TextFieldWidget(this.client.textRenderer, width / 10, height / 2 - 10, 8 * width / 10, 20, Text.empty()); + this.titleEntryWidget = new TextFieldWidget(this.client.textRenderer, width / 10, height / 2 - 30, 8 * width / 10, 20, Text.empty()); + this.titleEntryWidget.setMaxLength(Integer.MAX_VALUE); + this.titleEntryWidget.setText(this.hyperlinkBlockEntity.getTitle()); + this.titleEntryWidget.setPlaceholder(Text.translatable("gui.glowcase.title")); + + this.urlEntryWidget = new TextFieldWidget(this.client.textRenderer, width / 10, height / 2 + 10, 8 * width / 10, 20, Text.empty()); this.urlEntryWidget.setMaxLength(Integer.MAX_VALUE); this.urlEntryWidget.setText(this.hyperlinkBlockEntity.getUrl()); + this.urlEntryWidget.setPlaceholder(Text.translatable("gui.glowcase.url")); + this.addDrawableChild(this.titleEntryWidget); this.addDrawableChild(this.urlEntryWidget); } @@ -36,6 +44,8 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { if (keyCode == GLFW.GLFW_KEY_ENTER || keyCode == GLFW.GLFW_KEY_KP_ENTER || keyCode == GLFW.GLFW_KEY_ESCAPE) { this.close(); return true; + } else if (this.titleEntryWidget.isActive()) { + return this.titleEntryWidget.keyPressed(keyCode, scanCode, modifiers); } else if (this.urlEntryWidget.isActive()) { return this.urlEntryWidget.keyPressed(keyCode, scanCode, modifiers); }else { @@ -45,7 +55,7 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { @Override public void close() { - GlowcaseClientNetworking.editHyperlinkBlock(hyperlinkBlockEntity.getPos(), urlEntryWidget.getText()); + GlowcaseClientNetworking.editHyperlinkBlock(hyperlinkBlockEntity.getPos(), titleEntryWidget.getText(), urlEntryWidget.getText()); super.close(); } } diff --git a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/HyperlinkBlockEntityRenderer.java b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/HyperlinkBlockEntityRenderer.java index b090ad3..f9da0ce 100644 --- a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/HyperlinkBlockEntityRenderer.java +++ b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/HyperlinkBlockEntityRenderer.java @@ -37,10 +37,10 @@ public void render(HyperlinkBlockEntity entity, float f, MatrixStack matrices, V if (hitResult instanceof BlockHitResult && ((BlockHitResult) hitResult).getBlockPos().equals(entity.getPos())) { float scale = 0.025F; matrices.scale(scale, scale, scale); - matrices.translate(-context.getTextRenderer().getWidth(entity.getUrl()) / 2F, -4, scale); + matrices.translate(-context.getTextRenderer().getWidth(entity.getText()) / 2F, -4, scale); // Fixes shadow being rendered in front of actual text matrices.scale(1, 1, -1); - context.getTextRenderer().draw(entity.getUrl(), 0, 0, 0xFFFFFF, true, matrices.peek().getPositionMatrix(), vertexConsumers, TextLayerType.NORMAL, 0, LightmapTextureManager.MAX_LIGHT_COORDINATE); + context.getTextRenderer().draw(entity.getText(), 0, 0, 0xFFFFFF, true, matrices.peek().getPositionMatrix(), vertexConsumers, TextLayerType.NORMAL, 0, LightmapTextureManager.MAX_LIGHT_COORDINATE); } matrices.pop(); } diff --git a/src/main/java/dev/hephaestus/glowcase/networking/GlowcaseClientNetworking.java b/src/main/java/dev/hephaestus/glowcase/networking/GlowcaseClientNetworking.java index a1ed3ed..4bc2f45 100644 --- a/src/main/java/dev/hephaestus/glowcase/networking/GlowcaseClientNetworking.java +++ b/src/main/java/dev/hephaestus/glowcase/networking/GlowcaseClientNetworking.java @@ -9,8 +9,8 @@ import net.minecraft.util.math.Vec2f; public class GlowcaseClientNetworking { - public static void editHyperlinkBlock(BlockPos pos, String url) { - ClientPlayNetworking.send(new GlowcaseCommonNetworking.EditHyperlinkBlock(pos, url)); + public static void editHyperlinkBlock(BlockPos pos, String title, String url) { + ClientPlayNetworking.send(new GlowcaseCommonNetworking.EditHyperlinkBlock(pos, title, url)); } //TODO: Pretty spicy, copied from the old code. Should maybe break this into more packets, or dispatch off the type of property I'm setting. diff --git a/src/main/java/dev/hephaestus/glowcase/networking/GlowcaseCommonNetworking.java b/src/main/java/dev/hephaestus/glowcase/networking/GlowcaseCommonNetworking.java index 8704148..4380a37 100644 --- a/src/main/java/dev/hephaestus/glowcase/networking/GlowcaseCommonNetworking.java +++ b/src/main/java/dev/hephaestus/glowcase/networking/GlowcaseCommonNetworking.java @@ -25,13 +25,14 @@ public class GlowcaseCommonNetworking { - public record EditHyperlinkBlock(BlockPos pos, String url) implements CustomPayload { + public record EditHyperlinkBlock(BlockPos pos, String title, String url) implements CustomPayload { public static final Id PACKET_ID = new Id<>(Glowcase.id("channel.hyperlink.save")); - public static final PacketCodec PACKET_CODEC = PacketCodec.tuple(BlockPos.PACKET_CODEC, EditHyperlinkBlock::pos, PacketCodecs.STRING, EditHyperlinkBlock::url, EditHyperlinkBlock::new); + public static final PacketCodec PACKET_CODEC = PacketCodec.tuple(BlockPos.PACKET_CODEC, EditHyperlinkBlock::pos, PacketCodecs.STRING, EditHyperlinkBlock::title, PacketCodecs.STRING, EditHyperlinkBlock::url, EditHyperlinkBlock::new); public static void receive(EditHyperlinkBlock payload, ServerPlayNetworking.Context context) { context.player().server.submit(() -> { - if(canEditGlowcase(context.player(), payload.pos(), Glowcase.HYPERLINK_BLOCK) && context.player().getServerWorld().getBlockEntity(payload.pos()) instanceof HyperlinkBlockEntity link && payload.url().length() <= URL_MAX_LENGTH) { + if(canEditGlowcase(context.player(), payload.pos(), Glowcase.HYPERLINK_BLOCK) && context.player().getServerWorld().getBlockEntity(payload.pos()) instanceof HyperlinkBlockEntity link && payload.url().length() <= URL_MAX_LENGTH && payload.title().length() <= TITLE_MAX_LENGTH) { + link.setTitle(payload.title()); link.setUrl(payload.url()); } }); @@ -136,6 +137,7 @@ public Id getId() { } } + private static final int TITLE_MAX_LENGTH = 1024; private static final int URL_MAX_LENGTH = 1024; public static void onInitialize() { diff --git a/src/main/resources/assets/glowcase/lang/en_us.json b/src/main/resources/assets/glowcase/lang/en_us.json index 49ff6fc..f3e1a86 100644 --- a/src/main/resources/assets/glowcase/lang/en_us.json +++ b/src/main/resources/assets/glowcase/lang/en_us.json @@ -19,5 +19,7 @@ "command.glowcase.failed.no_world": "Failed to send message; sender must be in a world", "glowcase.mailbox.sender": "From %s", "glowcase.mailbox.reminder1": "Right click to delete this message", - "glowcase.mailbox.reminder2": "Sneak+Right click to delete all messages from this sender" + "glowcase.mailbox.reminder2": "Sneak+Right click to delete all messages from this sender", + "gui.glowcase.title": "Title", + "gui.glowcase.url": "URL" } \ No newline at end of file From 17c2b296856b4000714b6676242553135ff422d4 Mon Sep 17 00:00:00 2001 From: Chai <7232280+Chailotl@users.noreply.github.com> Date: Sat, 13 Jul 2024 19:51:46 -0400 Subject: [PATCH 03/14] Closed #25 title masks for hyperlink blocks --- .../block/entity/HyperlinkBlockEntity.java | 17 +++++++++++++++++ .../screen/ingame/HyperlinkBlockEditScreen.java | 14 ++++++++++++-- .../entity/HyperlinkBlockEntityRenderer.java | 4 ++-- .../networking/GlowcaseClientNetworking.java | 4 ++-- .../networking/GlowcaseCommonNetworking.java | 8 +++++--- .../resources/assets/glowcase/lang/en_us.json | 4 +++- 6 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/main/java/dev/hephaestus/glowcase/block/entity/HyperlinkBlockEntity.java b/src/main/java/dev/hephaestus/glowcase/block/entity/HyperlinkBlockEntity.java index 05bfd6d..b5bd7b3 100644 --- a/src/main/java/dev/hephaestus/glowcase/block/entity/HyperlinkBlockEntity.java +++ b/src/main/java/dev/hephaestus/glowcase/block/entity/HyperlinkBlockEntity.java @@ -13,12 +13,27 @@ import org.jetbrains.annotations.Nullable; public class HyperlinkBlockEntity extends BlockEntity { + private String title = ""; private String url = ""; public HyperlinkBlockEntity(BlockPos pos, BlockState state) { super(Glowcase.HYPERLINK_BLOCK_ENTITY, pos, state); } + public String getText() { + return !title.isEmpty() ? title : url; + } + + public String getTitle() { + return title; + } + + public void setTitle(String newTitle) { + title = newTitle; + markDirty(); + dispatch(); + } + public String getUrl() { return url; } @@ -32,12 +47,14 @@ public void setUrl(String newUrl) { @Override public void writeNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) { super.writeNbt(tag, registryLookup); + tag.putString("title", this.title); tag.putString("url", this.url); } @Override public void readNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) { super.readNbt(tag, registryLookup); + this.title = tag.getString("title"); this.url = tag.getString("url"); } diff --git a/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/HyperlinkBlockEditScreen.java b/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/HyperlinkBlockEditScreen.java index e76dd6c..cd59401 100644 --- a/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/HyperlinkBlockEditScreen.java +++ b/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/HyperlinkBlockEditScreen.java @@ -12,6 +12,7 @@ public class HyperlinkBlockEditScreen extends GlowcaseScreen { private final HyperlinkBlockEntity hyperlinkBlockEntity; + private TextFieldWidget titleEntryWidget; private TextFieldWidget urlEntryWidget; public HyperlinkBlockEditScreen(HyperlinkBlockEntity hyperlinkBlockEntity) { @@ -24,10 +25,17 @@ public void init() { if (this.client == null) return; - this.urlEntryWidget = new TextFieldWidget(this.client.textRenderer, width / 10, height / 2 - 10, 8 * width / 10, 20, Text.empty()); + this.titleEntryWidget = new TextFieldWidget(this.client.textRenderer, width / 10, height / 2 - 30, 8 * width / 10, 20, Text.empty()); + this.titleEntryWidget.setMaxLength(Integer.MAX_VALUE); + this.titleEntryWidget.setText(this.hyperlinkBlockEntity.getTitle()); + this.titleEntryWidget.setPlaceholder(Text.translatable("gui.glowcase.title")); + + this.urlEntryWidget = new TextFieldWidget(this.client.textRenderer, width / 10, height / 2 + 10, 8 * width / 10, 20, Text.empty()); this.urlEntryWidget.setMaxLength(Integer.MAX_VALUE); this.urlEntryWidget.setText(this.hyperlinkBlockEntity.getUrl()); + this.urlEntryWidget.setPlaceholder(Text.translatable("gui.glowcase.url")); + this.addDrawableChild(this.titleEntryWidget); this.addDrawableChild(this.urlEntryWidget); } @@ -36,6 +44,8 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { if (keyCode == GLFW.GLFW_KEY_ENTER || keyCode == GLFW.GLFW_KEY_KP_ENTER || keyCode == GLFW.GLFW_KEY_ESCAPE) { this.close(); return true; + } else if (this.titleEntryWidget.isActive()) { + return this.titleEntryWidget.keyPressed(keyCode, scanCode, modifiers); } else if (this.urlEntryWidget.isActive()) { return this.urlEntryWidget.keyPressed(keyCode, scanCode, modifiers); }else { @@ -45,7 +55,7 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { @Override public void close() { - GlowcaseClientNetworking.editHyperlinkBlock(hyperlinkBlockEntity.getPos(), urlEntryWidget.getText()); + GlowcaseClientNetworking.editHyperlinkBlock(hyperlinkBlockEntity.getPos(), titleEntryWidget.getText(), urlEntryWidget.getText()); super.close(); } } diff --git a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/HyperlinkBlockEntityRenderer.java b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/HyperlinkBlockEntityRenderer.java index b090ad3..f9da0ce 100644 --- a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/HyperlinkBlockEntityRenderer.java +++ b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/HyperlinkBlockEntityRenderer.java @@ -37,10 +37,10 @@ public void render(HyperlinkBlockEntity entity, float f, MatrixStack matrices, V if (hitResult instanceof BlockHitResult && ((BlockHitResult) hitResult).getBlockPos().equals(entity.getPos())) { float scale = 0.025F; matrices.scale(scale, scale, scale); - matrices.translate(-context.getTextRenderer().getWidth(entity.getUrl()) / 2F, -4, scale); + matrices.translate(-context.getTextRenderer().getWidth(entity.getText()) / 2F, -4, scale); // Fixes shadow being rendered in front of actual text matrices.scale(1, 1, -1); - context.getTextRenderer().draw(entity.getUrl(), 0, 0, 0xFFFFFF, true, matrices.peek().getPositionMatrix(), vertexConsumers, TextLayerType.NORMAL, 0, LightmapTextureManager.MAX_LIGHT_COORDINATE); + context.getTextRenderer().draw(entity.getText(), 0, 0, 0xFFFFFF, true, matrices.peek().getPositionMatrix(), vertexConsumers, TextLayerType.NORMAL, 0, LightmapTextureManager.MAX_LIGHT_COORDINATE); } matrices.pop(); } diff --git a/src/main/java/dev/hephaestus/glowcase/networking/GlowcaseClientNetworking.java b/src/main/java/dev/hephaestus/glowcase/networking/GlowcaseClientNetworking.java index a1ed3ed..4bc2f45 100644 --- a/src/main/java/dev/hephaestus/glowcase/networking/GlowcaseClientNetworking.java +++ b/src/main/java/dev/hephaestus/glowcase/networking/GlowcaseClientNetworking.java @@ -9,8 +9,8 @@ import net.minecraft.util.math.Vec2f; public class GlowcaseClientNetworking { - public static void editHyperlinkBlock(BlockPos pos, String url) { - ClientPlayNetworking.send(new GlowcaseCommonNetworking.EditHyperlinkBlock(pos, url)); + public static void editHyperlinkBlock(BlockPos pos, String title, String url) { + ClientPlayNetworking.send(new GlowcaseCommonNetworking.EditHyperlinkBlock(pos, title, url)); } //TODO: Pretty spicy, copied from the old code. Should maybe break this into more packets, or dispatch off the type of property I'm setting. diff --git a/src/main/java/dev/hephaestus/glowcase/networking/GlowcaseCommonNetworking.java b/src/main/java/dev/hephaestus/glowcase/networking/GlowcaseCommonNetworking.java index 8704148..4380a37 100644 --- a/src/main/java/dev/hephaestus/glowcase/networking/GlowcaseCommonNetworking.java +++ b/src/main/java/dev/hephaestus/glowcase/networking/GlowcaseCommonNetworking.java @@ -25,13 +25,14 @@ public class GlowcaseCommonNetworking { - public record EditHyperlinkBlock(BlockPos pos, String url) implements CustomPayload { + public record EditHyperlinkBlock(BlockPos pos, String title, String url) implements CustomPayload { public static final Id PACKET_ID = new Id<>(Glowcase.id("channel.hyperlink.save")); - public static final PacketCodec PACKET_CODEC = PacketCodec.tuple(BlockPos.PACKET_CODEC, EditHyperlinkBlock::pos, PacketCodecs.STRING, EditHyperlinkBlock::url, EditHyperlinkBlock::new); + public static final PacketCodec PACKET_CODEC = PacketCodec.tuple(BlockPos.PACKET_CODEC, EditHyperlinkBlock::pos, PacketCodecs.STRING, EditHyperlinkBlock::title, PacketCodecs.STRING, EditHyperlinkBlock::url, EditHyperlinkBlock::new); public static void receive(EditHyperlinkBlock payload, ServerPlayNetworking.Context context) { context.player().server.submit(() -> { - if(canEditGlowcase(context.player(), payload.pos(), Glowcase.HYPERLINK_BLOCK) && context.player().getServerWorld().getBlockEntity(payload.pos()) instanceof HyperlinkBlockEntity link && payload.url().length() <= URL_MAX_LENGTH) { + if(canEditGlowcase(context.player(), payload.pos(), Glowcase.HYPERLINK_BLOCK) && context.player().getServerWorld().getBlockEntity(payload.pos()) instanceof HyperlinkBlockEntity link && payload.url().length() <= URL_MAX_LENGTH && payload.title().length() <= TITLE_MAX_LENGTH) { + link.setTitle(payload.title()); link.setUrl(payload.url()); } }); @@ -136,6 +137,7 @@ public Id getId() { } } + private static final int TITLE_MAX_LENGTH = 1024; private static final int URL_MAX_LENGTH = 1024; public static void onInitialize() { diff --git a/src/main/resources/assets/glowcase/lang/en_us.json b/src/main/resources/assets/glowcase/lang/en_us.json index 49ff6fc..f3e1a86 100644 --- a/src/main/resources/assets/glowcase/lang/en_us.json +++ b/src/main/resources/assets/glowcase/lang/en_us.json @@ -19,5 +19,7 @@ "command.glowcase.failed.no_world": "Failed to send message; sender must be in a world", "glowcase.mailbox.sender": "From %s", "glowcase.mailbox.reminder1": "Right click to delete this message", - "glowcase.mailbox.reminder2": "Sneak+Right click to delete all messages from this sender" + "glowcase.mailbox.reminder2": "Sneak+Right click to delete all messages from this sender", + "gui.glowcase.title": "Title", + "gui.glowcase.url": "URL" } \ No newline at end of file From ec0b402ea8f66e4a8dc000b2e80ea093cbd83e63 Mon Sep 17 00:00:00 2001 From: Chai <7232280+Chailotl@users.noreply.github.com> Date: Sat, 13 Jul 2024 19:52:24 -0400 Subject: [PATCH 04/14] Closed #26 by using a different ItemActionResult --- .../java/dev/hephaestus/glowcase/block/HyperlinkBlock.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/hephaestus/glowcase/block/HyperlinkBlock.java b/src/main/java/dev/hephaestus/glowcase/block/HyperlinkBlock.java index 9b9adea..fd11e03 100644 --- a/src/main/java/dev/hephaestus/glowcase/block/HyperlinkBlock.java +++ b/src/main/java/dev/hephaestus/glowcase/block/HyperlinkBlock.java @@ -6,6 +6,8 @@ import net.minecraft.block.BlockState; import net.minecraft.block.ShapeContext; import net.minecraft.block.entity.BlockEntity; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.ConfirmLinkScreen; import net.minecraft.component.DataComponentTypes; import net.minecraft.component.type.NbtComponent; import net.minecraft.entity.LivingEntity; @@ -61,8 +63,9 @@ protected ActionResult onUse(BlockState state, World world, BlockPos pos, Player @Override protected ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { if (!(world.getBlockEntity(pos) instanceof HyperlinkBlockEntity be)) return ItemActionResult.CONSUME; - if (world.isClient && player.getStackInHand(hand).isIn(Glowcase.ITEM_TAG) && canEditGlowcase(player, pos)) { - Glowcase.proxy.openHyperlinkBlockEditScreen(pos); + if (player.getStackInHand(hand).isIn(Glowcase.ITEM_TAG) && canEditGlowcase(player, pos)) { + if (world.isClient) { Glowcase.proxy.openHyperlinkBlockEditScreen(pos); } + return ItemActionResult.SUCCESS; } return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; } From ad58963e04e704fea35e7858169a0f1f321aaa4d Mon Sep 17 00:00:00 2001 From: Chai <7232280+Chailotl@users.noreply.github.com> Date: Sat, 13 Jul 2024 20:17:29 -0400 Subject: [PATCH 05/14] Closed #27 by using lerped functions --- .../glowcase/block/entity/ItemDisplayBlockEntity.java | 6 +++--- .../render/block/entity/ItemDisplayBlockEntityRenderer.java | 2 +- .../glowcase/networking/GlowcaseClientNetworking.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/dev/hephaestus/glowcase/block/entity/ItemDisplayBlockEntity.java b/src/main/java/dev/hephaestus/glowcase/block/entity/ItemDisplayBlockEntity.java index 85e1587..0e6cc89 100644 --- a/src/main/java/dev/hephaestus/glowcase/block/entity/ItemDisplayBlockEntity.java +++ b/src/main/java/dev/hephaestus/glowcase/block/entity/ItemDisplayBlockEntity.java @@ -199,10 +199,10 @@ public void giveTo(PlayerEntity player, Hand hand) { } @Environment(EnvType.CLIENT) - public static Vec2f getPitchAndYaw(Entity camera, BlockPos pos) { - double d = pos.getX() - camera.getPos().x + 0.5; + public static Vec2f getPitchAndYaw(Entity camera, BlockPos pos, float delta) { + double d = pos.getX() - camera.getLerpedPos(delta).x + 0.5; double e = pos.getY() - camera.getEyeY() + 0.5; - double f = pos.getZ() - camera.getPos().z + 0.5; + double f = pos.getZ() - camera.getLerpedPos(delta).z + 0.5; double g = MathHelper.sqrt((float) (d * d + f * f)); float pitch = (float) ((-MathHelper.atan2(e, g))); diff --git a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/ItemDisplayBlockEntityRenderer.java b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/ItemDisplayBlockEntityRenderer.java index ac1dfb8..cfdf29e 100644 --- a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/ItemDisplayBlockEntityRenderer.java +++ b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/ItemDisplayBlockEntityRenderer.java @@ -39,7 +39,7 @@ public void render(ItemDisplayBlockEntity entity, float tickDelta, MatrixStack m switch (entity.rotationType) { case TRACKING -> { - Vec2f pitchAndYaw = ItemDisplayBlockEntity.getPitchAndYaw(camera, entity.getPos()); + Vec2f pitchAndYaw = ItemDisplayBlockEntity.getPitchAndYaw(camera, entity.getPos(), tickDelta); pitch = pitchAndYaw.x; yaw = pitchAndYaw.y; matrices.multiply(RotationAxis.POSITIVE_Y.rotation(yaw)); diff --git a/src/main/java/dev/hephaestus/glowcase/networking/GlowcaseClientNetworking.java b/src/main/java/dev/hephaestus/glowcase/networking/GlowcaseClientNetworking.java index 4bc2f45..bcaaa8f 100644 --- a/src/main/java/dev/hephaestus/glowcase/networking/GlowcaseClientNetworking.java +++ b/src/main/java/dev/hephaestus/glowcase/networking/GlowcaseClientNetworking.java @@ -16,7 +16,7 @@ public static void editHyperlinkBlock(BlockPos pos, String title, String url) { //TODO: Pretty spicy, copied from the old code. Should maybe break this into more packets, or dispatch off the type of property I'm setting. public static void editItemDisplayBlock(ItemDisplayBlockEntity be, boolean updatePitchAndYaw) { if (updatePitchAndYaw && MinecraftClient.getInstance().getCameraEntity() != null) { - Vec2f pitchAndYaw = ItemDisplayBlockEntity.getPitchAndYaw(MinecraftClient.getInstance().getCameraEntity(), be.getPos()); + Vec2f pitchAndYaw = ItemDisplayBlockEntity.getPitchAndYaw(MinecraftClient.getInstance().getCameraEntity(), be.getPos(), 0); be.pitch = pitchAndYaw.x; be.yaw = pitchAndYaw.y; } From dbdda4c52009390351605f438e5bf2a5395f00f8 Mon Sep 17 00:00:00 2001 From: Chai <7232280+Chailotl@users.noreply.github.com> Date: Sat, 13 Jul 2024 20:40:29 -0400 Subject: [PATCH 06/14] Closed #28 by adding a billboard tracking option --- .../glowcase/block/entity/ItemDisplayBlockEntity.java | 5 +++-- .../render/block/entity/ItemDisplayBlockEntityRenderer.java | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/hephaestus/glowcase/block/entity/ItemDisplayBlockEntity.java b/src/main/java/dev/hephaestus/glowcase/block/entity/ItemDisplayBlockEntity.java index 0e6cc89..eb58298 100644 --- a/src/main/java/dev/hephaestus/glowcase/block/entity/ItemDisplayBlockEntity.java +++ b/src/main/java/dev/hephaestus/glowcase/block/entity/ItemDisplayBlockEntity.java @@ -147,7 +147,8 @@ public ItemStack getDisplayedStack() { // -> yes, that means the setBlockState call is wacky public void cycleRotationType(PlayerEntity playerEntity) { switch (this.rotationType) { - case TRACKING -> { + case TRACKING -> this.rotationType = RotationType.BILLBOARD; + case BILLBOARD -> { this.rotationType = RotationType.HORIZONTAL; if (this.world != null) { this.world.setBlockState(this.pos, this.getCachedState().with(Properties.ROTATION, MathHelper.floor((double) ((playerEntity.getYaw()) * 16.0F / 360.0F) + 0.5D) & 15)); @@ -219,7 +220,7 @@ public static void tick(World world, BlockPos blockPos, BlockState state, ItemDi } public enum RotationType { - LOCKED, TRACKING, HORIZONTAL + LOCKED, TRACKING, HORIZONTAL, BILLBOARD } public enum GivesItem { diff --git a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/ItemDisplayBlockEntityRenderer.java b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/ItemDisplayBlockEntityRenderer.java index cfdf29e..3dd2a29 100644 --- a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/ItemDisplayBlockEntityRenderer.java +++ b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/ItemDisplayBlockEntityRenderer.java @@ -44,6 +44,11 @@ public void render(ItemDisplayBlockEntity entity, float tickDelta, MatrixStack m yaw = pitchAndYaw.y; matrices.multiply(RotationAxis.POSITIVE_Y.rotation(yaw)); } + case BILLBOARD -> { + pitch = (float) Math.toRadians(camera.getPitch()); + yaw = (float) Math.toRadians(-camera.getYaw()); + matrices.multiply(RotationAxis.POSITIVE_Y.rotation(yaw)); + } case HORIZONTAL -> { var rotation = -(entity.getCachedState().get(Properties.ROTATION) * 2 * Math.PI) / 16.0F; matrices.multiply(RotationAxis.POSITIVE_Y.rotation((float)rotation)); From 02278a2b465999607b09ab43a85d67eb4b5909a0 Mon Sep 17 00:00:00 2001 From: Chai <7232280+Chailotl@users.noreply.github.com> Date: Sun, 14 Jul 2024 21:17:54 -0400 Subject: [PATCH 07/14] Closed #30 and #31 --- .../glowcase/block/ItemDisplayBlock.java | 2 +- .../block/entity/ItemDisplayBlockEntity.java | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/dev/hephaestus/glowcase/block/ItemDisplayBlock.java b/src/main/java/dev/hephaestus/glowcase/block/ItemDisplayBlock.java index aab9be5..f73a3a6 100644 --- a/src/main/java/dev/hephaestus/glowcase/block/ItemDisplayBlock.java +++ b/src/main/java/dev/hephaestus/glowcase/block/ItemDisplayBlock.java @@ -55,7 +55,7 @@ protected ActionResult onUse(BlockState state, World world, BlockPos pos, Player if(!(world.getBlockEntity(pos) instanceof ItemDisplayBlockEntity be)) return ActionResult.CONSUME; if (be.canGiveTo(player)) { - if(!world.isClient) be.giveTo(player, player.getStackInHand(Hand.MAIN_HAND).isEmpty() ? Hand.MAIN_HAND : Hand.OFF_HAND); + if (!world.isClient) be.giveTo(player); return ActionResult.SUCCESS; } diff --git a/src/main/java/dev/hephaestus/glowcase/block/entity/ItemDisplayBlockEntity.java b/src/main/java/dev/hephaestus/glowcase/block/entity/ItemDisplayBlockEntity.java index eb58298..cd137c3 100644 --- a/src/main/java/dev/hephaestus/glowcase/block/entity/ItemDisplayBlockEntity.java +++ b/src/main/java/dev/hephaestus/glowcase/block/entity/ItemDisplayBlockEntity.java @@ -191,8 +191,18 @@ else return switch(this.givesItem) { }; } - public void giveTo(PlayerEntity player, Hand hand) { - player.setStackInHand(hand, getDisplayedStack().copy()); + public void giveTo(PlayerEntity player) { + ItemStack itemStack = player.getStackInHand(Hand.MAIN_HAND); + boolean holdingSameAsDisplay = ItemStack.areItemsEqual(getDisplayedStack(), itemStack); + + if (itemStack.isEmpty()) { + player.setStackInHand(Hand.MAIN_HAND, getDisplayedStack().copy()); + } else if (holdingSameAsDisplay) { + itemStack.increment(getDisplayedStack().getCount()); + itemStack.capCount(itemStack.getMaxCount()); + player.setStackInHand(Hand.MAIN_HAND, itemStack); + } + if (!player.isCreative()) { givenTo.add(player.getUuid()); markDirty(); From ca398235ac824e0bd83811eb99a151b717175f7c Mon Sep 17 00:00:00 2001 From: Chai <7232280+Chailotl@users.noreply.github.com> Date: Sun, 14 Jul 2024 21:23:25 -0400 Subject: [PATCH 08/14] Revert "Closed #30 and #31" This reverts commit 02278a2b465999607b09ab43a85d67eb4b5909a0. --- .../glowcase/block/ItemDisplayBlock.java | 2 +- .../block/entity/ItemDisplayBlockEntity.java | 14 ++------------ 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/main/java/dev/hephaestus/glowcase/block/ItemDisplayBlock.java b/src/main/java/dev/hephaestus/glowcase/block/ItemDisplayBlock.java index f73a3a6..aab9be5 100644 --- a/src/main/java/dev/hephaestus/glowcase/block/ItemDisplayBlock.java +++ b/src/main/java/dev/hephaestus/glowcase/block/ItemDisplayBlock.java @@ -55,7 +55,7 @@ protected ActionResult onUse(BlockState state, World world, BlockPos pos, Player if(!(world.getBlockEntity(pos) instanceof ItemDisplayBlockEntity be)) return ActionResult.CONSUME; if (be.canGiveTo(player)) { - if (!world.isClient) be.giveTo(player); + if(!world.isClient) be.giveTo(player, player.getStackInHand(Hand.MAIN_HAND).isEmpty() ? Hand.MAIN_HAND : Hand.OFF_HAND); return ActionResult.SUCCESS; } diff --git a/src/main/java/dev/hephaestus/glowcase/block/entity/ItemDisplayBlockEntity.java b/src/main/java/dev/hephaestus/glowcase/block/entity/ItemDisplayBlockEntity.java index cd137c3..eb58298 100644 --- a/src/main/java/dev/hephaestus/glowcase/block/entity/ItemDisplayBlockEntity.java +++ b/src/main/java/dev/hephaestus/glowcase/block/entity/ItemDisplayBlockEntity.java @@ -191,18 +191,8 @@ else return switch(this.givesItem) { }; } - public void giveTo(PlayerEntity player) { - ItemStack itemStack = player.getStackInHand(Hand.MAIN_HAND); - boolean holdingSameAsDisplay = ItemStack.areItemsEqual(getDisplayedStack(), itemStack); - - if (itemStack.isEmpty()) { - player.setStackInHand(Hand.MAIN_HAND, getDisplayedStack().copy()); - } else if (holdingSameAsDisplay) { - itemStack.increment(getDisplayedStack().getCount()); - itemStack.capCount(itemStack.getMaxCount()); - player.setStackInHand(Hand.MAIN_HAND, itemStack); - } - + public void giveTo(PlayerEntity player, Hand hand) { + player.setStackInHand(hand, getDisplayedStack().copy()); if (!player.isCreative()) { givenTo.add(player.getUuid()); markDirty(); From 14a854e17ec45bee57f96691c1941ae829fe2c3c Mon Sep 17 00:00:00 2001 From: Chai <7232280+Chailotl@users.noreply.github.com> Date: Sun, 14 Jul 2024 21:30:11 -0400 Subject: [PATCH 09/14] Reapply "Closed #30 and #31" This reverts commit ca398235ac824e0bd83811eb99a151b717175f7c. --- .../glowcase/block/ItemDisplayBlock.java | 2 +- .../block/entity/ItemDisplayBlockEntity.java | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/dev/hephaestus/glowcase/block/ItemDisplayBlock.java b/src/main/java/dev/hephaestus/glowcase/block/ItemDisplayBlock.java index aab9be5..f73a3a6 100644 --- a/src/main/java/dev/hephaestus/glowcase/block/ItemDisplayBlock.java +++ b/src/main/java/dev/hephaestus/glowcase/block/ItemDisplayBlock.java @@ -55,7 +55,7 @@ protected ActionResult onUse(BlockState state, World world, BlockPos pos, Player if(!(world.getBlockEntity(pos) instanceof ItemDisplayBlockEntity be)) return ActionResult.CONSUME; if (be.canGiveTo(player)) { - if(!world.isClient) be.giveTo(player, player.getStackInHand(Hand.MAIN_HAND).isEmpty() ? Hand.MAIN_HAND : Hand.OFF_HAND); + if (!world.isClient) be.giveTo(player); return ActionResult.SUCCESS; } diff --git a/src/main/java/dev/hephaestus/glowcase/block/entity/ItemDisplayBlockEntity.java b/src/main/java/dev/hephaestus/glowcase/block/entity/ItemDisplayBlockEntity.java index eb58298..cd137c3 100644 --- a/src/main/java/dev/hephaestus/glowcase/block/entity/ItemDisplayBlockEntity.java +++ b/src/main/java/dev/hephaestus/glowcase/block/entity/ItemDisplayBlockEntity.java @@ -191,8 +191,18 @@ else return switch(this.givesItem) { }; } - public void giveTo(PlayerEntity player, Hand hand) { - player.setStackInHand(hand, getDisplayedStack().copy()); + public void giveTo(PlayerEntity player) { + ItemStack itemStack = player.getStackInHand(Hand.MAIN_HAND); + boolean holdingSameAsDisplay = ItemStack.areItemsEqual(getDisplayedStack(), itemStack); + + if (itemStack.isEmpty()) { + player.setStackInHand(Hand.MAIN_HAND, getDisplayedStack().copy()); + } else if (holdingSameAsDisplay) { + itemStack.increment(getDisplayedStack().getCount()); + itemStack.capCount(itemStack.getMaxCount()); + player.setStackInHand(Hand.MAIN_HAND, itemStack); + } + if (!player.isCreative()) { givenTo.add(player.getUuid()); markDirty(); From a4aa8020f1c4f5d23057b48cda1554e373d84bf3 Mon Sep 17 00:00:00 2001 From: Chai <7232280+Chailotl@users.noreply.github.com> Date: Sun, 14 Jul 2024 22:16:00 -0400 Subject: [PATCH 10/14] Closed #33 --- .../screen/ingame/TextBlockEditScreen.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/TextBlockEditScreen.java b/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/TextBlockEditScreen.java index 2e077e0..c0fe6f2 100644 --- a/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/TextBlockEditScreen.java +++ b/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/TextBlockEditScreen.java @@ -225,7 +225,7 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { )); this.textBlockEntity.renderDirty = true; ++this.currentRow; - this.selectionManager.moveCursorToEnd(false); + this.selectionManager.moveCursorToStart(false); return true; } else if (keyCode == GLFW.GLFW_KEY_UP) { this.currentRow = Math.max(this.currentRow - 1, 0); @@ -245,7 +245,28 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { return true; } else { try { - return this.selectionManager.handleSpecialKey(keyCode) || super.keyPressed(keyCode, scanCode, modifiers); + boolean val = this.selectionManager.handleSpecialKey(keyCode) || super.keyPressed(keyCode, scanCode, modifiers); + int selectionOffset = this.textBlockEntity.getRawLine(this.currentRow).length() - this.selectionManager.getSelectionStart(); + + // Find line feed characters and create proper newlines + for (int i = 0; i < this.textBlockEntity.lines.size(); ++i) { + int lineFeedIndex = this.textBlockEntity.getRawLine(i).indexOf("\n"); + + if (lineFeedIndex >= 0) { + this.textBlockEntity.addRawLine(i + 1, + this.textBlockEntity.getRawLine(i).substring( + MathHelper.clamp(lineFeedIndex + 1, 0, this.textBlockEntity.getRawLine(i).length()) + )); + this.textBlockEntity.setRawLine(i, + this.textBlockEntity.getRawLine(i).substring(0, MathHelper.clamp(lineFeedIndex, 0, this.textBlockEntity.getRawLine(i).length()) + )); + this.textBlockEntity.renderDirty = true; + ++this.currentRow; + this.selectionManager.moveCursorToEnd(false); + this.selectionManager.moveCursor(-selectionOffset); + } + } + return val; } catch (StringIndexOutOfBoundsException e) { e.printStackTrace(); MinecraftClient.getInstance().setScreen(null); From 92ba0a6783717c24135712743c1854d2d536aaf7 Mon Sep 17 00:00:00 2001 From: Chai <7232280+Chailotl@users.noreply.github.com> Date: Mon, 15 Jul 2024 16:09:51 -0400 Subject: [PATCH 11/14] Changed item display block to also test for item components --- .../glowcase/block/entity/ItemDisplayBlockEntity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/dev/hephaestus/glowcase/block/entity/ItemDisplayBlockEntity.java b/src/main/java/dev/hephaestus/glowcase/block/entity/ItemDisplayBlockEntity.java index cd137c3..51e30a1 100644 --- a/src/main/java/dev/hephaestus/glowcase/block/entity/ItemDisplayBlockEntity.java +++ b/src/main/java/dev/hephaestus/glowcase/block/entity/ItemDisplayBlockEntity.java @@ -193,7 +193,7 @@ else return switch(this.givesItem) { public void giveTo(PlayerEntity player) { ItemStack itemStack = player.getStackInHand(Hand.MAIN_HAND); - boolean holdingSameAsDisplay = ItemStack.areItemsEqual(getDisplayedStack(), itemStack); + boolean holdingSameAsDisplay = ItemStack.areItemsAndComponentsEqual(getDisplayedStack(), itemStack); if (itemStack.isEmpty()) { player.setStackInHand(Hand.MAIN_HAND, getDisplayedStack().copy()); From c720a333aa4be6a96291945558dd0a4abcfcafe4 Mon Sep 17 00:00:00 2001 From: sisby-folk Date: Sun, 28 Jul 2024 11:41:55 +1000 Subject: [PATCH 12/14] oop, merge typo --- build.gradle | 4 +++- .../java/dev/hephaestus/glowcase/block/ItemDisplayBlock.java | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 9073f30..fddc1f5 100644 --- a/build.gradle +++ b/build.gradle @@ -63,7 +63,9 @@ java { } jar { - from "LICENSE" + from("LICENSE") { + rename { "${it}_${archivesBaseName}" } + } } publishing { diff --git a/src/main/java/dev/hephaestus/glowcase/block/ItemDisplayBlock.java b/src/main/java/dev/hephaestus/glowcase/block/ItemDisplayBlock.java index 733a1df..1d5974b 100644 --- a/src/main/java/dev/hephaestus/glowcase/block/ItemDisplayBlock.java +++ b/src/main/java/dev/hephaestus/glowcase/block/ItemDisplayBlock.java @@ -55,7 +55,7 @@ protected ActionResult onUse(BlockState state, World world, BlockPos pos, Player if(!(world.getBlockEntity(pos) instanceof ItemDisplayBlockEntity be)) return ActionResult.CONSUME; if (be.canGiveTo(player) && player.getStackInHand(Hand.MAIN_HAND).isEmpty()) { - if(!world.isClient) be.giveTo(player, Hand.MAIN_HAND); + if(!world.isClient) be.giveTo(player); return ActionResult.SUCCESS; } From c6f928def2af84c09f8800281a2ee3cc2647c46d Mon Sep 17 00:00:00 2001 From: sisby-folk Date: Sun, 28 Jul 2024 11:49:58 +1000 Subject: [PATCH 13/14] apply max lengths and move to entity --- .../java/dev/hephaestus/glowcase/block/HyperlinkBlock.java | 4 +--- .../glowcase/block/entity/HyperlinkBlockEntity.java | 2 ++ .../client/gui/screen/ingame/HyperlinkBlockEditScreen.java | 4 ++-- .../glowcase/networking/GlowcaseCommonNetworking.java | 5 +---- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/main/java/dev/hephaestus/glowcase/block/HyperlinkBlock.java b/src/main/java/dev/hephaestus/glowcase/block/HyperlinkBlock.java index fd11e03..f2e9e47 100644 --- a/src/main/java/dev/hephaestus/glowcase/block/HyperlinkBlock.java +++ b/src/main/java/dev/hephaestus/glowcase/block/HyperlinkBlock.java @@ -6,8 +6,6 @@ import net.minecraft.block.BlockState; import net.minecraft.block.ShapeContext; import net.minecraft.block.entity.BlockEntity; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.ConfirmLinkScreen; import net.minecraft.component.DataComponentTypes; import net.minecraft.component.type.NbtComponent; import net.minecraft.entity.LivingEntity; @@ -62,7 +60,7 @@ protected ActionResult onUse(BlockState state, World world, BlockPos pos, Player @Override protected ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { - if (!(world.getBlockEntity(pos) instanceof HyperlinkBlockEntity be)) return ItemActionResult.CONSUME; + if (!(world.getBlockEntity(pos) instanceof HyperlinkBlockEntity)) return ItemActionResult.CONSUME; if (player.getStackInHand(hand).isIn(Glowcase.ITEM_TAG) && canEditGlowcase(player, pos)) { if (world.isClient) { Glowcase.proxy.openHyperlinkBlockEditScreen(pos); } return ItemActionResult.SUCCESS; diff --git a/src/main/java/dev/hephaestus/glowcase/block/entity/HyperlinkBlockEntity.java b/src/main/java/dev/hephaestus/glowcase/block/entity/HyperlinkBlockEntity.java index c6368ac..8d99892 100644 --- a/src/main/java/dev/hephaestus/glowcase/block/entity/HyperlinkBlockEntity.java +++ b/src/main/java/dev/hephaestus/glowcase/block/entity/HyperlinkBlockEntity.java @@ -13,6 +13,8 @@ import org.jetbrains.annotations.Nullable; public class HyperlinkBlockEntity extends BlockEntity { + public static final int TITLE_MAX_LENGTH = 1024; + public static final int URL_MAX_LENGTH = 1024; private String title = ""; private String url = ""; diff --git a/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/HyperlinkBlockEditScreen.java b/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/HyperlinkBlockEditScreen.java index 76748d2..09d1c30 100644 --- a/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/HyperlinkBlockEditScreen.java +++ b/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/HyperlinkBlockEditScreen.java @@ -23,12 +23,12 @@ public void init() { if (this.client == null) return; this.titleEntryWidget = new TextFieldWidget(this.client.textRenderer, width / 10, height / 2 - 30, 8 * width / 10, 20, Text.empty()); - this.titleEntryWidget.setMaxLength(Integer.MAX_VALUE); + this.titleEntryWidget.setMaxLength(HyperlinkBlockEntity.TITLE_MAX_LENGTH); this.titleEntryWidget.setText(this.hyperlinkBlockEntity.getTitle()); this.titleEntryWidget.setPlaceholder(Text.translatable("gui.glowcase.title")); this.urlEntryWidget = new TextFieldWidget(this.client.textRenderer, width / 10, height / 2 + 10, 8 * width / 10, 20, Text.empty()); - this.urlEntryWidget.setMaxLength(Integer.MAX_VALUE); + this.urlEntryWidget.setMaxLength(HyperlinkBlockEntity.URL_MAX_LENGTH); this.urlEntryWidget.setText(this.hyperlinkBlockEntity.getUrl()); this.urlEntryWidget.setPlaceholder(Text.translatable("gui.glowcase.url")); diff --git a/src/main/java/dev/hephaestus/glowcase/networking/GlowcaseCommonNetworking.java b/src/main/java/dev/hephaestus/glowcase/networking/GlowcaseCommonNetworking.java index a741524..79c141e 100644 --- a/src/main/java/dev/hephaestus/glowcase/networking/GlowcaseCommonNetworking.java +++ b/src/main/java/dev/hephaestus/glowcase/networking/GlowcaseCommonNetworking.java @@ -31,7 +31,7 @@ public record EditHyperlinkBlock(BlockPos pos, String title, String url) impleme public static void receive(EditHyperlinkBlock payload, ServerPlayNetworking.Context context) { context.player().server.submit(() -> { - if(canEditGlowcase(context.player(), payload.pos(), Glowcase.HYPERLINK_BLOCK.get()) && context.player().getServerWorld().getBlockEntity(payload.pos()) instanceof HyperlinkBlockEntity link && payload.url().length() <= URL_MAX_LENGTH && payload.title().length() <= TITLE_MAX_LENGTH) { + if(canEditGlowcase(context.player(), payload.pos(), Glowcase.HYPERLINK_BLOCK.get()) && context.player().getServerWorld().getBlockEntity(payload.pos()) instanceof HyperlinkBlockEntity link && payload.url().length() <= HyperlinkBlockEntity.URL_MAX_LENGTH && payload.title().length() <= HyperlinkBlockEntity.TITLE_MAX_LENGTH) { link.setTitle(payload.title()); link.setUrl(payload.url()); } @@ -137,9 +137,6 @@ public Id getId() { } } - private static final int TITLE_MAX_LENGTH = 1024; - private static final int URL_MAX_LENGTH = 1024; - public static void onInitialize() { PayloadTypeRegistry.playC2S().register(EditHyperlinkBlock.PACKET_ID, EditHyperlinkBlock.PACKET_CODEC); PayloadTypeRegistry.playC2S().register(EditItemDisplayBlockSettings.PACKET_ID, EditItemDisplayBlockSettings.PACKET_CODEC); From 019680d43de9e4bb1a11780273a474ba560d7a9b Mon Sep 17 00:00:00 2001 From: Chai <7232280+Chailotl@users.noreply.github.com> Date: Sat, 27 Jul 2024 22:12:49 -0400 Subject: [PATCH 14/14] Removed empty hand check --- .../java/dev/hephaestus/glowcase/block/ItemDisplayBlock.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/hephaestus/glowcase/block/ItemDisplayBlock.java b/src/main/java/dev/hephaestus/glowcase/block/ItemDisplayBlock.java index 1d5974b..e0e3dbe 100644 --- a/src/main/java/dev/hephaestus/glowcase/block/ItemDisplayBlock.java +++ b/src/main/java/dev/hephaestus/glowcase/block/ItemDisplayBlock.java @@ -54,7 +54,7 @@ public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos po protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) { if(!(world.getBlockEntity(pos) instanceof ItemDisplayBlockEntity be)) return ActionResult.CONSUME; - if (be.canGiveTo(player) && player.getStackInHand(Hand.MAIN_HAND).isEmpty()) { + if (be.canGiveTo(player)) { if(!world.isClient) be.giveTo(player); return ActionResult.SUCCESS; } @@ -96,4 +96,4 @@ public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { public BlockEntityTicker getTicker(World world, BlockState state, BlockEntityType type) { return checkType(type, Glowcase.ITEM_DISPLAY_BLOCK_ENTITY.get(), ItemDisplayBlockEntity::tick); } -} \ No newline at end of file +}