|
| 1 | +package org.polyfrost.polyhitbox.mixin; |
| 2 | + |
| 3 | +import dev.deftu.omnicore.api.client.OmniClient; |
| 4 | +import dev.deftu.omnicore.api.client.render.stack.OmniMatrixStack; |
| 5 | +import dev.deftu.omnicore.api.client.render.stack.OmniMatrixStacks; |
| 6 | +import dev.deftu.omnicore.api.data.vec.OmniVec3d; |
| 7 | +import dev.deftu.omnicore.api.entity.OmniEntities; |
| 8 | +import net.minecraft.client.render.entity.EntityRenderDispatcher; |
| 9 | +import net.minecraft.entity.Entity; |
| 10 | +import net.minecraft.entity.LivingEntity; |
| 11 | +import org.polyfrost.polyhitbox.HitboxRendererKt; |
| 12 | +import org.spongepowered.asm.mixin.Mixin; |
| 13 | +import org.spongepowered.asm.mixin.injection.At; |
| 14 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 15 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 16 | + |
| 17 | +//#if MC >=1.21.5 |
| 18 | +import net.minecraft.client.render.entity.state.EntityHitbox; |
| 19 | +//#endif |
| 20 | + |
| 21 | +//#if MC >=1.16.5 |
| 22 | +import net.minecraft.client.util.math.MatrixStack; |
| 23 | +import net.minecraft.client.render.VertexConsumer; |
| 24 | +import net.minecraft.client.render.VertexConsumerProvider; |
| 25 | +import org.spongepowered.asm.mixin.Unique; |
| 26 | +//#endif |
| 27 | + |
| 28 | +@Mixin(EntityRenderDispatcher.class) |
| 29 | +public abstract class MixinRenderManager { |
| 30 | + //#if MC >=1.21.5 |
| 31 | + @Unique |
| 32 | + private static ThreadLocal<Entity> polyhitbox$entity = ThreadLocal.withInitial(() -> null); |
| 33 | + //#endif |
| 34 | + |
| 35 | + @Inject( |
| 36 | + //#if MC >=1.16.5 |
| 37 | + method = "renderHitbox", |
| 38 | + //#else |
| 39 | + //$$ method = "renderDebugBoundingBox", |
| 40 | + //#endif |
| 41 | + at = @At("HEAD"), |
| 42 | + cancellable = true |
| 43 | + ) |
| 44 | + //#if MC >=1.16.5 |
| 45 | + private |
| 46 | + //#if MC >=1.20.1 |
| 47 | + static |
| 48 | + //#endif |
| 49 | + void polyhitbox$customRendering( |
| 50 | + MatrixStack matrixStack, |
| 51 | + VertexConsumer vertexConsumer, |
| 52 | + //#if MC >=1.21.5 |
| 53 | + EntityHitbox entityHitbox, |
| 54 | + //#else |
| 55 | + //$$ Entity entity, |
| 56 | + //$$ float tickDelta, |
| 57 | + //#if MC >=1.21.1 |
| 58 | + //$$ float offsetX, float offsetY, float offsetZ, |
| 59 | + //#endif |
| 60 | + //#endif |
| 61 | + CallbackInfo ci |
| 62 | + ) { |
| 63 | + //#else |
| 64 | + //$$ private void polyhitbox$customRendering(Entity entity, double offsetX, double offsetY, double offsetZ, float yaw, float tickDelta, CallbackInfo ci) { |
| 65 | + //#endif |
| 66 | + ci.cancel(); |
| 67 | + OmniMatrixStack stack = OmniMatrixStacks.vanilla( |
| 68 | + //#if MC >=1.16.5 |
| 69 | + matrixStack |
| 70 | + //#endif |
| 71 | + ); |
| 72 | + |
| 73 | + //#if MC >=1.21.5 |
| 74 | + Entity entity = polyhitbox$entity.get(); |
| 75 | + OmniVec3d offset = new OmniVec3d(entityHitbox.comp_3855(), entityHitbox.comp_3856(), entityHitbox.comp_3857()); |
| 76 | + //#else |
| 77 | + //$$ OmniVec3d offset = OmniVec3d.ZERO; |
| 78 | + //#endif |
| 79 | + |
| 80 | + HitboxRendererKt.renderHitbox( |
| 81 | + stack, |
| 82 | + offset, |
| 83 | + OmniEntities.getCurrentPos(entity), |
| 84 | + new OmniVec3d(entity.getRotationVector()), |
| 85 | + entity.getStandingEyeHeight(), |
| 86 | + entity instanceof LivingEntity, |
| 87 | + entity == OmniClient.get().targetedEntity, |
| 88 | + //#if MC >=1.16.5 |
| 89 | + entity.getWidth(), |
| 90 | + //#else |
| 91 | + //$$ entity.width, |
| 92 | + //#endif |
| 93 | + entity.getTargetingMargin(), |
| 94 | + OmniEntities.getRenderBoundingBox(entity) |
| 95 | + ); |
| 96 | + } |
| 97 | + |
| 98 | + //#if MC >=1.21.5 |
| 99 | + @com.llamalad7.mixinextras.injector.v2.WrapWithCondition(method = "renderHitboxes(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/entity/state/EntityHitboxAndView;Lnet/minecraft/client/render/VertexConsumer;F)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/VertexRendering;drawVector(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;Lorg/joml/Vector3f;Lnet/minecraft/util/math/Vec3d;I)V")) |
| 100 | + private static boolean polyhitbox$removeViewRay( |
| 101 | + net.minecraft.client.util.math.MatrixStack matrixStack, |
| 102 | + net.minecraft.client.render.VertexConsumer vertexConsumer, |
| 103 | + org.joml.Vector3f vector3f, |
| 104 | + net.minecraft.util.math.Vec3d vec3d, |
| 105 | + int i |
| 106 | + ) { |
| 107 | + return false; |
| 108 | + } |
| 109 | + |
| 110 | + @Inject(method = "render(Lnet/minecraft/entity/Entity;DDDFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", at = @At("HEAD")) |
| 111 | + private static void polyhitbox$storeEntity( |
| 112 | + Entity entity, |
| 113 | + double x, double y, double z, float tickDelta, |
| 114 | + MatrixStack matrixStack, |
| 115 | + VertexConsumerProvider vertexConsumerProvider, |
| 116 | + int i, |
| 117 | + CallbackInfo ci |
| 118 | + ) { |
| 119 | + polyhitbox$entity.set(entity); |
| 120 | + } |
| 121 | + //#endif |
| 122 | +} |
0 commit comments