-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...ts/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/RenderLivingEntityEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.polyfrost.oneconfig.api.event.v1.events; | ||
|
||
public abstract class RenderLivingEntityEvent extends Event.Cancellable { | ||
|
||
private final Object entity; | ||
private final float partialTicks; | ||
private final double x, y, z; | ||
|
||
public RenderLivingEntityEvent(Object entity, float partialTicks, double x, double y, double z) { | ||
this.entity = entity; | ||
this.partialTicks = partialTicks; | ||
this.x = x; | ||
this.y = y; | ||
this.z = z; | ||
} | ||
|
||
public Object getEntity() { | ||
return entity; | ||
} | ||
|
||
public float getPartialTicks() { | ||
return partialTicks; | ||
} | ||
|
||
public double getX() { | ||
return x; | ||
} | ||
|
||
public double getY() { | ||
return y; | ||
} | ||
|
||
public double getZ() { | ||
return z; | ||
} | ||
|
||
public static class Pre extends RenderLivingEntityEvent { | ||
public Pre(Object entity, float partialTicks, double x, double y, double z) { | ||
super(entity, partialTicks, x, y, z); | ||
} | ||
} | ||
|
||
public static class Post extends RenderLivingEntityEvent { | ||
public Post(Object entity, float partialTicks, double x, double y, double z) { | ||
super(entity, partialTicks, x, y, z); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
versions/src/main/java/org/polyfrost/oneconfig/internal/mixin/RendererLivingEntityMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package org.polyfrost.oneconfig.internal.mixin; | ||
|
||
//#if MC >= 1.16.5 | ||
//$$ import com.mojang.blaze3d.matrix.MatrixStack; | ||
//$$ import net.minecraft.client.renderer.IRenderTypeBuffer; | ||
//$$ import net.minecraft.client.renderer.entity.LivingRenderer; | ||
//#else | ||
import net.minecraft.client.renderer.entity.RendererLivingEntity; | ||
//#endif | ||
|
||
import net.minecraft.entity.EntityLivingBase; | ||
import net.minecraft.profiler.Profiler; | ||
import org.polyfrost.oneconfig.api.event.v1.EventManager; | ||
import org.polyfrost.oneconfig.api.event.v1.events.RenderLivingEntityEvent; | ||
import org.polyfrost.universal.UMinecraft; | ||
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; | ||
|
||
//#if MC >= 1.16.5 | ||
//$$ @Mixin(LivingRenderer.class) | ||
//#else | ||
@Mixin(RendererLivingEntity.class) | ||
//#endif | ||
public class RendererLivingEntityMixin<T extends EntityLivingBase> { | ||
|
||
@Inject( | ||
//#if MC >= 1.17.1 | ||
//#if FABRIC | ||
//$$ method = "render(Lnet/minecraft/entity/LivingEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", | ||
//#else | ||
//$$ method = "render(Lnet/minecraft/world/entity/LivingEntity;FFLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V", | ||
//#endif | ||
//#elseif MC >= 1.16.5 | ||
//$$ method = "render(Lnet/minecraft/entity/LivingEntity;FFLcom/mojang/blaze3d/matrix/MatrixStack;Lnet/minecraft/client/renderer/IRenderTypeBuffer;I)V", | ||
//#else | ||
method = "doRender(Lnet/minecraft/entity/EntityLivingBase;DDDFF)V", | ||
//#endif | ||
at = @At("HEAD"), | ||
cancellable = true | ||
) | ||
private void onPreEntityRenderCallback( | ||
T entity, | ||
//#if MC <= 1.12.2 | ||
double x, | ||
double y, | ||
double z, | ||
//#endif | ||
float entityYaw, | ||
float partialTicks, | ||
//#if MC >= 1.16.5 | ||
//$$ MatrixStack matrixStack, | ||
//$$ IRenderTypeBuffer buffer, | ||
//$$ int packedLight, | ||
//#endif | ||
CallbackInfo ci | ||
) { | ||
Profiler profiler = UMinecraft.getMinecraft() | ||
//#if MC >= 1.16.5 | ||
//$$ .getProfiler(); | ||
//#else | ||
.mcProfiler; | ||
//#endif | ||
profiler.startSection("oneconfig_renderlivingentity_event_pre"); | ||
|
||
//#if MC >= 1.16.5 | ||
//$$ double x = entity.getPosX(); | ||
//$$ double y = entity.getPosY(); | ||
//$$ double z = entity.getPosZ(); | ||
//#endif | ||
RenderLivingEntityEvent event = new RenderLivingEntityEvent.Pre(entity, partialTicks, x, y, z); | ||
EventManager.INSTANCE.post(event); | ||
if (event.cancelled) { | ||
ci.cancel(); | ||
} | ||
|
||
profiler.endSection(); | ||
} | ||
|
||
@Inject( | ||
//#if MC >= 1.17.1 | ||
//#if FABRIC | ||
//$$ method = "render(Lnet/minecraft/entity/LivingEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", | ||
//#else | ||
//$$ method = "render(Lnet/minecraft/world/entity/LivingEntity;FFLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V", | ||
//#endif | ||
//#elseif MC >= 1.16.5 | ||
//$$ method = "render(Lnet/minecraft/entity/LivingEntity;FFLcom/mojang/blaze3d/matrix/MatrixStack;Lnet/minecraft/client/renderer/IRenderTypeBuffer;I)V", | ||
//#else | ||
method = "doRender(Lnet/minecraft/entity/EntityLivingBase;DDDFF)V", | ||
//#endif | ||
at = @At("TAIL") | ||
) | ||
private void onPostEntityRenderCallback( | ||
T entity, | ||
//#if MC <= 1.12.2 | ||
double x, | ||
double y, | ||
double z, | ||
//#endif | ||
float entityYaw, | ||
float partialTicks, | ||
//#if MC >= 1.16.5 | ||
//$$ MatrixStack matrixStack, | ||
//$$ IRenderTypeBuffer buffer, | ||
//$$ int packedLight, | ||
//#endif | ||
CallbackInfo ci | ||
) { | ||
Profiler profiler = UMinecraft.getMinecraft() | ||
//#if MC >= 1.16.5 | ||
//$$ .getProfiler(); | ||
//#else | ||
.mcProfiler; | ||
//#endif | ||
profiler.startSection("oneconfig_renderlivingentity_event_post"); | ||
|
||
//#if MC >= 1.16.5 | ||
//$$ double x = entity.getPosX(); | ||
//$$ double y = entity.getPosY(); | ||
//$$ double z = entity.getPosZ(); | ||
//#endif | ||
RenderLivingEntityEvent event = new RenderLivingEntityEvent.Post(entity, partialTicks, x, y, z); | ||
EventManager.INSTANCE.post(event); | ||
// Can't cancel when the method has already returned lol | ||
|
||
profiler.endSection(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters