-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add overlay renderer for lamp & try to fix tool bar renderer (#1571)
Co-authored-by: YoungOnion <[email protected]>
- Loading branch information
1 parent
7367103
commit 1a4e0c9
Showing
12 changed files
with
194 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/main/java/com/gregtechceu/gtceu/client/renderer/item/LampItemOverlayRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.gregtechceu.gtceu.client.renderer.item; | ||
|
||
import com.gregtechceu.gtceu.api.gui.GuiTextures; | ||
|
||
import net.minecraft.client.gui.GuiGraphics; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraftforge.api.distmarker.Dist; | ||
import net.minecraftforge.api.distmarker.OnlyIn; | ||
|
||
import com.mojang.blaze3d.systems.RenderSystem; | ||
|
||
import static com.gregtechceu.gtceu.common.block.LampBlock.isBloomEnabled; | ||
import static com.gregtechceu.gtceu.common.block.LampBlock.isLightEnabled; | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
public class LampItemOverlayRenderer { | ||
|
||
private LampItemOverlayRenderer() {} | ||
|
||
public static OverlayType getOverlayType(boolean light, boolean bloom) { | ||
if (light) { | ||
return bloom ? OverlayType.NONE : OverlayType.NO_BLOOM; | ||
} else { | ||
return bloom ? OverlayType.NO_LIGHT : OverlayType.NO_BLOOM_NO_LIGHT; | ||
} | ||
} | ||
|
||
public static void renderOverlay(GuiGraphics graphics, ItemStack stack, int xPosition, | ||
int yPosition) { | ||
if (stack.hasTag()) { | ||
var tag = stack.getTag(); | ||
var overlayType = getOverlayType(isLightEnabled(tag), isBloomEnabled(tag)); | ||
if (overlayType == OverlayType.NONE) { | ||
return; | ||
} | ||
|
||
RenderSystem.disableDepthTest(); | ||
if (overlayType.noBloom()) { | ||
GuiTextures.LAMP_NO_BLOOM.draw(graphics, 0, 0, xPosition, yPosition, 16, 16); | ||
} | ||
|
||
if (overlayType.noLight()) { | ||
GuiTextures.LAMP_NO_LIGHT.draw(graphics, 0, 0, xPosition, yPosition, 16, 16); | ||
} | ||
RenderSystem.enableDepthTest(); | ||
} | ||
} | ||
|
||
public enum OverlayType { | ||
|
||
NONE, | ||
NO_BLOOM, | ||
NO_LIGHT, | ||
NO_BLOOM_NO_LIGHT; | ||
|
||
public boolean noLight() { | ||
return this == NO_LIGHT || this == NO_BLOOM_NO_LIGHT; | ||
} | ||
|
||
public boolean noBloom() { | ||
return this == NO_BLOOM || this == NO_BLOOM_NO_LIGHT; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/main/java/com/gregtechceu/gtceu/client/util/DrawUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.gregtechceu.gtceu.client.util; | ||
|
||
import com.gregtechceu.gtceu.core.mixins.GuiGraphicsAccessor; | ||
|
||
import com.lowdragmc.lowdraglib.utils.ColorUtils; | ||
|
||
import net.minecraft.client.gui.GuiGraphics; | ||
import net.minecraft.client.renderer.RenderType; | ||
|
||
import com.mojang.blaze3d.vertex.VertexConsumer; | ||
import org.joml.Matrix4f; | ||
|
||
public class DrawUtil { | ||
|
||
/** | ||
* Fills a rectangle with a gradient color from colorFrom to colorTo at the specified z-level using the given render | ||
* type and coordinates as the boundaries. | ||
* | ||
* @param y2 the y-coordinate of the second corner of the rectangle. | ||
* @param x2 the x-coordinate of the second corner of the rectangle. | ||
* @param y1 the y-coordinate of the first corner of the rectangle. | ||
* @param x1 the x-coordinate of the first corner of the rectangle. | ||
* @param renderType the render type to use. | ||
* @param z the z-level of the rectangle. | ||
* @param colorTo the ending color of the gradient. | ||
* @param colorFrom the starting color of the gradient. | ||
*/ | ||
public static void fillHorizontalGradient(GuiGraphics graphics, RenderType renderType, int x1, int y1, int x2, | ||
int y2, int colorFrom, int colorTo, int z) { | ||
VertexConsumer vertexconsumer = graphics.bufferSource().getBuffer(renderType); | ||
fillHorizontalGradient(graphics, vertexconsumer, x1, y1, x2, y2, z, colorFrom, colorTo); | ||
((GuiGraphicsAccessor) graphics).callFlushIfUnmanaged(); | ||
} | ||
|
||
/** | ||
* The core `fillGradient` method. | ||
* <p> | ||
* Fills a rectangle with a gradient color from colorFrom to colorTo at the specified z-level using the given render | ||
* type and coordinates as the boundaries. | ||
* | ||
* @param consumer the {@linkplain VertexConsumer} object for drawing the vertices on screen. | ||
* @param x1 the x-coordinate of the first corner of the rectangle. | ||
* @param y1 the y-coordinate of the first corner of the rectangle. | ||
* @param x2 the x-coordinate of the second corner of the rectangle. | ||
* @param y2 the y-coordinate of the second corner of the rectangle. | ||
* @param z the z-level of the rectangle. | ||
* @param colorFrom the starting color of the gradient. | ||
* @param colorTo the ending color of the gradient. | ||
*/ | ||
private static void fillHorizontalGradient(GuiGraphics graphics, VertexConsumer consumer, int x1, int y1, int x2, | ||
int y2, int z, int colorFrom, int colorTo) { | ||
float a1 = ColorUtils.alpha(colorFrom); | ||
float r1 = ColorUtils.red(colorFrom); | ||
float g1 = ColorUtils.green(colorFrom); | ||
float b1 = ColorUtils.blue(colorFrom); | ||
float a2 = ColorUtils.alpha(colorTo); | ||
float r2 = ColorUtils.red(colorTo); | ||
float g2 = ColorUtils.green(colorTo); | ||
float b2 = ColorUtils.blue(colorTo); | ||
Matrix4f matrix4f = graphics.pose().last().pose(); | ||
consumer.vertex(matrix4f, (float) x1, (float) y1, (float) z).color(r1, g1, b1, a1).endVertex(); | ||
consumer.vertex(matrix4f, (float) x1, (float) y2, (float) z).color(r1, g1, b1, a1).endVertex(); | ||
consumer.vertex(matrix4f, (float) x2, (float) y2, (float) z).color(r2, g2, b2, a2).endVertex(); | ||
consumer.vertex(matrix4f, (float) x2, (float) y1, (float) z).color(r2, g2, b2, a2).endVertex(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.