diff --git a/src/main/java/dev/hephaestus/glowcase/block/HyperlinkBlock.java b/src/main/java/dev/hephaestus/glowcase/block/HyperlinkBlock.java index 8179f2f..6d6f32a 100644 --- a/src/main/java/dev/hephaestus/glowcase/block/HyperlinkBlock.java +++ b/src/main/java/dev/hephaestus/glowcase/block/HyperlinkBlock.java @@ -10,8 +10,12 @@ import net.minecraft.component.type.NbtComponent; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.item.tooltip.TooltipType; +import net.minecraft.text.Text; import net.minecraft.util.ActionResult; +import net.minecraft.util.Formatting; import net.minecraft.util.Hand; import net.minecraft.util.ItemActionResult; import net.minecraft.util.hit.BlockHitResult; @@ -22,6 +26,8 @@ import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; +import java.util.List; + public class HyperlinkBlock extends GlowcaseBlock implements BlockEntityProvider { private static final VoxelShape OUTLINE = VoxelShapes.cuboid(0.25, 0.25, 0.25, 0.75, 0.75, 0.75); @@ -69,4 +75,10 @@ protected ItemActionResult onUseWithItem(ItemStack stack, BlockState state, Worl } return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; } -} \ No newline at end of file + + @Override + public void appendTooltip(ItemStack itemStack, Item.TooltipContext context, List tooltip, TooltipType options) { + tooltip.add(Text.translatable("block.glowcase.hyperlink_block.tooltip.0").formatted(Formatting.GRAY)); + tooltip.add(Text.translatable("block.glowcase.generic.tooltip").formatted(Formatting.DARK_GRAY)); + } +} diff --git a/src/main/java/dev/hephaestus/glowcase/block/ItemDisplayBlock.java b/src/main/java/dev/hephaestus/glowcase/block/ItemDisplayBlock.java index c489d33..404a406 100644 --- a/src/main/java/dev/hephaestus/glowcase/block/ItemDisplayBlock.java +++ b/src/main/java/dev/hephaestus/glowcase/block/ItemDisplayBlock.java @@ -10,11 +10,15 @@ import net.minecraft.block.entity.BlockEntityTicker; import net.minecraft.block.entity.BlockEntityType; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.Item; import net.minecraft.item.ItemPlacementContext; import net.minecraft.item.ItemStack; +import net.minecraft.item.tooltip.TooltipType; import net.minecraft.state.StateManager; import net.minecraft.state.property.Properties; +import net.minecraft.text.Text; import net.minecraft.util.ActionResult; +import net.minecraft.util.Formatting; import net.minecraft.util.Hand; import net.minecraft.util.ItemActionResult; import net.minecraft.util.hit.BlockHitResult; @@ -26,6 +30,8 @@ import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; +import java.util.List; + public class ItemDisplayBlock extends GlowcaseBlock implements BlockEntityProvider { private static final VoxelShape OUTLINE = VoxelShapes.cuboid(0.25, 0.25, 0.25, 0.75, 0.75, 0.75); @@ -96,4 +102,11 @@ 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); } + + @Override + public void appendTooltip(ItemStack itemStack, Item.TooltipContext context, List tooltip, TooltipType options) { + tooltip.add(Text.translatable("block.glowcase.item_display_block.tooltip.0").formatted(Formatting.GRAY)); + tooltip.add(Text.translatable("block.glowcase.item_display_block.tooltip.1").formatted(Formatting.DARK_GRAY)); + tooltip.add(Text.translatable("block.glowcase.item_display_block.tooltip.2").formatted(Formatting.DARK_GRAY)); + } } diff --git a/src/main/java/dev/hephaestus/glowcase/block/TextBlock.java b/src/main/java/dev/hephaestus/glowcase/block/TextBlock.java index b085f04..90f5bd8 100644 --- a/src/main/java/dev/hephaestus/glowcase/block/TextBlock.java +++ b/src/main/java/dev/hephaestus/glowcase/block/TextBlock.java @@ -10,10 +10,14 @@ import net.minecraft.component.type.NbtComponent; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.Item; import net.minecraft.item.ItemPlacementContext; import net.minecraft.item.ItemStack; +import net.minecraft.item.tooltip.TooltipType; import net.minecraft.state.StateManager; import net.minecraft.state.property.Properties; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; import net.minecraft.util.Hand; import net.minecraft.util.ItemActionResult; import net.minecraft.util.hit.BlockHitResult; @@ -22,6 +26,8 @@ import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; +import java.util.List; + public class TextBlock extends GlowcaseBlock implements BlockEntityProvider { public TextBlock() { super(); @@ -68,4 +74,11 @@ protected ItemActionResult onUseWithItem(ItemStack stack, BlockState state, Worl return ItemActionResult.SUCCESS; } + + @Override + public void appendTooltip(ItemStack itemStack, Item.TooltipContext context, List tooltip, TooltipType options) { + tooltip.add(Text.translatable("block.glowcase.text_block.tooltip.0").formatted(Formatting.GRAY)); + tooltip.add(Text.translatable("block.glowcase.generic.tooltip").formatted(Formatting.DARK_GRAY)); + tooltip.add(Text.translatable("block.glowcase.text_block.tooltip.1").formatted(Formatting.DARK_GRAY)); + } } diff --git a/src/main/java/dev/hephaestus/glowcase/packet/C2SEditHyperlinkBlock.java b/src/main/java/dev/hephaestus/glowcase/packet/C2SEditHyperlinkBlock.java index 22b9cfb..e7856bf 100644 --- a/src/main/java/dev/hephaestus/glowcase/packet/C2SEditHyperlinkBlock.java +++ b/src/main/java/dev/hephaestus/glowcase/packet/C2SEditHyperlinkBlock.java @@ -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 ID = new Id<>(Glowcase.id("channel.hyperlink.save")); public static final PacketCodec 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 @@ -30,6 +31,9 @@ public Id 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()); } diff --git a/src/main/resources/assets/glowcase/lang/en_us.json b/src/main/resources/assets/glowcase/lang/en_us.json index a32d0e3..8f81d17 100644 --- a/src/main/resources/assets/glowcase/lang/en_us.json +++ b/src/main/resources/assets/glowcase/lang/en_us.json @@ -14,5 +14,12 @@ "item.glowcase.text_block": "Text Block", "item.glowcase.hyperlink_block": "Hyperlink Block", "gui.glowcase.title": "Title", - "gui.glowcase.url": "URL" + "gui.glowcase.url": "URL", + "block.glowcase.generic.tooltip": "Interact with a glowcase item to edit", + "block.glowcase.text_block.tooltip.0": "Displays formatted text", + "block.glowcase.text_block.tooltip.1": "Supports Placeholder QuickText", + "block.glowcase.hyperlink_block.tooltip.0": "Opens a URL when interacted", + "block.glowcase.item_display_block.tooltip.0": "Gives an item stack when interacted", + "block.glowcase.item_display_block.tooltip.1": "Interact with an item stack to set it", + "block.glowcase.item_display_block.tooltip.2": "Interact with the same item to edit" }