Allow gear better control of how they're positioned

This commit is contained in:
Sollace 2022-11-02 23:12:29 +01:00
parent b686bba005
commit bf7fe63b81
4 changed files with 30 additions and 44 deletions

View file

@ -2,6 +2,7 @@ package com.minelittlepony.api.model.gear;
import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.VertexConsumer;
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.util.Identifier; import net.minecraft.util.Identifier;
@ -9,10 +10,9 @@ import net.minecraft.util.Identifier;
import com.minelittlepony.api.model.BodyPart; import com.minelittlepony.api.model.BodyPart;
import com.minelittlepony.api.model.IModel; import com.minelittlepony.api.model.IModel;
import com.minelittlepony.api.pony.meta.Wearable; import com.minelittlepony.api.pony.meta.Wearable;
import com.minelittlepony.client.model.IPonyModel;
import com.minelittlepony.client.render.entity.feature.GearFeature; import com.minelittlepony.client.render.entity.feature.GearFeature;
import org.jetbrains.annotations.Nullable;
import java.util.UUID; import java.util.UUID;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -57,32 +57,41 @@ public interface IGear {
} }
/** /**
* Orients this wearable. * Applies body transformations for this wearable
*/ */
default void setModelAttributes(IModel model, Entity entity) { default <M extends EntityModel<?> & IPonyModel<?>> void transform(M model, MatrixStack matrices) {
BodyPart part = getGearLocation();
model.transform(part, matrices);
model.getBodyPart(part).rotate(matrices);
} }
/** /**
* Sets the model's various rotation angles. * Sets the model's various rotation angles.
* *
* See {@link AbstractPonyMode.setRotationAndAngle} for an explanation of the various parameters. * See {@link AbstractPonyMode.setRotationAndAngle} for an explanation of the various parameters.
*/ */
default void pose(boolean rainboom, UUID interpolatorId, float move, float swing, float bodySwing, float ticks) { default void pose(IModel model, Entity entity, boolean rainboom, UUID interpolatorId, float move, float swing, float bodySwing, float ticks) {
setModelAttributes(model, entity);
pose(rainboom, interpolatorId, move, swing, bodySwing, ticks);
} }
/**
* @deprecated Use pose(model, entity, rainboom, interpolatorId, move, swing, bodySwing, ticks) instead
*/
@Deprecated(forRemoval = true)
default void setModelAttributes(IModel model, Entity entity) { }
/**
* @deprecated Use pose(model, entity, rainboom, interpolatorId, move, swing, bodySwing, ticks) instead
*/
@Deprecated(forRemoval = true)
default void pose(boolean rainboom, UUID interpolatorId, float move, float swing, float bodySwing, float ticks) { }
/** /**
* Renders this model component. * Renders this model component.
*/ */
void render(MatrixStack stack, VertexConsumer vertices, int overlayUv, int lightUv, float red, float green, float blue, float alpha, UUID interpolatorId); void render(MatrixStack stack, VertexConsumer vertices, int overlayUv, int lightUv, float red, float green, float blue, float alpha, UUID interpolatorId);
/**
* Sets whether this part should be rendered.
*/
default void setVisible(boolean visible) {
}
/** /**
* A render context for instance of IGear. * A render context for instance of IGear.
* *
@ -102,11 +111,6 @@ public interface IGear {
return gear.canRender(model, entity); return gear.canRender(model, entity);
} }
@Nullable
default M getEntityModel() {
return null;
}
/** /**
* Gets the default texture to use for this entity and wearable. * Gets the default texture to use for this entity and wearable.
* *

View file

@ -50,12 +50,7 @@ public class ChristmasHat extends AbstractGear implements PonyModelConstants {
} }
@Override @Override
public void setModelAttributes(IModel model, Entity entity) { public void pose(IModel model, Entity entity, boolean rainboom, UUID interpolatorId, float move, float swing, float bodySwing, float ticks) {
tint = model.getMetadata().getGlowColor();
}
@Override
public void pose(boolean rainboom, UUID interpolatorId, float move, float swing, float bodySwing, float ticks) {
float pi = PI * (float) Math.pow(swing, 16); float pi = PI * (float) Math.pow(swing, 16);
float mve = move * 0.6662f; float mve = move * 0.6662f;
@ -65,6 +60,7 @@ public class ChristmasHat extends AbstractGear implements PonyModelConstants {
bodySwing += 0.1F; bodySwing += 0.1F;
tint = model.getMetadata().getGlowColor();
left.roll = bodySwing; left.roll = bodySwing;
right.roll = -bodySwing; right.roll = -bodySwing;
} }

View file

@ -28,8 +28,6 @@ public class SaddleBags extends AbstractGear implements PonyModelConstants {
float dropAmount = 0; float dropAmount = 0;
private IModel model;
public SaddleBags(ModelPart tree) { public SaddleBags(ModelPart tree) {
strap = tree.getChild("strap"); strap = tree.getChild("strap");
leftBag = tree.getChild("left_bag"); leftBag = tree.getChild("left_bag");
@ -37,18 +35,13 @@ public class SaddleBags extends AbstractGear implements PonyModelConstants {
} }
@Override @Override
public void setModelAttributes(IModel model, Entity entity) { public void pose(IModel model, Entity entity, boolean rainboom, UUID interpolatorId, float move, float swing, float bodySwing, float ticks) {
this.model = model;
hangLow = false; hangLow = false;
if (model instanceof IPegasus) { if (model instanceof IPegasus) {
hangLow = model.canFly() && ((IPegasus)model).wingsAreOpen(); hangLow = model.canFly() && ((IPegasus)model).wingsAreOpen();
} }
}
@Override
public void pose(boolean rainboom, UUID interpolatorId, float move, float swing, float bodySwing, float ticks) {
float pi = PI * (float) Math.pow(swing, 16); float pi = PI * (float) Math.pow(swing, 16);
float mve = move * 0.6662f; float mve = move * 0.6662f;
@ -68,6 +61,7 @@ public class SaddleBags extends AbstractGear implements PonyModelConstants {
rightBag.roll = -bodySwing; rightBag.roll = -bodySwing;
dropAmount = hangLow ? 0.15F : 0; dropAmount = hangLow ? 0.15F : 0;
dropAmount = model.getMetadata().getInterpolator(interpolatorId).interpolate("dropAmount", dropAmount, 3);
} }
public void sethangingLow(boolean veryLow) { public void sethangingLow(boolean veryLow) {
@ -76,8 +70,6 @@ public class SaddleBags extends AbstractGear implements PonyModelConstants {
@Override @Override
public void render(MatrixStack stack, VertexConsumer renderContext, int overlayUv, int lightUv, float red, float green, float blue, float alpha, UUID interpolatorId) { public void render(MatrixStack stack, VertexConsumer renderContext, int overlayUv, int lightUv, float red, float green, float blue, float alpha, UUID interpolatorId) {
dropAmount = model.getMetadata().getInterpolator(interpolatorId).interpolate("dropAmount", dropAmount, 3);
stack.push(); stack.push();
stack.translate(0, dropAmount, 0); stack.translate(0, dropAmount, 0);

View file

@ -69,8 +69,7 @@ public class GearFeature<T extends LivingEntity, M extends EntityModel<T> & IPon
.forEach(entry -> { .forEach(entry -> {
stack.push(); stack.push();
BodyPart part = entry.gear.getGearLocation(); BodyPart part = entry.gear.getGearLocation();
model.transform(part, stack); entry.gear.transform(model, stack);
model.getBodyPart(part).rotate(stack);
if (entry.gear instanceof IStackable) { if (entry.gear instanceof IStackable) {
renderStackingOffsets.compute(part, (k, v) -> { renderStackingOffsets.compute(part, (k, v) -> {
@ -89,13 +88,8 @@ public class GearFeature<T extends LivingEntity, M extends EntityModel<T> & IPon
} }
private void renderGear(M model, T entity, IGear gear, MatrixStack stack, VertexConsumerProvider renderContext, int lightUv, float limbDistance, float limbAngle, float tickDelta) { private void renderGear(M model, T entity, IGear gear, MatrixStack stack, VertexConsumerProvider renderContext, int lightUv, float limbDistance, float limbAngle, float tickDelta) {
gear.setModelAttributes(model, entity); gear.pose(model, entity, model.getAttributes().isGoingFast, entity.getUuid(), limbDistance, limbAngle, model.getWobbleAmount(), tickDelta);
gear.pose(model.getAttributes().isGoingFast, entity.getUuid(), limbDistance, limbAngle, model.getWobbleAmount(), tickDelta); gear.render(stack, renderContext.getBuffer(RenderLayer.getEntityTranslucent(gear.getTexture(entity, getContext()))), lightUv, OverlayTexture.DEFAULT_UV, 1, 1, 1, 1, entity.getUuid());
RenderLayer layer = RenderLayer.getEntityTranslucent(gear.getTexture(entity, getContext()));
VertexConsumer vertexConsumer = renderContext.getBuffer(layer);
gear.render(stack, vertexConsumer, lightUv, OverlayTexture.DEFAULT_UV, 1, 1, 1, 1, entity.getUuid());
} }
static record Entry(IGear gear, Wearable wearable) {} static record Entry(IGear gear, Wearable wearable) {}