mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2025-02-13 08:14:23 +01:00
Fixed third person magic rendering
This commit is contained in:
parent
4e57f6a267
commit
2ace8f8f37
6 changed files with 52 additions and 25 deletions
|
@ -43,8 +43,6 @@ abstract class MixinHeldItemRenderer {
|
||||||
VertexConsumerProvider vertices,
|
VertexConsumerProvider vertices,
|
||||||
@Nullable World world,
|
@Nullable World world,
|
||||||
int light, int overlay, int seed, Operation<Void> operation) {
|
int light, int overlay, int seed, Operation<Void> operation) {
|
||||||
|
|
||||||
|
|
||||||
if (!MineLittlePony.getInstance().getRenderDispatcher().getMagicRenderer().renderItem(target, entity, stack, mode, left, matrices, vertices, world, light, overlay, seed, operation)) {
|
if (!MineLittlePony.getInstance().getRenderDispatcher().getMagicRenderer().renderItem(target, entity, stack, mode, left, matrices, vertices, world, light, overlay, seed, operation)) {
|
||||||
operation.call(target, entity, stack, mode, left, matrices, vertices, world, light, overlay, seed);
|
operation.call(target, entity, stack, mode, left, matrices, vertices, world, light, overlay, seed);
|
||||||
}
|
}
|
||||||
|
|
|
@ -528,15 +528,7 @@ public abstract class AbstractPonyModel<T extends PonyRenderState> extends Clien
|
||||||
hat.visible = false;
|
hat.visible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void positionheldItem(T state, Arm arm, MatrixStack matrices) {
|
||||||
public final void setArmAngle(Arm arm, MatrixStack matrices) {
|
|
||||||
super.setArmAngle(arm, matrices);
|
|
||||||
if (currentState != null) {
|
|
||||||
positionheldItem(currentState, arm, matrices);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void positionheldItem(T state, Arm arm, MatrixStack matrices) {
|
|
||||||
float left = arm == Arm.LEFT ? -1 : 1;
|
float left = arm == Arm.LEFT ? -1 : 1;
|
||||||
|
|
||||||
UseAction action = state.attributes.heldStack.getUseAction();
|
UseAction action = state.attributes.heldStack.getUseAction();
|
||||||
|
|
|
@ -48,7 +48,7 @@ public class WitchPonyModel extends EarthPonyModel<WitchRenderer.State> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void positionheldItem(WitchRenderer.State state, Arm arm, MatrixStack matrices) {
|
public void positionheldItem(WitchRenderer.State state, Arm arm, MatrixStack matrices) {
|
||||||
super.positionheldItem(state, arm, matrices);
|
super.positionheldItem(state, arm, matrices);
|
||||||
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(10));
|
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(10));
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class UnicornModel<T extends PonyRenderState> extends EarthPonyModel<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void positionheldItem(T state, Arm arm, MatrixStack matrices) {
|
public void positionheldItem(T state, Arm arm, MatrixStack matrices) {
|
||||||
super.positionheldItem(state, arm, matrices);
|
super.positionheldItem(state, arm, matrices);
|
||||||
|
|
||||||
if (!PonyConfig.getInstance().tpsmagic.get() || !state.hasMagicGlow()) {
|
if (!PonyConfig.getInstance().tpsmagic.get() || !state.hasMagicGlow()) {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||||
import com.minelittlepony.api.config.PonyConfig;
|
import com.minelittlepony.api.config.PonyConfig;
|
||||||
import com.minelittlepony.api.pony.Pony;
|
import com.minelittlepony.api.pony.Pony;
|
||||||
import com.minelittlepony.client.MineLittlePony;
|
import com.minelittlepony.client.MineLittlePony;
|
||||||
|
import com.minelittlepony.client.render.entity.state.PonyRenderState;
|
||||||
import com.minelittlepony.common.util.render.RenderLayerUtil;
|
import com.minelittlepony.common.util.render.RenderLayerUtil;
|
||||||
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
@ -23,7 +24,7 @@ import net.minecraft.util.math.RotationAxis;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class LevitatingItemRenderer {
|
public class LevitatingItemRenderer {
|
||||||
private VertexConsumerProvider getProvider(Pony pony, VertexConsumerProvider provider) {
|
public static VertexConsumerProvider getProvider(Pony pony, VertexConsumerProvider provider) {
|
||||||
final int color = pony.metadata().glowColor();
|
final int color = pony.metadata().glowColor();
|
||||||
return layer -> {
|
return layer -> {
|
||||||
if (layer.getVertexFormat() != VertexFormats.POSITION_COLOR_TEXTURE_OVERLAY_LIGHT_NORMAL) {
|
if (layer.getVertexFormat() != VertexFormats.POSITION_COLOR_TEXTURE_OVERLAY_LIGHT_NORMAL) {
|
||||||
|
@ -59,7 +60,7 @@ public class LevitatingItemRenderer {
|
||||||
boolean doMagic = (mode.isFirstPerson() ? PonyConfig.getInstance().fpsmagic : PonyConfig.getInstance().tpsmagic).get() && state.hasMagicGlow();
|
boolean doMagic = (mode.isFirstPerson() ? PonyConfig.getInstance().fpsmagic : PonyConfig.getInstance().tpsmagic).get() && state.hasMagicGlow();
|
||||||
|
|
||||||
if (doMagic && mode.isFirstPerson()) {
|
if (doMagic && mode.isFirstPerson()) {
|
||||||
setupPerspective(entity, stack, left, matrices);
|
setupPerspective(state, stack, left, matrices);
|
||||||
}
|
}
|
||||||
|
|
||||||
original.call(itemRenderer, entity, stack, mode, left, matrices, vertices, world, light, overlay, seed);
|
original.call(itemRenderer, entity, stack, mode, left, matrices, vertices, world, light, overlay, seed);
|
||||||
|
@ -72,14 +73,11 @@ public class LevitatingItemRenderer {
|
||||||
stack.set(DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, false);
|
stack.set(DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
float tickDelta = MinecraftClient.getInstance().getRenderTickCounter().getTickDelta(false) + entity.age;
|
|
||||||
|
|
||||||
|
|
||||||
float driftStrength = 0.002F;
|
float driftStrength = 0.002F;
|
||||||
float xDrift = MathHelper.sin(tickDelta / 20F) * driftStrength;
|
float xDrift = MathHelper.sin(state.age / 20F) * driftStrength;
|
||||||
float zDrift = MathHelper.cos((tickDelta + 20) / 20F) * driftStrength;
|
float zDrift = MathHelper.cos((state.age + 20) / 20F) * driftStrength;
|
||||||
|
|
||||||
float scale = 1.1F + (MathHelper.sin(tickDelta / 20F) + 1) * driftStrength;
|
float scale = 1.1F + (MathHelper.sin(state.age / 20F) + 1) * driftStrength;
|
||||||
matrices.scale(scale, scale, scale);
|
matrices.scale(scale, scale, scale);
|
||||||
matrices.translate(0.015F + xDrift, 0.01F, 0.01F + zDrift);
|
matrices.translate(0.015F + xDrift, 0.01F, 0.01F + zDrift);
|
||||||
|
|
||||||
|
@ -96,14 +94,14 @@ public class LevitatingItemRenderer {
|
||||||
/**
|
/**
|
||||||
* Moves held items to look like they're floating in the player's field.
|
* Moves held items to look like they're floating in the player's field.
|
||||||
*/
|
*/
|
||||||
private void setupPerspective(LivingEntity entity, ItemStack item, boolean left, MatrixStack stack) {
|
public static void setupPerspective(PonyRenderState state, ItemStack item, boolean left, MatrixStack stack) {
|
||||||
UseAction action = item.getUseAction();
|
UseAction action = item.getUseAction();
|
||||||
|
|
||||||
boolean doNormal = entity.getItemUseTime() <= 0 || action == UseAction.NONE || (action == UseAction.CROSSBOW && CrossbowItem.isCharged(item));
|
boolean doNormal = state.itemUseTime <= 0 || action == UseAction.NONE || (action == UseAction.CROSSBOW && CrossbowItem.isCharged(item));
|
||||||
|
|
||||||
if (doNormal) { // eating, blocking, and drinking are not transformed. Only held items.
|
if (doNormal) { // eating, blocking, and drinking are not transformed. Only held items.
|
||||||
int sign = left ? 1 : -1;
|
int sign = left ? 1 : -1;
|
||||||
float ticks = entity.age * sign;
|
float ticks = state.age * sign;
|
||||||
|
|
||||||
float floatAmount = -(float)Math.sin(ticks / 9F) / 40F;
|
float floatAmount = -(float)Math.sin(ticks / 9F) / 40F;
|
||||||
float driftAmount = -(float)Math.cos(ticks / 6F) / 40F;
|
float driftAmount = -(float)Math.cos(ticks / 6F) / 40F;
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
package com.minelittlepony.client.render.entity.feature;
|
package com.minelittlepony.client.render.entity.feature;
|
||||||
|
|
||||||
|
import com.minelittlepony.api.config.PonyConfig;
|
||||||
import com.minelittlepony.api.model.*;
|
import com.minelittlepony.api.model.*;
|
||||||
|
import com.minelittlepony.client.model.AbstractPonyModel;
|
||||||
import com.minelittlepony.client.model.ClientPonyModel;
|
import com.minelittlepony.client.model.ClientPonyModel;
|
||||||
|
import com.minelittlepony.client.render.LevitatingItemRenderer;
|
||||||
import com.minelittlepony.client.render.PonyRenderContext;
|
import com.minelittlepony.client.render.PonyRenderContext;
|
||||||
import com.minelittlepony.client.render.entity.state.PonyRenderState;
|
import com.minelittlepony.client.render.entity.state.PonyRenderState;
|
||||||
|
|
||||||
|
@ -9,12 +12,16 @@ import net.minecraft.client.render.VertexConsumerProvider;
|
||||||
import net.minecraft.client.render.entity.feature.PlayerHeldItemFeatureRenderer;
|
import net.minecraft.client.render.entity.feature.PlayerHeldItemFeatureRenderer;
|
||||||
import net.minecraft.client.render.entity.state.PlayerEntityRenderState;
|
import net.minecraft.client.render.entity.state.PlayerEntityRenderState;
|
||||||
import net.minecraft.client.render.item.ItemRenderer;
|
import net.minecraft.client.render.item.ItemRenderer;
|
||||||
|
import net.minecraft.client.render.model.BakedModel;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
import net.minecraft.component.DataComponentTypes;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.ModelTransformationMode;
|
import net.minecraft.item.ModelTransformationMode;
|
||||||
import net.minecraft.util.Arm;
|
import net.minecraft.util.Arm;
|
||||||
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@SuppressWarnings(value = {"unchecked"})
|
|
||||||
public class HeldItemFeature<
|
public class HeldItemFeature<
|
||||||
S extends PonyRenderState,
|
S extends PonyRenderState,
|
||||||
M extends ClientPonyModel<S>
|
M extends ClientPonyModel<S>
|
||||||
|
@ -27,6 +34,7 @@ public class HeldItemFeature<
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings(value = {"unchecked"})
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
public final void render(MatrixStack matrices, VertexConsumerProvider vertices, int light, PlayerEntityRenderState state, float limbAngle, float limbDistance) {
|
public final void render(MatrixStack matrices, VertexConsumerProvider vertices, int light, PlayerEntityRenderState state, float limbAngle, float limbDistance) {
|
||||||
|
@ -50,4 +58,35 @@ public class HeldItemFeature<
|
||||||
matrices.pop();
|
matrices.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings(value = {"unchecked"})
|
||||||
|
protected void renderItem(S state, @Nullable BakedModel model, ItemStack item, ModelTransformationMode mode, Arm arm, MatrixStack matrices, VertexConsumerProvider vertices, int light) {
|
||||||
|
if (context.getEquineManager().getModels().body() instanceof AbstractPonyModel m) {
|
||||||
|
m.positionheldItem(state, arm, matrices);
|
||||||
|
}
|
||||||
|
renderItem((PlayerEntityRenderState)state, model, item, mode, arm, matrices, vertices, light);
|
||||||
|
|
||||||
|
if (PonyConfig.getInstance().tpsmagic.get() && state.hasMagicGlow()) {
|
||||||
|
vertices = LevitatingItemRenderer.getProvider(state.pony, vertices);
|
||||||
|
|
||||||
|
if (item.hasGlint()) {
|
||||||
|
item = item.copy();
|
||||||
|
item.set(DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
float driftStrength = 0.002F;
|
||||||
|
float xDrift = MathHelper.sin(state.age / 10F) * driftStrength;
|
||||||
|
float zDrift = MathHelper.cos((state.age + 20) / 10F) * driftStrength;
|
||||||
|
|
||||||
|
float scale = 1.1F + (MathHelper.sin(state.age / 20F) + 1) * driftStrength;
|
||||||
|
matrices.scale(scale, scale, scale);
|
||||||
|
matrices.translate(0.045F + xDrift, 0.01F - 0.12F, 0.03F + zDrift);
|
||||||
|
|
||||||
|
renderItem((PlayerEntityRenderState)state, model, item, mode, arm, matrices, vertices, light);
|
||||||
|
matrices.scale(scale, scale, scale);
|
||||||
|
matrices.translate(0.1F, -0.1F, 0.1F);
|
||||||
|
matrices.translate(-0.03F - xDrift, -0.02F, -0.02F - zDrift);
|
||||||
|
renderItem((PlayerEntityRenderState)state, model, item, mode, arm, matrices, vertices, light);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue