Skip to content

Commit

Permalink
Merge pull request #39 from Chailotl/1.21
Browse files Browse the repository at this point in the history
Fixes and tweaks
  • Loading branch information
sisby-folk authored Aug 30, 2024
2 parents bc9f387 + 57eaec4 commit 07e213b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 4 deletions.
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"
}

0 comments on commit 07e213b

Please sign in to comment.