2016-01-15 08:59:50 +01:00
|
|
|
package com.brohoof.minelittlepony.mixin;
|
2015-08-02 00:36:33 +02:00
|
|
|
|
|
|
|
import static net.minecraft.client.renderer.GlStateManager.scale;
|
|
|
|
|
2016-01-15 08:59:50 +01:00
|
|
|
import org.spongepowered.asm.mixin.Mixin;
|
|
|
|
import org.spongepowered.asm.mixin.Overwrite;
|
2016-01-19 06:34:07 +01:00
|
|
|
import org.spongepowered.asm.mixin.Shadow;
|
2016-01-15 08:59:50 +01:00
|
|
|
import org.spongepowered.asm.mixin.injection.At;
|
|
|
|
import org.spongepowered.asm.mixin.injection.Inject;
|
|
|
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
|
|
|
2015-11-17 06:09:04 +01:00
|
|
|
import com.brohoof.minelittlepony.MineLittlePony;
|
|
|
|
import com.brohoof.minelittlepony.Pony;
|
2015-12-09 04:14:42 +01:00
|
|
|
import com.brohoof.minelittlepony.PonySize;
|
2015-11-17 06:09:04 +01:00
|
|
|
import com.brohoof.minelittlepony.model.PMAPI;
|
|
|
|
import com.brohoof.minelittlepony.model.PlayerModel;
|
2015-12-16 05:29:47 +01:00
|
|
|
import com.brohoof.minelittlepony.model.pony.ModelHumanPlayer;
|
2016-01-15 08:59:50 +01:00
|
|
|
import com.brohoof.minelittlepony.renderer.IRenderPony;
|
2015-11-17 06:09:04 +01:00
|
|
|
import com.brohoof.minelittlepony.renderer.layer.LayerHeldPonyItem;
|
|
|
|
import com.brohoof.minelittlepony.renderer.layer.LayerPonyArmor;
|
|
|
|
import com.brohoof.minelittlepony.renderer.layer.LayerPonyCape;
|
|
|
|
import com.brohoof.minelittlepony.renderer.layer.LayerPonySkull;
|
2015-08-02 00:36:33 +02:00
|
|
|
|
|
|
|
import net.minecraft.client.entity.AbstractClientPlayer;
|
|
|
|
import net.minecraft.client.entity.EntityPlayerSP;
|
|
|
|
import net.minecraft.client.renderer.entity.RenderManager;
|
|
|
|
import net.minecraft.client.renderer.entity.RenderPlayer;
|
|
|
|
import net.minecraft.client.renderer.entity.RendererLivingEntity;
|
|
|
|
import net.minecraft.client.renderer.entity.layers.LayerArrow;
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.item.EnumAction;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
|
|
|
|
2016-01-15 08:59:50 +01:00
|
|
|
@Mixin(RenderPlayer.class)
|
|
|
|
public abstract class MixinRenderPlayer extends RendererLivingEntity implements IRenderPony {
|
|
|
|
|
2016-01-26 09:17:08 +01:00
|
|
|
private static final String RenderManager = "Lnet/minecraft/client/renderer/entity/RenderManager;";
|
|
|
|
private static final String AbstractClientPlayer = "Lnet/minecraft/client/entity/AbstractClientPlayer;";
|
|
|
|
|
2016-01-19 06:34:07 +01:00
|
|
|
@Shadow
|
|
|
|
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-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-01-26 09:17:08 +01:00
|
|
|
method = "<init>(" + RenderManager + "Z)V",
|
2016-01-19 06:34:07 +01: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();
|
|
|
|
this.shadowSize = this.playerModel.getShadowsize();
|
2015-08-02 00:36:33 +02:00
|
|
|
this.layerRenderers.clear();
|
|
|
|
|
|
|
|
this.addLayer(new LayerPonyArmor(this));
|
|
|
|
this.addLayer(new LayerHeldPonyItem(this));
|
|
|
|
this.addLayer(new LayerArrow(this));
|
|
|
|
this.addLayer(new LayerPonySkull(this));
|
2015-08-13 00:22:21 +02:00
|
|
|
this.addLayer(new LayerPonyCape(this));
|
2015-08-02 00:36:33 +02:00
|
|
|
}
|
|
|
|
|
2016-01-26 09:17:08 +01:00
|
|
|
/**
|
|
|
|
* @reason render a pony instead of a human
|
|
|
|
* @author JoyJoy
|
|
|
|
*/
|
2016-01-15 08:59:50 +01:00
|
|
|
@Overwrite
|
2015-08-02 00:36:33 +02:00
|
|
|
public void doRender(AbstractClientPlayer player, double x, double y, double z, float yaw, float partialTicks) {
|
2016-01-26 22:43:39 +01:00
|
|
|
updateModel(player);
|
2015-08-02 00:36:33 +02:00
|
|
|
ItemStack currentItemStack = player.inventory.getCurrentItem();
|
2016-01-26 22:43:39 +01:00
|
|
|
|
2015-12-14 09:29:10 +01:00
|
|
|
this.playerModel.getModel().heldItemRight = currentItemStack == null ? 0 : 1;
|
2016-01-26 22:43:39 +01:00
|
|
|
|
2015-08-02 00:36:33 +02:00
|
|
|
if (currentItemStack != null && player.getItemInUseCount() > 0) {
|
|
|
|
EnumAction yOrigin = currentItemStack.getItemUseAction();
|
|
|
|
if (yOrigin == EnumAction.BLOCK) {
|
2015-12-14 09:29:10 +01:00
|
|
|
this.playerModel.getModel().heldItemRight = 3;
|
2015-08-02 00:36:33 +02:00
|
|
|
} else if (yOrigin == EnumAction.BOW) {
|
2015-12-14 09:29:10 +01:00
|
|
|
this.playerModel.getModel().aimedBow = true;
|
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-01-26 09:17:08 +01:00
|
|
|
this.playerModel.getModel().isRiding = player.isRiding();
|
2015-08-02 00:36:33 +02:00
|
|
|
|
2016-01-26 09:16:11 +01:00
|
|
|
if (MineLittlePony.getConfig().showscale) {
|
2016-01-19 06:34:07 +01:00
|
|
|
if (this.playerModel.getModel().metadata.getRace() != null) {
|
2015-12-09 04:14:42 +01:00
|
|
|
PonySize size = thePony.metadata.getSize();
|
|
|
|
if (size == PonySize.FOAL)
|
2015-08-02 00:36:33 +02:00
|
|
|
this.shadowSize = 0.25F;
|
2015-12-09 04:14:42 +01:00
|
|
|
else if (size == PonySize.NORMAL)
|
2015-08-02 00:36:33 +02:00
|
|
|
this.shadowSize = 0.4F;
|
2015-12-16 05:29:47 +01:00
|
|
|
else if (size == PonySize.TALL)
|
2015-08-02 00:36:33 +02:00
|
|
|
this.shadowSize = 0.45F;
|
2015-12-09 04:14:42 +01:00
|
|
|
else
|
2015-08-02 00:36:33 +02:00
|
|
|
this.shadowSize = 0.5F;
|
|
|
|
} else {
|
|
|
|
this.shadowSize = 0.5F;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.shadowSize = 0.5F;
|
|
|
|
}
|
|
|
|
|
|
|
|
double yOrigin1 = y;
|
|
|
|
if (player.isSneaking() && !(player instanceof EntityPlayerSP)) {
|
|
|
|
yOrigin1 -= 0.125D;
|
|
|
|
}
|
|
|
|
|
2015-12-14 09:29:10 +01:00
|
|
|
this.playerModel.getModel().isSleeping = player.isPlayerSleeping();
|
|
|
|
this.playerModel.getModel().swingProgress = getSwingProgress(player, partialTicks);
|
2015-12-09 04:14:42 +01:00
|
|
|
|
2015-08-02 00:36:33 +02:00
|
|
|
super.doRender(player, x, yOrigin1, z, yaw, partialTicks);
|
2015-12-09 04:14:42 +01:00
|
|
|
|
2015-12-14 09:29:10 +01:00
|
|
|
this.playerModel.getModel().aimedBow = false;
|
|
|
|
this.playerModel.getModel().isSneak = false;
|
|
|
|
this.playerModel.getModel().heldItemRight = 0;
|
2015-08-02 00:36:33 +02:00
|
|
|
}
|
|
|
|
|
2016-01-19 06:34:07 +01:00
|
|
|
@Inject(method = "renderLivingAt", 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();
|
|
|
|
if (size == PonySize.LARGE)
|
2015-08-02 00:36:33 +02:00
|
|
|
scale(0.9F, 0.9F, 0.9F);
|
2015-12-09 04:14:42 +01:00
|
|
|
else if (size == PonySize.NORMAL || size == PonySize.FOAL)
|
2015-08-02 00:36:33 +02:00
|
|
|
scale(0.8F, 0.8F, 0.8F);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-26 09:17:08 +01:00
|
|
|
@Inject(method = "renderRightArm(" + AbstractClientPlayer + ")V", at = @At("HEAD") )
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Inject(method = "renderLeftArm(" + AbstractClientPlayer + ")V", at = @At("HEAD") )
|
|
|
|
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-01-26 22:43:39 +01:00
|
|
|
private void updateModel(AbstractClientPlayer player) {
|
|
|
|
this.thePony = MineLittlePony.getInstance().getManager().getPonyFromResourceRegistry(player);
|
|
|
|
thePony.checkSkin();
|
|
|
|
this.playerModel = this.getModel(player);
|
|
|
|
this.mainModel = this.playerModel.getModel();
|
|
|
|
this.playerModel.apply(thePony.metadata);
|
|
|
|
}
|
|
|
|
|
2016-01-15 08:59:50 +01:00
|
|
|
private 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();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-15 08:59:50 +01:00
|
|
|
public final ResourceLocation getEntityTexture(Entity entity) {
|
2015-08-02 00:36:33 +02:00
|
|
|
return this.getEntityTexture((AbstractClientPlayer) entity);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|