Skip to content

Commit

Permalink
Fixed crash with sodium in production
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocelot5836 committed Jan 2, 2025
1 parent b80a6fc commit 1da7b40
Show file tree
Hide file tree
Showing 25 changed files with 93 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@

import foundry.veil.api.client.necromancer.animation.Animator;

public interface SkeletonParent<P extends SkeletonParent<?,?,?>, S extends Skeleton<P>, A extends Animator<P, S>> {
public interface SkeletonParent<P extends SkeletonParent<?, ?>, S extends Skeleton<P>> {

void setSkeleton(S skeleton);
void setAnimator(A animator);

void setAnimator(Animator<P, S> animator);

S getSkeleton();
A getAnimator();

Animator<P, S> getAnimator();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.world.entity.Entity;

public abstract class NecromancerEntityRenderLayer<T extends Entity & SkeletonParent, M extends Skeleton<T>> {
public abstract class NecromancerEntityRenderLayer<T extends Entity & SkeletonParent<T, M>, M extends Skeleton<T>> {

public NecromancerEntityRenderer<T, M> renderer;

public NecromancerEntityRenderLayer(NecromancerEntityRenderer<T, M> pRenderer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import java.util.function.BiFunction;
import java.util.function.Function;

public abstract class NecromancerEntityRenderer<T extends Entity & SkeletonParent, M extends Skeleton<T>> extends EntityRenderer<T> {
public abstract class NecromancerEntityRenderer<T extends Entity & SkeletonParent<T, M>, M extends Skeleton<T>> extends EntityRenderer<T> {

final Function<T, M> skeletonFactory;
final BiFunction<T, M, Animator<T, M>> animatorFactory;
final List<NecromancerEntityRenderLayer<T, M>> layers;
Expand All @@ -42,13 +43,14 @@ public void addLayer(NecromancerEntityRenderLayer<T, M> layer) {
}

public void setupEntity(T entity) {
M skeleton = skeletonFactory.apply(entity);
M skeleton = this.skeletonFactory.apply(entity);
entity.setSkeleton(skeleton);
entity.setAnimator(animatorFactory.apply(entity, skeleton));
entity.setAnimator(this.animatorFactory.apply(entity, skeleton));
}

public abstract Skin<M> getSkin(T parent);

@Override
public void render(T pEntity, float pEntityYaw, float pPartialTicks, PoseStack poseStack, MultiBufferSource pBuffer, int pPackedLight) {
poseStack.pushPose();
float scale = 1.0F / 16.0F;
Expand All @@ -61,15 +63,17 @@ public void render(T pEntity, float pEntityYaw, float pPartialTicks, PoseStack p
boolean shouldRender = !invisible;

RenderType rendertype = this.getRenderType(pEntity, this.getTextureLocation(pEntity));
M skeleton = (M) pEntity.getSkeleton();
M skeleton = pEntity.getSkeleton();
Skin<M> skin = this.getSkin(pEntity);

if (shouldRender && skeleton != null && skin != null ) {
renderSkin(pEntity, skeleton, skin, pEntity.tickCount, pPartialTicks, poseStack, pBuffer.getBuffer(rendertype), pPackedLight, this.getOverlayCoords(pEntity), 1, 1, 1, 1);
if (shouldRender && skeleton != null && skin != null) {
this.renderSkin(pEntity, skeleton, skin, pEntity.tickCount, pPartialTicks, poseStack, pBuffer.getBuffer(rendertype), pPackedLight, this.getOverlayCoords(pEntity), 1, 1, 1, 1);
}

if (!pEntity.isSpectator() && rendertype != null && skeleton != null) {
for (NecromancerEntityRenderLayer<T, M> layer : this.layers) layer.render(poseStack, pBuffer, pPackedLight, pEntity, skeleton, pPartialTicks);
for (NecromancerEntityRenderLayer<T, M> layer : this.layers) {
layer.render(poseStack, pBuffer, pPackedLight, pEntity, skeleton, pPartialTicks);
}
}

poseStack.popPose();
Expand All @@ -88,7 +92,9 @@ public void renderSkin(T entity, M skeleton, Skin<M> skin, int ticksExisted, flo

protected RenderType getRenderType(T pLivingEntity, boolean visible, boolean spectator, boolean glowing) {
ResourceLocation texture = this.getTextureLocation(pLivingEntity);
if (!visible) return null;
if (!visible) {
return null;
}
return this.getRenderType(pLivingEntity, texture);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public Skin() {
}

public void addMesh(String boneID, Mesh mesh) {
meshes.put(boneID, mesh);
this.meshes.put(boneID, mesh);
}

public Mesh getMesh(Bone bone) {
return meshes.getOrDefault(bone.identifier, Mesh.EMPTY);
return this.meshes.getOrDefault(bone.identifier, Mesh.EMPTY);
}

public void render(T skeleton, int ticksExisted, float partialTick, PoseStack pPoseStack, VertexConsumer pVertexConsumer, int pPackedLight, int pPackedOverlay, float pRed, float pGreen, float pBlue, float pAlpha) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public CubeMesh(int textureWidth, int textureHeight) {
super();
this.textureWidth = textureWidth;
this.textureHeight = textureHeight;
faces = new ArrayList<>();
this.faces = new ArrayList<>();
}

public Face[] addCube(float xSize, float ySize, float zSize, float xOffset, float yOffset, float zOffset, float xInflate, float yInflate, float zInflate, float uOffset, float vOffset) {
Expand Down Expand Up @@ -68,21 +68,21 @@ public Face[] addCube(float xSize, float ySize, float zSize, float xOffset, floa
float v1 = vOffset + Mth.floor(zSize);
float v2 = vOffset + Mth.floor(zSize) + Mth.floor(ySize);

Face[] cubeFaces = {new Face(xoz, ooz, ooo, xoo, u3, v0, u2, v1, textureWidth, textureHeight, mirrored, Direction.UP),
new Face(xyo, oyo, oyz, xyz, u2, v1, u1, v0, textureWidth, textureHeight, mirrored, Direction.DOWN),
new Face(ooo, ooz, oyz, oyo, u4, v2, u2, v1, textureWidth, textureHeight, mirrored, Direction.EAST),
new Face(xoz, xoo, xyo, xyz, u1, v2, u0, v1, textureWidth, textureHeight, mirrored, Direction.WEST),
new Face(ooz, xoz, xyz, oyz, u5, v2, u4, v1, textureWidth, textureHeight, mirrored, Direction.NORTH),
new Face(xoo, ooo, oyo, xyo, u2, v2, u1, v1, textureWidth, textureHeight, mirrored, Direction.SOUTH)};
Face[] cubeFaces = {new Face(xoz, ooz, ooo, xoo, u3, v0, u2, v1, this.textureWidth, this.textureHeight, mirrored, Direction.UP),
new Face(xyo, oyo, oyz, xyz, u2, v1, u1, v0, this.textureWidth, this.textureHeight, mirrored, Direction.DOWN),
new Face(ooo, ooz, oyz, oyo, u4, v2, u2, v1, this.textureWidth, this.textureHeight, mirrored, Direction.EAST),
new Face(xoz, xoo, xyo, xyz, u1, v2, u0, v1, this.textureWidth, this.textureHeight, mirrored, Direction.WEST),
new Face(ooz, xoz, xyz, oyz, u5, v2, u4, v1, this.textureWidth, this.textureHeight, mirrored, Direction.NORTH),
new Face(xoo, ooo, oyo, xyo, u2, v2, u1, v1, this.textureWidth, this.textureHeight, mirrored, Direction.SOUTH)};

Collections.addAll(faces, cubeFaces);
Collections.addAll(this.faces, cubeFaces);

return cubeFaces;
}

public Face addTri(float x1, float y1, float z1, float u1, float v1, float x2, float y2, float z2, float u2, float v2, float x3, float y3, float z3, float u3, float v3, float normalX, float normalY, float normalZ) {
Face face = new Face(new Vertex[]{new Vertex(x1, y1, z1), new Vertex(x2, y2, z2), new Vertex(x2, y2, z2)}, new UV[]{new UV(u1, v1), new UV(u2, v2), new UV(u3, v3)}, new Vector3f(normalX, normalY, normalZ));
faces.add(face);
this.faces.add(face);
return face;
}

Expand All @@ -95,7 +95,7 @@ public Face addFace(float normalX, float normalY, float normalZ, FaceVertex... v
uvArray[i] = new UV(vertex.u() / (float)this.textureWidth, vertex.v() / (float)this.textureHeight);
}
Face face = new Face(vertArray, uvArray, new Vector3f(normalX, normalY, normalZ));
faces.add(face);
this.faces.add(face);
return face;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void render(PoseStack pPoseStack, VertexConsumer pVertexConsumer, int pPa

protected record Vertex(float x, float y, float z) {}
protected record UV(float u, float v) {}
protected static class Face {
public static class Face {
protected final Vertex[] vertices;
protected final UV[] uvs;
protected final Vector3f normal;
Expand Down
51 changes: 5 additions & 46 deletions common/src/main/java/foundry/veil/api/client/util/UIUtils.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package foundry.veil.api.client.util;

import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.platform.Lighting;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.*;
import com.mojang.datafixers.util.Either;
Expand All @@ -13,25 +11,19 @@
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.locale.Language;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.FormattedText;
import net.minecraft.network.chat.Style;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.inventory.tooltip.TooltipComponent;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;
import org.joml.Matrix4f;
import org.joml.Matrix4fStack;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand All @@ -45,8 +37,7 @@ public static void drawHoverText(Tooltippable tooltippable, float pticks, final
return;
}

List<ClientTooltipComponent> list = gatherTooltipComponents(stack, textLines,
stack.getTooltipImage(), mouseX, screenWidth, screenHeight, font, font);
List<ClientTooltipComponent> list = gatherTooltipComponents(stack, textLines, stack.getTooltipImage().orElse(null), mouseX, screenWidth, screenHeight, font, font);
// RenderSystem.disableRescaleNormal();
RenderSystem.disableDepthTest();
int tooltipTextWidth = 0;
Expand Down Expand Up @@ -198,13 +189,14 @@ public static void tryRenderGuiItem(@Nullable LivingEntity $$0, ItemStack $$1, f
tryRenderGuiItem($$0, $$1, $$2, $$3, $$4, 0);
}

public static List<ClientTooltipComponent> gatherTooltipComponents(ItemStack stack, List<? extends FormattedText> textElements, Optional<TooltipComponent> itemComponent, int mouseX, int screenWidth, int screenHeight, @Nullable Font forcedFont, Font fallbackFont) {
public static List<ClientTooltipComponent> gatherTooltipComponents(ItemStack stack, List<? extends FormattedText> textElements, @Nullable TooltipComponent itemComponent, int mouseX, int screenWidth, int screenHeight, @Nullable Font forcedFont, Font fallbackFont) {
Font font = forcedFont != null ? forcedFont : fallbackFont;
List<Either<FormattedText, TooltipComponent>> elements = textElements.stream()
.map((Function<FormattedText, Either<FormattedText, TooltipComponent>>) Either::left)
.collect(Collectors.toCollection(ArrayList::new));
itemComponent.ifPresent(c -> elements.add(1, Either.right(c)));

if (itemComponent != null) {
elements.add(1, Either.right(itemComponent));
}

// text wrapping
int tooltipTextWidth = elements.stream()
Expand Down Expand Up @@ -317,37 +309,4 @@ public static void tryRenderGuiItem(LivingEntity $$0, ItemStack $$1, float $$2,
// Minecraft.getInstance().getItemRenderer().blitOffset = $$6.isGui3d() ? Minecraft.getInstance().getItemRenderer().blitOffset - 50.0F - (float) $$5 : Minecraft.getInstance().getItemRenderer().blitOffset - 50.0F;
// }
}

public static void renderGuiItem(ItemStack stack, float x, float y, BakedModel bakedModel) {
Minecraft.getInstance().getTextureManager().getTexture(TextureAtlas.LOCATION_BLOCKS).setFilter(false, false);
RenderSystem.setShaderTexture(0, TextureAtlas.LOCATION_BLOCKS);
RenderSystem.enableBlend();
RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
Matrix4fStack $$4 = RenderSystem.getModelViewStack();
$$4.pushMatrix();
// $$4.translate((double) x, (double) y, (double) (100.0F + Minecraft.getInstance().getItemRenderer().blitOffset));
$$4.translate(8, 8, 0);
$$4.scale(1.0F, -1.0F, 1.0F);
$$4.scale(16.0F, 16.0F, 16.0F);
RenderSystem.applyModelViewMatrix();
PoseStack $$5 = new PoseStack();
MultiBufferSource.BufferSource $$6 = Minecraft.getInstance().renderBuffers().bufferSource();
boolean $$7 = !bakedModel.usesBlockLight();
if ($$7) {
Lighting.setupForFlatItems();
} else {
Lighting.setupFor3DItems();
}

Minecraft.getInstance().getItemRenderer().render(stack, ItemDisplayContext.GUI, false, $$5, $$6, 15728880, OverlayTexture.NO_OVERLAY, bakedModel);
$$6.endBatch();
RenderSystem.enableDepthTest();
if ($$7) {
Lighting.setupFor3DItems();
}

$$4.popMatrix();
RenderSystem.applyModelViewMatrix();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void endOpaque(CallbackInfo ci) {
VeilRenderSystem.renderer().getDynamicBufferManger().setEnabled(false);
}

@Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lit/unimi/dsi/fastutil/longs/Long2ObjectMap;long2ObjectEntrySet()Lit/unimi/dsi/fastutil/objects/ObjectSet;", shift = At.Shift.BEFORE))
@Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lit/unimi/dsi/fastutil/longs/Long2ObjectMap;long2ObjectEntrySet()Lit/unimi/dsi/fastutil/objects/ObjectSet;", shift = At.Shift.BEFORE, remap = false))
public void beginTranslucent(CallbackInfo ci) {
VeilRenderSystem.renderer().getDynamicBufferManger().setEnabled(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void unbindGuiCamera(CallbackInfo ci) {
VeilRenderSystem.renderer().getGuiInfo().unbind();
}

@Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;clear(IZ)V", shift = At.Shift.BEFORE))
@Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;clear(IZ)V", shift = At.Shift.BEFORE, remap = false))
public void bindFirstPerson(CallbackInfo ci) {
VeilFirstPersonRenderer.bind();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void setRainBlend(CallbackInfo ci) {
}

// Add custom world border shader
@ModifyArg(method = "renderWorldBorder", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;setShader(Ljava/util/function/Supplier;)V"))
@ModifyArg(method = "renderWorldBorder", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;setShader(Ljava/util/function/Supplier;)V", remap = false))
public Supplier<ShaderInstance> setWorldBorderShader(Supplier<ShaderInstance> supplier) {
return VeilVanillaShaders::getWorldborder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class MinecraftMixin {

@Inject(method = "runTick", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/pipeline/RenderTarget;bindWrite(Z)V"), slice = @Slice(
from = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;clear(IZ)V"),
from = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;clear(IZ)V", remap = false),
to = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GameRenderer;render(Lnet/minecraft/client/DeltaTracker;Z)V")))
public void beginFrame(CallbackInfo ci) {
VeilRenderSystem.beginFrame();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ParticleRenderTypeMixin {
*
* @author Ocelot
*/
@Redirect(method = "begin", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;defaultBlendFunc()V"))
@Redirect(method = "begin", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;defaultBlendFunc()V", remap = false))
public void changeBlendFunction() {
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void drawPatches(CallbackInfo ci) {
}
}

@ModifyArg(method = "draw", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;drawElements(III)V"), index = 0)
@ModifyArg(method = "draw", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;drawElements(III)V", remap = false), index = 0)
public int modifyDrawMode(int glMode) {
return this.veil$getDrawMode(glMode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
@Mixin(Window.class)
public class WindowMixin {

@ModifyArg(method = "<init>", at = @At(value = "INVOKE", target = "Lorg/lwjgl/glfw/GLFW;glfwWindowHint(II)V", ordinal = 2), index = 1)
@ModifyArg(method = "<init>", at = @At(value = "INVOKE", target = "Lorg/lwjgl/glfw/GLFW;glfwWindowHint(II)V", ordinal = 2, remap = false), index = 1)
public int captureMajorVersion(int hint, @Share("majorGLVersion") LocalIntRef majorGLVersion) {
majorGLVersion.set(hint);
return hint;
}

@ModifyArg(method = "<init>", at = @At(value = "INVOKE", target = "Lorg/lwjgl/glfw/GLFW;glfwWindowHint(II)V", ordinal = 3), index = 1)
@ModifyArg(method = "<init>", at = @At(value = "INVOKE", target = "Lorg/lwjgl/glfw/GLFW;glfwWindowHint(II)V", ordinal = 3, remap = false), index = 1)
public int captureMinorVersion(int hint, @Share("majorGLVersion") LocalIntRef majorGLVersion) {
return majorGLVersion.get() == 3 ? Math.max(3, hint) : hint;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
@Mixin(Minecraft.class)
public class MinecraftMixin {

@ModifyArg(method = "<init>", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;initRenderer(IZ)V"), index = 0)
@ModifyArg(method = "<init>", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;initRenderer(IZ)V", remap = false), index = 0)
private int modifyDebugVerbosity(int debugVerbosity) {
return Veil.DEBUG ? 100 : debugVerbosity;
}

@ModifyArg(method = "<init>", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;initRenderer(IZ)V"), index = 1)
@ModifyArg(method = "<init>", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;initRenderer(IZ)V", remap = false), index = 1)
private boolean modifySynchronousDebug(boolean synchronous) {
return synchronous || Veil.DEBUG;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void init(CallbackInfo ci) {
FabricVeilRegisterFixedBuffersEvent.EVENT.invoker().onRegisterFixedBuffers(FabricRenderTypeStageHandler::register);
}

@Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;setupDefaultState(IIII)V"))
@Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;setupDefaultState(IIII)V", remap = false))
public void registerBlockLayers(CallbackInfo ci) {
ImmutableList.Builder<RenderType> blockLayers = ImmutableList.builder();
FabricVeilRegisterBlockLayersEvent.EVENT.invoker().onRegisterBlockLayers(renderType -> {
Expand Down
Loading

0 comments on commit 1da7b40

Please sign in to comment.