Skip to content

Commit

Permalink
refactor: preprocess LivingEntityPreRenderEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
My-Name-Is-Jeff committed Dec 25, 2024
1 parent 6096e15 commit 063ea3f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

//#if MC>12000
//$$ import net.minecraft.client.render.entity.model.EntityModel
//$$ import net.minecraft.client.render.VertexConsumerProvider;
//$$ import net.minecraft.client.util.math.MatrixStack;
//#endif

@Mixin(RendererLivingEntity.class)
public class MixinRendererLivingEntity<T extends EntityLivingBase> {
public class MixinRendererLivingEntity
//#if MC<12000
<T extends EntityLivingBase>
//#else
//$$ <T extends LivingEntity, M extends EntityModel<T>>
//#endif
{
//#if MC<12000
@Inject(method = "doRender(Lnet/minecraft/entity/EntityLivingBase;DDDFF)V", at = @At("HEAD"), cancellable = true)
private void onRender(T entity, double x, double y, double z, float entityYaw, float partialTicks, CallbackInfo ci) {
Expand All @@ -49,7 +56,19 @@ private void onRender(T entity, double x, double y, double z, float entityYaw, f
double renderY = entity.lastTickPosY + (entity.getPositionVector().yCoord - entity.lastTickPosY - viewEntity.getPositionVector().yCoord + viewEntity.lastTickPosY) * partialTicks - viewEntity.lastTickPosY;
double renderZ = entity.lastTickPosZ + (entity.getPositionVector().zCoord - entity.lastTickPosZ - viewEntity.getPositionVector().zCoord + viewEntity.lastTickPosZ) * partialTicks - viewEntity.lastTickPosZ;
@SuppressWarnings("unchecked")
LivingEntityPreRenderEvent<T> event = new LivingEntityPreRenderEvent<>(entity, (RendererLivingEntity<T>) (Object) this, renderX, renderY, renderZ, partialTicks);
//#if MC<12000
LivingEntityPreRenderEvent<T>
//#else
//$$ LivingEntityPreRenderEvent<T, M>
//#endif
event =
new LivingEntityPreRenderEvent<>(entity,
//#if MC<12000
(RendererLivingEntity<T>) (Object) this,
//#else
//$$ (LivingEntityRenderer<T, M>) (Object) this,
//#endif
renderX, renderY, renderZ, partialTicks);
if (EventsKt.postCancellableSync(event)) {
ci.cancel();
}
Expand Down
19 changes: 18 additions & 1 deletion events/src/main/kotlin/gg/skytils/event/impl/render/entity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,28 @@ import net.minecraft.client.renderer.entity.RendererLivingEntity
import net.minecraft.entity.Entity
import net.minecraft.entity.EntityLivingBase

//#if MC>12000
//$$ import net.minecraft.client.render.entity.model.EntityModel
//#endif

/**
* [gg.skytils.event.mixins.render.MixinRendererLivingEntity.onRender]
*/
class LivingEntityPreRenderEvent<T : EntityLivingBase>(val entity: T, val renderer: RendererLivingEntity<T>, val x: Double, val y: Double, val z: Double, val partialTicks: Float) : CancellableEvent()
class LivingEntityPreRenderEvent
//#if MC<12000
<T : EntityLivingBase>
//#else
//$$ <T : LivingEntity, M: EntityModel<T>>
//#endif
(
val entity: T,
//#if MC<12000
val renderer: RendererLivingEntity<T>,
//#else
//$$ val renderer: LivingEntityRenderer<T, M>,
//#endif
val x: Double, val y: Double, val z: Double, val partialTicks: Float
) : CancellableEvent()

/**
* [gg.skytils.event.mixins.render.MixinRendererLivingEntity.onRenderPost]
Expand Down

0 comments on commit 063ea3f

Please sign in to comment.