Skip to content

Commit

Permalink
Misc style changes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheEpicBlock committed Jul 3, 2024
1 parent ff4977b commit 2c7fa8c
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 107 deletions.
16 changes: 5 additions & 11 deletions src/main/java/dev/hephaestus/glowcase/Glowcase.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dev.hephaestus.glowcase.block.HyperlinkBlock;
import dev.hephaestus.glowcase.block.ItemDisplayBlock;
import dev.hephaestus.glowcase.block.MailboxBlock;
Expand All @@ -14,15 +13,14 @@
import dev.hephaestus.glowcase.block.entity.TextBlockEntity;
import dev.hephaestus.glowcase.compat.PolydexCompatibility;
import dev.hephaestus.glowcase.networking.GlowcaseCommonNetworking;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.command.argument.BlockPosArgumentType;
import net.minecraft.entity.player.PlayerEntity;
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;
Expand All @@ -33,10 +31,6 @@
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;

public class Glowcase implements ModInitializer {
public static final String MODID = "glowcase";

Expand Down Expand Up @@ -94,7 +88,7 @@ public void onInitialize() {
}
}

private int sendMessage(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
private int sendMessage(CommandContext<ServerCommandSource> ctx) {
BlockPos pos = BlockPosArgumentType.getBlockPos(ctx, "pos");
String message = ctx.getArgument("message", String.class);
PlayerEntity sender = ctx.getSource().getPlayer();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/hephaestus/glowcase/GlowcaseClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import dev.hephaestus.glowcase.block.entity.MailboxBlockEntity;
import dev.hephaestus.glowcase.client.GlowcaseClientProxy;
import dev.hephaestus.glowcase.client.render.block.entity.BakedBlockEntityRenderer;
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.BakedBlockEntityRenderer;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
import net.minecraft.component.type.NbtComponent;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.ItemActionResult;
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/dev/hephaestus/glowcase/block/MailboxBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import dev.hephaestus.glowcase.Glowcase;
import dev.hephaestus.glowcase.block.entity.MailboxBlockEntity;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.*;
import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -14,7 +16,6 @@
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.decoration.ItemFrameEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.SpawnEggItem;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
package dev.hephaestus.glowcase.block.entity;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.UUID;

import dev.hephaestus.glowcase.Glowcase;
import dev.hephaestus.glowcase.block.MailboxBlock;
import net.minecraft.registry.RegistryWrapper;
import org.jetbrains.annotations.Nullable;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.nbt.NbtCompound;
Expand All @@ -16,9 +10,15 @@
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.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.UUID;

public class MailboxBlockEntity extends BlockEntity {
private final Deque<Message> messages = new ArrayDeque<>();
Expand Down Expand Up @@ -117,7 +117,7 @@ public void removeAllMessagesFromMostRecentSender() {
}
}

public static record Message(UUID sender, String senderName, String message) {}
public record Message(UUID sender, String senderName, String message) {}

// standard blockentity boilerplate

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
package dev.hephaestus.glowcase.block.entity;

import java.util.ArrayList;
import java.util.List;

import dev.hephaestus.glowcase.Glowcase;
import dev.hephaestus.glowcase.client.render.block.entity.BakedBlockEntityRenderer;

import eu.pb4.placeholders.api.ParserContext;
import eu.pb4.placeholders.api.parsers.NodeParser;
import eu.pb4.placeholders.api.parsers.TagParser;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.text.Style;
import org.jetbrains.annotations.Nullable;

import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.nbt.NbtCompound;
Expand All @@ -22,14 +14,19 @@
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.text.MutableText;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

public class TextBlockEntity extends BlockEntity {
public static final NodeParser PARSER = TagParser.DEFAULT;
public List<MutableText> lines = new ArrayList<>();
public List<Text> lines = new ArrayList<>();
public TextAlignment textAlignment = TextAlignment.CENTER;
public ZOffset zOffset = ZOffset.CENTER;
public ShadowType shadowType = ShadowType.DROP;
Expand All @@ -39,7 +36,7 @@ public class TextBlockEntity extends BlockEntity {

public TextBlockEntity(BlockPos pos, BlockState state) {
super(Glowcase.TEXT_BLOCK_ENTITY, pos, state);
lines.add((MutableText) Text.empty());
lines.add(Text.empty());
}

@Override
Expand All @@ -54,7 +51,7 @@ protected void writeNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryL
tag.putString("shadow_type", this.shadowType.name());

NbtList lines = tag.getList("lines", 8);
for (MutableText text : this.lines) {
for (var text : this.lines) {
lines.add(NbtString.of(Text.Serialization.toJsonString(text, registryLookup)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import dev.hephaestus.glowcase.networking.GlowcaseClientNetworking;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import org.lwjgl.glfw.GLFW;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.text.Text;
import org.lwjgl.glfw.GLFW;

@Environment(EnvType.CLIENT)
public class HyperlinkBlockEditScreen extends GlowcaseScreen {
Expand All @@ -24,8 +24,6 @@ public void init() {

if (this.client == null) return;

// this.client.keyboard.setRepeatEvents(true);

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,19 @@
import com.mojang.blaze3d.systems.RenderSystem;
import dev.hephaestus.glowcase.block.entity.TextBlockEntity;
import dev.hephaestus.glowcase.networking.GlowcaseClientNetworking;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.BufferRenderer;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.render.*;
import net.minecraft.client.util.SelectionManager;
import net.minecraft.text.Text;
import net.minecraft.text.TextColor;
import net.minecraft.util.math.MathHelper;
import org.lwjgl.glfw.GLFW;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

//TODO: multi-character selection at some point? it may be a bit complex but it'd be nice
@Environment(EnvType.CLIENT)
public class TextBlockEditScreen extends GlowcaseScreen {
Expand Down Expand Up @@ -50,10 +45,6 @@ public void init() {

int innerPadding = width / 100;

// if (this.client != null) {
// this.client.keyboard.setRepeatEvents(true);
// }

this.selectionManager = new SelectionManager(
() -> this.textBlockEntity.getRawLine(this.currentRow),
(string) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@
import com.google.common.collect.Sets;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.logging.LogUtils;

import it.unimi.dsi.fastutil.objects.Object2ReferenceMap;
import it.unimi.dsi.fastutil.objects.Object2ReferenceOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import it.unimi.dsi.fastutil.objects.Reference2ReferenceMap;
import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap;
import it.unimi.dsi.fastutil.objects.ReferenceArrayList;
import it.unimi.dsi.fastutil.objects.*;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.MinecraftClient;
Expand All @@ -22,7 +16,7 @@
import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.NotNull;
import org.joml.Matrix4f;
import org.slf4j.Logger;

Expand All @@ -39,7 +33,8 @@ protected BakedBlockEntityRenderer(BlockEntityRendererFactory.Context context) {

/**
* Handles invalidation and passing of rendered vertices to the baking system.
* Override renderBaked and renderUnbaked instead of this method.
* Override {@link #renderBaked(BlockEntity, MatrixStack, VertexConsumerProvider, int, int)} and
* {@link #renderBaked(BlockEntity, MatrixStack, VertexConsumerProvider, int, int)} instead of this method.
*/
@Override
public final void render(T entity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) {
Expand All @@ -49,24 +44,23 @@ public final void render(T entity, float tickDelta, MatrixStack matrices, Vertex

/**
* Render vertices to be baked into the render region. This method will be called every time the render region is rebuilt - so
* you should only render vertices that don't move here. You can call invalidateSelf or VertexBufferManager.invalidate to
* you should only render vertices that don't move here. You can call {@link Manager#markForRebuild(BlockPos)} to
* cause the render region to be rebuilt, but do not call this too frequently as it will affect performance.
*
* You must use the provided VertexConsumerProvider and MatrixStack to render your vertices - any use of Tessellator
* or RenderSystem here will not work. If you need custom rendering settings, you can use a custom RenderLayer.
*/
public abstract void renderBaked(T entity, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay);

/**
* Render vertices immediately. This works exactly the same way as a normal BER render method, and can be used for dynamic
* rendering that changes every frame. In this method you can also check for render invalidation and call invalidateSelf
* rendering that changes every frame. In this method you can also check for render invalidation and call {@link Manager#markForRebuild(BlockPos)}
* as appropriate.
*/
public abstract void renderUnbaked(T entity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay);

public abstract boolean shouldBake(T entity);

private static record RenderRegionPos(int x, int z, @Nullable BlockPos origin) {
private record RenderRegionPos(int x, int z, @NotNull BlockPos origin) {
public RenderRegionPos(int x, int z) {
this(x, z, new BlockPos(x << Manager.REGION_SHIFT, 0, z << Manager.REGION_SHIFT));
}
Expand Down Expand Up @@ -201,12 +195,10 @@ public static void render(WorldRenderContext wrc) {
wrc.profiler().push("rebuild");

// Make builders for regions that are marked for rebuild, render and upload to RegionBuffers
Set<RenderRegionPos> rebuilt = Sets.newHashSet();
Set<RenderRegionPos> removing = Sets.newHashSet();
List<BlockEntity> blockEntities = new ArrayList<>();
MatrixStack bakeMatrices = new MatrixStack();
for (RenderRegionPos rrp : needsRebuild) {
rebuilt.add(rrp);
if (isVisiblePos(rrp, cam)) {
// For the current region, rebuild each render layer using the buffer builders
// Find all block entities in this region
Expand Down Expand Up @@ -248,7 +240,9 @@ public static void render(WorldRenderContext wrc) {
}
}
}
rebuilt.forEach(needsRebuild::remove);
// We've processed all pending rebuilds now
needsRebuild.clear();
// These regions no longer contain anything
removing.forEach(rrp -> {
RegionBuffer buf = regions.get(rrp);
if (buf != null) {
Expand All @@ -263,10 +257,10 @@ public static void render(WorldRenderContext wrc) {
if (!regions.isEmpty()) {
wrc.profiler().push("render");

/**
* Set the fog end to a extremely high value, this is a total hack but.
/*
* Set the fog end to an extremely high value, this is a total hack but.
* It's needed to make fog not bleed into text blocks
*/
*/
float originalFogEnd = RenderSystem.getShaderFogEnd();
RenderSystem.setShaderFogEnd(Float.MAX_VALUE);
// Iterate over all RegionBuffers, render visible and remove non-visible RegionBuffers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dev.hephaestus.glowcase.client.render.block.entity;

import dev.hephaestus.glowcase.block.entity.ItemDisplayBlockEntity;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer.TextLayerType;
import net.minecraft.client.render.LightmapTextureManager;
Expand All @@ -14,7 +13,6 @@
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.SpawnEggItem;
import net.minecraft.state.property.Properties;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package dev.hephaestus.glowcase.client.render.block.entity;

import org.joml.Matrix4f;

import dev.hephaestus.glowcase.block.entity.TextBlockEntity;
import dev.hephaestus.glowcase.client.GlowcaseRenderLayers;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.font.TextRenderer.TextLayerType;
import net.minecraft.client.render.*;
import net.minecraft.client.render.LightmapTextureManager;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexConsumerProvider;
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.math.RotationAxis;
import org.joml.Matrix4f;

public class TextBlockEntityRenderer extends BakedBlockEntityRenderer<TextBlockEntity> {
public TextBlockEntityRenderer(BlockEntityRendererFactory.Context context) {
Expand Down
Loading

0 comments on commit 2c7fa8c

Please sign in to comment.