mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-26 06:18:00 +01:00
A bunch of refactoring and cleaning up of old patterns
This commit is contained in:
parent
3c357c9061
commit
960b98eac9
28 changed files with 255 additions and 298 deletions
|
@ -1,6 +1,7 @@
|
||||||
package com.minelittlepony.api.model;
|
package com.minelittlepony.api.model;
|
||||||
|
|
||||||
import com.minelittlepony.api.pony.IPony;
|
import com.minelittlepony.api.pony.IPony;
|
||||||
|
import com.minelittlepony.api.pony.PonyPosture;
|
||||||
import com.minelittlepony.util.MathUtil;
|
import com.minelittlepony.util.MathUtil;
|
||||||
|
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
|
@ -122,16 +123,16 @@ public class ModelAttributes {
|
||||||
|
|
||||||
public void updateLivingState(LivingEntity entity, IPony pony, Mode mode) {
|
public void updateLivingState(LivingEntity entity, IPony pony, Mode mode) {
|
||||||
visualHeight = entity.getHeight() + 0.125F;
|
visualHeight = entity.getHeight() + 0.125F;
|
||||||
isSitting = pony.isSitting(entity);
|
isSitting = PonyPosture.isSitting(entity);
|
||||||
isCrouching = !isSitting && mode == Mode.THIRD_PERSON && pony.isCrouching(entity);
|
isCrouching = !isSitting && mode == Mode.THIRD_PERSON && PonyPosture.isCrouching(pony, entity);
|
||||||
isSleeping = entity.isSleeping();
|
isSleeping = entity.isSleeping();
|
||||||
isFlying = mode == Mode.THIRD_PERSON && pony.isFlying(entity);
|
isFlying = mode == Mode.THIRD_PERSON && PonyPosture.isFlying(entity);
|
||||||
isGliding = entity.isFallFlying();
|
isGliding = entity.isFallFlying();
|
||||||
isSwimming = mode == Mode.THIRD_PERSON && pony.isSwimming(entity);
|
isSwimming = mode == Mode.THIRD_PERSON && PonyPosture.isSwimming(entity);
|
||||||
isSwimmingRotated = isSwimming && (entity instanceof PlayerEntity || entity instanceof Swimmer);
|
isSwimmingRotated = isSwimming && (entity instanceof PlayerEntity || entity instanceof Swimmer);
|
||||||
isRiptide = entity.isUsingRiptide();
|
isRiptide = entity.isUsingRiptide();
|
||||||
isHorizontal = isSwimming;
|
isHorizontal = isSwimming;
|
||||||
isRidingInteractive = pony.isRidingInteractive(entity);
|
isRidingInteractive = PonyPosture.isRidingAPony(entity);
|
||||||
interpolatorId = entity.getUuid();
|
interpolatorId = entity.getUuid();
|
||||||
isLeftHanded = entity.getMainArm() == Arm.LEFT;
|
isLeftHanded = entity.getMainArm() == Arm.LEFT;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
package com.minelittlepony.api.pony;
|
package com.minelittlepony.api.pony;
|
||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraft.entity.LivingEntity;
|
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.math.Box;
|
|
||||||
import net.minecraft.util.math.Vec3d;
|
|
||||||
|
|
||||||
import com.minelittlepony.api.pony.meta.Race;
|
import com.minelittlepony.api.pony.meta.Race;
|
||||||
import com.minelittlepony.client.MineLittlePony;
|
import com.minelittlepony.client.MineLittlePony;
|
||||||
|
|
||||||
|
@ -29,85 +24,28 @@ public interface IPony {
|
||||||
return getManager().getPony(texture);
|
return getManager().getPony(texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggers state updates on the passed entity.
|
|
||||||
*/
|
|
||||||
void updateForEntity(Entity entity);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether this is one of the default ponies assigned to a player without a custom skin.
|
* Returns whether this is one of the default ponies assigned to a player without a custom skin.
|
||||||
*/
|
*/
|
||||||
boolean isDefault();
|
boolean defaulted();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unlike sneaking, crouching is a more specific animation parameter that controls whether the player is visible
|
* Returns whether this pony's metadata block has been initialized.
|
||||||
* nose to the ground, crouching the sand.
|
|
||||||
*
|
|
||||||
* You cannot crouch whilst flying or swimming.
|
|
||||||
*/
|
*/
|
||||||
boolean isCrouching(LivingEntity entity);
|
boolean hasMetadata();
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the provided entity is flying like a pegasus.
|
|
||||||
* True if the entity is off the ground.
|
|
||||||
* Creative flight counts only if the entity is <i>not</i> on the ground.
|
|
||||||
*
|
|
||||||
* Entities that are riding, climbing a ladder, or swimming are <i>not</i> flying.
|
|
||||||
*/
|
|
||||||
boolean isFlying(LivingEntity entity);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the provided entity is actively swimming.
|
|
||||||
* That is, it should be fully submerged (isFullySubmerged returns true)
|
|
||||||
* and is not standing on the (river) bed or riding a ladder or any other entity.
|
|
||||||
*/
|
|
||||||
boolean isSwimming(LivingEntity entity);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the provided entity is partially submerged. That is if any part of it is in contact with water.
|
|
||||||
*/
|
|
||||||
boolean isPartiallySubmerged(LivingEntity entity);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the race associated with this pony.
|
* Gets the race associated with this pony.
|
||||||
*/
|
*/
|
||||||
Race getRace();
|
Race race();
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if an entity is sitting as when riding a vehicle or
|
|
||||||
* a customized habitually actuated indoors rester (CHAIR)
|
|
||||||
*/
|
|
||||||
boolean isSitting(LivingEntity entity);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if an entity is riding a pony or other sentient life-form.
|
|
||||||
*
|
|
||||||
* Boats do not count.
|
|
||||||
*/
|
|
||||||
boolean isRidingInteractive(LivingEntity entity);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the pony this entity is currently riding if any.
|
|
||||||
*/
|
|
||||||
IPony getMountedPony(LivingEntity entity);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the texture used for rendering this pony.
|
* Gets the texture used for rendering this pony.
|
||||||
*/
|
*/
|
||||||
Identifier getTexture();
|
Identifier texture();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the metadata associated with this pony's model texture.
|
* Gets the metadata associated with this pony's model texture.
|
||||||
*/
|
*/
|
||||||
IPonyData getMetadata();
|
IPonyData metadata();
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the riding offset of this entity relative to its lowermost mount.
|
|
||||||
*/
|
|
||||||
Vec3d getAbsoluteRidingOffset(LivingEntity entity);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the actual bounding box of this entity as a pony.
|
|
||||||
*/
|
|
||||||
Box getComputedBoundingBox(LivingEntity entity);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
package com.minelittlepony.api.pony;
|
package com.minelittlepony.api.pony;
|
||||||
|
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -14,6 +18,13 @@ public interface IPonyManager {
|
||||||
Identifier STEVE = new Identifier("minelittlepony", "textures/entity/steve_pony.png");
|
Identifier STEVE = new Identifier("minelittlepony", "textures/entity/steve_pony.png");
|
||||||
Identifier ALEX = new Identifier("minelittlepony", "textures/entity/alex_pony.png");
|
Identifier ALEX = new Identifier("minelittlepony", "textures/entity/alex_pony.png");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a pony representation of the passed in entity.
|
||||||
|
*
|
||||||
|
* If the supplied entity is null or can't be determined to be a pony, returns the empty optional.
|
||||||
|
*/
|
||||||
|
Optional<IPony> getPony(@Nullable Entity entity);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets or creates a pony for the given player.
|
* Gets or creates a pony for the given player.
|
||||||
* Delegates to the background-ponies registry if no pony skins were available and client settings allows it.
|
* Delegates to the background-ponies registry if no pony skins were available and client settings allows it.
|
||||||
|
|
85
src/main/java/com/minelittlepony/api/pony/PonyPosture.java
Normal file
85
src/main/java/com/minelittlepony/api/pony/PonyPosture.java
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
package com.minelittlepony.api.pony;
|
||||||
|
|
||||||
|
import com.minelittlepony.api.pony.meta.Race;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.block.Material;
|
||||||
|
import net.minecraft.block.StairsBlock;
|
||||||
|
import net.minecraft.entity.LivingEntity;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
|
||||||
|
public final class PonyPosture {
|
||||||
|
public static Optional<IPony> getMountPony(LivingEntity entity) {
|
||||||
|
return entity.getVehicle() instanceof LivingEntity mount
|
||||||
|
? IPony.getManager().getPony(mount)
|
||||||
|
: Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isCrouching(IPony pony, LivingEntity entity) {
|
||||||
|
boolean isSneak = entity.isInSneakingPose();
|
||||||
|
boolean isFlying = isFlying(entity);
|
||||||
|
boolean isSwimming = isSwimming(entity);
|
||||||
|
|
||||||
|
return !isPerformingRainboom(pony, entity) && !isSwimming && isSneak && !isFlying;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isPerformingRainboom(IPony pony, LivingEntity entity) {
|
||||||
|
Vec3d motion = entity.getVelocity();
|
||||||
|
double zMotion = Math.sqrt(motion.x * motion.x + motion.z * motion.z);
|
||||||
|
|
||||||
|
return (isFlying(entity) && pony.race().hasWings()) || entity.isFallFlying() & zMotion > 0.4F;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isFlying(LivingEntity entity) {
|
||||||
|
return !(isOnGround(entity)
|
||||||
|
|| entity.hasVehicle()
|
||||||
|
|| (entity.isClimbing() && !(entity instanceof PlayerEntity && ((PlayerEntity)entity).getAbilities().allowFlying))
|
||||||
|
|| entity.isSubmergedInWater()
|
||||||
|
|| entity.isSleeping());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the entity is on the ground, or close enough to be "effectively" grounded.
|
||||||
|
* this is to keep Pegasus wings from flapping in odd situations (Hypixel).
|
||||||
|
*/
|
||||||
|
private static boolean isOnGround(LivingEntity entity) {
|
||||||
|
if (entity.isOnGround()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
BlockState below = entity.getEntityWorld()
|
||||||
|
.getBlockState(entity.getBlockPos().down(1));
|
||||||
|
|
||||||
|
// Check for stairs so we can keep Pegasi from flailing their wings as they descend
|
||||||
|
double offsetAmount = below.getBlock() instanceof StairsBlock ? 1 : 0.05;
|
||||||
|
|
||||||
|
Vec3d pos = entity.getPos();
|
||||||
|
BlockPos blockpos = new BlockPos(
|
||||||
|
Math.floor(pos.x),
|
||||||
|
Math.floor(pos.y - offsetAmount),
|
||||||
|
Math.floor(pos.z));
|
||||||
|
|
||||||
|
return !entity.getEntityWorld().isAir(blockpos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isSwimming(LivingEntity entity) {
|
||||||
|
return entity.isSwimming() || entity.isInSwimmingPose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isPartiallySubmerged(LivingEntity entity) {
|
||||||
|
return entity.isSubmergedInWater()
|
||||||
|
|| entity.getEntityWorld().getBlockState(entity.getBlockPos()).getMaterial() == Material.WATER;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isSitting(LivingEntity entity) {
|
||||||
|
return entity.hasVehicle();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isRidingAPony(LivingEntity entity) {
|
||||||
|
return isSitting(entity) && getMountPony(entity).map(IPony::race).orElse(Race.HUMAN) != Race.HUMAN;
|
||||||
|
}
|
||||||
|
}
|
|
@ -39,7 +39,7 @@ public class Channel {
|
||||||
registered = true;
|
registered = true;
|
||||||
MineLittlePony.logger.info("Server has just consented");
|
MineLittlePony.logger.info("Server has just consented");
|
||||||
|
|
||||||
sender.sendPacket(CLIENT_PONY_DATA, new MsgPonyData(pony.getMetadata(), pony.isDefault()).toBuffer(PacketByteBufs.create()));
|
sender.sendPacket(CLIENT_PONY_DATA, new MsgPonyData(pony.metadata(), pony.defaulted()).toBuffer(PacketByteBufs.create()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ServerPlayNetworking.registerGlobalReceiver(CLIENT_PONY_DATA, (server, player, ignore, buffer, ignore2) -> {
|
ServerPlayNetworking.registerGlobalReceiver(CLIENT_PONY_DATA, (server, player, ignore, buffer, ignore2) -> {
|
||||||
|
|
|
@ -15,7 +15,7 @@ import com.minelittlepony.client.MineLittlePony;
|
||||||
public interface PonyDataCallback {
|
public interface PonyDataCallback {
|
||||||
|
|
||||||
Event<PonyDataCallback> EVENT = EventFactory.createArrayBacked(PonyDataCallback.class, listeners -> (sender, data, noSkin, env) -> {
|
Event<PonyDataCallback> EVENT = EventFactory.createArrayBacked(PonyDataCallback.class, listeners -> (sender, data, noSkin, env) -> {
|
||||||
MineLittlePony.logger.info("Got pony data on the " + env + " from " + sender.getName().getString() + " with " + (noSkin ? "un" : "") + "set skin and he is a " + data.getRace() + "!");
|
MineLittlePony.logger.info("Got pony data on the " + env + " from " + sender.getUuidAsString() + " with " + (noSkin ? "un" : "") + "set skin and he is a " + data.getRace() + "!");
|
||||||
for (PonyDataCallback event : listeners) {
|
for (PonyDataCallback event : listeners) {
|
||||||
event.onPonyDataAvailable(sender, data, noSkin, env);
|
event.onPonyDataAvailable(sender, data, noSkin, env);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class HorseCam {
|
||||||
|
|
||||||
IPony pony = MineLittlePony.getInstance().getManager().getPony(player);
|
IPony pony = MineLittlePony.getInstance().getManager().getPony(player);
|
||||||
|
|
||||||
if (!pony.getRace().isHuman()) {
|
if (!pony.race().isHuman()) {
|
||||||
Setting<Boolean> fillyCam = MineLittlePony.getInstance().getConfig().fillycam;
|
Setting<Boolean> fillyCam = MineLittlePony.getInstance().getConfig().fillycam;
|
||||||
|
|
||||||
fillyCam.set(false);
|
fillyCam.set(false);
|
||||||
|
|
50
src/main/java/com/minelittlepony/client/PonyBounds.java
Normal file
50
src/main/java/com/minelittlepony/client/PonyBounds.java
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
package com.minelittlepony.client;
|
||||||
|
|
||||||
|
import com.minelittlepony.api.pony.IPony;
|
||||||
|
import com.minelittlepony.api.pony.PonyPosture;
|
||||||
|
import com.minelittlepony.client.transform.PonyTransformation;
|
||||||
|
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.LivingEntity;
|
||||||
|
import net.minecraft.util.math.Box;
|
||||||
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
|
||||||
|
public class PonyBounds {
|
||||||
|
public static Vec3d getAbsoluteRidingOffset(LivingEntity entity) {
|
||||||
|
return PonyPosture.getMountPony(entity).map(ridingPony -> {
|
||||||
|
LivingEntity vehicle = (LivingEntity)entity.getVehicle();
|
||||||
|
|
||||||
|
Vec3d offset = PonyTransformation.forSize(ridingPony.metadata().getSize()).getRiderOffset();
|
||||||
|
float scale = ridingPony.metadata().getSize().getScaleFactor();
|
||||||
|
|
||||||
|
return getAbsoluteRidingOffset(vehicle).add(
|
||||||
|
0,
|
||||||
|
offset.y - vehicle.getHeight() * 1 / scale,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
}).orElseGet(() -> getBaseRidingOffset(entity));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Vec3d getBaseRidingOffset(LivingEntity entity) {
|
||||||
|
float delta = MinecraftClient.getInstance().getTickDelta();
|
||||||
|
|
||||||
|
Entity vehicle = entity.getVehicle();
|
||||||
|
double vehicleOffset = vehicle == null ? 0 : vehicle.getHeight() - vehicle.getMountedHeightOffset();
|
||||||
|
|
||||||
|
return new Vec3d(
|
||||||
|
MathHelper.lerp(delta, entity.prevX, entity.getX()),
|
||||||
|
MathHelper.lerp(delta, entity.prevY, entity.getY()) + vehicleOffset,
|
||||||
|
MathHelper.lerp(delta, entity.prevZ, entity.getZ())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Box getBoundingBox(IPony pony, LivingEntity entity) {
|
||||||
|
final float scale = pony.metadata().getSize().getScaleFactor() + 0.1F;
|
||||||
|
final float width = entity.getWidth() * scale;
|
||||||
|
final float height = entity.getHeight() * scale;
|
||||||
|
|
||||||
|
return new Box(-width, height, -width, width, 0, width).offset(getAbsoluteRidingOffset(entity));
|
||||||
|
}
|
||||||
|
}
|
|
@ -42,7 +42,7 @@ public class SkinsProxy {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Identifier getSeaponySkin(EquineRenderManager<AbstractClientPlayerEntity, ClientPonyModel<AbstractClientPlayerEntity>> manager, AbstractClientPlayerEntity player) {
|
public Identifier getSeaponySkin(EquineRenderManager<AbstractClientPlayerEntity, ClientPonyModel<AbstractClientPlayerEntity>> manager, AbstractClientPlayerEntity player) {
|
||||||
return manager.getPony(player).getTexture();
|
return manager.getPony(player).texture();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.minelittlepony.client.hdskins;
|
||||||
import net.minecraft.client.world.ClientWorld;
|
import net.minecraft.client.world.ClientWorld;
|
||||||
|
|
||||||
import com.minelittlepony.api.model.ModelAttributes;
|
import com.minelittlepony.api.model.ModelAttributes;
|
||||||
|
import com.minelittlepony.api.pony.IPony;
|
||||||
import com.minelittlepony.api.pony.IPonyManager;
|
import com.minelittlepony.api.pony.IPonyManager;
|
||||||
import com.minelittlepony.client.IPreviewModel;
|
import com.minelittlepony.client.IPreviewModel;
|
||||||
import com.minelittlepony.client.MineLittlePony;
|
import com.minelittlepony.client.MineLittlePony;
|
||||||
|
@ -19,7 +20,7 @@ class DummyPony extends DummyPlayer implements IPreviewModel, ModelAttributes.Sw
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldUpdateRegistration(Pony pony) {
|
public boolean shouldUpdateRegistration(IPony pony) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +36,7 @@ class DummyPony extends DummyPlayer implements IPreviewModel, ModelAttributes.Sw
|
||||||
}
|
}
|
||||||
return MineLittlePony.getInstance().getManager()
|
return MineLittlePony.getInstance().getManager()
|
||||||
.getPony(this)
|
.getPony(this)
|
||||||
.getMetadata()
|
.metadata()
|
||||||
.getRace()
|
.getRace()
|
||||||
.getModelId(getTextures().usesThinSkin());
|
.getModelId(getTextures().usesThinSkin());
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ class PonyPreview extends PlayerPreview {
|
||||||
MatrixStack matrices, @Nullable Consumer<DummyPlayer> postAction) {
|
MatrixStack matrices, @Nullable Consumer<DummyPlayer> postAction) {
|
||||||
super.renderWorldAndPlayer(thePlayer, frame, horizon, mouseX, mouseY, ticks, partialTick, scale, matrices, postAction);
|
super.renderWorldAndPlayer(thePlayer, frame, horizon, mouseX, mouseY, ticks, partialTick, scale, matrices, postAction);
|
||||||
thePlayer.ifPresent(p -> {
|
thePlayer.ifPresent(p -> {
|
||||||
IPonyData data = MineLittlePony.getInstance().getManager().getPony(p).getMetadata();
|
IPonyData data = MineLittlePony.getInstance().getManager().getPony(p).metadata();
|
||||||
int[] index = new int[1];
|
int[] index = new int[1];
|
||||||
data.getTriggerPixels().forEach((key, value) -> {
|
data.getTriggerPixels().forEach((key, value) -> {
|
||||||
drawLegendBlock(matrices, index[0]++, frame.left, frame.top, mouseX, mouseY, key, value);
|
drawLegendBlock(matrices, index[0]++, frame.left, frame.top, mouseX, mouseY, key, value);
|
||||||
|
|
|
@ -21,8 +21,8 @@ abstract class MixinCamera {
|
||||||
|
|
||||||
IPony pony = MineLittlePony.getInstance().getManager().getPony(MinecraftClient.getInstance().player);
|
IPony pony = MineLittlePony.getInstance().getManager().getPony(MinecraftClient.getInstance().player);
|
||||||
|
|
||||||
if (!pony.getRace().isHuman()) {
|
if (!pony.race().isHuman()) {
|
||||||
value *= pony.getMetadata().getSize().getEyeDistanceFactor();
|
value *= pony.metadata().getSize().getEyeDistanceFactor();
|
||||||
}
|
}
|
||||||
|
|
||||||
info.setReturnValue(value);
|
info.setReturnValue(value);
|
||||||
|
|
|
@ -46,8 +46,8 @@ abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity implem
|
||||||
|
|
||||||
IPony pony = MineLittlePony.getInstance().getManager().getPony(this);
|
IPony pony = MineLittlePony.getInstance().getManager().getPony(this);
|
||||||
|
|
||||||
if (!pony.getRace().isHuman()) {
|
if (!pony.race().isHuman()) {
|
||||||
float factor = pony.getMetadata().getSize().getEyeHeightFactor();
|
float factor = pony.metadata().getSize().getEyeHeightFactor();
|
||||||
if (factor != 1) {
|
if (factor != 1) {
|
||||||
value *= factor;
|
value *= factor;
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ abstract class MixinDefaultPlayerSkin {
|
||||||
|
|
||||||
cir.setReturnValue(MineLittlePony.getInstance().getManager()
|
cir.setReturnValue(MineLittlePony.getInstance().getManager()
|
||||||
.getPony(IPonyManager.getDefaultSkin(uuid), uuid)
|
.getPony(IPonyManager.getDefaultSkin(uuid), uuid)
|
||||||
.getRace()
|
.race()
|
||||||
.getModelId(IPonyManager.isSlimSkin(uuid)));
|
.getModelId(IPonyManager.isSlimSkin(uuid)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ abstract class MixinEntityRenderDispatcher {
|
||||||
}
|
}
|
||||||
return MineLittlePony.getInstance().getManager()
|
return MineLittlePony.getInstance().getManager()
|
||||||
.getPony(player)
|
.getPony(player)
|
||||||
.getRace()
|
.race()
|
||||||
.getModelId(player.getModel().contains("slim"));
|
.getModelId(player.getModel().contains("slim"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,41 +4,19 @@ import com.google.common.base.MoreObjects;
|
||||||
import com.minelittlepony.api.pony.IPony;
|
import com.minelittlepony.api.pony.IPony;
|
||||||
import com.minelittlepony.api.pony.IPonyData;
|
import com.minelittlepony.api.pony.IPonyData;
|
||||||
import com.minelittlepony.api.pony.meta.Race;
|
import com.minelittlepony.api.pony.meta.Race;
|
||||||
import com.minelittlepony.api.pony.meta.Size;
|
|
||||||
import com.minelittlepony.api.pony.meta.Sizes;
|
|
||||||
import com.minelittlepony.api.pony.network.MsgPonyData;
|
import com.minelittlepony.api.pony.network.MsgPonyData;
|
||||||
import com.minelittlepony.api.pony.network.fabric.Channel;
|
|
||||||
import com.minelittlepony.api.pony.network.fabric.PonyDataCallback;
|
|
||||||
import com.minelittlepony.client.render.IPonyRenderContext;
|
|
||||||
import com.minelittlepony.client.render.PonyRenderDispatcher;
|
|
||||||
import com.minelittlepony.client.transform.PonyTransformation;
|
|
||||||
import com.minelittlepony.settings.PonyConfig;
|
import com.minelittlepony.settings.PonyConfig;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import net.fabricmc.api.EnvType;
|
|
||||||
import net.minecraft.block.BlockState;
|
|
||||||
import net.minecraft.block.Material;
|
|
||||||
import net.minecraft.block.StairsBlock;
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraft.entity.LivingEntity;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.math.Box;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.util.math.MathHelper;
|
|
||||||
import net.minecraft.util.math.Vec3d;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.Unmodifiable;
|
import org.jetbrains.annotations.Unmodifiable;
|
||||||
|
|
||||||
@Unmodifiable
|
@Unmodifiable
|
||||||
public class Pony implements IPony {
|
public class Pony implements IPony {
|
||||||
|
|
||||||
private final Identifier texture;
|
private final Identifier texture;
|
||||||
private final Memoize<IPonyData> metadata;
|
private final Memoize<IPonyData> metadata;
|
||||||
|
|
||||||
private boolean defaulted = false;
|
private boolean defaulted;
|
||||||
|
|
||||||
Pony(Identifier resource, Memoize<IPonyData> data) {
|
Pony(Identifier resource, Memoize<IPonyData> data) {
|
||||||
texture = resource;
|
texture = resource;
|
||||||
|
@ -49,196 +27,46 @@ public class Pony implements IPony {
|
||||||
this(resource, PonyData.parse(resource));
|
this(resource, PonyData.parse(resource));
|
||||||
}
|
}
|
||||||
|
|
||||||
public IPony defaulted() {
|
public IPony markDefaulted() {
|
||||||
defaulted = true;
|
defaulted = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isDefault() {
|
public boolean defaulted() {
|
||||||
return defaulted;
|
return defaulted;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateForEntity(Entity entity) {
|
public boolean hasMetadata() {
|
||||||
if (!metadata.isPresent()) {
|
return metadata.isPresent();
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entity instanceof RegistrationHandler && ((RegistrationHandler)entity).shouldUpdateRegistration(this)) {
|
|
||||||
entity.calculateDimensions();
|
|
||||||
|
|
||||||
PlayerEntity clientPlayer = MinecraftClient.getInstance().player;
|
|
||||||
if (clientPlayer != null) {
|
|
||||||
if (Objects.equals(entity, clientPlayer) || Objects.equals(((PlayerEntity)entity).getGameProfile(), clientPlayer.getGameProfile())) {
|
|
||||||
Channel.broadcastPonyData(new MsgPonyData(getMetadata(), defaulted));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PonyDataCallback.EVENT.invoker().onPonyDataAvailable((PlayerEntity)entity, getMetadata(), defaulted, EnvType.CLIENT);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCrouching(LivingEntity entity) {
|
public Race race() {
|
||||||
|
return PonyConfig.getEffectiveRace(metadata().getRace());
|
||||||
boolean isSneak = entity.isInSneakingPose();
|
|
||||||
boolean isFlying = isFlying(entity);
|
|
||||||
boolean isSwimming = isSwimming(entity);
|
|
||||||
|
|
||||||
return !isPerformingRainboom(entity) && !isSwimming && isSneak && !isFlying;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isPerformingRainboom(LivingEntity entity) {
|
|
||||||
Vec3d motion = entity.getVelocity();
|
|
||||||
double zMotion = Math.sqrt(motion.x * motion.x + motion.z * motion.z);
|
|
||||||
|
|
||||||
return (isFlying(entity) && getRace().hasWings()) || entity.isFallFlying() & zMotion > 0.4F;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isFlying(LivingEntity entity) {
|
public Identifier texture() {
|
||||||
return !(isOnGround(entity)
|
|
||||||
|| entity.hasVehicle()
|
|
||||||
|| (entity.isClimbing() && !(entity instanceof PlayerEntity && ((PlayerEntity)entity).getAbilities().allowFlying))
|
|
||||||
|| entity.isSubmergedInWater()
|
|
||||||
|| entity.isSleeping());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the entity is on the ground, or close enough to be "effectively" grounded.
|
|
||||||
* this is to keep Pegasus wings from flapping in odd situations (Hypixel).
|
|
||||||
*/
|
|
||||||
private boolean isOnGround(LivingEntity entity) {
|
|
||||||
if (entity.isOnGround()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
BlockState below = entity.getEntityWorld()
|
|
||||||
.getBlockState(entity.getBlockPos().down(1));
|
|
||||||
|
|
||||||
// Check for stairs so we can keep Pegasi from flailing their wings as they descend
|
|
||||||
double offsetAmount = below.getBlock() instanceof StairsBlock ? 1 : 0.05;
|
|
||||||
|
|
||||||
Vec3d pos = entity.getPos();
|
|
||||||
BlockPos blockpos = new BlockPos(
|
|
||||||
Math.floor(pos.x),
|
|
||||||
Math.floor(pos.y - offsetAmount),
|
|
||||||
Math.floor(pos.z));
|
|
||||||
|
|
||||||
return !entity.getEntityWorld().isAir(blockpos);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSwimming(LivingEntity entity) {
|
|
||||||
return entity.isSwimming() || entity.isInSwimmingPose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPartiallySubmerged(LivingEntity entity) {
|
|
||||||
return entity.isSubmergedInWater()
|
|
||||||
|| entity.getEntityWorld().getBlockState(entity.getBlockPos()).getMaterial() == Material.WATER;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Vec3d getVisualEyePosition(LivingEntity entity) {
|
|
||||||
Size size = entity.isBaby() ? Sizes.FOAL : getMetadata().getSize();
|
|
||||||
|
|
||||||
return new Vec3d(
|
|
||||||
entity.getX(),
|
|
||||||
entity.getY() + (double) entity.getEyeHeight(entity.getPose()) * size.getScaleFactor(),
|
|
||||||
entity.getZ()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Race getRace() {
|
|
||||||
return PonyConfig.getEffectiveRace(getMetadata().getRace());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Identifier getTexture() {
|
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IPonyData getMetadata() {
|
public IPonyData metadata() {
|
||||||
return metadata.get(PonyData.NULL);
|
return metadata.get(PonyData.NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSitting(LivingEntity entity) {
|
|
||||||
return entity.hasVehicle();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isRidingInteractive(LivingEntity entity) {
|
|
||||||
|
|
||||||
if (isSitting(entity) && entity.getVehicle() instanceof LivingEntity) {
|
|
||||||
return PonyRenderDispatcher.getInstance().getPonyRenderer((LivingEntity) entity.getVehicle()) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IPony getMountedPony(LivingEntity entity) {
|
|
||||||
if (entity.hasVehicle() && entity.getVehicle() instanceof LivingEntity) {
|
|
||||||
LivingEntity mount = (LivingEntity) entity.getVehicle();
|
|
||||||
|
|
||||||
IPonyRenderContext<LivingEntity, ?> render = PonyRenderDispatcher.getInstance().getPonyRenderer(mount);
|
|
||||||
|
|
||||||
return render == null ? null : render.getEntityPony(mount);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Vec3d getAbsoluteRidingOffset(LivingEntity entity) {
|
|
||||||
IPony ridingPony = getMountedPony(entity);
|
|
||||||
|
|
||||||
if (ridingPony != null) {
|
|
||||||
LivingEntity ridee = (LivingEntity)entity.getVehicle();
|
|
||||||
|
|
||||||
Vec3d offset = PonyTransformation.forSize(ridingPony.getMetadata().getSize()).getRiderOffset();
|
|
||||||
float scale = ridingPony.getMetadata().getSize().getScaleFactor();
|
|
||||||
|
|
||||||
return ridingPony.getAbsoluteRidingOffset(ridee)
|
|
||||||
.add(0, offset.y - ridee.getHeight() * 1/scale, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
float delta = MinecraftClient.getInstance().getTickDelta();
|
|
||||||
|
|
||||||
Entity vehicle = entity.getVehicle();
|
|
||||||
double vehicleOffset = vehicle == null ? 0 : vehicle.getHeight() - vehicle.getMountedHeightOffset();
|
|
||||||
|
|
||||||
return new Vec3d(
|
|
||||||
MathHelper.lerp(delta, entity.prevX, entity.getX()),
|
|
||||||
MathHelper.lerp(delta, entity.prevY, entity.getY()) + vehicleOffset,
|
|
||||||
MathHelper.lerp(delta, entity.prevZ, entity.getZ())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Box getComputedBoundingBox(LivingEntity entity) {
|
|
||||||
float scale = getMetadata().getSize().getScaleFactor() + 0.1F;
|
|
||||||
|
|
||||||
Vec3d pos = getAbsoluteRidingOffset(entity);
|
|
||||||
|
|
||||||
float width = entity.getWidth() * scale;
|
|
||||||
|
|
||||||
return new Box(
|
|
||||||
- width, (entity.getHeight() * scale), -width,
|
|
||||||
width, 0, width).offset(pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return MoreObjects.toStringHelper(this)
|
return MoreObjects.toStringHelper(this)
|
||||||
.add("texture", texture)
|
.add("texture", texture)
|
||||||
.add("metadata", metadata)
|
.add("metadata", metadata)
|
||||||
|
.add("defaulted", defaulted)
|
||||||
.toString();
|
.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface RegistrationHandler {
|
public interface RegistrationHandler {
|
||||||
boolean shouldUpdateRegistration(Pony pony);
|
boolean shouldUpdateRegistration(IPony pony);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@ import com.google.common.cache.LoadingCache;
|
||||||
import com.minelittlepony.api.pony.IPony;
|
import com.minelittlepony.api.pony.IPony;
|
||||||
import com.minelittlepony.api.pony.IPonyManager;
|
import com.minelittlepony.api.pony.IPonyManager;
|
||||||
import com.minelittlepony.client.MineLittlePony;
|
import com.minelittlepony.client.MineLittlePony;
|
||||||
|
import com.minelittlepony.client.render.IPonyRenderContext;
|
||||||
|
import com.minelittlepony.client.render.PonyRenderDispatcher;
|
||||||
import com.minelittlepony.client.render.blockentity.skull.PonySkullRenderer;
|
import com.minelittlepony.client.render.blockentity.skull.PonySkullRenderer;
|
||||||
import com.minelittlepony.settings.PonyConfig;
|
import com.minelittlepony.settings.PonyConfig;
|
||||||
import com.minelittlepony.settings.PonyLevel;
|
import com.minelittlepony.settings.PonyLevel;
|
||||||
|
@ -15,9 +17,12 @@ import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
|
||||||
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
||||||
import net.minecraft.client.util.DefaultSkinHelper;
|
import net.minecraft.client.util.DefaultSkinHelper;
|
||||||
import net.minecraft.resource.ResourceManager;
|
import net.minecraft.resource.ResourceManager;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -41,12 +46,28 @@ public class PonyManager implements IPonyManager, SimpleSynchronousResourceReloa
|
||||||
this.config = config;
|
this.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<IPony> getPony(@Nullable Entity entity) {
|
||||||
|
if (entity instanceof PlayerEntity player) {
|
||||||
|
return Optional.of(getPony(player));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entity instanceof LivingEntity living) {
|
||||||
|
IPonyRenderContext<LivingEntity, ?> dispatcher = PonyRenderDispatcher.getInstance().getPonyRenderer(living);
|
||||||
|
if (dispatcher != null) {
|
||||||
|
return Optional.of(dispatcher.getEntityPony(living));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IPony getPony(Identifier resource) {
|
public IPony getPony(Identifier resource) {
|
||||||
try {
|
try {
|
||||||
return poniesCache.get(resource);
|
return poniesCache.get(resource);
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
return new Pony(resource, Memoize.of(PonyData.NULL));
|
return new Pony(resource, PonyData.MEM_NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +104,7 @@ public class PonyManager implements IPonyManager, SimpleSynchronousResourceReloa
|
||||||
public IPony getPony(Identifier resource, UUID uuid) {
|
public IPony getPony(Identifier resource, UUID uuid) {
|
||||||
IPony pony = getPony(resource);
|
IPony pony = getPony(resource);
|
||||||
|
|
||||||
if (config.ponyLevel.get() == PonyLevel.PONIES && pony.getMetadata().getRace().isHuman()) {
|
if (config.ponyLevel.get() == PonyLevel.PONIES && pony.metadata().getRace().isHuman()) {
|
||||||
return getBackgroundPony(uuid);
|
return getBackgroundPony(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +114,7 @@ public class PonyManager implements IPonyManager, SimpleSynchronousResourceReloa
|
||||||
@Override
|
@Override
|
||||||
public IPony getDefaultPony(UUID uuid) {
|
public IPony getDefaultPony(UUID uuid) {
|
||||||
if (config.ponyLevel.get() != PonyLevel.PONIES) {
|
if (config.ponyLevel.get() != PonyLevel.PONIES) {
|
||||||
return ((Pony)getPony(DefaultSkinHelper.getTexture(uuid))).defaulted();
|
return ((Pony)getPony(DefaultSkinHelper.getTexture(uuid))).markDefaulted();
|
||||||
}
|
}
|
||||||
|
|
||||||
return getBackgroundPony(uuid);
|
return getBackgroundPony(uuid);
|
||||||
|
@ -101,7 +122,7 @@ public class PonyManager implements IPonyManager, SimpleSynchronousResourceReloa
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IPony getBackgroundPony(UUID uuid) {
|
public IPony getBackgroundPony(UUID uuid) {
|
||||||
return ((Pony)getPony(MineLittlePony.getInstance().getVariatedTextures().get(BACKGROUND_PONIES, uuid))).defaulted();
|
return ((Pony)getPony(MineLittlePony.getInstance().getVariatedTextures().get(BACKGROUND_PONIES, uuid))).markDefaulted();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -13,6 +13,7 @@ import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
|
||||||
import com.minelittlepony.api.pony.IPony;
|
import com.minelittlepony.api.pony.IPony;
|
||||||
|
import com.minelittlepony.client.PonyBounds;
|
||||||
|
|
||||||
public final class DebugBoundingBoxRenderer {
|
public final class DebugBoundingBoxRenderer {
|
||||||
|
|
||||||
|
@ -29,7 +30,7 @@ public final class DebugBoundingBoxRenderer {
|
||||||
stack.push();
|
stack.push();
|
||||||
stack.translate(-offset.x, -offset.y, -offset.z);
|
stack.translate(-offset.x, -offset.y, -offset.z);
|
||||||
|
|
||||||
Box boundingBox = pony.getComputedBoundingBox(entity);
|
Box boundingBox = PonyBounds.getBoundingBox(pony, entity);
|
||||||
|
|
||||||
Vec3d pos = entity.getPos();
|
Vec3d pos = entity.getPos();
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,13 @@ package com.minelittlepony.client.render;
|
||||||
|
|
||||||
import com.minelittlepony.api.model.ModelAttributes;
|
import com.minelittlepony.api.model.ModelAttributes;
|
||||||
import com.minelittlepony.api.pony.IPony;
|
import com.minelittlepony.api.pony.IPony;
|
||||||
|
import com.minelittlepony.api.pony.network.MsgPonyData;
|
||||||
|
import com.minelittlepony.api.pony.network.fabric.Channel;
|
||||||
|
import com.minelittlepony.api.pony.network.fabric.PonyDataCallback;
|
||||||
import com.minelittlepony.client.MineLittlePony;
|
import com.minelittlepony.client.MineLittlePony;
|
||||||
import com.minelittlepony.client.model.IPonyModel;
|
import com.minelittlepony.client.model.IPonyModel;
|
||||||
import com.minelittlepony.client.model.ModelWrapper;
|
import com.minelittlepony.client.model.ModelWrapper;
|
||||||
|
import com.minelittlepony.client.pony.Pony;
|
||||||
import com.minelittlepony.client.transform.PonyPosture;
|
import com.minelittlepony.client.transform.PonyPosture;
|
||||||
import com.minelittlepony.mson.api.ModelKey;
|
import com.minelittlepony.mson.api.ModelKey;
|
||||||
import com.minelittlepony.util.MathUtil;
|
import com.minelittlepony.util.MathUtil;
|
||||||
|
@ -12,13 +16,18 @@ import com.mojang.blaze3d.platform.GlStateManager.DstFactor;
|
||||||
import com.mojang.blaze3d.platform.GlStateManager.SrcFactor;
|
import com.mojang.blaze3d.platform.GlStateManager.SrcFactor;
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import net.fabricmc.api.EnvType;
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.render.Frustum;
|
import net.minecraft.client.render.Frustum;
|
||||||
import net.minecraft.client.render.entity.model.EntityModel;
|
import net.minecraft.client.render.entity.model.EntityModel;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
public class EquineRenderManager<T extends LivingEntity, M extends EntityModel<T> & IPonyModel<T>> {
|
public class EquineRenderManager<T extends LivingEntity, M extends EntityModel<T> & IPonyModel<T>> {
|
||||||
|
@ -146,18 +155,32 @@ public class EquineRenderManager<T extends LivingEntity, M extends EntityModel<T
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateMetadata(Identifier texture) {
|
public void updateMetadata(Identifier texture) {
|
||||||
pony = MineLittlePony.getInstance().getManager().getPony(texture);
|
pony = IPony.getManager().getPony(texture);
|
||||||
playerModel.applyMetadata(pony.getMetadata());
|
playerModel.applyMetadata(pony.metadata());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateModel(T entity, ModelAttributes.Mode mode) {
|
public void updateModel(T entity, ModelAttributes.Mode mode) {
|
||||||
pony = renderer.getEntityPony(entity);
|
pony = renderer.getEntityPony(entity);
|
||||||
playerModel.applyMetadata(pony.getMetadata());
|
playerModel.applyMetadata(pony.metadata());
|
||||||
pony.updateForEntity(entity);
|
updateForEntity(pony, entity);
|
||||||
|
|
||||||
getModel().updateLivingState(entity, pony, mode);
|
getModel().updateLivingState(entity, pony, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateForEntity(IPony pony, Entity entity) {
|
||||||
|
if (pony.hasMetadata() && entity instanceof Pony.RegistrationHandler && ((Pony.RegistrationHandler)entity).shouldUpdateRegistration(pony)) {
|
||||||
|
entity.calculateDimensions();
|
||||||
|
|
||||||
|
PlayerEntity clientPlayer = MinecraftClient.getInstance().player;
|
||||||
|
if (clientPlayer != null) {
|
||||||
|
if (Objects.equals(entity, clientPlayer) || Objects.equals(((PlayerEntity)entity).getGameProfile(), clientPlayer.getGameProfile())) {
|
||||||
|
Channel.broadcastPonyData(new MsgPonyData(pony.metadata(), pony.defaulted()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PonyDataCallback.EVENT.invoker().onPonyDataAvailable((PlayerEntity)entity, pony.metadata(), pony.defaulted(), EnvType.CLIENT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public IPony getPony(T entity) {
|
public IPony getPony(T entity) {
|
||||||
updateModel(entity, ModelAttributes.Mode.THIRD_PERSON);
|
updateModel(entity, ModelAttributes.Mode.THIRD_PERSON);
|
||||||
return pony;
|
return pony;
|
||||||
|
|
|
@ -6,7 +6,7 @@ import net.minecraft.util.math.Box;
|
||||||
|
|
||||||
import org.joml.Matrix4f;
|
import org.joml.Matrix4f;
|
||||||
|
|
||||||
import com.minelittlepony.api.pony.IPony;
|
import com.minelittlepony.client.PonyBounds;
|
||||||
|
|
||||||
public class FrustrumCheck<T extends LivingEntity> extends Frustum {
|
public class FrustrumCheck<T extends LivingEntity> extends Frustum {
|
||||||
|
|
||||||
|
@ -29,11 +29,7 @@ public class FrustrumCheck<T extends LivingEntity> extends Frustum {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isVisible(Box bounds) {
|
public boolean isVisible(Box bounds) {
|
||||||
IPony pony = renderer.getPony(entity);
|
return vanilla.isVisible(PonyBounds.getBoundingBox(renderer.getPony(entity), entity));
|
||||||
|
|
||||||
Box boundingBox = pony.getComputedBoundingBox(entity);
|
|
||||||
|
|
||||||
return vanilla.isVisible(boundingBox);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -27,10 +27,10 @@ public interface IPonyRenderContext<T extends LivingEntity, M extends EntityMode
|
||||||
* Called by riders to have their transportation adjust their position.
|
* Called by riders to have their transportation adjust their position.
|
||||||
*/
|
*/
|
||||||
default void translateRider(T entity, IPony entityPony, LivingEntity passenger, IPony passengerPony, MatrixStack stack, float ticks) {
|
default void translateRider(T entity, IPony entityPony, LivingEntity passenger, IPony passengerPony, MatrixStack stack, float ticks) {
|
||||||
if (!passengerPony.getRace().isHuman()) {
|
if (!passengerPony.race().isHuman()) {
|
||||||
float yaw = MathUtil.interpolateDegress((float)entity.prevY, (float)entity.getY(), ticks);
|
float yaw = MathUtil.interpolateDegress((float)entity.prevY, (float)entity.getY(), ticks);
|
||||||
|
|
||||||
getModelWrapper().applyMetadata(entityPony.getMetadata());
|
getModelWrapper().applyMetadata(entityPony.metadata());
|
||||||
M model = getModelWrapper().body();
|
M model = getModelWrapper().body();
|
||||||
|
|
||||||
model.transform(BodyPart.BACK, stack);
|
model.transform(BodyPart.BACK, stack);
|
||||||
|
|
|
@ -84,7 +84,7 @@ public class LevitatingItemRenderer {
|
||||||
|
|
||||||
matrix.push();
|
matrix.push();
|
||||||
|
|
||||||
boolean doMagic = MineLittlePony.getInstance().getConfig().fpsmagic.get() && pony.getMetadata().hasMagic();
|
boolean doMagic = MineLittlePony.getInstance().getConfig().fpsmagic.get() && pony.metadata().hasMagic();
|
||||||
|
|
||||||
if (doMagic) {
|
if (doMagic) {
|
||||||
setupPerspective(itemRenderer, entity, stack, left, matrix);
|
setupPerspective(itemRenderer, entity, stack, left, matrix);
|
||||||
|
@ -93,7 +93,7 @@ public class LevitatingItemRenderer {
|
||||||
itemRenderer.renderItem(entity, stack, mode, left, matrix, renderContext, world, lightUv, OverlayTexture.DEFAULT_UV, posLong);
|
itemRenderer.renderItem(entity, stack, mode, left, matrix, renderContext, world, lightUv, OverlayTexture.DEFAULT_UV, posLong);
|
||||||
|
|
||||||
if (doMagic) {
|
if (doMagic) {
|
||||||
setColor(pony.getMetadata().getGlowColor());
|
setColor(pony.metadata().getGlowColor());
|
||||||
|
|
||||||
matrix.scale(1.1F, 1.1F, 1.1F);
|
matrix.scale(1.1F, 1.1F, 1.1F);
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class MobSkull implements ISkull {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean bindPony(IPony pony) {
|
public boolean bindPony(IPony pony) {
|
||||||
ponyHead.get().setMetadata(pony.getMetadata());
|
ponyHead.get().setMetadata(pony.metadata());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class PlayerPonySkull implements ISkull {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Identifier getSkinResource(@Nullable GameProfile profile) {
|
public Identifier getSkinResource(@Nullable GameProfile profile) {
|
||||||
deadMau5.get().setVisible(true);//profile != null && "deadmau5".equals(profile.getName()));
|
deadMau5.get().setVisible(profile != null && "deadmau5".equals(profile.getName()));
|
||||||
|
|
||||||
if (profile != null) {
|
if (profile != null) {
|
||||||
Identifier skin = SkinsProxy.instance.getSkinTexture(profile);
|
Identifier skin = SkinsProxy.instance.getSkinTexture(profile);
|
||||||
|
@ -54,12 +54,12 @@ public class PlayerPonySkull implements ISkull {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean bindPony(IPony pony) {
|
public boolean bindPony(IPony pony) {
|
||||||
Race race = pony.getRace();
|
Race race = pony.race();
|
||||||
if (race.isHuman()) {
|
if (race.isHuman()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ponyHead = modelCache.computeIfAbsent(ModelType.getPlayerModel(race), key -> key.getKey(false).createModel());
|
ponyHead = modelCache.computeIfAbsent(ModelType.getPlayerModel(race), key -> key.getKey(false).createModel());
|
||||||
ponyHead.setMetadata(pony.getMetadata());
|
ponyHead.setMetadata(pony.metadata());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,7 +99,7 @@ public class PlayerPonyRenderer extends PlayerEntityRenderer implements IPonyRen
|
||||||
// (shadows are drawn after us)
|
// (shadows are drawn after us)
|
||||||
if (!entity.hasVehicle() && !entity.isSleeping()) {
|
if (!entity.hasVehicle() && !entity.isSleeping()) {
|
||||||
float yaw = MathHelper.lerpAngleDegrees(tickDelta, entity.prevBodyYaw, entity.bodyYaw);
|
float yaw = MathHelper.lerpAngleDegrees(tickDelta, entity.prevBodyYaw, entity.bodyYaw);
|
||||||
float l = entity.getWidth() / 2 * manager.getPony(entity).getMetadata().getSize().getScaleFactor();
|
float l = entity.getWidth() / 2 * manager.getPony(entity).metadata().getSize().getScaleFactor();
|
||||||
|
|
||||||
stack.multiply(RotationAxis.NEGATIVE_Y.rotationDegrees(yaw));
|
stack.multiply(RotationAxis.NEGATIVE_Y.rotationDegrees(yaw));
|
||||||
stack.translate(0, 0, -l);
|
stack.translate(0, 0, -l);
|
||||||
|
@ -178,7 +178,7 @@ public class PlayerPonyRenderer extends PlayerEntityRenderer implements IPonyRen
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Identifier getTexture(AbstractClientPlayerEntity player) {
|
public Identifier getTexture(AbstractClientPlayerEntity player) {
|
||||||
return manager.getPony(player).getTexture();
|
return manager.getPony(player).texture();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.minelittlepony.client.render.entity;
|
package com.minelittlepony.client.render.entity;
|
||||||
|
|
||||||
import com.minelittlepony.api.pony.IPony;
|
import com.minelittlepony.api.pony.IPony;
|
||||||
|
import com.minelittlepony.api.pony.PonyPosture;
|
||||||
import com.minelittlepony.api.pony.meta.Race;
|
import com.minelittlepony.api.pony.meta.Race;
|
||||||
import com.minelittlepony.client.SkinsProxy;
|
import com.minelittlepony.client.SkinsProxy;
|
||||||
import com.minelittlepony.client.model.ClientPonyModel;
|
import com.minelittlepony.client.model.ClientPonyModel;
|
||||||
|
@ -35,12 +36,12 @@ public class PlayerSeaponyRenderer extends PlayerPonyRenderer {
|
||||||
public IPony getEntityPony(AbstractClientPlayerEntity player) {
|
public IPony getEntityPony(AbstractClientPlayerEntity player) {
|
||||||
IPony pony = super.getEntityPony(player);
|
IPony pony = super.getEntityPony(player);
|
||||||
|
|
||||||
boolean wet = pony.isPartiallySubmerged(player);
|
boolean wet = PonyPosture.isPartiallySubmerged(player);
|
||||||
|
|
||||||
model = manager.setModel(wet ? seapony : normalPony).body();
|
model = manager.setModel(wet ? seapony : normalPony).body();
|
||||||
|
|
||||||
float state = wet ? 100 : 0;
|
float state = wet ? 100 : 0;
|
||||||
float interpolated = pony.getMetadata().getInterpolator(player.getUuid()).interpolate("seapony_state", state, 5);
|
float interpolated = pony.metadata().getInterpolator(player.getUuid()).interpolate("seapony_state", state, 5);
|
||||||
|
|
||||||
if (!MathUtil.compareFloats(interpolated, state)) {
|
if (!MathUtil.compareFloats(interpolated, state)) {
|
||||||
double x = player.getX() + (player.getEntityWorld().getRandom().nextFloat() * 2) - 1;
|
double x = player.getX() + (player.getEntityWorld().getRandom().nextFloat() * 2) - 1;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.minelittlepony.client.render.entity.feature;
|
package com.minelittlepony.client.render.entity.feature;
|
||||||
|
|
||||||
import com.minelittlepony.api.model.BodyPart;
|
import com.minelittlepony.api.model.BodyPart;
|
||||||
|
import com.minelittlepony.api.pony.PonyPosture;
|
||||||
import com.minelittlepony.client.model.IPonyModel;
|
import com.minelittlepony.client.model.IPonyModel;
|
||||||
import com.minelittlepony.client.model.ModelType;
|
import com.minelittlepony.client.model.ModelType;
|
||||||
import com.minelittlepony.client.model.PonyElytra;
|
import com.minelittlepony.client.model.PonyElytra;
|
||||||
|
@ -43,7 +44,7 @@ public class ElytraFeature<T extends LivingEntity, M extends EntityModel<T> & IP
|
||||||
|
|
||||||
getContextModel().copyStateTo(elytra);
|
getContextModel().copyStateTo(elytra);
|
||||||
if (elytra instanceof PonyElytra) {
|
if (elytra instanceof PonyElytra) {
|
||||||
((PonyElytra<T>)elytra).isSneaking = getContext().getEntityPony(entity).isCrouching(entity);
|
((PonyElytra<T>)elytra).isSneaking = PonyPosture.isCrouching(getContext().getEntityPony(entity), entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
elytra.setAngles(entity, limbDistance, limbAngle, age, headYaw, headPitch);
|
elytra.setAngles(entity, limbDistance, limbAngle, age, headYaw, headPitch);
|
||||||
|
|
|
@ -57,7 +57,7 @@ abstract class AbstractNpcRenderer<T extends MobEntity & VillagerDataContainer>
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(T entity, float entityYaw, float tickDelta, MatrixStack stack, VertexConsumerProvider renderContext, int lightUv) {
|
public void render(T entity, float entityYaw, float tickDelta, MatrixStack stack, VertexConsumerProvider renderContext, int lightUv) {
|
||||||
model = manager.setModel(models.computeIfAbsent(getEntityPony(entity).getRace(), this::createModel)).body();
|
model = manager.setModel(models.computeIfAbsent(getEntityPony(entity).race(), this::createModel)).body();
|
||||||
|
|
||||||
super.render(entity, entityYaw, tickDelta, stack, renderContext, lightUv);
|
super.render(entity, entityYaw, tickDelta, stack, renderContext, lightUv);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue