diff --git a/build.gradle b/build.gradle index f61ec14c1..4c0404f55 100644 --- a/build.gradle +++ b/build.gradle @@ -165,6 +165,8 @@ dependencies { implementation fg.deobf("maven.modrinth:simple-hats:1.20.1-0.3.2-forge") implementation fg.deobf("maven.modrinth:curios:5.9.1+1.20.1-forge") + implementation fg.deobf("maven.modrinth:torohealth-damage-indicators-updated:1.20.1-forge-1") + annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' } diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/entity/GeckoMaidEntity.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/entity/GeckoMaidEntity.java index d0b956110..912be433c 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/entity/GeckoMaidEntity.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/entity/GeckoMaidEntity.java @@ -13,6 +13,7 @@ import com.github.tartaricacid.touhoulittlemaid.geckolib3.geo.animated.AnimatedGeoModel; import com.github.tartaricacid.touhoulittlemaid.geckolib3.model.provider.data.EntityModelData; import com.github.tartaricacid.touhoulittlemaid.geckolib3.resource.GeckoLibCache; +import com.github.tartaricacid.touhoulittlemaid.geckolib3.util.RenderUtils; import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.EquipmentSlot; @@ -27,6 +28,7 @@ public class GeckoMaidEntity extends AnimatableEntity { private static final ResourceLocation GECKO_DEFAULT_TEXTURE = new ResourceLocation(TouhouLittleMaid.MOD_ID, "textures/entity/empty.png"); private static final int FPS = 60; + private volatile boolean renderedWithTempChanges = false; private final IMaid maid; private MaidModelInfo maidInfo; private final Vector2f headRot = new Vector2f(); @@ -115,6 +117,14 @@ public ResourceLocation getAnimationFileLocation() { @Override protected boolean forceUpdate(AnimationEvent animationEvent) { + if (RenderUtils.isRenderingEntitiesInInventory()) { + renderedWithTempChanges = true; + return true; + } + if (renderedWithTempChanges) { + renderedWithTempChanges = false; + return true; + } var tick = (float) getCurrentTick(animationEvent); if (tick != this.currentTick) { this.currentTick = tick; @@ -125,7 +135,6 @@ protected boolean forceUpdate(AnimationEvent animationEvent) { if (this.modelDirty || !this.state.compareState()) { this.state.updateState(); this.modelDirty = false; - return true; } return false; } diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/compat/torocraft/TorocraftCompat.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/compat/torocraft/TorocraftCompat.java new file mode 100644 index 000000000..996d054b5 --- /dev/null +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/compat/torocraft/TorocraftCompat.java @@ -0,0 +1,16 @@ +package com.github.tartaricacid.touhoulittlemaid.compat.torocraft; + +import net.minecraftforge.fml.loading.LoadingModList; + +public class TorocraftCompat { + private static final String MOD_ID = "torohealth"; + private static boolean INSTALLED; + + public static void init() { + INSTALLED = LoadingModList.get().getModFileById(MOD_ID) != null; + } + + public static boolean isInstalled() { + return INSTALLED; + } +} \ No newline at end of file diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/geckolib3/util/RenderUtils.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/geckolib3/util/RenderUtils.java index 388dc343f..7776082d6 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/geckolib3/util/RenderUtils.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/geckolib3/util/RenderUtils.java @@ -1,6 +1,7 @@ package com.github.tartaricacid.touhoulittlemaid.geckolib3.util; import com.github.tartaricacid.touhoulittlemaid.geckolib3.core.processor.IBone; +import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import org.joml.Matrix4f; import org.joml.Quaternionf; @@ -8,6 +9,16 @@ import java.util.List; public final class RenderUtils { + private static boolean renderingEntitiesInInventory = false; + + public static void setRenderingEntitiesInInventory(boolean value) { + renderingEntitiesInInventory = value; + } + + public static boolean isRenderingEntitiesInInventory() { + return RenderSystem.isOnRenderThread() && renderingEntitiesInInventory; + } + public static void translateMatrixToBone(PoseStack poseStack, IBone bone) { poseStack.translate(-bone.getPositionX() / 16f, bone.getPositionY() / 16f, bone.getPositionZ() / 16f); } diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/mixin/client/ItemPropertiesMixin.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/mixin/client/ItemPropertiesMixin.java index 37e02b640..a7832f5fd 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/mixin/client/ItemPropertiesMixin.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/mixin/client/ItemPropertiesMixin.java @@ -12,10 +12,11 @@ import javax.annotation.Nullable; +@SuppressWarnings("all") @Mixin(ItemProperties.class) public class ItemPropertiesMixin { @Inject(method = "lambda$static$18(Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/client/multiplayer/ClientLevel;Lnet/minecraft/world/entity/LivingEntity;I)F", at = @At("HEAD"), cancellable = true) - private static void createEntityIgnoreException(ItemStack stack, @Nullable ClientLevel pLevel, @Nullable LivingEntity entity, int pSeed, CallbackInfoReturnable ci) { + private static void onItemRender(ItemStack stack, @Nullable ClientLevel pLevel, @Nullable LivingEntity entity, int pSeed, CallbackInfoReturnable ci) { if (entity instanceof EntityMaid maid && maid.getMainHandItem() == stack) { float result = maid.hasFishingHook() ? 1.0F : 0.0F; ci.setReturnValue(result); diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/mixin/client/RenderSystemMixin.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/mixin/client/RenderSystemMixin.java new file mode 100644 index 000000000..9055beb8f --- /dev/null +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/mixin/client/RenderSystemMixin.java @@ -0,0 +1,21 @@ +package com.github.tartaricacid.touhoulittlemaid.mixin.client; + +import com.github.tartaricacid.touhoulittlemaid.geckolib3.util.RenderUtils; +import com.mojang.blaze3d.systems.RenderSystem; +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; + +@Mixin(RenderSystem.class) +public class RenderSystemMixin { + @Inject(at = @At("HEAD"), method = "runAsFancy(Ljava/lang/Runnable;)V") + private static void beforeRunAsFancy(Runnable fancyRunnable, CallbackInfo ci) { + RenderUtils.setRenderingEntitiesInInventory(true); + } + + @Inject(at = @At("TAIL"), method = "runAsFancy(Ljava/lang/Runnable;)V") + private static void afterRunAsFancy(Runnable fancyRunnable, CallbackInfo ci) { + RenderUtils.setRenderingEntitiesInInventory(false); + } +} \ No newline at end of file diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/mixin/plugin/MixinTweaker.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/mixin/plugin/MixinTweaker.java new file mode 100644 index 000000000..70cf78f09 --- /dev/null +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/mixin/plugin/MixinTweaker.java @@ -0,0 +1,53 @@ +package com.github.tartaricacid.touhoulittlemaid.mixin.plugin; + +import com.github.tartaricacid.touhoulittlemaid.compat.torocraft.TorocraftCompat; +import com.google.common.collect.Lists; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.loading.FMLEnvironment; +import org.objectweb.asm.tree.ClassNode; +import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; + +import java.util.List; +import java.util.Set; + +public class MixinTweaker implements IMixinConfigPlugin { + public MixinTweaker() { + TorocraftCompat.init(); + } + + @Override + public void onLoad(String mixinPackage) { + } + + @Override + public String getRefMapperConfig() { + return null; + } + + @Override + public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { + return true; + } + + @Override + public void acceptTargets(Set myTargets, Set otherTargets) { + } + + @Override + public List getMixins() { + if (TorocraftCompat.isInstalled() && FMLEnvironment.dist == Dist.CLIENT) { + return Lists.newArrayList("plugin.TorocraftEntityDisplayMixin"); + } else { + return null; + } + } + + @Override + public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + } + + @Override + public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + } +} diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/mixin/plugin/TorocraftEntityDisplayMixin.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/mixin/plugin/TorocraftEntityDisplayMixin.java new file mode 100644 index 000000000..87acb9f22 --- /dev/null +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/mixin/plugin/TorocraftEntityDisplayMixin.java @@ -0,0 +1,20 @@ +package com.github.tartaricacid.touhoulittlemaid.mixin.plugin; + +import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid; +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.world.entity.LivingEntity; +import net.torocraft.torohealth.display.EntityDisplay; +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; + +@Mixin(EntityDisplay.class) +public class TorocraftEntityDisplayMixin { + @Inject(at = @At("HEAD"), method = "drawEntity(Lcom/mojang/blaze3d/vertex/PoseStack;IIIFFLnet/minecraft/world/entity/LivingEntity;F)V", remap = false, cancellable = true) + private static void getEntityInCrosshair(PoseStack matrixStack2, int x, int y, int size, float mouseX, float mouseY, LivingEntity entity, float scale, CallbackInfo ci) { + if (entity instanceof EntityMaid) { + ci.cancel(); + } + } +} \ No newline at end of file diff --git a/src/main/resources/touhou_little_maid.mixins.json b/src/main/resources/touhou_little_maid.mixins.json index 33d0f2b8c..f5441e05e 100644 --- a/src/main/resources/touhou_little_maid.mixins.json +++ b/src/main/resources/touhou_little_maid.mixins.json @@ -2,12 +2,15 @@ "required": true, "minVersion": "0.8", "package": "com.github.tartaricacid.touhoulittlemaid.mixin", + "plugin": "com.github.tartaricacid.touhoulittlemaid.mixin.plugin.MixinTweaker", "compatibilityLevel": "JAVA_17", "refmap": "touhou_little_maid.refmap.json", - "mixins": ["EntityMixin", "FenceGateBlockAccessor", "MixinArrowEntity", "MixinStructureTemplate"], + "mixins": [ + "EntityMixin", "FenceGateBlockAccessor", "MixinArrowEntity", "MixinStructureTemplate" + ], "client": [ "client.HumanoidModelMixin", "client.ItemPropertiesMixin", "client.LanguageMixin", - "client.LivingEntityRendererMixin" + "client.LivingEntityRendererMixin", "client.RenderSystemMixin" ], "injectors": { "defaultRequire": 1