Added better polearm animations. Closes #172

This commit is contained in:
Sollace 2023-09-07 18:37:38 +01:00
parent 1c7f166dd8
commit 2e9482b305
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
2 changed files with 43 additions and 10 deletions

View file

@ -4,6 +4,7 @@ import java.util.Optional;
import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.unicopia.UTags;
import com.minelittlepony.unicopia.client.minelittlepony.MineLPDelegate; import com.minelittlepony.unicopia.client.minelittlepony.MineLPDelegate;
import com.minelittlepony.unicopia.command.CommandArgumentEnum; import com.minelittlepony.unicopia.command.CommandArgumentEnum;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
@ -20,6 +21,7 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.sound.SoundEvent; import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Arm; import net.minecraft.util.Arm;
import net.minecraft.util.Hand;
import net.minecraft.util.StringIdentifiable; import net.minecraft.util.StringIdentifiable;
import net.minecraft.util.math.*; import net.minecraft.util.math.*;
@ -40,9 +42,34 @@ public class PlayerPoser {
boolean liftRightArm = mainArm == Arm.RIGHT || !ponyRace.isEquine(); boolean liftRightArm = mainArm == Arm.RIGHT || !ponyRace.isEquine();
ItemStack glasses = GlassesItem.getForEntity(player); ItemStack glasses = GlassesItem.getForEntity(player);
ModelPart head = model.getHead(); ModelPart head = model.getHead();
if (context == Context.THIRD_PERSON && !player.isSneaking()) {
Hand leftHand = mainArm == Arm.LEFT ? Hand.MAIN_HAND : Hand.OFF_HAND;
Hand rightHand = mainArm == Arm.LEFT ? Hand.OFF_HAND : Hand.MAIN_HAND;
float pitchChange = -0.5F;
float yawChange = 0.8F;
if (player.getStackInHand(rightHand).isIn(UTags.POLEARMS) && (!ponyRace.isEquine() || model.rightArm.pitch != 0)) {
model.rightArm.pitch += pitchChange;
model.rightArm.yaw += yawChange;
if (player.handSwingTicks > 0 && rightHand == Hand.MAIN_HAND) {
model.rightArm.yaw -= 0.5F;
model.rightArm.pitch += 1.5F;
}
}
if (player.getStackInHand(leftHand).isIn(UTags.POLEARMS) && (!ponyRace.isEquine() || model.leftArm.pitch != 0)) {
model.leftArm.pitch += pitchChange;
model.leftArm.yaw -= yawChange;
if (player.handSwingTicks > 0 && leftHand == Hand.MAIN_HAND) {
model.leftArm.yaw -= 0.5F;
model.leftArm.pitch += 1.5F;
}
}
}
if (glasses.hasCustomName() && "Cool Shades".equals(glasses.getName().getString())) { if (glasses.hasCustomName() && "Cool Shades".equals(glasses.getName().getString())) {
final float bop = AnimationUtil.beat(player.age, HEAD_NOD_DURATION, HEAD_NOD_GAP) * 3F; final float bop = AnimationUtil.beat(player.age, HEAD_NOD_DURATION, HEAD_NOD_GAP) * 3F;
head.pitch += bop / 10F; head.pitch += bop / 10F;

View file

@ -4,7 +4,6 @@ import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry; import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry.DynamicItemRenderer; import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry.DynamicItemRenderer;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.item.ClampedModelPredicateProvider;
import net.minecraft.client.item.ModelPredicateProviderRegistry; import net.minecraft.client.item.ModelPredicateProviderRegistry;
import net.minecraft.client.model.*; import net.minecraft.client.model.*;
import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.VertexConsumerProvider;
@ -18,9 +17,10 @@ import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.item.*; import net.minecraft.item.*;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.RotationAxis;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
public class PolearmRenderer implements DynamicItemRenderer, ClampedModelPredicateProvider { public class PolearmRenderer implements DynamicItemRenderer {
private static final PolearmRenderer INSTANCE = new PolearmRenderer(); private static final PolearmRenderer INSTANCE = new PolearmRenderer();
private static final Identifier THROWING = new Identifier("throwing"); private static final Identifier THROWING = new Identifier("throwing");
@ -29,7 +29,9 @@ public class PolearmRenderer implements DynamicItemRenderer, ClampedModelPredica
public static void register(Item item) { public static void register(Item item) {
BuiltinItemRendererRegistry.INSTANCE.register(item, INSTANCE); BuiltinItemRendererRegistry.INSTANCE.register(item, INSTANCE);
ModelPredicateProviderRegistry.register(item, THROWING, INSTANCE); ModelPredicateProviderRegistry.register(item, THROWING, (ItemStack stack, ClientWorld world, LivingEntity entity, int seed) -> {
return entity != null && entity.isUsingItem() && entity.getActiveItem() == stack ? 1 : 0;
});
ModelLoadingRegistry.INSTANCE.registerModelProvider((renderer, out) -> out.accept(getModelId(item))); ModelLoadingRegistry.INSTANCE.registerModelProvider((renderer, out) -> out.accept(getModelId(item)));
} }
@ -65,16 +67,20 @@ public class PolearmRenderer implements DynamicItemRenderer, ClampedModelPredica
matrices.push(); matrices.push();
} else { } else {
matrices.push(); matrices.push();
matrices.scale(1, -1, -1); if (mode == ModelTransformationMode.THIRD_PERSON_LEFT_HAND || mode == ModelTransformationMode.THIRD_PERSON_RIGHT_HAND) {
int swap = mode == ModelTransformationMode.THIRD_PERSON_LEFT_HAND ? -1 : 1;
matrices.scale(1.5F, -1.5F, -1.5F);
float offsetX = swap * 0.05F;
matrices.translate(offsetX, 0, 0.05F);
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(-30 * swap), offsetX, 0.5F, offsetX);
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(-30 * swap), offsetX, 0.5F, offsetX);
} else {
matrices.scale(1, -1, -1);
}
Identifier id = Registries.ITEM.getId(stack.getItem()); Identifier id = Registries.ITEM.getId(stack.getItem());
Identifier texture = new Identifier(id.getNamespace(), "textures/entity/polearm/" + id.getPath() + ".png"); Identifier texture = new Identifier(id.getNamespace(), "textures/entity/polearm/" + id.getPath() + ".png");
model.render(matrices, ItemRenderer.getDirectItemGlintConsumer(vertexConsumers, model.getLayer(texture), false, stack.hasGlint()), light, overlay, 1, 1, 1, 1); model.render(matrices, ItemRenderer.getDirectItemGlintConsumer(vertexConsumers, model.getLayer(texture), false, stack.hasGlint()), light, overlay, 1, 1, 1, 1);
matrices.pop(); matrices.pop();
} }
} }
@Override
public float unclampedCall(ItemStack stack, ClientWorld world, LivingEntity entity, int seed) {
return entity != null && entity.isUsingItem() && entity.getActiveItem() == stack ? 1 : 0;
}
} }