aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorHacktheTime <l4bg0jb7@duck.com>2023-07-13 12:46:40 +0200
committerhackthetime <l4bg0jb7@duck.com>2023-09-05 08:21:59 +0200
commit2bb0bc909c95dd534b404f21e17b7985ce97777c (patch)
tree2055105d1afc35ee4273c6d23f27c39e3f004001 /src/main
parentee998f5a34e3fff6ddebc24bbcc71ac406e5783b (diff)
downloadBBsentials-2bb0bc909c95dd534b404f21e17b7985ce97777c.tar.gz
BBsentials-2bb0bc909c95dd534b404f21e17b7985ce97777c.tar.bz2
BBsentials-2bb0bc909c95dd534b404f21e17b7985ce97777c.zip
changed the item highlighter for the hub. did some other small changes as well
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/de/hype/bbsentials/communication/highlighter.java92
-rw-r--r--src/main/java/de/hype/bbsentials/mixins/renderItemMixin.java26
-rw-r--r--src/main/resources/modid.mixins.json1
3 files changed, 119 insertions, 0 deletions
diff --git a/src/main/java/de/hype/bbsentials/communication/highlighter.java b/src/main/java/de/hype/bbsentials/communication/highlighter.java
new file mode 100644
index 0000000..4809a5c
--- /dev/null
+++ b/src/main/java/de/hype/bbsentials/communication/highlighter.java
@@ -0,0 +1,92 @@
+//https://github.com/AHilyard/ItemBorders/blob/main/src/main/java/com/anthonyhilyard/itemborders/ItemBorders.java
+package de.hype;
+
+import net.minecraft.ChatFormatting;
+import net.minecraft.client.renderer.MultiBufferSource;
+import net.minecraft.client.renderer.MultiBufferSource.BufferSource;
+import net.minecraft.network.chat.TextColor;
+import net.minecraft.world.inventory.Slot;
+import net.minecraft.world.item.ItemStack;
+
+import com.mojang.blaze3d.systems.RenderSystem;
+import com.mojang.blaze3d.vertex.PoseStack;
+import com.mojang.blaze3d.vertex.Tesselator;
+import com.mojang.math.Matrix4f;
+
+public class ItemBorders
+{
+ public static void renderBorder(PoseStack poseStack, Slot slot)
+ {
+ // Container GUIs.
+ render(poseStack, slot.getItem(), slot.x, slot.y);
+ }
+
+ public static void renderBorder(PoseStack poseStack, ItemStack item, int x, int y)
+ {
+ // If borders are enabled for the hotbar...
+ if (ItemBordersConfig.INSTANCE.hotBar.get())
+ {
+ render(new PoseStack(), item, x, y);
+ }
+ }
+
+ private static void render(PoseStack poseStack, ItemStack item, int x, int y)
+ {
+ if (item.isEmpty())
+ {
+ return;
+ }
+
+ TextColor color = ItemBordersConfig.INSTANCE.getBorderColorForItem(item);
+
+ // If the color is null, default to white.
+ if (color == null)
+ {
+ color = TextColor.fromLegacyFormat(ChatFormatting.WHITE);
+ }
+
+ if (color.getValue() == ChatFormatting.WHITE.getColor() && !ItemBordersConfig.INSTANCE.showForCommon.get())
+ {
+ return;
+ }
+
+ RenderSystem.disableDepthTest();
+
+ poseStack.pushPose();
+ poseStack.translate(0, 0, ItemBordersConfig.INSTANCE.overItems.get() ? 290 : 100);
+ Matrix4f matrix = poseStack.last().pose();
+
+ int startColor = color.getValue() | 0xEE000000;
+ int endColor = color.getValue() & 0x00FFFFFF;
+
+ int topColor = ItemBordersConfig.INSTANCE.fullBorder.get() ? startColor : endColor;
+ int bottomColor = startColor;
+
+ int xOffset = ItemBordersConfig.INSTANCE.squareCorners.get() ? 0 : 1;
+
+ BufferSource bufferSource = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder());
+ GuiUtils.drawGradientRect(matrix, -1, x, y + 1, x + 1, y + 15, topColor, bottomColor);
+ GuiUtils.drawGradientRect(matrix, -1, x + 15, y + 1, x + 16, y + 15, topColor, bottomColor);
+
+ GuiUtils.drawGradientRect(matrix, -1, x + xOffset, y, x + 16 - xOffset, y + 1, topColor, topColor);
+ GuiUtils.drawGradientRect(matrix, -1, x + xOffset, y + 15, x + 16 - xOffset, y + 16, bottomColor, bottomColor);
+
+ if (ItemBordersConfig.INSTANCE.extraGlow.get())
+ {
+ int topAlpha = ((topColor >> 24) & 0xFF) / 3;
+ int bottomAlpha = ((bottomColor >> 24) & 0xFF) / 3;
+
+ int topGlowColor = (topAlpha << 24) | (topColor & 0x00FFFFFF);
+ int bottomGlowColor = (bottomAlpha << 24) | (bottomColor & 0x00FFFFFF);
+
+ GuiUtils.drawGradientRect(matrix, -1, x + 1, y + 1, x + 2, y + 15, topGlowColor, bottomGlowColor);
+ GuiUtils.drawGradientRect(matrix, -1, x + 14, y + 1, x + 15, y + 15, topGlowColor, bottomGlowColor);
+
+ GuiUtils.drawGradientRect(matrix, -1, x + 1, y + 1, x + 15, y + 2, topGlowColor, topGlowColor);
+ GuiUtils.drawGradientRect(matrix, -1, x + 1, y + 14, x + 15, y + 15, bottomGlowColor, bottomGlowColor);
+ }
+
+ bufferSource.endBatch();
+ poseStack.popPose();
+ }
+} \ No newline at end of file
diff --git a/src/main/java/de/hype/bbsentials/mixins/renderItemMixin.java b/src/main/java/de/hype/bbsentials/mixins/renderItemMixin.java
new file mode 100644
index 0000000..c4ab2cd
--- /dev/null
+++ b/src/main/java/de/hype/bbsentials/mixins/renderItemMixin.java
@@ -0,0 +1,26 @@
+import com.anthonyhilyard.itemborders.ItemBorders;
+import com.mojang.blaze3d.vertex.PoseStack;
+
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.At.Shift;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import net.minecraft.client.gui.screens.Screen;
+import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
+import net.minecraft.world.inventory.Slot;
+import net.minecraft.network.chat.Component;
+
+@Mixin(AbstractContainerScreen.class)
+public class AbstractContainerScreenMixin extends Screen
+{
+ protected AbstractContainerScreenMixin(Component titleIn) { super(titleIn); }
+
+ @Inject(method = "renderSlot", at = @At(value = "INVOKE",
+ target = "Lnet/minecraft/client/renderer/entity/ItemRenderer;renderAndDecorateItem(Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/item/ItemStack;III)V", shift = Shift.AFTER))
+ public void renderSlot(PoseStack poseStack, Slot slot, CallbackInfo info)
+ {
+ ItemBorders.renderBorder(poseStack, slot);
+ }
+} \ No newline at end of file
diff --git a/src/main/resources/modid.mixins.json b/src/main/resources/modid.mixins.json
index 50a63d3..62ccbf4 100644
--- a/src/main/resources/modid.mixins.json
+++ b/src/main/resources/modid.mixins.json
@@ -9,6 +9,7 @@
],
"client": [
"SimpleOptionMixin",
+ "renderItemMixin",
"ClientCommandSourceMixin"],
"injectors": {
"defaultRequire": 1