fix #294
This commit is contained in:
parent
dd6c871d3d
commit
5920e0b9a4
4 changed files with 44 additions and 36 deletions
|
@ -10,6 +10,7 @@ import at.petrak.hexcasting.api.utils.NBTHelper;
|
|||
import at.petrak.hexcasting.client.be.BlockEntityAkashicBookshelfRenderer;
|
||||
import at.petrak.hexcasting.client.be.BlockEntitySlateRenderer;
|
||||
import at.petrak.hexcasting.client.entity.WallScrollRenderer;
|
||||
import at.petrak.hexcasting.client.gui.PatternTooltipComponent;
|
||||
import at.petrak.hexcasting.common.blocks.akashic.BlockAkashicBookshelf;
|
||||
import at.petrak.hexcasting.common.blocks.akashic.BlockEntityAkashicBookshelf;
|
||||
import at.petrak.hexcasting.common.entities.HexEntities;
|
||||
|
@ -23,6 +24,7 @@ import at.petrak.hexcasting.common.lib.HexItems;
|
|||
import at.petrak.hexcasting.xplat.IClientXplatAbstractions;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.color.block.BlockColor;
|
||||
import net.minecraft.client.color.item.ItemColor;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
|
@ -32,6 +34,7 @@ import net.minecraft.core.Direction;
|
|||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.network.chat.TextColor;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
@ -132,6 +135,14 @@ public class RegisterClientStuff {
|
|||
}
|
||||
return HexIotaTypes.getColor(iotaTag);
|
||||
}, HexBlocks.AKASHIC_BOOKSHELF);
|
||||
|
||||
for (var tex : new ResourceLocation[]{
|
||||
PatternTooltipComponent.PRISTINE_BG,
|
||||
PatternTooltipComponent.ANCIENT_BG,
|
||||
PatternTooltipComponent.SLATE_BG
|
||||
}) {
|
||||
Minecraft.getInstance().getTextureManager().bindForSetup(tex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,9 +5,9 @@ import at.petrak.hexcasting.client.RenderLib;
|
|||
import at.petrak.hexcasting.common.misc.PatternTooltip;
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.*;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.GuiComponent;
|
||||
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.client.renderer.entity.ItemRenderer;
|
||||
|
@ -19,17 +19,21 @@ import org.jetbrains.annotations.Nullable;
|
|||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static at.petrak.hexcasting.api.HexAPI.modLoc;
|
||||
|
||||
// https://github.com/VazkiiMods/Botania/blob/95bd2d3fbc857b7c102687554e1d1b112f8af436/Xplat/src/main/java/vazkii/botania/client/gui/ManaBarTooltipComponent.java
|
||||
// yoink
|
||||
public class PatternTooltipComponent implements ClientTooltipComponent {
|
||||
public static final ResourceLocation PRISTINE_BG = new ResourceLocation(
|
||||
"hexcasting:textures/gui/scroll.png");
|
||||
public static final ResourceLocation ANCIENT_BG = new ResourceLocation(
|
||||
"hexcasting:textures/gui/scroll_ancient.png");
|
||||
public static final ResourceLocation SLATE_BG = new ResourceLocation(
|
||||
"hexcasting:textures/gui/slate.png");
|
||||
|
||||
private static final float SIZE = 72f;
|
||||
/**
|
||||
* @see PatternTooltip the associated data for this
|
||||
*/
|
||||
public class PatternTooltipComponent implements ClientTooltipComponent {
|
||||
public static final ResourceLocation PRISTINE_BG = modLoc("textures/gui/scroll.png");
|
||||
public static final ResourceLocation ANCIENT_BG = modLoc("textures/gui/scroll_ancient.png");
|
||||
public static final ResourceLocation SLATE_BG = modLoc("textures/gui/slate.png");
|
||||
|
||||
private static final float RENDER_SIZE = 72f;
|
||||
private static final float TEXTURE_SIZE = 48f;
|
||||
|
||||
private final HexPattern pattern;
|
||||
private final List<Vec2> zappyPoints;
|
||||
|
@ -41,7 +45,7 @@ public class PatternTooltipComponent implements ClientTooltipComponent {
|
|||
this.pattern = tt.pattern();
|
||||
this.background = tt.background();
|
||||
|
||||
var pair = RenderLib.getCenteredPattern(pattern, SIZE, SIZE, 8f);
|
||||
var pair = RenderLib.getCenteredPattern(pattern, RENDER_SIZE, RENDER_SIZE, 8f);
|
||||
this.scale = pair.getFirst();
|
||||
var dots = pair.getSecond();
|
||||
this.zappyPoints = RenderLib.makeZappy(dots, RenderLib.findDupIndices(pattern.positions()), 10f, 0.8f, 0f, 0f);
|
||||
|
@ -58,7 +62,7 @@ public class PatternTooltipComponent implements ClientTooltipComponent {
|
|||
|
||||
@Override
|
||||
public void renderImage(Font font, int mouseX, int mouseY, PoseStack ps, ItemRenderer pItemRenderer,
|
||||
int pBlitOffset) {
|
||||
int pBlitOffset) {
|
||||
var width = this.getWidth(font);
|
||||
var height = this.getHeight();
|
||||
|
||||
|
@ -66,7 +70,7 @@ public class PatternTooltipComponent implements ClientTooltipComponent {
|
|||
ps.pushPose();
|
||||
ps.translate(mouseX, mouseY, 500);
|
||||
RenderSystem.enableBlend();
|
||||
renderBG(ps, this.background);
|
||||
renderBG(ps, this.background, pBlitOffset);
|
||||
|
||||
// renderText happens *before* renderImage for some asinine reason
|
||||
// RenderSystem.disableBlend();
|
||||
|
@ -75,7 +79,7 @@ public class PatternTooltipComponent implements ClientTooltipComponent {
|
|||
RenderSystem.setShader(GameRenderer::getPositionColorShader);
|
||||
RenderSystem.disableCull();
|
||||
RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA,
|
||||
GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
|
||||
GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
|
||||
ps.translate(width / 2f, height / 2f, 1);
|
||||
|
||||
var mat = ps.last().pose();
|
||||
|
@ -83,9 +87,9 @@ public class PatternTooltipComponent implements ClientTooltipComponent {
|
|||
var innerLight = 0xc8_aba2a2;
|
||||
var innerDark = 0xc8_322b33;
|
||||
RenderLib.drawLineSeq(mat, this.zappyPoints, 5f, 0,
|
||||
outer, outer);
|
||||
outer, outer);
|
||||
RenderLib.drawLineSeq(mat, this.zappyPoints, 2f, 0,
|
||||
innerDark, innerLight);
|
||||
innerDark, innerLight);
|
||||
RenderLib.drawSpot(mat, this.zappyPoints.get(0), 2.5f, 1f, 0.1f, 0.15f, 0.6f);
|
||||
|
||||
for (var dot : this.pathfinderDots) {
|
||||
|
@ -95,31 +99,21 @@ public class PatternTooltipComponent implements ClientTooltipComponent {
|
|||
ps.popPose();
|
||||
}
|
||||
|
||||
private static void renderBG(PoseStack ps, ResourceLocation background) {
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
private static void renderBG(PoseStack ps, ResourceLocation background, int blitOffset) {
|
||||
RenderSystem.setShaderColor(1f, 1f, 1f, 1f);
|
||||
RenderSystem.setShaderTexture(0, background);
|
||||
|
||||
|
||||
// i wish i liked mobius front enough ot get to the TIS puzzles
|
||||
BufferBuilder buffer = Tesselator.getInstance().getBuilder();
|
||||
Matrix4f neo = ps.last().pose();
|
||||
|
||||
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX);
|
||||
buffer.vertex(neo, 0, 0, 0.0F).uv(0.0F, 0.0F).endVertex();
|
||||
buffer.vertex(neo, 0, SIZE, 0.0F).uv(0.0F, 1.0f).endVertex();
|
||||
buffer.vertex(neo, SIZE, SIZE, 0.0F).uv(1.0F, 1.0f).endVertex();
|
||||
buffer.vertex(neo, SIZE, 0, 0.0F).uv(1.0F, 0.0F).endVertex();
|
||||
BufferUploader.draw(buffer.end());
|
||||
// x y blitoffset sw sh w h ... ?
|
||||
// parchment doesn't have this mapped
|
||||
GuiComponent.blit(ps, 0, 0, blitOffset, 0f, 0f, (int) RENDER_SIZE, (int) RENDER_SIZE, (int) RENDER_SIZE, (int) RENDER_SIZE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth(Font pFont) {
|
||||
return (int) SIZE;
|
||||
return (int) RENDER_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return (int) SIZE;
|
||||
return (int) RENDER_SIZE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ public class ItemScroll extends Item implements IotaHolderItem {
|
|||
var ancientId = NBTHelper.getString(pStack, TAG_OP_ID);
|
||||
if (ancientId != null) {
|
||||
return Component.translatable(descID + ".of",
|
||||
Component.translatable("hexcasting.spell." + ResourceLocation.tryParse(ancientId)));
|
||||
Component.translatable("hexcasting.spell." + ResourceLocation.tryParse(ancientId)));
|
||||
} else if (NBTHelper.hasCompound(pStack, TAG_PATTERN)) {
|
||||
return Component.translatable(descID);
|
||||
} else {
|
||||
|
@ -137,9 +137,10 @@ public class ItemScroll extends Item implements IotaHolderItem {
|
|||
if (compound != null) {
|
||||
var pattern = HexPattern.fromNBT(compound);
|
||||
return Optional.of(new PatternTooltip(
|
||||
pattern,
|
||||
NBTHelper.hasString(stack,
|
||||
ItemScroll.TAG_OP_ID) ? PatternTooltipComponent.ANCIENT_BG : PatternTooltipComponent.PRISTINE_BG));
|
||||
pattern,
|
||||
NBTHelper.hasString(stack, ItemScroll.TAG_OP_ID)
|
||||
? PatternTooltipComponent.ANCIENT_BG
|
||||
: PatternTooltipComponent.PRISTINE_BG));
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
|
|
|
@ -6,6 +6,8 @@ import net.minecraft.world.inventory.tooltip.TooltipComponent;
|
|||
|
||||
/**
|
||||
* Used for displaying patterns on the tooltips for scrolls and slates.
|
||||
*
|
||||
* @see at.petrak.hexcasting.client.gui.PatternTooltipComponent the client-side renderer for this
|
||||
*/
|
||||
public record PatternTooltip(HexPattern pattern, ResourceLocation background) implements TooltipComponent {
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue