diff options
author | inglettronald <inglettronald@gmail.com> | 2023-07-17 03:05:11 -0500 |
---|---|---|
committer | inglettronald <inglettronald@gmail.com> | 2023-07-17 03:05:11 -0500 |
commit | 1a8e45d8519a8ae69e14db8ea103a7fdf7b80923 (patch) | |
tree | 5568ffc7575c4da682a9526199ea535be57ae637 /src/main/java/com/dulkirfabric | |
parent | 2003a3d2be24ae3faed0e45a8c6cc5e0b8343cc3 (diff) | |
download | DulkirMod-Fabric-1a8e45d8519a8ae69e14db8ea103a7fdf7b80923.tar.gz DulkirMod-Fabric-1a8e45d8519a8ae69e14db8ea103a7fdf7b80923.tar.bz2 DulkirMod-Fabric-1a8e45d8519a8ae69e14db8ea103a7fdf7b80923.zip |
wip
Diffstat (limited to 'src/main/java/com/dulkirfabric')
4 files changed, 143 insertions, 0 deletions
diff --git a/src/main/java/com/dulkirfabric/mixin/ItemMixin.java b/src/main/java/com/dulkirfabric/mixin/ItemMixin.java new file mode 100644 index 0000000..53e637e --- /dev/null +++ b/src/main/java/com/dulkirfabric/mixin/ItemMixin.java @@ -0,0 +1,24 @@ +package com.dulkirfabric.mixin; + +import com.dulkirfabric.features.CooldownDisplays; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +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.CallbackInfoReturnable; + +@Mixin(Item.class) +public class ItemMixin { + + @Inject(method = "isItemBarVisible(Lnet/minecraft/item/ItemStack;)Z", + at = @At("HEAD"), cancellable = true) + public void shouldDisplayDurabilityBar(ItemStack stack, CallbackInfoReturnable<Boolean> cir) { + CooldownDisplays.INSTANCE.shouldDisplay(stack, cir); + } + @Inject(method = "getItemBarStep(Lnet/minecraft/item/ItemStack;)I", + at = @At("HEAD"), cancellable = true) + public void calculateItemHealth(ItemStack stack, CallbackInfoReturnable<Integer> cir) { + CooldownDisplays.INSTANCE.calcDurability(stack, cir); + } +} diff --git a/src/main/java/com/dulkirfabric/mixin/render/LivingEntityMixin.java b/src/main/java/com/dulkirfabric/mixin/render/LivingEntityMixin.java new file mode 100644 index 0000000..1b86f5c --- /dev/null +++ b/src/main/java/com/dulkirfabric/mixin/render/LivingEntityMixin.java @@ -0,0 +1,44 @@ +package com.dulkirfabric.mixin.render; + +import com.dulkirfabric.util.GlowingEntityInterface; +import net.minecraft.entity.LivingEntity; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; + +import java.awt.*; + +@Mixin(LivingEntity.class) +public class LivingEntityMixin implements GlowingEntityInterface { + + @Unique + private boolean shouldGlow_DulkirMod; + @Unique + private Color glowColor_DulkirMod; + @Unique + private boolean shouldESP_DulkirMod; + + @Override + public void setDulkirEntityGlow(boolean shouldGlow, @NotNull Color glowColor, boolean shouldESP) { + this.shouldGlow_DulkirMod = shouldGlow; + this.glowColor_DulkirMod = glowColor; + this.shouldESP_DulkirMod = shouldESP; + } + + @Override + public boolean shouldDulkirEntityGlow() { + return shouldGlow_DulkirMod; + } + + @Nullable + @Override + public Color getDulkirEntityGlowColor() { + return glowColor_DulkirMod; + } + + @Override + public boolean shouldDulkirEntityESP() { + return shouldESP_DulkirMod; + } +} diff --git a/src/main/java/com/dulkirfabric/mixin/render/MinecraftClientMixin.java b/src/main/java/com/dulkirfabric/mixin/render/MinecraftClientMixin.java index 9ab55ae..13285e3 100644 --- a/src/main/java/com/dulkirfabric/mixin/render/MinecraftClientMixin.java +++ b/src/main/java/com/dulkirfabric/mixin/render/MinecraftClientMixin.java @@ -1,9 +1,23 @@ package com.dulkirfabric.mixin.render; +import com.dulkirfabric.util.GlowingEntityInterface; import net.minecraft.client.MinecraftClient; +import net.minecraft.entity.Entity; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(MinecraftClient.class) public class MinecraftClientMixin { + @Inject(method = "hasOutline(Lnet/minecraft/entity/Entity;)Z", at = @At("HEAD"), cancellable = true) + public void outlineCheck(Entity entity, CallbackInfoReturnable<Boolean> cir) { + if (entity instanceof GlowingEntityInterface gEntity) { + if (gEntity.shouldDulkirEntityGlow()) { + cir.setReturnValue(true); + } + } + } } diff --git a/src/main/java/com/dulkirfabric/mixin/render/WorldRendererMixin.java b/src/main/java/com/dulkirfabric/mixin/render/WorldRendererMixin.java new file mode 100644 index 0000000..bb1a9be --- /dev/null +++ b/src/main/java/com/dulkirfabric/mixin/render/WorldRendererMixin.java @@ -0,0 +1,61 @@ +package com.dulkirfabric.mixin.render; + +import com.dulkirfabric.util.GlowingEntityInterface; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import com.llamalad7.mixinextras.sugar.Local; +import net.minecraft.client.gl.Framebuffer; +import net.minecraft.client.render.Camera; +import net.minecraft.client.render.GameRenderer; +import net.minecraft.client.render.LightmapTextureManager; +import net.minecraft.client.render.WorldRenderer; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.entity.Entity; +import org.jetbrains.annotations.Nullable; +import org.joml.Matrix4f; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import static com.dulkirfabric.DulkirModFabric.mc; + +@Mixin(WorldRenderer.class) +public class WorldRendererMixin { + + @Shadow private @Nullable Framebuffer entityOutlinesFramebuffer; + @Unique + Framebuffer temp = this.entityOutlinesFramebuffer; + @ModifyExpressionValue(method = "render(Lnet/minecraft/client/util/math/MatrixStack;FJZLnet/minecraft/client/render/Camera;Lnet/minecraft/client/render/GameRenderer;Lnet/minecraft/client/render/LightmapTextureManager;Lorg/joml/Matrix4f;)V", + at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getTeamColorValue()I")) + public int getGlowColor(int existing, @Local Entity entity) { + if (entity instanceof GlowingEntityInterface dEntity) { + if (dEntity.getDulkirEntityGlowColor() != null) { + return dEntity.getDulkirEntityGlowColor().getRGB(); + } + } + return existing; + } + + @Inject(method = "render(Lnet/minecraft/client/util/math/MatrixStack;FJZLnet/minecraft/client/render/Camera;Lnet/minecraft/client/render/GameRenderer;Lnet/minecraft/client/render/LightmapTextureManager;Lorg/joml/Matrix4f;)V", + at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/BufferBuilderStorage;getEntityVertexConsumers()Lnet/minecraft/client/render/VertexConsumerProvider$Immediate;", shift = At.Shift.AFTER)) + public void saveDefaultBufferESP(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f positionMatrix, CallbackInfo ci) { + temp = this.entityOutlinesFramebuffer; + } + + @Inject(method = "render(Lnet/minecraft/client/util/math/MatrixStack;FJZLnet/minecraft/client/render/Camera;Lnet/minecraft/client/render/GameRenderer;Lnet/minecraft/client/render/LightmapTextureManager;Lorg/joml/Matrix4f;)V", + at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/EntityRenderDispatcher;shouldRender(Lnet/minecraft/entity/Entity;Lnet/minecraft/client/render/Frustum;DDD)Z")) + public void setOutlineESP(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f positionMatrix, CallbackInfo ci, @Local Entity entity) { + if (entity instanceof GlowingEntityInterface dEntity) { + if (dEntity.shouldDulkirEntityGlow() && !dEntity.shouldDulkirEntityESP()) { + if (this.entityOutlinesFramebuffer != null) + this.entityOutlinesFramebuffer.copyDepthFrom(mc.getFramebuffer()); + } + } else { + // give esp back here + if (this.entityOutlinesFramebuffer != null) + this.entityOutlinesFramebuffer.copyDepthFrom(temp); + } + } +} |