MineLittlePony/src/main/java/com/brohoof/minelittlepony/mixin/MixinRenderPlayer.java

190 lines
7.6 KiB
Java
Raw Normal View History

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-05-04 03:23:57 +02:00
import org.objectweb.asm.Opcodes;
2016-01-15 08:59:50 +01:00
import org.spongepowered.asm.mixin.Mixin;
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;
2016-05-04 03:23:57 +02:00
import org.spongepowered.asm.mixin.injection.Redirect;
2016-01-15 08:59:50 +01:00
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;
import com.brohoof.minelittlepony.PonySize;
import com.brohoof.minelittlepony.ducks.IRenderPony;
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;
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;
2016-05-04 03:23:57 +02:00
import net.minecraft.client.model.ModelPlayer;
import net.minecraft.client.model.ModelRenderer;
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-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
@Shadow
private boolean smallArms;
2015-08-02 00:36:33 +02:00
private PlayerModel playerModel;
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);
}
@Inject(
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) {
this.playerModel = smallArms ? PMAPI.ponySmall : PMAPI.pony;
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));
this.addLayer(new LayerPonyCape(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
this.playerModel.getModel().isSneak = player.isSneaking();
this.playerModel.getModel().isFlying = thePony.isPegasusFlying(player);
2015-08-02 00:36:33 +02:00
2016-01-26 09:16:11 +01:00
if (MineLittlePony.getConfig().showscale) {
if (this.playerModel.getModel().metadata.getRace() != null) {
PonySize size = thePony.metadata.getSize();
if (size == PonySize.FOAL)
2015-08-02 00:36:33 +02:00
this.shadowSize = 0.25F;
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;
else
2015-08-02 00:36:33 +02:00
this.shadowSize = 0.5F;
} else {
this.shadowSize = 0.5F;
}
} else {
this.shadowSize = 0.5F;
}
}
2016-05-04 03:23:57 +02: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)) {
PonySize size = thePony.metadata.getSize();
if (size == PonySize.LARGE)
2015-08-02 00:36:33 +02:00
scale(0.9F, 0.9F, 0.9F);
else if (size == PonySize.NORMAL || size == PonySize.FOAL)
2015-08-02 00:36:33 +02:00
scale(0.8F, 0.8F, 0.8F);
}
}
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-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);
}
@Override
public ResourceLocation getEntityTexture(AbstractClientPlayer player) {
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) {
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;
}
}