Add some improvements to seaponies

This commit is contained in:
Sollace 2023-08-01 22:46:36 +01:00
parent b4632c7358
commit 7c099cd0b1
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
2 changed files with 49 additions and 7 deletions

View file

@ -1,11 +1,14 @@
package com.minelittlepony.api.pony;
import com.minelittlepony.api.pony.meta.Race;
import com.minelittlepony.client.SkinsProxy;
import com.minelittlepony.client.render.entity.PlayerSeaponyRenderer;
import java.util.Optional;
import net.minecraft.block.BlockState;
import net.minecraft.block.StairsBlock;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.registry.tag.FluidTags;
@ -83,4 +86,12 @@ public final class PonyPosture {
public static boolean isRidingAPony(LivingEntity entity) {
return isSitting(entity) && getMountPony(entity).map(IPony::race).orElse(Race.HUMAN) != Race.HUMAN;
}
public static boolean isSeaponyModifier(LivingEntity entity) {
return IPony.getManager().getPony(entity).filter(pony -> {
return (pony.race() == Race.SEAPONY
|| (entity instanceof AbstractClientPlayerEntity player && SkinsProxy.instance.getSkin(PlayerSeaponyRenderer.SKIN_TYPE_ID, player).isPresent())
) && PonyPosture.isPartiallySubmerged(entity);
}).isPresent();
}
}

View file

@ -2,7 +2,6 @@ package com.minelittlepony.client.render.entity;
import com.minelittlepony.api.pony.IPony;
import com.minelittlepony.api.pony.PonyPosture;
import com.minelittlepony.api.pony.meta.Race;
import com.minelittlepony.client.SkinsProxy;
import com.minelittlepony.client.model.*;
import com.minelittlepony.util.MathUtil;
@ -44,8 +43,42 @@ public class PlayerSeaponyRenderer extends PlayerPonyRenderer {
public void render(AbstractClientPlayerEntity player, float entityYaw, float tickDelta, MatrixStack stack, VertexConsumerProvider renderContext, int light) {
updateSeaponyState(player);
super.render(player, entityYaw, tickDelta, stack, renderContext, light);
if (wet && player.getVelocity().length() > 0.1F) {
double x = player.getEntityWorld().getRandom().nextTriangular(player.getX(), 1);
double y = player.getEntityWorld().getRandom().nextTriangular(player.getY(), 1);
double z = player.getEntityWorld().getRandom().nextTriangular(player.getZ(), 1);
player.getEntityWorld().addParticle(ParticleTypes.BUBBLE, x, y, z, 0, 0, 0);
}
}
@Override
protected void setupTransforms(AbstractClientPlayerEntity entity, MatrixStack stack, float ageInTicks, float rotationYaw, float partialTicks) {
if (wet) {
stack.translate(0, 0.6, 0);
boolean sneaking = entity.isInSneakingPose();
float state = sneaking ? 100 : 0;
float interpolated = getEntityPony(entity).metadata().getInterpolator(entity.getUuid()).interpolate("seapony_splashing", state, 5);
if (sneaking) {
stack.translate(0, 0.125, 0);
}
if (!MathUtil.compareFloats(interpolated, state)) {
for (int i = 0; i < 10; i++) {
double x = entity.getEntityWorld().getRandom().nextTriangular(entity.getX(), 1);
double y = entity.getY() + 0.6;
double z = entity.getEntityWorld().getRandom().nextTriangular(entity.getZ(), 1);
entity.getEntityWorld().addParticle(ParticleTypes.BUBBLE, x, y, z, 0, 0, 0);
}
}
}
super.setupTransforms(entity, stack, ageInTicks, rotationYaw, partialTicks);
}
@Override
protected void renderArm(MatrixStack stack, VertexConsumerProvider renderContext, int lightUv, AbstractClientPlayerEntity player, Arm side) {
updateSeaponyState(player);
super.renderArm(stack, renderContext, lightUv, player, side);
@ -53,18 +86,16 @@ public class PlayerSeaponyRenderer extends PlayerPonyRenderer {
private void updateSeaponyState(AbstractClientPlayerEntity player) {
IPony pony = getEntityPony(player);
wet = (pony.race() == Race.SEAPONY || SkinsProxy.instance.getSkin(SKIN_TYPE_ID, player).isPresent())
&& PonyPosture.isPartiallySubmerged(player);
wet = PonyPosture.isSeaponyModifier(player);
model = manager.setModel(wet ? wetPony : dryPony).body();
float state = wet ? 100 : 0;
float interpolated = pony.metadata().getInterpolator(player.getUuid()).interpolate("seapony_state", state, 5);
if (!MathUtil.compareFloats(interpolated, state)) {
double x = player.getX() + (player.getEntityWorld().getRandom().nextFloat() * 2) - 1;
double y = player.getY() + (player.getEntityWorld().getRandom().nextFloat() * 2);
double z = player.getZ() + (player.getEntityWorld().getRandom().nextFloat() * 2) - 1;
double x = player.getEntityWorld().getRandom().nextTriangular(player.getX(), 1);
double y = player.getEntityWorld().getRandom().nextTriangular(player.getY() + player.getHeight() * 0.5F, 1);
double z = player.getEntityWorld().getRandom().nextTriangular(player.getZ(), 1);
player.getEntityWorld().addParticle(ParticleTypes.END_ROD, x, y, z, 0, 0, 0);
}