diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/de/hype/bbsentials/communication/highlighter.java | 92 | ||||
-rw-r--r-- | src/main/java/de/hype/bbsentials/mixins/renderItemMixin.java | 26 | ||||
-rw-r--r-- | src/main/resources/modid.mixins.json | 1 |
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 |