aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/xmrvizzy/skyblocker/utils/RenderHelper.java
diff options
context:
space:
mode:
authorSpencer <spenceralj@gmail.com>2023-07-10 17:52:19 -0400
committerSpencer <spenceralj@gmail.com>2023-07-10 17:52:19 -0400
commit0f0f322d85c6b5ec40bdf3e569db67bf1252f4bc (patch)
tree4081363c9ecf4c4de324d8bf485b2766175d8d04 /src/main/java/me/xmrvizzy/skyblocker/utils/RenderHelper.java
parent7a223d5a93b26a701911f7606d135296c1d5822c (diff)
parent4e5b4fb480339e303e0b31ab0a3a07c90c3912fc (diff)
downloadSkyblocker-0f0f322d85c6b5ec40bdf3e569db67bf1252f4bc.tar.gz
Skyblocker-0f0f322d85c6b5ec40bdf3e569db67bf1252f4bc.tar.bz2
Skyblocker-0f0f322d85c6b5ec40bdf3e569db67bf1252f4bc.zip
Fix merge conflicts
Diffstat (limited to 'src/main/java/me/xmrvizzy/skyblocker/utils/RenderHelper.java')
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/utils/RenderHelper.java86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/utils/RenderHelper.java b/src/main/java/me/xmrvizzy/skyblocker/utils/RenderHelper.java
new file mode 100644
index 00000000..6fa93735
--- /dev/null
+++ b/src/main/java/me/xmrvizzy/skyblocker/utils/RenderHelper.java
@@ -0,0 +1,86 @@
+package me.xmrvizzy.skyblocker.utils;
+
+import me.x150.renderer.render.Renderer3d;
+import me.xmrvizzy.skyblocker.mixin.accessor.BeaconBlockEntityRendererInvoker;
+import me.xmrvizzy.skyblocker.utils.title.Title;
+import me.xmrvizzy.skyblocker.utils.title.TitleContainer;
+import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.client.render.block.entity.BeaconBlockEntityRenderer;
+import net.minecraft.sound.SoundEvent;
+import net.minecraft.text.Text;
+import net.minecraft.util.Formatting;
+import net.minecraft.util.Identifier;
+import net.minecraft.util.math.BlockPos;
+import net.minecraft.util.math.Vec3d;
+
+import java.awt.*;
+
+public class RenderHelper {
+ private static final Vec3d ONE = new Vec3d(1, 1, 1);
+
+ public static void renderFilledThroughWallsWithBeaconBeam(WorldRenderContext context, BlockPos pos, float[] colorComponents, float alpha) {
+ renderFilledThroughWalls(context, pos, colorComponents, alpha);
+ renderBeaconBeam(context, pos, colorComponents);
+ }
+
+ public static void renderFilledThroughWalls(WorldRenderContext context, BlockPos pos, float[] colorComponents, float alpha) {
+ Renderer3d.renderThroughWalls();
+ renderFilled(context, pos, colorComponents, alpha);
+ Renderer3d.stopRenderThroughWalls();
+ }
+
+ public static void renderFilledIfVisible(WorldRenderContext context, BlockPos pos, float[] colorComponents, float alpha) {
+ if (FrustumUtils.isVisible(pos.getX(), pos.getY(), pos.getZ(), pos.getX() + 1, pos.getY() + 1, pos.getZ() + 1)) {
+ renderFilled(context, pos, colorComponents, alpha);
+ }
+ }
+
+ public static void renderFilled(WorldRenderContext context, BlockPos pos, float[] colorComponents, float alpha) {
+ Renderer3d.renderFilled(context.matrixStack(), new Color(colorComponents[0], colorComponents[1], colorComponents[2], alpha), Vec3d.of(pos), ONE);
+ }
+
+ public static void renderBeaconBeam(WorldRenderContext context, BlockPos pos, float[] colorComponents) {
+ context.matrixStack().push();
+ context.matrixStack().translate(pos.getX() - context.camera().getPos().x, pos.getY() - context.camera().getPos().y, pos.getZ() - context.camera().getPos().z);
+ BeaconBlockEntityRendererInvoker.renderBeam(context.matrixStack(), context.consumers(), context.tickDelta(), context.world().getTime(), 0, BeaconBlockEntityRenderer.MAX_BEAM_HEIGHT, colorComponents);
+ context.matrixStack().pop();
+ }
+
+ public static void displayTitleAndPlaySound(int stayTicks, int fadeOutTicks, String titleKey, Formatting formatting) {
+ MinecraftClient.getInstance().inGameHud.setTitleTicks(0, stayTicks, fadeOutTicks);
+ MinecraftClient.getInstance().inGameHud.setTitle(Text.translatable(titleKey).formatted(formatting));
+ playNotificationSound();
+ }
+
+ /**
+ * Adds the title to {@link TitleContainer} and {@link #playNotificationSound() plays the notification sound} if the title is not in the {@link TitleContainer} already.
+ * No checking needs to be done on whether the title is in the {@link TitleContainer} already by the caller.
+ *
+ * @param title the title
+ */
+ public static void displayInTitleContainerAndPlaySound(Title title) {
+ if (TitleContainer.addTitle(title)) {
+ playNotificationSound();
+ }
+ }
+
+ /**
+ * Adds the title to {@link TitleContainer} for a set number of ticks and {@link #playNotificationSound() plays the notification sound} if the title is not in the {@link TitleContainer} already.
+ * No checking needs to be done on whether the title is in the {@link TitleContainer} already by the caller.
+ *
+ * @param title the title
+ * @param ticks the number of ticks the title will remain
+ */
+ public static void displayInTitleContainerAndPlaySound(Title title, int ticks) {
+ if (TitleContainer.addTitle(title, ticks)) {
+ playNotificationSound();
+ }
+ }
+
+ private static void playNotificationSound() {
+ if (MinecraftClient.getInstance().player != null) {
+ MinecraftClient.getInstance().player.playSound(SoundEvent.of(new Identifier("entity.experience_orb.pickup")), 100f, 0.1f);
+ }
+ }
+}