Skip to content

Commit

Permalink
修正动画抖动问题
Browse files Browse the repository at this point in the history
- 现在打开女仆 GUI,背景女仆不会抖动了
- toro 血量模组禁用了女仆渲染
  • Loading branch information
TartaricAcid committed Oct 8, 2024
1 parent 5b43e4b commit 5936cf1
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 4 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,6 +28,7 @@ public class GeckoMaidEntity<T extends Mob> extends AnimatableEntity<T> {
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();
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
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;

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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Float> ci) {
private static void onItemRender(ItemStack stack, @Nullable ClientLevel pLevel, @Nullable LivingEntity entity, int pSeed, CallbackInfoReturnable<Float> ci) {
if (entity instanceof EntityMaid maid && maid.getMainHandItem() == stack) {
float result = maid.hasFishingHook() ? 1.0F : 0.0F;
ci.setReturnValue(result);
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<String> myTargets, Set<String> otherTargets) {
}

@Override
public List<String> 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) {
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
7 changes: 5 additions & 2 deletions src/main/resources/touhou_little_maid.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5936cf1

Please sign in to comment.