Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] 1.17 fabric 3rd person render #398

Open
wants to merge 4 commits into
base: 1.17-fabric
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ private void drawMinimap(MatrixStack matrices, int atlasID, VertexConsumerProvid
matrices.push();
matrices.translate(0, 0, 0.01);
Textures.BOOK.drawWithLight(buffer, matrices, 0, 0, (int) (GuiAtlas.WIDTH * 1.5), (int) (GuiAtlas.HEIGHT * 1.5), light);
// Book backside
Textures.BOOK.drawWithLightFlipped(buffer, matrices, 0, 0, (int) (GuiAtlas.WIDTH * 1.5), (int) (GuiAtlas.HEIGHT * 1.5), light);
Copy link
Member

Choose a reason for hiding this comment

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

I guess without NEA this should not be drawn, as nobody would see it anyways

Copy link
Author

Choose a reason for hiding this comment

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

Yea in the current state this is missing these checks since I don't know the way you guys are planning to implement it. When there is no way to see the backside(so no NEA), this can be skipped of cause.

matrices.pop();

matrices.push();
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/hunternif/mc/impl/atlas/client/texture/ATexture.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ public void draw(MatrixStack matrices, int x, int y, int width, int height, int
public void drawWithLight(VertexConsumerProvider consumer, MatrixStack matrices, int x, int y, int width, int height, int light) {
drawWithLight(consumer, matrices, x, y, width, height, 0, 0, this.width(), this.height(), light);
}

public void drawWithLightFlipped(VertexConsumerProvider consumer, MatrixStack matrices, int x, int y, int width, int height, int light) {
drawWithLightFlipped(consumer, matrices, x, y, width, height, 0, 0, this.width(), this.height(), light);
}

public void drawWithLightFlipped(VertexConsumerProvider consumer, MatrixStack matrices, int x, int y, int width, int height, int u, int v, int regionWidth, int regionHeight, int light) {
if (autobind) {
bind();
}
drawTexturedQuadWithLightFlipped(consumer, matrices.peek().getModel(), x, x + width, y, y + height, (u + 0.0F) / (float) this.width(), (u + (float) regionWidth) / (float) this.width(), (v + 0.0F) / (float) this.height(), (v + (float) regionHeight) / (float) this.height(), light);
}

public void drawWithLight(VertexConsumerProvider consumer, MatrixStack matrices, int x, int y, int width, int height, int u, int v, int regionWidth, int regionHeight, int light) {
if (autobind) {
Expand All @@ -79,4 +90,12 @@ private void drawTexturedQuadWithLight(VertexConsumerProvider vertexConsumer, Ma
consumer.vertex(matrices, (float) x1, (float) y0, 0f).color(255, 255, 255, 255).texture(u1, v0).light(light).next();
consumer.vertex(matrices, (float) x0, (float) y0, 0f).color(255, 255, 255, 255).texture(u0, v0).light(light).next();
}

private void drawTexturedQuadWithLightFlipped(VertexConsumerProvider vertexConsumer, Matrix4f matrices, int x0, int x1, int y0, int y1, float u0, float u1, float v0, float v1, int light) {
VertexConsumer consumer = vertexConsumer.getBuffer(this.LAYER);
consumer.vertex(matrices, (float) x0, (float) y0, 0f).color(255, 255, 255, 255).texture(u0, v0).light(light).next();
consumer.vertex(matrices, (float) x1, (float) y0, 0f).color(255, 255, 255, 255).texture(u1, v0).light(light).next();
consumer.vertex(matrices, (float) x1, (float) y1, 0f).color(255, 255, 255, 255).texture(u1, v1).light(light).next();
consumer.vertex(matrices, (float) x0, (float) y1, 0f).color(255, 255, 255, 255).texture(u0, v1).light(light).next();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public interface ITexture {
void draw(MatrixStack matrices, int x, int y, int u, int v, int regionWidth, int regionHeight);

void drawWithLight(VertexConsumerProvider consumer, MatrixStack matrices, int x, int y, int width, int height, int light);

void drawWithLightFlipped(VertexConsumerProvider consumer, MatrixStack matrices, int x, int y, int width, int height, int light);

void drawWithLight(VertexConsumerProvider consumer, MatrixStack matrices, int x, int y, int width, int height, int u, int v, int regionWidth, int regionHeight, int light);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package hunternif.mc.impl.atlas.mixin;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import hunternif.mc.impl.atlas.RegistrarAntiqueAtlas;
import hunternif.mc.impl.atlas.client.OverlayRenderer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.feature.FeatureRenderer;
import net.minecraft.client.render.entity.feature.FeatureRendererContext;
import net.minecraft.client.render.entity.feature.HeldItemFeatureRenderer;
import net.minecraft.client.render.entity.model.EntityModel;
import net.minecraft.client.render.entity.model.ModelWithArms;
import net.minecraft.client.render.model.json.ModelTransformation;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Arm;
import net.minecraft.util.math.Vec3f;


@Mixin(HeldItemFeatureRenderer.class)
public abstract class HeldItemFeatureRendererMixin<T extends LivingEntity, M extends EntityModel<T>>
extends FeatureRenderer<T, M> {

public HeldItemFeatureRendererMixin(FeatureRendererContext<T, M> context) {
super(context);
}

private OverlayRenderer atlasOverlayRenderer = new OverlayRenderer();
private boolean enableBigMaps = false;

@Inject(method = "<init>*", at = @At("RETURN"))
public void constructor(CallbackInfo info) {
try {
Class.forName("dev.tr7zw.notenoughanimations.NEAnimationsLoader");
enableBigMaps = true;
}catch(Exception ex) {
// No "Not Enough Animations" loaded
}
}

@Inject(at = @At("HEAD"), method = "renderItem", cancellable = true)
private void renderItem(LivingEntity entity, ItemStack stack, ModelTransformation.Mode transformationMode, Arm arm,
MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo info) {
if (arm == entity.getMainArm() && entity.getMainHandStack().getItem().equals(RegistrarAntiqueAtlas.ATLAS)) { // Mainhand with or without the offhand
matrices.push();
((ModelWithArms) getContextModel()).setArmAngle(arm, matrices);
matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(-90.0f));
matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(200.0f));
boolean bl = arm.equals(Arm.LEFT);
matrices.translate((double) ((float) (bl ? -1 : 1) / 16.0f), 0.125, -0.625);
renderThirdPersonAtlas(matrices, vertexConsumers, light, stack, !entity.getOffHandStack().isEmpty(), bl);
matrices.pop();
info.cancel();
return;
}
if (arm != entity.getMainArm() && entity.getOffHandStack().getItem().equals(RegistrarAntiqueAtlas.ATLAS)) { // Only offhand
matrices.push();
((ModelWithArms) getContextModel()).setArmAngle(arm, matrices);
Copy link
Member

Choose a reason for hiding this comment

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

I have the very strong feeling, this code redundancy could be refactored away.

Copy link
Author

Choose a reason for hiding this comment

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

That's true, its a bit of a copy and paste job that was different, but now could be refactored since these differences are not there any more.

matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(-90.0f));
matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(200.0f));
boolean bl = arm.equals(Arm.LEFT);
matrices.translate((double) ((float) (bl ? -1 : 1) / 16.0f), 0.125, -0.625);
renderThirdPersonAtlas(matrices, vertexConsumers, light, stack, true, bl);
matrices.pop();
info.cancel();
return;
}
}

private void renderThirdPersonAtlas(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, ItemStack item, boolean smallMap, boolean leftHanded) {
if (smallMap || !enableBigMaps) {
matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(160.0f));
matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(180.0f));
matrices.scale(0.38f/3, 0.38f/3, 0.38f/3);

matrices.translate(-0.8, -3.2, 0.0);
matrices.scale(0.0098125f, 0.0098125f, 0.0098125f);
} else {
if(leftHanded) {
matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(160.0f));
matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(150.0f));
matrices.scale(0.38f/3, 0.38f/3, 0.38f/3);

matrices.translate(0, -3.6, 0.0);
} else {
matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(160.0f));
matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(210.0f));
matrices.scale(0.38f/3, 0.38f/3, 0.38f/3);

matrices.translate(-4.0, -5.0, 0.0);
}

matrices.scale(0.0138125f, 0.0138125f, 0.0138125f);
}

atlasOverlayRenderer.drawOverlay(matrices, vertexConsumers, light, item);
}

}
3 changes: 2 additions & 1 deletion src/main/resources/antiqueatlas.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"MixinClientPlayNetworkHandler",
"MixinInGameHud",
"MixinMinecraftClient",
"HeldItemRendererMixin"
"HeldItemRendererMixin",
"HeldItemFeatureRendererMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down