package com.minelittlepony.client.model; import net.minecraft.client.model.Cuboid; import net.minecraft.client.render.entity.model.BipedEntityModel; import net.minecraft.client.render.entity.model.PlayerEntityModel; import net.minecraft.entity.LivingEntity; import com.minelittlepony.client.pony.PonyData; import com.minelittlepony.model.ModelAttributes; import com.minelittlepony.pony.IPony; import com.minelittlepony.pony.IPonyData; import com.minelittlepony.pony.meta.Size; import java.util.Random; /** * The raw pony model without any implementations. * Will act effectively the same as a normal player model without any hints * of being cute and adorable. * * Modders can extend this class to make their own pony models if they wish. */ public abstract class ClientPonyModel extends PlayerEntityModel implements IPonyModel { /** * The model attributes. */ protected ModelAttributes attributes = new ModelAttributes<>(); /** * Associated pony data. */ protected IPonyData metadata = new PonyData(); public ClientPonyModel(float float_1, boolean boolean_1) { super(float_1, boolean_1); } @Override public void updateLivingState(T entity, IPony pony) { isChild = entity.isBaby(); /*This was a bug, but I'm calling it a feature * isSneaking = entity.isInSneakingPose() *If a pony is able to get into a 1.5 tall gap whilst sneaking and releases the sneak key, *they will stop crouching. Vanilla behaviour would have them continue to crouch, but that *would look weird, especially with winged pegasi and bat ponies. */ isSneaking = entity.isSneaking(); attributes.updateLivingState(entity, pony); } @Override public ModelAttributes getAttributes() { return attributes; } @Override public IPonyData getMetadata() { return metadata; } @Override public Size getSize() { return isChild ? Size.FOAL : getMetadata().getSize(); } @Override public void apply(IPonyData meta) { metadata = meta; } @Override public Cuboid getHead() { return head; } @Override public boolean isRiding() { return isRiding; } @Override public float getSwingAmount() { return handSwingProgress; } /** * Copies this model's attributes into the passed model. */ @Override public void setAttributes(BipedEntityModel model) { super.setAttributes(model); if (model instanceof ClientPonyModel) { ((ClientPonyModel)model).attributes = attributes; ((ClientPonyModel)model).metadata = metadata; } } @Override public Cuboid getRandomCuboid(Random rand) { // grab one at random, but cycle through the list until you find one that's filled. // Return if you find one, or if you get back to where you started in which case there isn't any. int randomI = rand.nextInt(cuboidList.size()); int index = randomI; Cuboid result; do { result = cuboidList.get(randomI); if (!result.boxes.isEmpty()) return result; index = (index + 1) % cuboidList.size(); } while (index != randomI); if (result.boxes.isEmpty()) { result.addBox(0, 0, 0, 0, 0, 0); } if (result.boxes.isEmpty()) { throw new IllegalStateException("This model contains absolutely no boxes and a box could not be added!"); } return result; } }