-
Notifications
You must be signed in to change notification settings - Fork 67
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
base: 1.17-fabric
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.