Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/main/java/twilightforest/client/overlay/ItemDisplayOverlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.mojang.blaze3d.platform.Window;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.GuiGraphicsExtractor;
import net.minecraft.core.NonNullList;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.player.Player;
Expand All @@ -21,7 +21,7 @@
import java.util.List;

public class ItemDisplayOverlay {
public static void render(GuiGraphics graphics, Minecraft minecraft, Window window, Gui gui, Player player) {
public static void render(GuiGraphicsExtractor graphics, Minecraft minecraft, Window window, Gui gui, Player player) {
if (player == null || gui.getDebugOverlay().showDebugScreen() || minecraft.options.hideGui)
return;

Expand All @@ -41,20 +41,20 @@ public static void render(GuiGraphics graphics, Minecraft minecraft, Window wind
renderHolders(graphics, minecraft, gui, player, typesToRender, widest);
}

private static void renderHolders(GuiGraphics graphics, Minecraft minecraft, Gui gui, Player player, List<DisplayHolder> typesToRender, int widest) {
graphics.pose().pushPose();
graphics.pose().translate(TFConfig.itemDisplayXOffs, TFConfig.itemDisplayYOffs, 0.0D);
graphics.pose().scale((float) TFConfig.itemDisplayScale, (float) TFConfig.itemDisplayScale, (float) TFConfig.itemDisplayScale);
private static void renderHolders(GuiGraphicsExtractor graphics, Minecraft minecraft, Gui gui, Player player, List<DisplayHolder> typesToRender, int widest) {
graphics.pose().pushMatrix();
graphics.pose().translate(TFConfig.itemDisplayXOffs, TFConfig.itemDisplayYOffs);
graphics.pose().scale((float) TFConfig.itemDisplayScale, (float) TFConfig.itemDisplayScale);
typesToRender.sort(Comparator.comparing(holder -> holder.display().displayPosition()));
for (DisplayHolder holder : typesToRender) {
graphics.pose().pushPose();
graphics.pose().pushMatrix();
holder.display().render(holder.stack(), graphics, minecraft, gui, player, widest);
//debug fill to see widget sizes
//graphics.fill(holder.bounds().startX(), holder.bounds().startY(), holder.bounds().startX() + holder.bounds().width(), holder.bounds().startY() + holder.bounds().height(), 0x80FF0000);
graphics.pose().popPose();
graphics.pose().translate(0.0F, holder.bounds().height(), 0.0F);
graphics.pose().popMatrix();
graphics.pose().translate(0.0F, holder.bounds().height());
}
graphics.pose().popPose();
graphics.pose().pushMatrix();
}

private static int fillDisplayHolders(List<DisplayHolder> typesToRender, ItemDisplayContents contents, Minecraft minecraft, Gui gui, Player player) {
Expand Down
27 changes: 13 additions & 14 deletions src/main/java/twilightforest/client/overlay/PortalOverlay.java
Comment thread
albazavr-alba marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
package twilightforest.client.overlay;

import com.mojang.blaze3d.pipeline.DepthStencilState;
import com.mojang.blaze3d.pipeline.RenderPipeline;
import com.mojang.blaze3d.platform.CompareOp;
import com.mojang.blaze3d.platform.Window;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.gui.GuiGraphicsExtractor;
import net.minecraft.client.renderer.RenderPipelines;
import net.minecraft.client.resources.model.sprite.Material;
import net.minecraft.util.ARGB;
import net.minecraft.world.entity.player.Player;
import twilightforest.components.entity.TFPortalAttachment;
import twilightforest.init.TFBlocks;
import twilightforest.init.TFDataAttachments;

public class PortalOverlay {

public static void render(GuiGraphics graphics, Minecraft minecraft, Player player) {
public static void render(GuiGraphicsExtractor graphics, Minecraft minecraft, Player player) {
Window window = minecraft.getWindow();
if (player != null) {
TFPortalAttachment portal = player.getData(TFDataAttachments.TF_PORTAL_COOLDOWN);
if (portal.getPortalTimer() > 0) {
RenderSystem.disableDepthTest();
RenderSystem.depthMask(false);
RenderSystem.enableBlend();
graphics.setColor(1.0F, 1.0F, 1.0F, (float) portal.getPortalTimer() / (float) TFPortalAttachment.MAX_TICKS);
TextureAtlasSprite textureatlassprite = minecraft.getBlockRenderer().getBlockModelShaper().getParticleIcon(TFBlocks.TWILIGHT_PORTAL.get().defaultBlockState());
graphics.blit(0, 0, -90, window.getGuiScaledWidth(), window.getGuiScaledHeight(), textureatlassprite);
RenderSystem.disableBlend();
RenderSystem.depthMask(true);
RenderSystem.enableDepthTest();
graphics.setColor(1.0F, 1.0F, 1.0F, 1.0F);
RenderPipeline pipeline = RenderPipeline.builder(RenderPipelines.GUI_TEXTURED_SNIPPET)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this pipeline is unnecessary and graphics.blit call is wrong. You can compare Gui.renderPortalOverlay() in 1.21.1 and Gui.extractPortalOverlay() in 26.1.
Also, I think it's better to move all pipelines to TFRenderPipelines and register them using RegisterRenderPipelinesEvent.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I can delete this class, because it is unused?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, but there is a lambda doing the same thing in OverlayHandler. Maybe this class is intended to replace that according to the commit date.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There may be cases where classes should be deleted, but it's probably best to confirm with a team member before deleting any files.

.withDepthStencilState(new DepthStencilState(CompareOp.ALWAYS_PASS, false))
.build();
Material.Baked textureatlassprite = minecraft.getModelManager().getBlockStateModelSet().getParticleMaterial(TFBlocks.TWILIGHT_PORTAL.get().defaultBlockState());
graphics.blit(pipeline, textureatlassprite.sprite().atlasLocation(), 0, 0, 0, 0, -90, window.getGuiScaledWidth(), window.getGuiScaledHeight(), ARGB.color(portal.getPortalTimer() / TFPortalAttachment.MAX_TICKS, 0, 0, 0));
Comment thread
albazavr-alba marked this conversation as resolved.
Outdated
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package twilightforest.client.overlay;

import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.GuiGraphicsExtractor;
import net.minecraft.client.renderer.RenderPipelines;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
Expand All @@ -24,24 +23,20 @@ public class QuestingRamIndicatorOverlay {
@Autowired(dist = Dist.CLIENT)
private static QuestingRamCurrentContext questingRamCurrentContext;

public static void render(Minecraft minecraft, GuiGraphics graphics, Gui gui, Player player) {
public static void render(Minecraft minecraft, GuiGraphicsExtractor graphics, Gui gui, Player player) {
if (player != null && !minecraft.options.hideGui && TFConfig.showQuestRamCrosshairIndicator) {
if (minecraft.options.getCameraType().isFirstPerson() && (minecraft.gameMode.getPlayerMode() != GameType.SPECTATOR || gui.canRenderCrosshairForSpectator(minecraft.hitResult)) && minecraft.crosshairPickEntity instanceof QuestRam ram) {
ItemStack stack = player.getInventory().getItem(player.getInventory().selected);
ItemStack stack = player.getInventory().getItem(player.getInventory().getSelectedSlot());
if (!stack.isEmpty()) {
for (var questEntry : questingRamCurrentContext.getContext().questItems().entrySet()) {
if (questEntry.getValue().test(stack)) {
RenderSystem.enableBlend();
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.ONE_MINUS_DST_COLOR, GlStateManager.DestFactor.ONE_MINUS_SRC_COLOR, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
int j = ((graphics.guiHeight() - 1) / 2) - 11;
int k = ((graphics.guiHeight() - 1) / 2) - 3;
if (!ram.isColorPresent(questEntry.getKey())) {
graphics.blitSprite(QUESTING_RAM_X_SPRITE, k, j, 7, 7);
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, QUESTING_RAM_X_SPRITE, k, j, 7, 7);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be RenderPipelines.CROSSHAIR based on the blendFunc. Relevant methods: Gui.extractCrosshair(), Gui.renderCrosshair()

} else {
graphics.blitSprite(QUESTING_RAM_CHECK_SPRITE, k, j, 7, 7);
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, QUESTING_RAM_CHECK_SPRITE, k, j, 7, 7);
}
RenderSystem.defaultBlendFunc();
RenderSystem.disableBlend();
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.GuiGraphicsExtractor;
import net.minecraft.client.renderer.RenderPipelines;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.player.Player;
import org.jetbrains.annotations.Nullable;
Expand All @@ -14,11 +15,11 @@ public class ShieldOverlay {

private static final Identifier FORTIFICATION_SHIELD_SPRITE = TwilightForestMod.prefix("fortification_shield");

public static void render(GuiGraphics graphics, Minecraft minecraft, Gui gui, @Nullable Player player) {
public static void render(GuiGraphicsExtractor graphics, Minecraft minecraft, Gui gui, @Nullable Player player) {
if (player != null && !minecraft.options.hideGui && (minecraft.gameMode.canHurtPlayer() || TFConfig.showFortificationShieldIndicatorInCreative) && player.hasData(TFDataAttachments.FORTIFICATION_SHIELDS) && player.getData(TFDataAttachments.FORTIFICATION_SHIELDS).shieldsLeft() > 0 && TFConfig.showFortificationShieldIndicator) {
int shieldCount = player.getData(TFDataAttachments.FORTIFICATION_SHIELDS).shieldsLeft();
for (int i = 0; i < Math.min(shieldCount, 10); i++) {
graphics.blitSprite(FORTIFICATION_SHIELD_SPRITE, graphics.guiWidth() / 2 - 91 + (i * 8), graphics.guiHeight() - gui.leftHeight, 9, 9);
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, FORTIFICATION_SHIELD_SPRITE, graphics.guiWidth() / 2 - 91 + (i * 8), graphics.guiHeight() - gui.leftHeight, 9, 9);
}
gui.leftHeight += 10;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.GuiGraphicsExtractor;
import net.minecraft.network.chat.Component;
import net.minecraft.util.FormattedCharSequence;
import net.minecraft.world.entity.player.Player;
Expand Down Expand Up @@ -36,28 +36,30 @@ private static long getMinecraftClockTimeInTicks(long ticks) {
}

private static Component getGameTime(Level level, boolean use24HourFormat) {
if (!level.dimensionType().natural())
if (level.dimensionType().hasFixedTime())
return Component.translatable("travellers_gear.modifier.twilightforest.item_display.clock.unknown");

long rawTime = level.dimensionType().fixedTime().orElse(level.getDayTime());
long rawTime = level.getOverworldClockTime();
long ticksOfDay = getMinecraftClockTimeInTicks(rawTime);
long secondsOfDay = (ticksOfDay * REAL_LIFE_DAY_LENGTH_IN_SECONDS) / MINECRAFT_DAY_LENGTH_IN_TICKS;
LocalTime localTime = LocalTime.ofSecondOfDay(secondsOfDay);
return Component.literal(localTime.format(use24HourFormat ? FORMAT_24 : FORMAT_12));
}

@Override
public void render(ItemStack item, GuiGraphics graphics, Minecraft minecraft, Gui gui, Player player, int widestWidgetWidth) {
public void render(ItemStack item, GuiGraphicsExtractor graphics, Minecraft minecraft, Gui gui, Player player, int widestWidgetWidth) {
FormattedCharSequence formattedcharsequence = this.getText(minecraft).getVisualOrderText();
if (minecraft.level.dimensionType().natural()) {
int k = this.getFrameForTime(minecraft.level.dimensionType().fixedTime().orElse(minecraft.level.getDayTime())).frame;
boolean natural = !minecraft.level.dimensionType().hasFixedTime();
if (natural) {
long timeValue = minecraft.level.getOverworldClockTime();
int k = this.getFrameForTime(timeValue).frame;
int xRow = k % 2;
int yRow = k / 2 % 2;
float xMin = xRow * 8;
float yMin = yRow * 8;
int xMin = xRow * 8;
int yMin = yRow * 8;
graphics.blit(TwilightForestMod.getGuiTexture("time.png"), (widestWidgetWidth / 2 - 5) - minecraft.font.width(formattedcharsequence) / 2, 0, xMin, yMin, 8, 8, 16, 16);
}
graphics.drawString(minecraft.font, formattedcharsequence, Math.max(0, (widestWidgetWidth / 2 + 5) - minecraft.font.width(formattedcharsequence) / 2), 0, 0xFFFFFF);
graphics.text(minecraft.font, formattedcharsequence, Math.max(0, (widestWidgetWidth / 2 + 5) - minecraft.font.width(formattedcharsequence) / 2), 0, 0xFFFFFF);
}

private TimeFrame getFrameForTime(long dayTimeInTicks) {
Expand All @@ -68,7 +70,7 @@ private TimeFrame getFrameForTime(long dayTimeInTicks) {
@Override
public Bounds getWidgetSize(ItemStack item, Minecraft minecraft, Gui gui, Player player, int widestWidgetWidth) {
int textWidth = minecraft.font.width(this.getText(minecraft));
boolean natural = minecraft.level.dimensionType().natural();
boolean natural = minecraft.level.dimensionType().hasSkyLight();
return new Bounds(Math.max(0, (widestWidgetWidth / 2 - (natural ? 5 : 0)) - (textWidth / 2)), 0, textWidth + (natural ? 10 : 0), minecraft.font.lineHeight);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package twilightforest.client.overlay.display;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.GuiGraphicsExtractor;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import twilightforest.util.Vec2i;

public interface ItemDisplay {

void render(ItemStack item, GuiGraphics graphics, Minecraft minecraft, Gui gui, Player player, int widestWidgetWidth);
void render(ItemStack item, GuiGraphicsExtractor graphics, Minecraft minecraft, Gui gui, Player player, int widestWidgetWidth);

default DisplayPosition displayPosition() {
return DisplayPosition.DEFAULT;
Expand Down
47 changes: 31 additions & 16 deletions src/main/java/twilightforest/client/overlay/display/MapDisplay.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package twilightforest.client.overlay.display;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.blaze3d.vertex.*;
import com.mojang.math.Axis;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.gui.GuiGraphicsExtractor;
import net.minecraft.client.renderer.SubmitNodeStorage;
import net.minecraft.client.renderer.rendertype.RenderType;
import net.minecraft.client.renderer.rendertype.RenderTypes;
import net.minecraft.client.renderer.state.MapRenderState;
import net.minecraft.core.component.DataComponents;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.player.Player;
Expand All @@ -19,27 +20,38 @@

public class MapDisplay implements ItemDisplay {

private static final RenderType MAP_BACKGROUND = RenderType.text(Identifier.withDefaultNamespace("textures/map/map_background.png"));
private static final RenderType MAP_BACKGROUND_CHECKERBOARD = RenderType.text(Identifier.withDefaultNamespace("textures/map/map_background_checkerboard.png"));
private static final RenderType MAP_BACKGROUND = RenderTypes.text(Identifier.withDefaultNamespace("textures/map/map_background.png"));
private static final RenderType MAP_BACKGROUND_CHECKERBOARD = RenderTypes.text(Identifier.withDefaultNamespace("textures/map/map_background_checkerboard.png"));

private static final int FULL_BRIGHT = 15728880;

private final MapRenderState cachedMapRenderState = new MapRenderState();

@Override
public void render(ItemStack item, GuiGraphics graphics, Minecraft minecraft, Gui gui, Player player, int widestWidgetWidth) {
PoseStack stack = graphics.pose();
public void render(ItemStack item, GuiGraphicsExtractor graphics, Minecraft minecraft, Gui gui, Player player, int widestWidgetWidth) {
PoseStack stack = new PoseStack();
MapId mapid = item.get(DataComponents.MAP_ID);
if (mapid == null)
return;

MapItemSavedData data = MapItem.getSavedData(item, minecraft.level);
if (data == null)
return;
VertexConsumer consumer = graphics.bufferSource().getBuffer(MAP_BACKGROUND_CHECKERBOARD);

ByteBufferBuilder byteBuffer = new ByteBufferBuilder(256);
VertexConsumer consumer = new BufferBuilder(byteBuffer, VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP);

Matrix4f matrix4f = stack.last().pose();

//render map background
float start = Math.max(widestWidgetWidth / 2 - 50, 0);
consumer.addVertex(matrix4f, start, 100.0F, -2.0F).setColor(-1).setUv(0.0F, 1.0F).setLight(LightTexture.FULL_BRIGHT);
consumer.addVertex(matrix4f, start + 100.0F, 100.0F, -2.0F).setColor(-1).setUv(1.0F, 1.0F).setLight(LightTexture.FULL_BRIGHT);
consumer.addVertex(matrix4f, start + 100.0F, 0.0F, -2.0F).setColor(-1).setUv(1.0F, 0.0F).setLight(LightTexture.FULL_BRIGHT);
consumer.addVertex(matrix4f, start, 0.0F, -2.0F).setColor(-1).setUv(0.0F, 0.0F).setLight(LightTexture.FULL_BRIGHT);
consumer.addVertex(matrix4f, start, 100.0F, -2.0F).setColor(-1).setUv(0.0F, 1.0F).setLight(FULL_BRIGHT);
consumer.addVertex(matrix4f, start + 100.0F, 100.0F, -2.0F).setColor(-1).setUv(1.0F, 1.0F).setLight(FULL_BRIGHT);
consumer.addVertex(matrix4f, start + 100.0F, 0.0F, -2.0F).setColor(-1).setUv(1.0F, 0.0F).setLight(FULL_BRIGHT);
consumer.addVertex(matrix4f, start, 0.0F, -2.0F).setColor(-1).setUv(0.0F, 0.0F).setLight(FULL_BRIGHT);

byteBuffer.close();

//render map data
stack.pushPose();
//these transformations are very important, otherwise icons render behind the map graphics
Comment thread
albazavr-alba marked this conversation as resolved.
Expand All @@ -48,11 +60,14 @@ public void render(ItemStack item, GuiGraphics graphics, Minecraft minecraft, Gu
stack.translate(-start, 0.0F, 0.0F);
stack.scale(0.7075F, 0.7075F, -0.7075F);
stack.mulPose(Axis.ZP.rotationDegrees(180.0F));
minecraft.gameRenderer.getMapRenderer().render(stack, graphics.bufferSource(), mapid, data, false, LightTexture.FULL_BRIGHT);
graphics.flush();

minecraft.getMapRenderer().extractRenderState(mapid, data, this.cachedMapRenderState);
minecraft.getMapRenderer().render(this.cachedMapRenderState, stack, new SubmitNodeStorage(), false, FULL_BRIGHT);

stack.popPose();
}


@Override
public DisplayPosition displayPosition() {
return DisplayPosition.TOP;
Expand Down
Loading
Loading