Skip to content

Commit

Permalink
[wip] the rest of the owl
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamefrede committed Dec 12, 2023
1 parent 85ef344 commit 8108c6c
Show file tree
Hide file tree
Showing 82 changed files with 353 additions and 324 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import com.mojang.blaze3d.vertex.PoseStack;

import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -70,7 +71,7 @@ public void setCrashData(CompiledSpell spell, SpellPiece piece) {

@Override
@OnlyIn(Dist.CLIENT)
public void renderTooltip(PoseStack ms, int x, int y, List<Component> tooltipData, int color, int color2, int width, int height) {
public void renderTooltip(GuiGraphics graphics, int x, int y, List<Component> tooltipData, int color, int color2, int width, int height) {
// NO-OP
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import com.mojang.blaze3d.vertex.PoseStack;

import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -70,7 +71,7 @@ public interface IInternalMethodHandler {
* Renders a tooltip with the specified colors at the given x,y position
*/
@OnlyIn(Dist.CLIENT)
void renderTooltip(PoseStack ms, int x, int y, List<Component> tooltipData, int color, int color2, int width, int height);
void renderTooltip(GuiGraphics graphics, int x, int y, List<Component> tooltipData, int color, int color2, int width, int height);

/**
* Creates a CAD with the given components
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/vazkii/psi/api/spell/Spell.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import com.mojang.blaze3d.vertex.PoseStack;

import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
Expand Down Expand Up @@ -46,8 +47,8 @@ public Spell() {
}

@OnlyIn(Dist.CLIENT)
public void draw(PoseStack ms, MultiBufferSource buffers, int light) {
grid.draw(ms, buffers, light);
public void draw(GuiGraphics graphics, MultiBufferSource buffers, int light) {
grid.draw(graphics, buffers, light);
}

@Nullable
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/vazkii/psi/api/spell/SpellGrid.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.google.common.collect.Multimap;
import com.mojang.blaze3d.vertex.PoseStack;

import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
Expand Down Expand Up @@ -45,15 +46,15 @@ public final class SpellGrid {
private int leftmost, rightmost, topmost, bottommost;

@OnlyIn(Dist.CLIENT)
public void draw(PoseStack ms, MultiBufferSource buffers, int light) {
public void draw(GuiGraphics graphics, MultiBufferSource buffers, int light) {
for(int i = 0; i < GRID_SIZE; i++) {
for(int j = 0; j < GRID_SIZE; j++) {
SpellPiece p = gridData[i][j];
if(p != null) {
ms.pushPose();
ms.translate(i * 18, j * 18, 0);
p.draw(ms, buffers, light);
ms.popPose();
graphics.pose().pushPose();
graphics.pose().translate(i * 18, j * 18, 0);
p.draw(graphics, buffers, light);
graphics.pose().popPose();
}
}
}
Expand Down
51 changes: 26 additions & 25 deletions src/main/java/vazkii/psi/api/spell/SpellPiece.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.mojang.blaze3d.vertex.VertexFormat;

import net.minecraft.ChatFormatting;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
Expand Down Expand Up @@ -279,19 +280,19 @@ public void setStatLabel(EnumSpellStat type, StatLabel descriptor) {
* To avoid z-fighting in the TE projection, translations are applied every step.
*/
@OnlyIn(Dist.CLIENT)
public void draw(PoseStack ms, MultiBufferSource buffers, int light) {
ms.pushPose();
drawBackground(ms, buffers, light);
ms.translate(0F, 0F, 0.1F);
drawAdditional(ms, buffers, light);
public void draw(GuiGraphics graphics, MultiBufferSource buffers, int light) {
graphics.pose().pushPose();
drawBackground(graphics, buffers, light);
graphics.pose().translate(0F, 0F, 0.1F);
drawAdditional(graphics, buffers, light);
if(isInGrid) {
ms.translate(0F, 0F, 0.1F);
drawParams(ms, buffers, light);
ms.translate(0F, 0F, 0.1F);
drawComment(ms, buffers, light);
graphics.pose().translate(0F, 0F, 0.1F);
drawParams(graphics, buffers, light);
graphics.pose().translate(0F, 0F, 0.1F);
drawComment(graphics, buffers, light);
}

ms.popPose();
graphics.pose().popPose();
}

@OnlyIn(Dist.CLIENT)
Expand Down Expand Up @@ -319,10 +320,10 @@ public static RenderType getLayer() {
* Draws this piece's background.
*/
@OnlyIn(Dist.CLIENT)
public void drawBackground(PoseStack ms, MultiBufferSource buffers, int light) {
public void drawBackground(GuiGraphics graphics, MultiBufferSource buffers, int light) {
Material material = ClientPsiAPI.getSpellPieceMaterial(registryKey);
VertexConsumer buffer = material.buffer(buffers, ignored -> getLayer());
Matrix4f mat = ms.last().pose();
Matrix4f mat = graphics.pose().last().pose();
// Cannot call .texture() on the chained object because SpriteAwareVertexBuilder is buggy
// and does not return itself, it returns the inner buffer
// This leads to .texture() using the implementation of the inner buffer,
Expand All @@ -346,15 +347,15 @@ public void drawBackground(PoseStack ms, MultiBufferSource buffers, int light) {
* to draw the lines.
*/
@OnlyIn(Dist.CLIENT)
public void drawAdditional(PoseStack ms, MultiBufferSource buffers, int light) {
public void drawAdditional(GuiGraphics graphics, MultiBufferSource buffers, int light) {
// NO-OP
}

/**
* Draws the little comment indicator in this piece, if one exists.
*/
@OnlyIn(Dist.CLIENT)
public void drawComment(PoseStack ms, MultiBufferSource buffers, int light) {
public void drawComment(GuiGraphics graphics, MultiBufferSource buffers, int light) {
if(comment != null && !comment.isEmpty()) {
VertexConsumer buffer = buffers.getBuffer(PsiAPI.internalHandler.getProgrammerLayer());

Expand All @@ -363,7 +364,7 @@ public void drawComment(PoseStack ms, MultiBufferSource buffers, int light) {
float minV = 184 / 256F;
float maxU = (150 + wh) / 256F;
float maxV = (184 + wh) / 256F;
Matrix4f mat = ms.last().pose();
Matrix4f mat = graphics.pose().last().pose();

buffer.vertex(mat, -2, 4, 0).color(1F, 1F, 1F, 1F).uv(minU, maxV).uv2(light).endVertex();
buffer.vertex(mat, 4, 4, 0).color(1F, 1F, 1F, 1F).uv(maxU, maxV).uv2(light).endVertex();
Expand All @@ -376,15 +377,15 @@ public void drawComment(PoseStack ms, MultiBufferSource buffers, int light) {
* Draws the parameters coming into this piece.
*/
@OnlyIn(Dist.CLIENT)
public void drawParams(PoseStack ms, MultiBufferSource buffers, int light) {
public void drawParams(GuiGraphics graphics, MultiBufferSource buffers, int light) {
VertexConsumer buffer = buffers.getBuffer(PsiAPI.internalHandler.getProgrammerLayer());
for(SpellParam<?> param : paramSides.keySet()) {
drawParam(ms, buffer, light, param);
drawParam(graphics, buffer, light, param);
}
}

@OnlyIn(Dist.CLIENT)
public void drawParam(PoseStack ms, VertexConsumer buffer, int light, SpellParam<?> param) {
public void drawParam(GuiGraphics graphics, VertexConsumer buffer, int light, SpellParam<?> param) {
SpellParam.Side side = paramSides.get(param);
if(!side.isEnabled() || param.getArrowType() == ArrowType.NONE) {
return;
Expand All @@ -405,11 +406,11 @@ public void drawParam(PoseStack ms, VertexConsumer buffer, int light, SpellParam
if(count > 1) {
percent = (float) index / (count - 1);
}
drawParam(ms, buffer, light, side, param.color, param.getArrowType(), percent);
drawParam(graphics, buffer, light, side, param.color, param.getArrowType(), percent);
}

@OnlyIn(Dist.CLIENT)
public void drawParam(PoseStack ms, VertexConsumer buffer, int light, SpellParam.Side side, int color, SpellParam.ArrowType arrowType, float percent) {
public void drawParam(GuiGraphics graphics, VertexConsumer buffer, int light, SpellParam.Side side, int color, SpellParam.ArrowType arrowType, float percent) {
if(arrowType == ArrowType.NONE) {
return;
}
Expand All @@ -432,7 +433,7 @@ public void drawParam(PoseStack ms, VertexConsumer buffer, int light, SpellParam
int g = PsiRenderHelper.g(color);
int b = PsiRenderHelper.b(color);
int a = 255;
Matrix4f mat = ms.last().pose();
Matrix4f mat = graphics.pose().last().pose();

buffer.vertex(mat, minX, maxY, 0).color(r, g, b, a).uv(minU, maxV).uv2(light).endVertex();
buffer.vertex(mat, maxX, maxY, 0).color(r, g, b, a).uv(maxU, maxV).uv2(light).endVertex();
Expand Down Expand Up @@ -470,16 +471,16 @@ public int getParamArrowIndex(SpellParam<?> param) {
* Draws this piece's tooltip.
*/
@OnlyIn(Dist.CLIENT)
public void drawTooltip(PoseStack ms, int tooltipX, int tooltipY, List<Component> tooltip, Screen screen) {
PsiAPI.internalHandler.renderTooltip(ms, tooltipX, tooltipY, tooltip, 0x505000ff, 0xf0100010, screen.width, screen.height);
public void drawTooltip(GuiGraphics graphics, int tooltipX, int tooltipY, List<Component> tooltip, Screen screen) {
PsiAPI.internalHandler.renderTooltip(graphics, tooltipX, tooltipY, tooltip, 0x505000ff, 0xf0100010, screen.width, screen.height);
}

/**
* Draws this piece's comment tooltip.
*/
@OnlyIn(Dist.CLIENT)
public void drawCommentText(PoseStack ms, int tooltipX, int tooltipY, List<Component> commentText, Screen screen) {
PsiAPI.internalHandler.renderTooltip(ms, tooltipX, tooltipY - 9 - commentText.size() * 10, commentText, 0x5000a000, 0xf0001e00, screen.width, screen.height);
public void drawCommentText(GuiGraphics graphics, int tooltipX, int tooltipY, List<Component> commentText, Screen screen) {
PsiAPI.internalHandler.renderTooltip(graphics, tooltipX, tooltipY - 9 - commentText.size() * 10, commentText, 0x5000a000, 0xf0001e00, screen.width, screen.height);
}

@OnlyIn(Dist.CLIENT)
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/vazkii/psi/client/core/proxy/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,13 @@ private void addCADModels(ModelEvent.RegisterAdditional event) {
event.register(new ResourceLocation(LibMisc.MOD_ID, "item/" + LibItemNames.CAD_EBONY_PSIMETAL));
event.register(new ResourceLocation(LibMisc.MOD_ID, "item/" + LibItemNames.CAD_IVORY_PSIMETAL));
event.register(new ResourceLocation(LibMisc.MOD_ID, "item/" + LibItemNames.CAD_CREATIVE)); //TODO models
ModelBakery.UNREFERENCED_TEXTURES.addAll(ClientPsiAPI.getAllSpellPieceMaterial());
ModelBakery.UNREFERENCED_TEXTURES.add(new Material(ClientPsiAPI.PSI_PIECE_TEXTURE_ATLAS, PieceConnector.LINES_TEXTURE));
//ModelBakery.UNREFERENCED_TEXTURES.addAll(ClientPsiAPI.getAllSpellPieceMaterial());
//ModelBakery.UNREFERENCED_TEXTURES.add(new Material(ClientPsiAPI.PSI_PIECE_TEXTURE_ATLAS, PieceConnector.LINES_TEXTURE));
for (Material spellpieceMaterial:
ClientPsiAPI.getAllSpellPieceMaterial()) {
event.register(spellpieceMaterial.texture());
}
event.register(PieceConnector.LINES_TEXTURE);
}

@Override
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/vazkii/psi/client/gui/GuiCADAssembler.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.mojang.blaze3d.vertex.PoseStack;

import net.minecraft.ChatFormatting;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.network.chat.Component;
Expand Down Expand Up @@ -44,19 +45,19 @@ public GuiCADAssembler(ContainerCADAssembler containerCADAssembler, Inventory in
}

@Override
public void render(PoseStack ms, int x, int y, float pTicks) {
this.renderBackground(ms);
super.render(ms, x, y, pTicks);
this.renderTooltip(ms, x, y);
this.renderComponentHoverEffect(ms, Style.EMPTY, x, y);
public void render(GuiGraphics graphics, int x, int y, float pTicks) {
this.renderBackground(graphics);
super.render(graphics, x, y, pTicks);
this.renderTooltip(graphics, x, y);
//this.renderComponentHoverEffect(ms, Style.EMPTY, x, y); TODO(Kamefrede): 1.20 figure out what this breaks
}

@Override
protected void renderLabels(PoseStack ms, int mouseX, int mouseY) {
protected void renderLabels(GuiGraphics graphics, int mouseX, int mouseY) {
int color = 4210752;

String name = new ItemStack(ModBlocks.cadAssembler).getHoverName().getString();
font.draw(ms, name, imageWidth / 2 - font.width(name) / 2, 10, color);
graphics.drawString(this.font, name, imageWidth / 2 - font.width(name) / 2, 10, color);

ItemStack cad = assembler.getCachedCAD(player);
if(!cad.isEmpty()) {
Expand All @@ -66,27 +67,26 @@ protected void renderLabels(PoseStack ms, int mouseX, int mouseY) {
ICAD cadItem = (ICAD) cad.getItem();
String stats = I18n.get("psimisc.stats");
String s = ChatFormatting.BOLD + stats;
font.drawShadow(ms, s, 213 - font.width(s) / 2f, 32, color);
graphics.drawString(this.font, s, 213 - font.width(s) / 2f, 32, color, true);

for(EnumCADStat stat : EnumCADStat.class.getEnumConstants()) {
s = (Psi.magical ? ChatFormatting.LIGHT_PURPLE : ChatFormatting.AQUA) + I18n.get(stat.getName()) + ChatFormatting.RESET + ": " + cadItem.getStatValue(cad, stat);
font.drawShadow(ms, s, 179, 45 + i * 10, color);
graphics.drawString(this.font, s, 179, 45 + i * 10, color, true);
i++;
}
}
}

@Override
protected void renderBg(PoseStack ms, float partialTicks, int mouseX, int mouseY) {
RenderSystem.setShaderColor(1F, 1F, 1F, 1F);
RenderSystem.setShaderTexture(0, texture);
protected void renderBg(GuiGraphics graphics, float partialTicks, int mouseX, int mouseY) {
graphics.setColor(1F, 1F, 1F, 1F);
int x = (width - imageWidth) / 2;
int y = (height - imageHeight) / 2;
blit(ms, x, y, 0, 0, imageWidth, imageHeight);
graphics.blit(texture, x, y, 0, 0, imageWidth, imageHeight);

for(int i = 0; i < 12; i++) {
if(!assembler.isBulletSlotEnabled(i)) {
blit(ms, x + 17 + i % 3 * 18, y + 57 + i / 3 * 18, 16, imageHeight, 16, 16);
graphics.blit(texture, x + 17 + i % 3 * 18, y + 57 + i / 3 * 18, 16, imageHeight, 16, 16);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/vazkii/psi/client/gui/GuiProgrammer.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTi
tooltip.clear();
graphics.pose().translate(gridLeft, gridTop, 0);
MultiBufferSource.BufferSource buffers = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder());
spell.draw(graphics.pose(), buffers, 0xF000F0);
spell.draw(graphics, buffers, 0xF000F0);
buffers.endBatch();

compileResult.right().ifPresent(ex -> {
Expand Down Expand Up @@ -454,12 +454,12 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTi
}
if(!takingScreenshot && pieceAtCursor != null && mouseMoved) {
if(tooltip != null && !tooltip.isEmpty()) {
pieceAtCursor.drawTooltip(graphics.pose(), mouseX, mouseY, tooltip, this);
pieceAtCursor.drawTooltip(graphics, mouseX, mouseY, tooltip, this);
}

if(comment != null && !comment.isEmpty()) {
List<Component> commentList = Arrays.stream(comment.split(";")).map(Component::literal).collect(Collectors.toList());
pieceAtCursor.drawCommentText(graphics.pose(), mouseX, mouseY, commentList, this);
pieceAtCursor.drawCommentText(graphics, mouseX, mouseY, commentList, this);
}
}

Expand Down
Loading

0 comments on commit 8108c6c

Please sign in to comment.