From 295ea9efe0756b14e411e06ebab7478440a61250 Mon Sep 17 00:00:00 2001 From: Chai <7232280+Chailotl@users.noreply.github.com> Date: Thu, 29 Aug 2024 21:19:22 -0400 Subject: [PATCH 1/8] Added the sprite block --- .../dev/hephaestus/glowcase/Glowcase.java | 13 +-- .../glowcase/GlowcaseCommonProxy.java | 4 + .../glowcase/GlowcaseNetworking.java | 3 + .../glowcase/block/SpriteBlock.java | 84 ++++++++++++++++++ .../block/entity/SpriteBlockEntity.java | 74 +++++++++++++++ .../glowcase/client/GlowcaseClient.java | 2 + .../glowcase/client/GlowcaseClientProxy.java | 10 +++ .../screen/ingame/SpriteBlockEditScreen.java | 67 ++++++++++++++ .../entity/SpriteBlockEntityRenderer.java | 56 ++++++++++++ .../glowcase/packet/C2SEditSpriteBlock.java | 44 +++++++++ .../glowcase/blockstates/sprite_block.json | 7 ++ .../resources/assets/glowcase/lang/en_us.json | 6 +- .../glowcase/models/item/sprite_block.json | 6 ++ .../glowcase/textures/item/sprite_block.png | Bin 0 -> 215 bytes .../assets/glowcase/textures/sprite/arrow.png | Bin 0 -> 217 bytes .../glowcase/textures/sprite/double_arrow.png | Bin 0 -> 229 bytes .../textures/sprite/double_line_arrow.png | Bin 0 -> 202 bytes .../glowcase/textures/sprite/fancy_arrow.png | Bin 0 -> 247 bytes .../glowcase/textures/sprite/real_arrow.png | Bin 0 -> 195 bytes .../glowcase/textures/sprite/small_arrow.png | Bin 0 -> 196 bytes .../glowcase/textures/sprite/triple_arrow.png | Bin 0 -> 206 bytes .../textures/sprite/triple_line_arrow.png | Bin 0 -> 186 bytes .../glowcase/textures/sprite/wide_arrow.png | Bin 0 -> 191 bytes .../data/glowcase/tags/item/items.json | 3 +- 24 files changed, 372 insertions(+), 7 deletions(-) create mode 100644 src/main/java/dev/hephaestus/glowcase/block/SpriteBlock.java create mode 100644 src/main/java/dev/hephaestus/glowcase/block/entity/SpriteBlockEntity.java create mode 100644 src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/SpriteBlockEditScreen.java create mode 100644 src/main/java/dev/hephaestus/glowcase/client/render/block/entity/SpriteBlockEntityRenderer.java create mode 100644 src/main/java/dev/hephaestus/glowcase/packet/C2SEditSpriteBlock.java create mode 100644 src/main/resources/assets/glowcase/blockstates/sprite_block.json create mode 100644 src/main/resources/assets/glowcase/models/item/sprite_block.json create mode 100644 src/main/resources/assets/glowcase/textures/item/sprite_block.png create mode 100644 src/main/resources/assets/glowcase/textures/sprite/arrow.png create mode 100644 src/main/resources/assets/glowcase/textures/sprite/double_arrow.png create mode 100644 src/main/resources/assets/glowcase/textures/sprite/double_line_arrow.png create mode 100644 src/main/resources/assets/glowcase/textures/sprite/fancy_arrow.png create mode 100644 src/main/resources/assets/glowcase/textures/sprite/real_arrow.png create mode 100644 src/main/resources/assets/glowcase/textures/sprite/small_arrow.png create mode 100644 src/main/resources/assets/glowcase/textures/sprite/triple_arrow.png create mode 100644 src/main/resources/assets/glowcase/textures/sprite/triple_line_arrow.png create mode 100644 src/main/resources/assets/glowcase/textures/sprite/wide_arrow.png diff --git a/src/main/java/dev/hephaestus/glowcase/Glowcase.java b/src/main/java/dev/hephaestus/glowcase/Glowcase.java index 84476b4..ce24197 100644 --- a/src/main/java/dev/hephaestus/glowcase/Glowcase.java +++ b/src/main/java/dev/hephaestus/glowcase/Glowcase.java @@ -4,9 +4,11 @@ import com.google.common.base.Suppliers; import dev.hephaestus.glowcase.block.HyperlinkBlock; import dev.hephaestus.glowcase.block.ItemDisplayBlock; +import dev.hephaestus.glowcase.block.SpriteBlock; import dev.hephaestus.glowcase.block.TextBlock; import dev.hephaestus.glowcase.block.entity.HyperlinkBlockEntity; import dev.hephaestus.glowcase.block.entity.ItemDisplayBlockEntity; +import dev.hephaestus.glowcase.block.entity.SpriteBlockEntity; import dev.hephaestus.glowcase.block.entity.TextBlockEntity; import dev.hephaestus.glowcase.compat.PolydexCompatibility; import net.fabricmc.api.ModInitializer; @@ -15,11 +17,7 @@ import net.minecraft.block.Block; import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntityType; -import net.minecraft.item.BlockItem; -import net.minecraft.item.Item; -import net.minecraft.item.ItemGroup; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; +import net.minecraft.item.*; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; import net.minecraft.registry.RegistryKeys; @@ -46,6 +44,10 @@ public class Glowcase implements ModInitializer { public static final Supplier TEXT_BLOCK_ITEM = registerItem("text_block", () -> new BlockItem(TEXT_BLOCK.get(), new Item.Settings())); public static final Supplier> TEXT_BLOCK_ENTITY = registerBlockEntity("text_block", () -> BlockEntityType.Builder.create(TextBlockEntity::new, TEXT_BLOCK.get()).build(null)); + public static final Supplier SPRITE_BLOCK = registerBlock("sprite_block", SpriteBlock::new); + public static final Supplier SPRITE_BLOCK_ITEM = registerItem("sprite_block", () -> new BlockItem(SPRITE_BLOCK.get(), new Item.Settings())); + public static final Supplier> SPRITE_BLOCK_ENTITY = registerBlockEntity("sprite_block", () -> BlockEntityType.Builder.create(SpriteBlockEntity::new, SPRITE_BLOCK.get()).build(null)); + public static final Supplier ITEM_GROUP = registerItemGroup("items", () -> FabricItemGroup.builder() .displayName(Text.translatable("itemGroup.glowcase.items")) .icon(() -> new ItemStack(Items.GLOWSTONE)) @@ -53,6 +55,7 @@ public class Glowcase implements ModInitializer { entries.add(HYPERLINK_BLOCK_ITEM.get()); entries.add(ITEM_DISPLAY_BLOCK_ITEM.get()); entries.add(TEXT_BLOCK_ITEM.get()); + entries.add(SPRITE_BLOCK_ITEM.get()); }) .build() ); diff --git a/src/main/java/dev/hephaestus/glowcase/GlowcaseCommonProxy.java b/src/main/java/dev/hephaestus/glowcase/GlowcaseCommonProxy.java index 65ee6c0..409d528 100644 --- a/src/main/java/dev/hephaestus/glowcase/GlowcaseCommonProxy.java +++ b/src/main/java/dev/hephaestus/glowcase/GlowcaseCommonProxy.java @@ -18,4 +18,8 @@ public void openItemDisplayBlockEditScreen(BlockPos pos) { public void openTextBlockEditScreen(BlockPos pos) { //No-op } + + public void openSpriteBlockEditScreen(BlockPos pos) { + //No-op + } } diff --git a/src/main/java/dev/hephaestus/glowcase/GlowcaseNetworking.java b/src/main/java/dev/hephaestus/glowcase/GlowcaseNetworking.java index 8b932a4..d385630 100644 --- a/src/main/java/dev/hephaestus/glowcase/GlowcaseNetworking.java +++ b/src/main/java/dev/hephaestus/glowcase/GlowcaseNetworking.java @@ -2,6 +2,7 @@ import dev.hephaestus.glowcase.packet.C2SEditHyperlinkBlock; import dev.hephaestus.glowcase.packet.C2SEditItemDisplayBlock; +import dev.hephaestus.glowcase.packet.C2SEditSpriteBlock; import dev.hephaestus.glowcase.packet.C2SEditTextBlock; import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; @@ -11,9 +12,11 @@ public static void init() { PayloadTypeRegistry.playC2S().register(C2SEditHyperlinkBlock.ID, C2SEditHyperlinkBlock.PACKET_CODEC); PayloadTypeRegistry.playC2S().register(C2SEditItemDisplayBlock.ID, C2SEditItemDisplayBlock.PACKET_CODEC); PayloadTypeRegistry.playC2S().register(C2SEditTextBlock.ID, C2SEditTextBlock.PACKET_CODEC); + PayloadTypeRegistry.playC2S().register(C2SEditSpriteBlock.ID, C2SEditSpriteBlock.PACKET_CODEC); ServerPlayNetworking.registerGlobalReceiver(C2SEditHyperlinkBlock.ID, C2SEditHyperlinkBlock::receive); ServerPlayNetworking.registerGlobalReceiver(C2SEditItemDisplayBlock.ID, C2SEditItemDisplayBlock::receive); ServerPlayNetworking.registerGlobalReceiver(C2SEditTextBlock.ID, C2SEditTextBlock::receive); + ServerPlayNetworking.registerGlobalReceiver(C2SEditSpriteBlock.ID, C2SEditSpriteBlock::receive); } } diff --git a/src/main/java/dev/hephaestus/glowcase/block/SpriteBlock.java b/src/main/java/dev/hephaestus/glowcase/block/SpriteBlock.java new file mode 100644 index 0000000..5a80591 --- /dev/null +++ b/src/main/java/dev/hephaestus/glowcase/block/SpriteBlock.java @@ -0,0 +1,84 @@ +package dev.hephaestus.glowcase.block; + +import dev.hephaestus.glowcase.Glowcase; +import dev.hephaestus.glowcase.block.entity.SpriteBlockEntity; +import net.minecraft.block.Block; +import net.minecraft.block.BlockEntityProvider; +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.component.DataComponentTypes; +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; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.world.World; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class SpriteBlock extends GlowcaseBlock implements BlockEntityProvider { + public SpriteBlock() { + super(); + this.setDefaultState(this.getDefaultState().with(Properties.ROTATION, 0)); + } + + @Override + protected void appendProperties(StateManager.Builder builder) { + super.appendProperties(builder); + builder.add(Properties.ROTATION); + } + + @Override + public BlockState getPlacementState(ItemPlacementContext ctx) { + return this.getDefaultState().with(Properties.ROTATION, MathHelper.floor((double) ((180.0F + ctx.getPlayerYaw()) * 16.0F / 360.0F) + 0.5D) & 15); + } + + @Nullable + @Override + public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { + return new SpriteBlockEntity(pos, state); + } + + @Override + public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) { + if (world.isClient && placer instanceof PlayerEntity player && canEditGlowcase(player, pos)) { + //load any ctrl-picked NBT clientside + NbtComponent blockEntityTag = stack.get(DataComponentTypes.BLOCK_ENTITY_DATA); + if (blockEntityTag != null && world.getBlockEntity(pos) instanceof SpriteBlockEntity be) { + blockEntityTag.applyToBlockEntity(be, world.getRegistryManager()); + } + + Glowcase.proxy.openSpriteBlockEditScreen(pos); + } + } + + @Override + protected ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { + if (!(world.getBlockEntity(pos) instanceof SpriteBlockEntity be)) return ItemActionResult.CONSUME; + + if (world.isClient && player.getStackInHand(hand).isIn(Glowcase.ITEM_TAG) && canEditGlowcase(player, pos)) { + Glowcase.proxy.openSpriteBlockEditScreen(pos); + } + + return ItemActionResult.SUCCESS; + } + + @Override + public void appendTooltip(ItemStack itemStack, Item.TooltipContext context, List tooltip, TooltipType options) { + tooltip.add(Text.translatable("block.glowcase.sprite_block.tooltip.0").formatted(Formatting.GRAY)); + tooltip.add(Text.translatable("block.glowcase.generic.tooltip").formatted(Formatting.DARK_GRAY)); + tooltip.add(Text.translatable("block.glowcase.sprite_block.tooltip.1").formatted(Formatting.DARK_GRAY)); + } +} diff --git a/src/main/java/dev/hephaestus/glowcase/block/entity/SpriteBlockEntity.java b/src/main/java/dev/hephaestus/glowcase/block/entity/SpriteBlockEntity.java new file mode 100644 index 0000000..fba7ba8 --- /dev/null +++ b/src/main/java/dev/hephaestus/glowcase/block/entity/SpriteBlockEntity.java @@ -0,0 +1,74 @@ +package dev.hephaestus.glowcase.block.entity; + +import dev.hephaestus.glowcase.Glowcase; +import dev.hephaestus.glowcase.client.render.block.entity.BakedBlockEntityRenderer; +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.network.listener.ClientPlayPacketListener; +import net.minecraft.network.packet.Packet; +import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket; +import net.minecraft.registry.RegistryWrapper; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; +import org.jetbrains.annotations.Nullable; + +public class SpriteBlockEntity extends BlockEntity { + public TextBlockEntity.ZOffset zOffset = TextBlockEntity.ZOffset.CENTER; + public int rotation = 0; + public String sprite = "arrow"; + + public SpriteBlockEntity(BlockPos pos, BlockState state) { + super(Glowcase.SPRITE_BLOCK_ENTITY.get(), pos, state); + } + + public void setSprite(String newSprite) { + sprite = newSprite; + markDirty(); + dispatch(); + } + + @Override + public void writeNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) { + super.writeNbt(tag, registryLookup); + + tag.putString("z_offset", this.zOffset.name()); + tag.putInt("rotation", this.rotation); + tag.putString("sprite", this.sprite); + } + + @Override + public void readNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) { + super.readNbt(tag, registryLookup); + + this.zOffset = TextBlockEntity.ZOffset.valueOf(tag.getString("z_offset")); + this.rotation = tag.getInt("rotation"); + this.sprite = tag.getString("sprite"); + } + + @SuppressWarnings({"MethodCallSideOnly", "VariableUseSideOnly"}) + @Override + public void markRemoved() { + if (world != null && world.isClient) { + BakedBlockEntityRenderer.Manager.markForRebuild(getPos()); + } + super.markRemoved(); + } + + // standard blockentity boilerplate + + public void dispatch() { + if (world instanceof ServerWorld sworld) sworld.getChunkManager().markForUpdate(pos); + } + + @Override + public NbtCompound toInitialChunkDataNbt(RegistryWrapper.WrapperLookup registryLookup) { + return createNbt(registryLookup); + } + + @Nullable + @Override + public Packet toUpdatePacket() { + return BlockEntityUpdateS2CPacket.create(this); + } +} diff --git a/src/main/java/dev/hephaestus/glowcase/client/GlowcaseClient.java b/src/main/java/dev/hephaestus/glowcase/client/GlowcaseClient.java index 02b4a8e..c70a52e 100644 --- a/src/main/java/dev/hephaestus/glowcase/client/GlowcaseClient.java +++ b/src/main/java/dev/hephaestus/glowcase/client/GlowcaseClient.java @@ -5,6 +5,7 @@ import dev.hephaestus.glowcase.client.render.block.entity.HyperlinkBlockEntityRenderer; import dev.hephaestus.glowcase.client.render.block.entity.ItemDisplayBlockEntityRenderer; import dev.hephaestus.glowcase.client.render.block.entity.TextBlockEntityRenderer; +import dev.hephaestus.glowcase.client.render.block.entity.SpriteBlockEntityRenderer; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.client.rendering.v1.InvalidateRenderStateCallback; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; @@ -18,6 +19,7 @@ public void onInitializeClient() { BlockEntityRendererFactories.register(Glowcase.TEXT_BLOCK_ENTITY.get(), TextBlockEntityRenderer::new); BlockEntityRendererFactories.register(Glowcase.HYPERLINK_BLOCK_ENTITY.get(), HyperlinkBlockEntityRenderer::new); BlockEntityRendererFactories.register(Glowcase.ITEM_DISPLAY_BLOCK_ENTITY.get(), ItemDisplayBlockEntityRenderer::new); + BlockEntityRendererFactories.register(Glowcase.SPRITE_BLOCK_ENTITY.get(), SpriteBlockEntityRenderer::new); WorldRenderEvents.AFTER_TRANSLUCENT.register(BakedBlockEntityRenderer.Manager::render); InvalidateRenderStateCallback.EVENT.register(BakedBlockEntityRenderer.Manager::reset); diff --git a/src/main/java/dev/hephaestus/glowcase/client/GlowcaseClientProxy.java b/src/main/java/dev/hephaestus/glowcase/client/GlowcaseClientProxy.java index 2cf548d..765d84b 100644 --- a/src/main/java/dev/hephaestus/glowcase/client/GlowcaseClientProxy.java +++ b/src/main/java/dev/hephaestus/glowcase/client/GlowcaseClientProxy.java @@ -3,9 +3,11 @@ import dev.hephaestus.glowcase.GlowcaseCommonProxy; import dev.hephaestus.glowcase.block.entity.HyperlinkBlockEntity; import dev.hephaestus.glowcase.block.entity.ItemDisplayBlockEntity; +import dev.hephaestus.glowcase.block.entity.SpriteBlockEntity; import dev.hephaestus.glowcase.block.entity.TextBlockEntity; import dev.hephaestus.glowcase.client.gui.screen.ingame.HyperlinkBlockEditScreen; import dev.hephaestus.glowcase.client.gui.screen.ingame.ItemDisplayBlockEditScreen; +import dev.hephaestus.glowcase.client.gui.screen.ingame.SpriteBlockEditScreen; import dev.hephaestus.glowcase.client.gui.screen.ingame.TextBlockEditScreen; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.ConfirmLinkScreen; @@ -40,4 +42,12 @@ public void openTextBlockEditScreen(BlockPos pos) { MinecraftClient.getInstance().setScreen(new TextBlockEditScreen(be)); } } + + @Override + public void openSpriteBlockEditScreen(BlockPos pos) { + MinecraftClient client = MinecraftClient.getInstance(); + if (client.world != null && client.world.getBlockEntity(pos) instanceof SpriteBlockEntity be) { + MinecraftClient.getInstance().setScreen(new SpriteBlockEditScreen(be)); + } + } } diff --git a/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/SpriteBlockEditScreen.java b/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/SpriteBlockEditScreen.java new file mode 100644 index 0000000..a8cf66b --- /dev/null +++ b/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/SpriteBlockEditScreen.java @@ -0,0 +1,67 @@ +package dev.hephaestus.glowcase.client.gui.screen.ingame; + +import dev.hephaestus.glowcase.block.entity.SpriteBlockEntity; +import dev.hephaestus.glowcase.block.entity.TextBlockEntity; +import dev.hephaestus.glowcase.packet.C2SEditSpriteBlock; +import net.minecraft.client.gui.widget.ButtonWidget; +import net.minecraft.client.gui.widget.TextFieldWidget; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; + +public class SpriteBlockEditScreen extends GlowcaseScreen { + private final SpriteBlockEntity spriteBlockEntity; + + private ButtonWidget zOffsetToggle; + private ButtonWidget rotationWidget; + private TextFieldWidget spriteWidget; + + public SpriteBlockEditScreen(SpriteBlockEntity spriteBlockEntity) { + this.spriteBlockEntity = spriteBlockEntity; + } + + @Override + public void init() { + super.init(); + + if (this.client == null) return; + + this.zOffsetToggle = ButtonWidget.builder(Text.literal(this.spriteBlockEntity.zOffset.name()), action -> { + switch (spriteBlockEntity.zOffset) { + case FRONT -> spriteBlockEntity.zOffset = TextBlockEntity.ZOffset.CENTER; + case CENTER -> spriteBlockEntity.zOffset = TextBlockEntity.ZOffset.BACK; + case BACK -> spriteBlockEntity.zOffset = TextBlockEntity.ZOffset.FRONT; + } + + this.zOffsetToggle.setMessage(Text.literal(this.spriteBlockEntity.zOffset.name())); + //GlowcaseClientNetworking.editArrowBlock(spriteBlockEntity); + }).dimensions(width / 2 - 75, height / 2 - 40, 150, 20).build(); + + this.rotationWidget = ButtonWidget.builder(Text.literal("Rotate"), (action) -> { + this.spriteBlockEntity.rotation += 45; + if (this.spriteBlockEntity.rotation >= 360) { + this.spriteBlockEntity.rotation = 0; + } + //GlowcaseClientNetworking.editArrowBlock(spriteBlockEntity); + }).dimensions(width / 2 - 75, height / 2 - 10, 150, 20).build(); + + this.spriteWidget = new TextFieldWidget(this.client.textRenderer, width / 2 - 75, height / 2 + 20, 150, 20, Text.empty()); + this.spriteWidget.setText(spriteBlockEntity.sprite); + this.spriteWidget.setChangedListener(string -> { + if (Identifier.isPathValid(this.spriteWidget.getText())) { + this.spriteBlockEntity.sprite = this.spriteWidget.getText(); + //this.spriteBlockEntity.renderDirty = true; + } + }); + + this.addDrawableChild(this.zOffsetToggle); + this.addDrawableChild(this.rotationWidget); + this.addDrawableChild(this.spriteWidget); + } + + @Override + public void close() { + spriteBlockEntity.setSprite(spriteWidget.getText()); + C2SEditSpriteBlock.of(spriteBlockEntity).send(); + super.close(); + } +} diff --git a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/SpriteBlockEntityRenderer.java b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/SpriteBlockEntityRenderer.java new file mode 100644 index 0000000..0d408a6 --- /dev/null +++ b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/SpriteBlockEntityRenderer.java @@ -0,0 +1,56 @@ +package dev.hephaestus.glowcase.client.render.block.entity; + +import dev.hephaestus.glowcase.Glowcase; +import dev.hephaestus.glowcase.block.entity.SpriteBlockEntity; +import net.minecraft.client.render.*; +import net.minecraft.client.render.block.entity.BlockEntityRenderer; +import net.minecraft.client.render.block.entity.BlockEntityRendererFactory; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.state.property.Properties; +import net.minecraft.util.Colors; +import net.minecraft.util.math.RotationAxis; +import org.joml.Vector3f; + +public record SpriteBlockEntityRenderer(BlockEntityRendererFactory.Context context) implements BlockEntityRenderer { + private static final Vector3f[] vertices = new Vector3f[] { + new Vector3f(-0.5F, -0.5F, 0.0F), + new Vector3f(0.5F, -0.5F, 0.0F), + new Vector3f(0.5F, 0.5F, 0.0F), + new Vector3f(-0.5F, 0.5F, 0.0F) + }; + + public void render(SpriteBlockEntity entity, float f, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) { + matrices.push(); + matrices.translate(0.5D, 0.5D, 0.5D); + + float rotation = -(entity.getCachedState().get(Properties.ROTATION) * 360) / 16.0F; + matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(rotation)); + matrices.multiply(RotationAxis.NEGATIVE_Z.rotationDegrees(entity.rotation)); + + switch (entity.zOffset) { + case FRONT -> matrices.translate(0D, 0D, 0.4D); + case BACK -> matrices.translate(0D, 0D, -0.4D); + } + + var entry = matrices.peek(); + var vertexConsumer = vertexConsumers.getBuffer(RenderLayer.getEntityCutout(Glowcase.id("textures/sprite/" + entity.sprite + ".png"))); + + vertex(entry, vertexConsumer, vertices[0], 0, 1); + vertex(entry, vertexConsumer, vertices[1], 1, 1); + vertex(entry, vertexConsumer, vertices[2], 1, 0); + vertex(entry, vertexConsumer, vertices[3], 0, 0); + + matrices.pop(); + } + + private void vertex( + MatrixStack.Entry matrix, VertexConsumer vertexConsumer, Vector3f vertex, float u, float v + ) { + vertexConsumer.vertex(matrix, vertex.x(), vertex.y(), vertex.z()) + .color(Colors.WHITE) + .texture(u, v) + .overlay(OverlayTexture.DEFAULT_UV) + .light(LightmapTextureManager.MAX_LIGHT_COORDINATE) + .normal(0, 1, 0); + } +} diff --git a/src/main/java/dev/hephaestus/glowcase/packet/C2SEditSpriteBlock.java b/src/main/java/dev/hephaestus/glowcase/packet/C2SEditSpriteBlock.java new file mode 100644 index 0000000..893fe57 --- /dev/null +++ b/src/main/java/dev/hephaestus/glowcase/packet/C2SEditSpriteBlock.java @@ -0,0 +1,44 @@ +package dev.hephaestus.glowcase.packet; + +import dev.hephaestus.glowcase.Glowcase; +import dev.hephaestus.glowcase.block.entity.SpriteBlockEntity; +import dev.hephaestus.glowcase.block.entity.TextBlockEntity; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.network.RegistryByteBuf; +import net.minecraft.network.codec.PacketCodec; +import net.minecraft.network.codec.PacketCodecs; +import net.minecraft.network.packet.CustomPayload; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; + +public record C2SEditSpriteBlock(BlockPos pos, TextBlockEntity.ZOffset offset, int rotation, String sprite) implements C2SEditBlockEntity { + public static final Id ID = new Id<>(Glowcase.id("channel.sprite.save")); + public static final PacketCodec PACKET_CODEC = PacketCodec.tuple( + BlockPos.PACKET_CODEC, C2SEditSpriteBlock::pos, + PacketCodecs.INTEGER.xmap(index -> TextBlockEntity.ZOffset.values()[index], TextBlockEntity.ZOffset::ordinal), C2SEditSpriteBlock::offset, + PacketCodecs.INTEGER, C2SEditSpriteBlock::rotation, + PacketCodecs.STRING, C2SEditSpriteBlock::sprite, + C2SEditSpriteBlock::new + ); + + public static C2SEditSpriteBlock of(SpriteBlockEntity be) { + return new C2SEditSpriteBlock(be.getPos(), be.zOffset, be.rotation, be.sprite); + } + + @Override + public Id getId() { + return ID; + } + + @Override + public void receive(ServerWorld world, BlockEntity blockEntity) { + if (!(blockEntity instanceof SpriteBlockEntity be)) return; + + be.zOffset = this.offset(); + be.rotation = this.rotation(); + be.setSprite(this.sprite()); + + be.markDirty(); + be.dispatch(); + } +} diff --git a/src/main/resources/assets/glowcase/blockstates/sprite_block.json b/src/main/resources/assets/glowcase/blockstates/sprite_block.json new file mode 100644 index 0000000..eb3ed52 --- /dev/null +++ b/src/main/resources/assets/glowcase/blockstates/sprite_block.json @@ -0,0 +1,7 @@ +{ + "variants": { + "": { + "model": "glowcase:block/glowcase_block" + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/glowcase/lang/en_us.json b/src/main/resources/assets/glowcase/lang/en_us.json index a32d0e3..927fc28 100644 --- a/src/main/resources/assets/glowcase/lang/en_us.json +++ b/src/main/resources/assets/glowcase/lang/en_us.json @@ -3,6 +3,7 @@ "block.glowcase.text_block": "Text Block", "block.glowcase.hyperlink_block": "Hyperlink Block", "block.glowcase.item_display_block": "Item Display Block", + "block.glowcase.sprite_block": "Sprite Block", "gui.glowcase.scale": "Scale: %d", "gui.glowcase.alignment": "Alignment: %s", "gui.glowcase.gives_item": "Gives Item: %s", @@ -14,5 +15,8 @@ "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.sprite_block.tooltip.0": "Displays a sprite", + "block.glowcase.sprite_block.tooltip.1": "Can be extended with resource packs" } diff --git a/src/main/resources/assets/glowcase/models/item/sprite_block.json b/src/main/resources/assets/glowcase/models/item/sprite_block.json new file mode 100644 index 0000000..fad38b9 --- /dev/null +++ b/src/main/resources/assets/glowcase/models/item/sprite_block.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "glowcase:item/sprite_block" + } +} diff --git a/src/main/resources/assets/glowcase/textures/item/sprite_block.png b/src/main/resources/assets/glowcase/textures/item/sprite_block.png new file mode 100644 index 0000000000000000000000000000000000000000..00b7df6a4a68ad856d2606b69a11a90e59c66912 GIT binary patch literal 215 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJV{wqX6T`Z5GB1G~mUKs7M+SzC z{oH>NS%G}c0G|-o|NsA+o0|i9l9#QH0V(E^Aiv=M{~4~I;svT@;4JWnEM{QfI|Rav zq8eTeKtT^r7sn8d;I%!5LJWo+Oc(##{}TH$Ysp!$E}j*36{#H0n5OJXcyFI*xUpx| zoHM2os!@w(6!3^2Kf$m5$x_t&_}PCArz7|l|7Lzu#JEA%+vp?EOa@O^KbLh*2~7YW C+(J$O literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/glowcase/textures/sprite/arrow.png b/src/main/resources/assets/glowcase/textures/sprite/arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..02dc5bbdb7aab3f2324069954940fca5b19a69eb GIT binary patch literal 217 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz#^NA%Cx&(BWL^R}Ea{HEjtmSN z`?>!lvI6;>1s;*b3=Dh+L6~vJ#O${~!8}hF$B+p3w^tpx4k+-rT)gr7{?4@qn+2UT zx;iuOxy3%yUOVOSorcF-xL40^yK3ThH|~aCXS~Di_kUQooYc%`%>H!sk;n~O%b(&O zX3crUd!<|Zo_1^xW@=+GlQqA KpUXO@geCxYdr?3D literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/glowcase/textures/sprite/double_arrow.png b/src/main/resources/assets/glowcase/textures/sprite/double_arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..8c8abf1b2f209dd8616bd2285902bef2599d8472 GIT binary patch literal 229 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE3?yBabR7dyjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCils0(?ST|Ns9FWQHEPTnD6>N`m}?|1&(@Zr}yvaTa()7BevL9ROj*tZSW| zK*1@rC-bjlx@m58vbz`y;<1?#pbZhfd43 R?F8Dw;OXk;vd$@?2>?E~OlSZA literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/glowcase/textures/sprite/double_line_arrow.png b/src/main/resources/assets/glowcase/textures/sprite/double_line_arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..145b649b4b4a1831b7137924e544ad713b17e57b GIT binary patch literal 202 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE3?yBabR7dyjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCils0(?ST|Ns9FWQHEPTnD6>N`m}?|1&(@Zr}yvaTa()7BevL9ROj*tZSW| zKtX#?7sn6_|Ffqy3Nje*9CFzF|57A_OrUDXoVt>mYH oY-Uc5YBDO982qgse3SEF@4Lyo()!CukZTz{UHx3vIVCg!0AR5`K>z>% literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/glowcase/textures/sprite/fancy_arrow.png b/src/main/resources/assets/glowcase/textures/sprite/fancy_arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..12ab41bbd5ceff65039c3139a6a75fb2ac21b6a7 GIT binary patch literal 247 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz#^NA%Cx&(BWL^R}Ea{HEjtmSN z`?>!lvI6;>1s;*b3=DkxL735kHCP2G*yHKq7!u+B_R2-B1_c3^z_f^2XW9q48>c(}VY-!cVVd(ErfW$XrXBvl zx~Kc#Zkc1+0lOu#raS*9 literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/glowcase/textures/sprite/real_arrow.png b/src/main/resources/assets/glowcase/textures/sprite/real_arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..e3d1cb5d5653f7c824fb4e30f53876533507be16 GIT binary patch literal 195 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz#^NA%Cx&(BWL^R}Ea{HEjtmSN z`?>!lvI6;>1s;*b3=Dh+L6~vJ#O${~!3a+m$B+p3x0f8b4k+-rTzv8O{hd`adR1E* z3}XLmmlT+ia)E&%D>waxWZJewS&^TAJ??9MzNs~9$1R6#JNGZoSD5`}+h)&y2mVW0 n{8YQj7IUp-4gTe~DWM4fOIStc literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/glowcase/textures/sprite/small_arrow.png b/src/main/resources/assets/glowcase/textures/sprite/small_arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..af6dcd2c0d206a20b80a1b85b0bf40e12ff5a8ee GIT binary patch literal 196 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz#^NA%Cx&(BWL^R}Ea{HEjtmSN z`?>!lvI6;>1s;*b3=Dh+L6~vJ#O${~!AMUR$B+p3w^vSc0gZAAeEa|ZPWB#Y!uMZPUE`XQy!RRYH&(Is=zq*@ mTpgNp&@kpNlgpQBCm0^}YX7^Y`RWkR5(ZCKKbLh*2~7armqlLy literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/glowcase/textures/sprite/triple_arrow.png b/src/main/resources/assets/glowcase/textures/sprite/triple_arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..a9db5b251d54ad874c4293249b7e73e2133c835f GIT binary patch literal 206 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz#^NA%Cx&(BWL^R}Ea{HEjtmSN z`?>!lvI6;>1s;*b3=Dh+L6~vJ#O${~!DLSt$B+p3w^tmw4k+-rT)gr7{?6P4rnRaf zE05~@yS>7o+pvR;;py8&$zB^D-dR>UbJ^F2w=Qj+yv;nm_^a9lbKbva)1JQaQOK5B w^zn^MenWl2PnNjK;^iRaF@HH34(va}$77rQWWG`i570UWPgg&ebxsLQ00+rTh5!Hn literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/glowcase/textures/sprite/triple_line_arrow.png b/src/main/resources/assets/glowcase/textures/sprite/triple_line_arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..fe10c77d658ab9afe865c06e7e9d73aaf90ee55b GIT binary patch literal 186 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz#^NA%Cx&(BWL^R}Ea{HEjtmSN z`?>!lvI6;>1s;*b3=Dh+K$tP>S|=w^(BIR=F(ktM?G;5n1_d7Hi><%!OZsRFc1-H} z&!af=h14MihrPPH;xgY<=DmEgc)`ZAYu7Wf_U7l=@@l-;ezw>Afc=Hr4Vo2eI{&dT cC}cll5IVa&{dB@Q5uniwp00i_>zopr0F_fcY5)KL literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/glowcase/textures/sprite/wide_arrow.png b/src/main/resources/assets/glowcase/textures/sprite/wide_arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..ea73088cc4114bd0d3f4e951dabc5a19250a6ff3 GIT binary patch literal 191 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz#^NA%Cx&(BWL^R}Ea{HEjtmSN z`?>!lvI6;>1s;*b3=DkxL735kHCP2G7~<*T7!u+B_KG1NgCPgA56_KMHcDz9I89ZJ6T-G@yGywnt<~u$B literal 0 HcmV?d00001 diff --git a/src/main/resources/data/glowcase/tags/item/items.json b/src/main/resources/data/glowcase/tags/item/items.json index 26dc5c1..13dde99 100644 --- a/src/main/resources/data/glowcase/tags/item/items.json +++ b/src/main/resources/data/glowcase/tags/item/items.json @@ -3,6 +3,7 @@ "values": [ "glowcase:hyperlink_block", "glowcase:item_display_block", - "glowcase:text_block" + "glowcase:text_block", + "glowcase:sprite_block" ] } From 993639c0429dd7521ca122775e53ec0612d8ded1 Mon Sep 17 00:00:00 2001 From: Chai <7232280+Chailotl@users.noreply.github.com> Date: Thu, 29 Aug 2024 21:51:38 -0400 Subject: [PATCH 2/8] A smattering of sprites --- .../assets/glowcase/textures/sprite/checkmark.png | Bin 0 -> 197 bytes .../glowcase/textures/sprite/exclamation.png | Bin 0 -> 173 bytes .../glowcase/textures/sprite/information.png | Bin 0 -> 209 bytes .../glowcase/textures/sprite/interrobang.png | Bin 0 -> 204 bytes .../assets/glowcase/textures/sprite/no_entry.png | Bin 0 -> 208 bytes .../assets/glowcase/textures/sprite/o.png | Bin 0 -> 210 bytes .../assets/glowcase/textures/sprite/question.png | Bin 0 -> 200 bytes .../assets/glowcase/textures/sprite/x.png | Bin 0 -> 241 bytes 8 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/main/resources/assets/glowcase/textures/sprite/checkmark.png create mode 100644 src/main/resources/assets/glowcase/textures/sprite/exclamation.png create mode 100644 src/main/resources/assets/glowcase/textures/sprite/information.png create mode 100644 src/main/resources/assets/glowcase/textures/sprite/interrobang.png create mode 100644 src/main/resources/assets/glowcase/textures/sprite/no_entry.png create mode 100644 src/main/resources/assets/glowcase/textures/sprite/o.png create mode 100644 src/main/resources/assets/glowcase/textures/sprite/question.png create mode 100644 src/main/resources/assets/glowcase/textures/sprite/x.png diff --git a/src/main/resources/assets/glowcase/textures/sprite/checkmark.png b/src/main/resources/assets/glowcase/textures/sprite/checkmark.png new file mode 100644 index 0000000000000000000000000000000000000000..bc729a9149511e5e77c87cd1eebf2fe6d8a0b829 GIT binary patch literal 197 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1quc!6;7`#}Etut9_0_2NXDtZ214bI9FosMKOVV zQ+C1WD~j~KGjGk6sfr$I}@0%!|^r>mdKI;Vst0Qwq4bpQYW literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/glowcase/textures/sprite/exclamation.png b/src/main/resources/assets/glowcase/textures/sprite/exclamation.png new file mode 100644 index 0000000000000000000000000000000000000000..0cb1c705d0663ccf05f2cfaa579231bc5088681e GIT binary patch literal 173 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1qucK_^ca#}Etuc;63a(Py7SZhTn}0r;aj7NHF+qQvd8Uvq}?a O8iS{+pUXO@geCwYmoI|= literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/glowcase/textures/sprite/information.png b/src/main/resources/assets/glowcase/textures/sprite/information.png new file mode 100644 index 0000000000000000000000000000000000000000..c50e34b56f75ef19d3515d15f1292313e8e524d8 GIT binary patch literal 209 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJV{wqX6T`Z5GB1G~mUKs7M+SzC z{oH>NS%G}E0G|-o|Ns93nW2X+*8wS}k|4j}{|ryJ8+ZYEoCO|{#S9F5he4R}c>anM zprD(li(`mJaBi0;6N3T=)7Ss=*Kuy(JL@R6vd!v*AB$+&HK)#or4znieJ6G@u`7J5 w#81(CYNvOpKdL<{9 literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/glowcase/textures/sprite/interrobang.png b/src/main/resources/assets/glowcase/textures/sprite/interrobang.png new file mode 100644 index 0000000000000000000000000000000000000000..1fc52db48d6f2fe084648336820cc8de3c40f7ae GIT binary patch literal 204 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJV{wqX6T`Z5GB1G~mUKs7M+SzC z{oH>NS%G}E0G|-o|Ns93nW2X+*8wS}k|4j}{|ryJ8+ZYEoCO|{#S9F5he4R}c>anM zprE6ti(`mJaBh#I5Q72-)5rhw{Vr^gvDDa|e2^h|!4ti2Qj=Gocbafo=TRD$V{roa qM}3p4^L3K!I@fPntE3;fcZRHYI>S6=!OA3{VGN$GelF{r5}E+S&pjLf literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/glowcase/textures/sprite/no_entry.png b/src/main/resources/assets/glowcase/textures/sprite/no_entry.png new file mode 100644 index 0000000000000000000000000000000000000000..f7ccac716d58e73e0e27a52330fcc137f87b74aa GIT binary patch literal 208 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJV{wqX6T`Z5GB1G~mUKs7M+SzC z{oH>NS%G}E0G|-o|Ns93nW2X+*8wS}k|4j}{|ryJ8+ZYEoCO|{#S9F5he4R}c>anM zprEU#i(`mJaPGO2f(!~A%nmR1XP!Oyu&2gHOx`7_Y4HtF<$_PrcU{{A-$q}U5noub vFy(+##G$YSYu`nDvc6kysc~aw-U%BI2Zr{z^U@E21~PcM`njxgN@xNAMcYDq literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/glowcase/textures/sprite/o.png b/src/main/resources/assets/glowcase/textures/sprite/o.png new file mode 100644 index 0000000000000000000000000000000000000000..53598416b5795b486bce6906fd07e5f60e2d1100 GIT binary patch literal 210 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJV{wqX6T`Z5GB1G~mUKs7M+SzC z{oH>NS%G}E0G|-o|Ns93nW2X+*8wS}k|4j}{|ryJ8+ZYEoCO|{#S9F5he4R}c>anM zprE^_i(`mJaBq(zAA(QtWtKVi$ xYCr$zXNbGcf-M(2C*9nfZ>rOG#xMbfg|%}S-GN3jc)I$ztaD0e0sz5jLSg^_ literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/glowcase/textures/sprite/question.png b/src/main/resources/assets/glowcase/textures/sprite/question.png new file mode 100644 index 0000000000000000000000000000000000000000..7dc7c1e1e16e2cfe684114e968d4a515ef41a890 GIT binary patch literal 200 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJV{wqX6T`Z5GB1G~mUKs7M+SzC z{oH>NS%G}E0G|-o|Ns93nW2X+*8wS}k|4j}{|ryJ8+ZYEoCO|{#S9F5he4R}c>anM zprEa%i(`mJaB1&FK864mr=S1l@6$f?=9Ocq*$ihl*Ee!3&J)ELZ2xjE;r+#Cy8psv n{sj}_tPaMloUMML>o;?1AHyk?txFYw1~GWL`njxgN@xNA2gf}w literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/glowcase/textures/sprite/x.png b/src/main/resources/assets/glowcase/textures/sprite/x.png new file mode 100644 index 0000000000000000000000000000000000000000..cc639e6c70e405774b06b21ab2c5fa2b23fa045c GIT binary patch literal 241 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE3?yBabR7dyjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCils0(?ST|Ns9FWQHEPTnD6>N`m}?|1&(@Zr}yvaTa()7BevL9R^{>!PC{xWt~$(69DctPR#%S literal 0 HcmV?d00001 From 4dc2756c8c818c08be95332dff4f1f42ca03a62c Mon Sep 17 00:00:00 2001 From: Chai <7232280+Chailotl@users.noreply.github.com> Date: Fri, 30 Aug 2024 20:05:08 -0400 Subject: [PATCH 3/8] Update text_block.png --- .../glowcase/textures/item/text_block.png | Bin 214 -> 205 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/src/main/resources/assets/glowcase/textures/item/text_block.png b/src/main/resources/assets/glowcase/textures/item/text_block.png index 9b835974e88956facdaa4ebe049ab0c5c2f6e3d5..16b82fbbdecc71582d41e578f44cbe5fe6158363 100644 GIT binary patch delta 159 zcmcb{c$RU3BnLAC1A~SxfAB;_#rgoB5ZC|z|C^he0|g~7TO9*Z%q2m7!TVGd003)AL_t(I zPu-JC4!|G?M5ULK`>(teIs_96HR*5Dz66Jbj%J7?BIOC2>1}>!fJ9?~sflPn%&ZO6 zN)Jy>V2lSPwN{Asj=1ks286}G#&ape)|#4mUZ27W8n;`!XJwF{I>3Zd2A}^-r4@8h W1x$8M9LMee0000 Date: Fri, 30 Aug 2024 21:35:43 -0400 Subject: [PATCH 4/8] Unflipped the hyperlink block entity renderer --- .../client/render/block/entity/HyperlinkBlockEntityRenderer.java | 1 - 1 file changed, 1 deletion(-) 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 264cc1a..0fd0eea 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 @@ -30,7 +30,6 @@ public void render(HyperlinkBlockEntity entity, float f, MatrixStack matrices, V float n = -camera.getYaw(); matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(n)); matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(camera.getPitch())); - matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(180)); context.getItemRenderer().renderItem(STACK, ModelTransformationMode.FIXED, light, OverlayTexture.DEFAULT_UV, matrices, vertexConsumers, entity.getWorld(), 0); HitResult hitResult = mc.crosshairTarget; From 900713f0814146a907a3510757dc1dce821ad694 Mon Sep 17 00:00:00 2001 From: Chai <7232280+Chailotl@users.noreply.github.com> Date: Fri, 30 Aug 2024 23:41:00 -0400 Subject: [PATCH 5/8] It seems this 180 degree roll flip was necessary, just in a different spot --- .../client/render/block/entity/HyperlinkBlockEntityRenderer.java | 1 + 1 file changed, 1 insertion(+) 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 0fd0eea..b380aae 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 @@ -36,6 +36,7 @@ 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.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(180)); matrices.translate(-context.getTextRenderer().getWidth(entity.getText()) / 2F, -4, scale); // Fixes shadow being rendered in front of actual text matrices.scale(1, 1, -1); From 70e817119b142cc7e0cf869df72b6a95a4aa689b Mon Sep 17 00:00:00 2001 From: Chai <7232280+Chailotl@users.noreply.github.com> Date: Fri, 30 Aug 2024 23:50:42 -0400 Subject: [PATCH 6/8] Fixed text shadow rendering behind hyperlink icon --- .../render/block/entity/HyperlinkBlockEntityRenderer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b380aae..066e36f 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,7 +37,7 @@ public void render(HyperlinkBlockEntity entity, float f, MatrixStack matrices, V float scale = 0.025F; matrices.scale(scale, scale, scale); matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(180)); - matrices.translate(-context.getTextRenderer().getWidth(entity.getText()) / 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.getText(), 0, 0, 0xFFFFFF, true, matrices.peek().getPositionMatrix(), vertexConsumers, TextLayerType.NORMAL, 0, LightmapTextureManager.MAX_LIGHT_COORDINATE); From 9cb01f9e5b48aebfab042147ceb9926be2173499 Mon Sep 17 00:00:00 2001 From: Chai <7232280+Chailotl@users.noreply.github.com> Date: Sat, 31 Aug 2024 13:21:29 -0400 Subject: [PATCH 7/8] Added color to sprite block --- .../block/entity/SpriteBlockEntity.java | 15 +++--- .../screen/ingame/SpriteBlockEditScreen.java | 50 +++++++++++-------- .../entity/SpriteBlockEntityRenderer.java | 15 +++--- .../glowcase/packet/C2SEditSpriteBlock.java | 14 +++--- 4 files changed, 53 insertions(+), 41 deletions(-) diff --git a/src/main/java/dev/hephaestus/glowcase/block/entity/SpriteBlockEntity.java b/src/main/java/dev/hephaestus/glowcase/block/entity/SpriteBlockEntity.java index fba7ba8..9e171ab 100644 --- a/src/main/java/dev/hephaestus/glowcase/block/entity/SpriteBlockEntity.java +++ b/src/main/java/dev/hephaestus/glowcase/block/entity/SpriteBlockEntity.java @@ -14,9 +14,10 @@ import org.jetbrains.annotations.Nullable; public class SpriteBlockEntity extends BlockEntity { - public TextBlockEntity.ZOffset zOffset = TextBlockEntity.ZOffset.CENTER; - public int rotation = 0; public String sprite = "arrow"; + public int rotation = 0; + public TextBlockEntity.ZOffset zOffset = TextBlockEntity.ZOffset.CENTER; + public int color = 0xFFFFFF; public SpriteBlockEntity(BlockPos pos, BlockState state) { super(Glowcase.SPRITE_BLOCK_ENTITY.get(), pos, state); @@ -32,18 +33,20 @@ public void setSprite(String newSprite) { public void writeNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) { super.writeNbt(tag, registryLookup); - tag.putString("z_offset", this.zOffset.name()); - tag.putInt("rotation", this.rotation); tag.putString("sprite", this.sprite); + tag.putInt("rotation", this.rotation); + tag.putString("z_offset", this.zOffset.name()); + tag.putInt("color", this.color); } @Override public void readNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) { super.readNbt(tag, registryLookup); - this.zOffset = TextBlockEntity.ZOffset.valueOf(tag.getString("z_offset")); - this.rotation = tag.getInt("rotation"); this.sprite = tag.getString("sprite"); + this.rotation = tag.getInt("rotation"); + this.zOffset = TextBlockEntity.ZOffset.valueOf(tag.getString("z_offset")); + this.color = tag.getInt("color"); } @SuppressWarnings({"MethodCallSideOnly", "VariableUseSideOnly"}) diff --git a/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/SpriteBlockEditScreen.java b/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/SpriteBlockEditScreen.java index a8cf66b..7e21327 100644 --- a/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/SpriteBlockEditScreen.java +++ b/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/SpriteBlockEditScreen.java @@ -6,14 +6,16 @@ import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.gui.widget.TextFieldWidget; import net.minecraft.text.Text; +import net.minecraft.text.TextColor; import net.minecraft.util.Identifier; public class SpriteBlockEditScreen extends GlowcaseScreen { private final SpriteBlockEntity spriteBlockEntity; - private ButtonWidget zOffsetToggle; - private ButtonWidget rotationWidget; private TextFieldWidget spriteWidget; + private ButtonWidget rotationWidget; + private ButtonWidget zOffsetToggle; + private TextFieldWidget colorEntryWidget; public SpriteBlockEditScreen(SpriteBlockEntity spriteBlockEntity) { this.spriteBlockEntity = spriteBlockEntity; @@ -25,37 +27,43 @@ public void init() { if (this.client == null) return; - this.zOffsetToggle = ButtonWidget.builder(Text.literal(this.spriteBlockEntity.zOffset.name()), action -> { - switch (spriteBlockEntity.zOffset) { - case FRONT -> spriteBlockEntity.zOffset = TextBlockEntity.ZOffset.CENTER; - case CENTER -> spriteBlockEntity.zOffset = TextBlockEntity.ZOffset.BACK; - case BACK -> spriteBlockEntity.zOffset = TextBlockEntity.ZOffset.FRONT; + this.spriteWidget = new TextFieldWidget(this.client.textRenderer, width / 2 - 75, height / 2 - 55, 150, 20, Text.empty()); + this.spriteWidget.setText(spriteBlockEntity.sprite); + this.spriteWidget.setChangedListener(string -> { + if (Identifier.isPathValid(this.spriteWidget.getText())) { + this.spriteBlockEntity.sprite = this.spriteWidget.getText(); } - - this.zOffsetToggle.setMessage(Text.literal(this.spriteBlockEntity.zOffset.name())); - //GlowcaseClientNetworking.editArrowBlock(spriteBlockEntity); - }).dimensions(width / 2 - 75, height / 2 - 40, 150, 20).build(); + }); this.rotationWidget = ButtonWidget.builder(Text.literal("Rotate"), (action) -> { this.spriteBlockEntity.rotation += 45; if (this.spriteBlockEntity.rotation >= 360) { this.spriteBlockEntity.rotation = 0; } - //GlowcaseClientNetworking.editArrowBlock(spriteBlockEntity); - }).dimensions(width / 2 - 75, height / 2 - 10, 150, 20).build(); + }).dimensions(width / 2 - 75, height / 2 - 25, 150, 20).build(); - this.spriteWidget = new TextFieldWidget(this.client.textRenderer, width / 2 - 75, height / 2 + 20, 150, 20, Text.empty()); - this.spriteWidget.setText(spriteBlockEntity.sprite); - this.spriteWidget.setChangedListener(string -> { - if (Identifier.isPathValid(this.spriteWidget.getText())) { - this.spriteBlockEntity.sprite = this.spriteWidget.getText(); - //this.spriteBlockEntity.renderDirty = true; + this.zOffsetToggle = ButtonWidget.builder(Text.literal(this.spriteBlockEntity.zOffset.name()), action -> { + switch (spriteBlockEntity.zOffset) { + case FRONT -> spriteBlockEntity.zOffset = TextBlockEntity.ZOffset.CENTER; + case CENTER -> spriteBlockEntity.zOffset = TextBlockEntity.ZOffset.BACK; + case BACK -> spriteBlockEntity.zOffset = TextBlockEntity.ZOffset.FRONT; } + + this.zOffsetToggle.setMessage(Text.literal(this.spriteBlockEntity.zOffset.name())); + }).dimensions(width / 2 - 75, height / 2 + 5, 150, 20).build(); + + this.colorEntryWidget = new TextFieldWidget(this.client.textRenderer, width / 2 - 75, height / 2 + 35, 150, 20, Text.empty()); + this.colorEntryWidget.setText("#" + String.format("%1$06X", this.spriteBlockEntity.color & 0x00FFFFFF)); + this.colorEntryWidget.setChangedListener(string -> { + TextColor.parse(this.colorEntryWidget.getText()).ifSuccess(color -> { + this.spriteBlockEntity.color = color == null ? 0xFFFFFFFF : color.getRgb() | 0xFF000000; + }); }); - this.addDrawableChild(this.zOffsetToggle); - this.addDrawableChild(this.rotationWidget); this.addDrawableChild(this.spriteWidget); + this.addDrawableChild(this.rotationWidget); + this.addDrawableChild(this.zOffsetToggle); + this.addDrawableChild(this.colorEntryWidget); } @Override diff --git a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/SpriteBlockEntityRenderer.java b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/SpriteBlockEntityRenderer.java index 0d408a6..b23ce31 100644 --- a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/SpriteBlockEntityRenderer.java +++ b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/SpriteBlockEntityRenderer.java @@ -7,7 +7,6 @@ import net.minecraft.client.render.block.entity.BlockEntityRendererFactory; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.state.property.Properties; -import net.minecraft.util.Colors; import net.minecraft.util.math.RotationAxis; import org.joml.Vector3f; @@ -35,19 +34,19 @@ public void render(SpriteBlockEntity entity, float f, MatrixStack matrices, Vert var entry = matrices.peek(); var vertexConsumer = vertexConsumers.getBuffer(RenderLayer.getEntityCutout(Glowcase.id("textures/sprite/" + entity.sprite + ".png"))); - vertex(entry, vertexConsumer, vertices[0], 0, 1); - vertex(entry, vertexConsumer, vertices[1], 1, 1); - vertex(entry, vertexConsumer, vertices[2], 1, 0); - vertex(entry, vertexConsumer, vertices[3], 0, 0); + vertex(entry, vertexConsumer, vertices[0], 0, 1, entity.color); + vertex(entry, vertexConsumer, vertices[1], 1, 1, entity.color); + vertex(entry, vertexConsumer, vertices[2], 1, 0, entity.color); + vertex(entry, vertexConsumer, vertices[3], 0, 0, entity.color); matrices.pop(); } private void vertex( - MatrixStack.Entry matrix, VertexConsumer vertexConsumer, Vector3f vertex, float u, float v - ) { + MatrixStack.Entry matrix, VertexConsumer vertexConsumer, Vector3f vertex, float u, float v, + int color) { vertexConsumer.vertex(matrix, vertex.x(), vertex.y(), vertex.z()) - .color(Colors.WHITE) + .color(color) .texture(u, v) .overlay(OverlayTexture.DEFAULT_UV) .light(LightmapTextureManager.MAX_LIGHT_COORDINATE) diff --git a/src/main/java/dev/hephaestus/glowcase/packet/C2SEditSpriteBlock.java b/src/main/java/dev/hephaestus/glowcase/packet/C2SEditSpriteBlock.java index 893fe57..4ba3597 100644 --- a/src/main/java/dev/hephaestus/glowcase/packet/C2SEditSpriteBlock.java +++ b/src/main/java/dev/hephaestus/glowcase/packet/C2SEditSpriteBlock.java @@ -11,18 +11,19 @@ import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; -public record C2SEditSpriteBlock(BlockPos pos, TextBlockEntity.ZOffset offset, int rotation, String sprite) implements C2SEditBlockEntity { +public record C2SEditSpriteBlock(BlockPos pos, String sprite, int rotation, TextBlockEntity.ZOffset offset, int color) implements C2SEditBlockEntity { public static final Id ID = new Id<>(Glowcase.id("channel.sprite.save")); public static final PacketCodec PACKET_CODEC = PacketCodec.tuple( BlockPos.PACKET_CODEC, C2SEditSpriteBlock::pos, - PacketCodecs.INTEGER.xmap(index -> TextBlockEntity.ZOffset.values()[index], TextBlockEntity.ZOffset::ordinal), C2SEditSpriteBlock::offset, - PacketCodecs.INTEGER, C2SEditSpriteBlock::rotation, PacketCodecs.STRING, C2SEditSpriteBlock::sprite, + PacketCodecs.INTEGER, C2SEditSpriteBlock::rotation, + PacketCodecs.INTEGER.xmap(index -> TextBlockEntity.ZOffset.values()[index], TextBlockEntity.ZOffset::ordinal), C2SEditSpriteBlock::offset, + PacketCodecs.INTEGER, C2SEditSpriteBlock::color, C2SEditSpriteBlock::new ); public static C2SEditSpriteBlock of(SpriteBlockEntity be) { - return new C2SEditSpriteBlock(be.getPos(), be.zOffset, be.rotation, be.sprite); + return new C2SEditSpriteBlock(be.getPos(), be.sprite, be.rotation, be.zOffset, be.color); } @Override @@ -34,9 +35,10 @@ public Id getId() { public void receive(ServerWorld world, BlockEntity blockEntity) { if (!(blockEntity instanceof SpriteBlockEntity be)) return; - be.zOffset = this.offset(); - be.rotation = this.rotation(); be.setSprite(this.sprite()); + be.rotation = this.rotation(); + be.zOffset = this.offset(); + be.color = this.color(); be.markDirty(); be.dispatch(); From a3c53e0e78b509e4676a4778e728c9c22294b2eb Mon Sep 17 00:00:00 2001 From: Chai <7232280+Chailotl@users.noreply.github.com> Date: Sat, 31 Aug 2024 13:23:54 -0400 Subject: [PATCH 8/8] Fixed padding issue with the text block hex color input --- .../glowcase/client/gui/screen/ingame/TextBlockEditScreen.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ae97861..05af351 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 @@ -89,7 +89,7 @@ public void init() { }).dimensions(120 + innerPadding, 20 + innerPadding, 160, 20).build(); this.colorEntryWidget = new TextFieldWidget(this.client.textRenderer, 280 + innerPadding * 2, 0, 50, 20, Text.empty()); - this.colorEntryWidget.setText("#" + Integer.toHexString(this.textBlockEntity.color & 0x00FFFFFF)); + this.colorEntryWidget.setText("#" + String.format("%1$06X", this.textBlockEntity.color & 0x00FFFFFF)); this.colorEntryWidget.setChangedListener(string -> { TextColor.parse(this.colorEntryWidget.getText()).ifSuccess(color -> { this.textBlockEntity.color = color == null ? 0xFFFFFFFF : color.getRgb() | 0xFF000000;