Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes and tweaks #39

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/main/java/dev/hephaestus/glowcase/block/HyperlinkBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -69,4 +75,10 @@ protected ItemActionResult onUseWithItem(ItemStack stack, BlockState state, Worl
}
return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
}
}

@Override
public void appendTooltip(ItemStack itemStack, Item.TooltipContext context, List<Text> 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));
}
}
13 changes: 13 additions & 0 deletions src/main/java/dev/hephaestus/glowcase/block/ItemDisplayBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -96,4 +102,11 @@ public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) {
return checkType(type, Glowcase.ITEM_DISPLAY_BLOCK_ENTITY.get(), ItemDisplayBlockEntity::tick);
}

@Override
public void appendTooltip(ItemStack itemStack, Item.TooltipContext context, List<Text> 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));
}
}
13 changes: 13 additions & 0 deletions src/main/java/dev/hephaestus/glowcase/block/TextBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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<Text> 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));
}
}
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
9 changes: 8 additions & 1 deletion src/main/resources/assets/glowcase/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}