2016-11-17 05:45:04 +01:00
|
|
|
package com.minelittlepony.mixin;
|
2015-08-02 00:36:33 +02:00
|
|
|
|
2016-11-17 05:45:04 +01:00
|
|
|
import com.minelittlepony.MineLittlePony;
|
|
|
|
import com.minelittlepony.Pony;
|
2017-06-13 05:55:50 +02:00
|
|
|
import com.minelittlepony.PonyRace;
|
2016-11-17 05:45:04 +01:00
|
|
|
import com.minelittlepony.PonySize;
|
|
|
|
import com.minelittlepony.ducks.IRenderPony;
|
|
|
|
import com.minelittlepony.model.PMAPI;
|
|
|
|
import com.minelittlepony.model.PlayerModel;
|
|
|
|
import com.minelittlepony.model.pony.ModelHumanPlayer;
|
|
|
|
import com.minelittlepony.model.pony.ModelPlayerPony;
|
2017-06-13 05:55:50 +02:00
|
|
|
import com.minelittlepony.renderer.layer.LayerEntityOnPonyShoulder;
|
|
|
|
import com.minelittlepony.renderer.layer.LayerHeldPonyItem;
|
|
|
|
import com.minelittlepony.renderer.layer.LayerPonyArmor;
|
|
|
|
import com.minelittlepony.renderer.layer.LayerPonyCape;
|
|
|
|
import com.minelittlepony.renderer.layer.LayerPonyCustomHead;
|
|
|
|
import com.minelittlepony.renderer.layer.LayerPonyElytra;
|
2015-08-02 00:36:33 +02:00
|
|
|
import net.minecraft.client.entity.AbstractClientPlayer;
|
2016-05-04 03:23:57 +02:00
|
|
|
import net.minecraft.client.model.ModelPlayer;
|
|
|
|
import net.minecraft.client.model.ModelRenderer;
|
2016-05-10 21:10:29 +02:00
|
|
|
import net.minecraft.client.renderer.GlStateManager;
|
2016-05-04 03:23:57 +02:00
|
|
|
import net.minecraft.client.renderer.entity.RenderLivingBase;
|
2015-08-02 00:36:33 +02:00
|
|
|
import net.minecraft.client.renderer.entity.RenderManager;
|
|
|
|
import net.minecraft.client.renderer.entity.RenderPlayer;
|
|
|
|
import net.minecraft.client.renderer.entity.layers.LayerArrow;
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
2016-11-25 05:40:19 +01:00
|
|
|
import org.objectweb.asm.Opcodes;
|
2016-12-20 11:19:57 +01:00
|
|
|
import org.spongepowered.asm.mixin.Final;
|
2016-11-25 05:40:19 +01:00
|
|
|
import org.spongepowered.asm.mixin.Mixin;
|
|
|
|
import org.spongepowered.asm.mixin.Shadow;
|
|
|
|
import org.spongepowered.asm.mixin.injection.At;
|
|
|
|
import org.spongepowered.asm.mixin.injection.At.Shift;
|
|
|
|
import org.spongepowered.asm.mixin.injection.Inject;
|
|
|
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
|
|
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
|
|
|
2017-06-13 05:55:50 +02:00
|
|
|
import javax.annotation.Nonnull;
|
2017-06-13 05:55:50 +02:00
|
|
|
|
2016-01-15 08:59:50 +01:00
|
|
|
@Mixin(RenderPlayer.class)
|
2016-05-04 03:23:57 +02:00
|
|
|
public abstract class MixinRenderPlayer extends RenderLivingBase<AbstractClientPlayer> implements IRenderPony {
|
2016-01-15 08:59:50 +01:00
|
|
|
|
2016-01-19 06:34:07 +01:00
|
|
|
@Shadow
|
2016-12-20 11:19:57 +01:00
|
|
|
@Final
|
2016-01-19 06:34:07 +01:00
|
|
|
private boolean smallArms;
|
2015-08-02 00:36:33 +02:00
|
|
|
private PlayerModel playerModel;
|
2015-12-09 04:14:42 +01:00
|
|
|
private Pony thePony;
|
2015-08-02 00:36:33 +02:00
|
|
|
|
2016-12-27 02:58:21 +01:00
|
|
|
@SuppressWarnings("ConstantConditions")
|
2016-01-15 08:59:50 +01:00
|
|
|
private MixinRenderPlayer(RenderManager renderManager) {
|
2015-08-02 00:36:33 +02:00
|
|
|
super(renderManager, null, 0.5F);
|
|
|
|
}
|
|
|
|
|
2016-01-19 06:34:07 +01:00
|
|
|
@Inject(
|
2016-07-07 08:57:52 +02:00
|
|
|
method = "<init>(Lnet/minecraft/client/renderer/entity/RenderManager;Z)V",
|
2016-05-04 03:23:57 +02:00
|
|
|
at = @At("RETURN"))
|
2016-01-15 08:59:50 +01:00
|
|
|
private void init(RenderManager renderManager, boolean useSmallArms, CallbackInfo ci) {
|
2016-01-19 06:34:07 +01:00
|
|
|
this.playerModel = smallArms ? PMAPI.ponySmall : PMAPI.pony;
|
2015-12-09 04:14:42 +01:00
|
|
|
this.mainModel = this.playerModel.getModel();
|
2015-08-02 00:36:33 +02:00
|
|
|
this.layerRenderers.clear();
|
|
|
|
|
|
|
|
this.addLayer(new LayerPonyArmor(this));
|
2016-11-24 08:01:23 +01:00
|
|
|
this.addLayer(new LayerHeldPonyItem(this));
|
2015-08-02 00:36:33 +02:00
|
|
|
this.addLayer(new LayerArrow(this));
|
2015-08-13 00:22:21 +02:00
|
|
|
this.addLayer(new LayerPonyCape(this));
|
2016-12-29 09:08:05 +01:00
|
|
|
this.addLayer(new LayerPonyCustomHead(this));
|
2017-06-13 05:55:50 +02:00
|
|
|
this.addLayer(new LayerPonyElytra(this));
|
|
|
|
this.addLayer(new LayerEntityOnPonyShoulder(renderManager, this));
|
|
|
|
|
2015-08-02 00:36:33 +02:00
|
|
|
}
|
|
|
|
|
2016-05-04 03:23:57 +02:00
|
|
|
@Inject(
|
|
|
|
method = "doRender(Lnet/minecraft/client/entity/AbstractClientPlayer;DDDFF)V",
|
|
|
|
at = @At("HEAD"))
|
|
|
|
private void onDoRender(AbstractClientPlayer player, double x, double y, double z, float yaw, float partialTicks, CallbackInfo ci) {
|
2016-01-26 22:43:39 +01:00
|
|
|
updateModel(player);
|
2015-08-02 00:36:33 +02:00
|
|
|
|
2015-12-14 09:29:10 +01:00
|
|
|
this.playerModel.getModel().isSneak = player.isSneaking();
|
|
|
|
this.playerModel.getModel().isFlying = thePony.isPegasusFlying(player);
|
2016-07-10 05:57:05 +02:00
|
|
|
this.playerModel.getModel().isSleeping = player.isPlayerSleeping();
|
2015-08-02 00:36:33 +02:00
|
|
|
|
2017-06-13 05:55:50 +02:00
|
|
|
if (MineLittlePony.getConfig().showscale && this.playerModel.getModel().metadata.getRace() != PonyRace.HUMAN) {
|
|
|
|
PonySize size = thePony.metadata.getSize();
|
|
|
|
if (size == PonySize.FOAL) {
|
|
|
|
this.shadowSize = 0.25F;
|
|
|
|
} else if (size == PonySize.NORMAL) {
|
|
|
|
this.shadowSize = 0.4F;
|
|
|
|
} else if (size == PonySize.TALL) {
|
|
|
|
this.shadowSize = 0.45F;
|
2015-08-02 00:36:33 +02:00
|
|
|
} else {
|
|
|
|
this.shadowSize = 0.5F;
|
|
|
|
}
|
2017-06-13 05:55:50 +02:00
|
|
|
|
2015-08-02 00:36:33 +02:00
|
|
|
} else {
|
|
|
|
this.shadowSize = 0.5F;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-04 03:23:57 +02:00
|
|
|
@Inject(
|
2016-11-22 22:13:24 +01:00
|
|
|
method = "renderLivingAt(Lnet/minecraft/client/entity/AbstractClientPlayer;DDD)V",
|
2016-05-04 03:23:57 +02:00
|
|
|
at = @At("RETURN"))
|
2016-01-15 08:59:50 +01:00
|
|
|
private void setupPlayerScale(AbstractClientPlayer player, double xPosition, double yPosition, double zPosition, CallbackInfo ci) {
|
2015-08-02 00:36:33 +02:00
|
|
|
|
2016-01-26 09:16:11 +01:00
|
|
|
if (MineLittlePony.getConfig().showscale && !(playerModel.getModel() instanceof ModelHumanPlayer)) {
|
2015-12-09 04:14:42 +01:00
|
|
|
PonySize size = thePony.metadata.getSize();
|
2017-06-13 05:55:50 +02:00
|
|
|
if (size == PonySize.LARGE) {
|
2016-12-27 02:58:21 +01:00
|
|
|
GlStateManager.scale(0.9F, 0.9F, 0.9F);
|
2017-06-13 05:55:50 +02:00
|
|
|
} else if (size == PonySize.NORMAL || size == PonySize.FOAL) {
|
2016-12-27 02:58:21 +01:00
|
|
|
GlStateManager.scale(0.8F, 0.8F, 0.8F);
|
2017-06-13 05:55:50 +02:00
|
|
|
}
|
2015-08-02 00:36:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-04 03:23:57 +02:00
|
|
|
@Inject(
|
|
|
|
method = "renderRightArm(Lnet/minecraft/client/entity/AbstractClientPlayer;)V",
|
|
|
|
at = @At("HEAD"))
|
2016-01-26 09:17:08 +01:00
|
|
|
private void onRenderRightArm(AbstractClientPlayer player, CallbackInfo ci) {
|
2016-01-26 22:43:39 +01:00
|
|
|
updateModel(player);
|
2016-01-26 09:17:08 +01:00
|
|
|
bindEntityTexture(player);
|
|
|
|
}
|
|
|
|
|
2016-05-04 03:23:57 +02:00
|
|
|
@Inject(
|
|
|
|
method = "renderLeftArm(Lnet/minecraft/client/entity/AbstractClientPlayer;)V",
|
|
|
|
at = @At("HEAD"))
|
2016-01-26 09:17:08 +01:00
|
|
|
private void onRenderLeftArm(AbstractClientPlayer player, CallbackInfo ci) {
|
2016-01-26 22:43:39 +01:00
|
|
|
updateModel(player);
|
2016-01-26 09:17:08 +01:00
|
|
|
bindEntityTexture(player);
|
|
|
|
}
|
|
|
|
|
2016-05-04 03:23:57 +02:00
|
|
|
@Redirect(
|
|
|
|
method = "renderLeftArm(Lnet/minecraft/client/entity/AbstractClientPlayer;)V",
|
|
|
|
at = @At(
|
|
|
|
value = "FIELD",
|
|
|
|
target = "Lnet/minecraft/client/model/ModelPlayer;bipedLeftArm:Lnet/minecraft/client/model/ModelRenderer;",
|
|
|
|
opcode = Opcodes.GETFIELD),
|
|
|
|
require = 2)
|
|
|
|
private ModelRenderer redirectLeftArm(ModelPlayer mr) {
|
|
|
|
return this.playerModel.getModel().steveLeftArm;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Redirect(
|
|
|
|
method = "renderLeftArm(Lnet/minecraft/client/entity/AbstractClientPlayer;)V",
|
|
|
|
at = @At(
|
|
|
|
value = "FIELD",
|
|
|
|
target = "Lnet/minecraft/client/model/ModelPlayer;bipedLeftArmwear:Lnet/minecraft/client/model/ModelRenderer;",
|
|
|
|
opcode = Opcodes.GETFIELD),
|
|
|
|
require = 2)
|
|
|
|
private ModelRenderer redirectLeftArmwear(ModelPlayer mr) {
|
|
|
|
return this.playerModel.getModel().steveLeftArmwear;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Redirect(
|
|
|
|
method = "renderRightArm(Lnet/minecraft/client/entity/AbstractClientPlayer;)V",
|
|
|
|
at = @At(
|
|
|
|
value = "FIELD",
|
|
|
|
target = "Lnet/minecraft/client/model/ModelPlayer;bipedRightArm:Lnet/minecraft/client/model/ModelRenderer;",
|
|
|
|
opcode = Opcodes.GETFIELD),
|
|
|
|
require = 2)
|
|
|
|
private ModelRenderer redirectRightArm(ModelPlayer mr) {
|
|
|
|
return this.playerModel.getModel().steveRightArm;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Redirect(
|
|
|
|
method = "renderRightArm(Lnet/minecraft/client/entity/AbstractClientPlayer;)V",
|
|
|
|
at = @At(
|
|
|
|
value = "FIELD",
|
|
|
|
target = "Lnet/minecraft/client/model/ModelPlayer;bipedRightArmwear:Lnet/minecraft/client/model/ModelRenderer;",
|
|
|
|
opcode = Opcodes.GETFIELD),
|
|
|
|
require = 2)
|
|
|
|
private ModelRenderer redirectRightArmwear(ModelPlayer mr) {
|
|
|
|
return this.playerModel.getModel().steveRightArmwear;
|
|
|
|
}
|
|
|
|
|
2016-06-15 03:37:41 +02:00
|
|
|
@Inject(
|
2016-11-22 22:13:24 +01:00
|
|
|
method = "applyRotations(Lnet/minecraft/client/entity/AbstractClientPlayer;FFF)V",
|
2016-06-15 03:37:41 +02:00
|
|
|
at = @At(
|
|
|
|
value = "INVOKE",
|
|
|
|
target = "Lnet/minecraft/client/renderer/entity/RenderLivingBase;"
|
2016-11-22 22:13:24 +01:00
|
|
|
+ "applyRotations(Lnet/minecraft/entity/EntityLivingBase;FFF)V",
|
2016-06-15 03:37:41 +02:00
|
|
|
ordinal = 1,
|
|
|
|
shift = Shift.AFTER))
|
|
|
|
private void onRotateCorpse(AbstractClientPlayer player, float yaw, float pitch, float ticks, CallbackInfo ci) {
|
|
|
|
if (this.mainModel instanceof ModelPlayerPony) {
|
2016-11-22 22:13:24 +01:00
|
|
|
// require arms to be stretched out (sorry mud ponies, no flight
|
|
|
|
// skills for you)
|
2016-07-08 08:27:45 +02:00
|
|
|
if (!((ModelPlayerPony) this.mainModel).rainboom) {
|
|
|
|
this.playerModel.getModel().motionPitch = 0;
|
|
|
|
return;
|
|
|
|
}
|
2016-06-15 03:56:54 +02:00
|
|
|
double motionX = player.posX - player.prevPosX;
|
|
|
|
double motionY = player.posY - player.prevPosY;
|
|
|
|
double motionZ = player.posZ - player.prevPosZ;
|
2016-06-15 03:37:41 +02:00
|
|
|
if (player.onGround) {
|
|
|
|
motionY = 0;
|
|
|
|
}
|
2016-06-15 03:56:54 +02:00
|
|
|
double dist = Math.sqrt(motionX * motionX + motionZ * motionZ);
|
2016-06-15 03:37:41 +02:00
|
|
|
double angle = Math.atan2(motionY, dist);
|
|
|
|
if (!player.capabilities.isFlying) {
|
|
|
|
if (angle > 0) {
|
|
|
|
angle = 0;
|
|
|
|
} else {
|
|
|
|
angle /= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-13 05:55:50 +02:00
|
|
|
if (angle > Math.PI / 3) {
|
2016-06-15 03:37:41 +02:00
|
|
|
angle = Math.PI / 3;
|
2017-06-13 05:55:50 +02:00
|
|
|
}
|
|
|
|
if (angle < -Math.PI / 3) {
|
2016-06-15 03:37:41 +02:00
|
|
|
angle = -Math.PI / 3;
|
2017-06-13 05:55:50 +02:00
|
|
|
}
|
2016-06-15 03:37:41 +02:00
|
|
|
|
|
|
|
this.playerModel.getModel().motionPitch = (float) Math.toDegrees(angle);
|
|
|
|
|
|
|
|
GlStateManager.rotate((float) Math.toDegrees(angle), 1F, 0F, 0F);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-10 21:10:29 +02:00
|
|
|
@Redirect(
|
2016-11-22 22:13:24 +01:00
|
|
|
method = "applyRotations(Lnet/minecraft/client/entity/AbstractClientPlayer;FFF)V",
|
2016-05-10 21:10:29 +02:00
|
|
|
at = @At(
|
|
|
|
value = "INVOKE",
|
|
|
|
target = "Lnet/minecraft/client/renderer/GlStateManager;rotate(FFFF)V",
|
|
|
|
ordinal = 3))
|
|
|
|
private void rotateRedirect(float f1, float f2, float f3, float f4) {
|
2016-12-27 02:58:21 +01:00
|
|
|
boolean isPony = this.playerModel.getModel() instanceof ModelPlayerPony;
|
2017-06-13 05:55:50 +02:00
|
|
|
if (isPony) {
|
2016-05-10 21:10:29 +02:00
|
|
|
f1 += 90;
|
2017-06-13 05:55:50 +02:00
|
|
|
}
|
2016-12-27 02:58:21 +01:00
|
|
|
|
2016-05-10 21:10:29 +02:00
|
|
|
GlStateManager.rotate(f1, f2, f3, f4);
|
2017-06-13 05:55:50 +02:00
|
|
|
if (isPony) {
|
2016-12-27 02:58:21 +01:00
|
|
|
GlStateManager.translate(0, -1, 0);
|
2017-06-13 05:55:50 +02:00
|
|
|
}
|
2016-05-10 21:10:29 +02:00
|
|
|
}
|
|
|
|
|
2016-01-26 22:43:39 +01:00
|
|
|
private void updateModel(AbstractClientPlayer player) {
|
|
|
|
this.thePony = MineLittlePony.getInstance().getManager().getPonyFromResourceRegistry(player);
|
2016-05-20 22:22:07 +02:00
|
|
|
thePony.invalidateSkinCheck();
|
2016-01-26 22:43:39 +01:00
|
|
|
thePony.checkSkin();
|
|
|
|
this.playerModel = this.getModel(player);
|
|
|
|
this.mainModel = this.playerModel.getModel();
|
|
|
|
this.playerModel.apply(thePony.metadata);
|
|
|
|
}
|
|
|
|
|
2016-03-01 06:33:09 +01:00
|
|
|
@Override
|
2017-06-13 05:55:50 +02:00
|
|
|
@Nonnull
|
2016-03-01 06:33:09 +01:00
|
|
|
public ResourceLocation getEntityTexture(AbstractClientPlayer player) {
|
2015-11-17 06:17:35 +01:00
|
|
|
Pony thePony = MineLittlePony.getInstance().getManager().getPonyFromResourceRegistry(player);
|
2015-08-02 00:36:33 +02:00
|
|
|
return thePony.getTextureResourceLocation();
|
|
|
|
}
|
|
|
|
|
2016-01-15 08:59:50 +01:00
|
|
|
private PlayerModel getModel(AbstractClientPlayer player) {
|
2016-01-19 06:34:07 +01:00
|
|
|
ResourceLocation skin = getEntityTexture(player);
|
|
|
|
Pony thePony = MineLittlePony.getInstance().getManager().getPonyFromResourceRegistry(skin);
|
|
|
|
return thePony.getModel(false, this.smallArms);
|
2015-08-02 00:36:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PlayerModel getPony() {
|
|
|
|
return this.playerModel;
|
|
|
|
}
|
|
|
|
}
|