Skip to content

Commit

Permalink
ensure compatibility with RenderPlayerAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
zlainsama committed Sep 3, 2015
1 parent 0a24d79 commit dca4128
Show file tree
Hide file tree
Showing 3 changed files with 250 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/main/java/lain/mods/skinport/SkinPort.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.concurrent.TimeUnit;
import lain.mods.skinport.api.ISkin;
import lain.mods.skinport.api.SkinProviderAPI;
import lain.mods.skinport.compat.SkinPortRenderPlayer_RPA;
import lain.mods.skinport.network.NetworkManager;
import lain.mods.skinport.network.packet.PacketGet0;
import lain.mods.skinport.network.packet.PacketGet1;
Expand All @@ -37,6 +38,7 @@
import com.google.common.cache.LoadingCache;
import com.google.common.collect.Maps;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
Expand Down Expand Up @@ -130,8 +132,17 @@ public static Render RenderManager_getEntityRenderObject(RenderManager manager,
public static void RenderManager_postRenderManagerInit(RenderManager manager)
{
skinMap = Maps.newHashMap();
skinMap.put("default", new SkinPortRenderPlayer(false));
skinMap.put("slim", new SkinPortRenderPlayer(true));

if (Loader.isModLoaded("RenderPlayerAPI")) // Compatibility with RenderPlayerAPI
{
skinMap.put("default", new SkinPortRenderPlayer_RPA(false));
skinMap.put("slim", new SkinPortRenderPlayer_RPA(true));
}
else
{
skinMap.put("default", new SkinPortRenderPlayer(false));
skinMap.put("slim", new SkinPortRenderPlayer(true));
}

for (Render entry : skinMap.values())
entry.setRenderManager(manager);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package lain.mods.skinport.compat;

import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
import api.player.model.ModelPlayer;

public class SkinPortModelPlayer_RPA extends ModelPlayer
{

public ModelRenderer bipedLeftArmwear;
public ModelRenderer bipedRightArmwear;
public ModelRenderer bipedLeftLegwear;
public ModelRenderer bipedRightLegwear;
public ModelRenderer bipedBodyWear;
public boolean smallArms;

public SkinPortModelPlayer_RPA(float z, boolean smallArms)
{
super(z, 0.0F, 64, 64);

this.smallArms = smallArms;

if (smallArms)
{
bipedLeftArm = new ModelRenderer(this, 32, 48);
bipedLeftArm.addBox(-1.0F, -2.0F, -2.0F, 3, 12, 4, z);
bipedLeftArm.setRotationPoint(5.0F, 2.5F, 0.0F);

bipedRightArm = new ModelRenderer(this, 40, 16);
bipedRightArm.addBox(-2.0F, -2.0F, -2.0F, 3, 12, 4, z);
bipedRightArm.setRotationPoint(-5.0F, 2.5F, 0.0F);

bipedLeftArmwear = new ModelRenderer(this, 48, 48);
bipedLeftArmwear.addBox(-1.0F, -2.0F, -2.0F, 3, 12, 4, z + 0.25F);
bipedLeftArm.addChild(bipedLeftArmwear);

bipedRightArmwear = new ModelRenderer(this, 40, 32);
bipedRightArmwear.addBox(-2.0F, -2.0F, -2.0F, 3, 12, 4, z + 0.25F);
bipedRightArm.addChild(bipedRightArmwear);
}
else
{
bipedLeftArm = new ModelRenderer(this, 32, 48);
bipedLeftArm.addBox(-1.0F, -2.0F, -2.0F, 4, 12, 4, z);
bipedLeftArm.setRotationPoint(5.0F, 2.0F, 0.0F);

bipedLeftArmwear = new ModelRenderer(this, 48, 48);
bipedLeftArmwear.addBox(-1.0F, -2.0F, -2.0F, 4, 12, 4, z + 0.25F);
bipedLeftArm.addChild(bipedLeftArmwear);

bipedRightArmwear = new ModelRenderer(this, 40, 32);
bipedRightArmwear.addBox(-3.0F, -2.0F, -2.0F, 4, 12, 4, z + 0.25F);
bipedRightArm.addChild(bipedRightArmwear);
}

bipedLeftLeg = new ModelRenderer(this, 16, 48);
bipedLeftLeg.addBox(-2.0F, 0.0F, -2.0F, 4, 12, 4, z);
bipedLeftLeg.setRotationPoint(1.9F, 12.0F, 0.0F);

bipedLeftLegwear = new ModelRenderer(this, 0, 48);
bipedLeftLegwear.addBox(-2.0F, 0.0F, -2.0F, 4, 12, 4, z + 0.25F);
bipedLeftLeg.addChild(bipedLeftLegwear);

bipedRightLegwear = new ModelRenderer(this, 0, 32);
bipedRightLegwear.addBox(-2.0F, 0.0F, -2.0F, 4, 12, 4, z + 0.25F);
bipedRightLeg.addChild(bipedRightLegwear);

bipedBodyWear = new ModelRenderer(this, 16, 32);
bipedBodyWear.addBox(-4.0F, 0.0F, -2.0F, 8, 12, 4, z + 0.25F);
bipedBody.addChild(bipedBodyWear);
}

@Override
public void render(Entity p_render_1_, float p_render_2_, float p_render_3_, float p_render_4_, float p_render_5_, float p_render_6_, float p_render_7_)
{
super.render(p_render_1_, p_render_2_, p_render_3_, p_render_4_, p_render_5_, p_render_6_, p_render_7_);

if (smallArms)
bipedRightArm.rotationPointX += 1.0F;
}

}
155 changes: 155 additions & 0 deletions src/main/java/lain/mods/skinport/compat/SkinPortRenderPlayer_RPA.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
package lain.mods.skinport.compat;

import lain.mods.skinport.SkinCustomization;
import lain.mods.skinport.SkinPort;
import lain.mods.skinport.api.ISkin;
import lain.mods.skinport.api.SkinProviderAPI;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.renderer.entity.RenderPlayer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;

public class SkinPortRenderPlayer_RPA extends RenderPlayer
{

public SkinPortModelPlayer_RPA modelPlayer;

public SkinPortRenderPlayer_RPA(boolean smallArms)
{
super();

mainModel = new SkinPortModelPlayer_RPA(0.0F, smallArms);
modelBipedMain = (ModelBiped) mainModel;
modelPlayer = (SkinPortModelPlayer_RPA) mainModel;
}

@Override
public void doRender(AbstractClientPlayer p_76986_1_, double p_76986_2_, double p_76986_4_, double p_76986_6_, float p_76986_8_, float p_76986_9_)
{
boolean smHeadwear = modelPlayer.bipedHeadwear.showModel;
boolean smLeftLegwear = modelPlayer.bipedLeftLegwear.showModel;
boolean smRightLegwear = modelPlayer.bipedRightLegwear.showModel;
boolean smLeftArmwear = modelPlayer.bipedLeftArmwear.showModel;
boolean smRightArmwear = modelPlayer.bipedRightArmwear.showModel;
boolean smBodyWear = modelPlayer.bipedBodyWear.showModel;
boolean smCloak = modelPlayer.bipedCloak.showModel;

int flags = SkinPort.clientCache.getUnchecked(p_76986_1_.getUniqueID());
if (modelPlayer.bipedHeadwear.showModel)
modelPlayer.bipedHeadwear.showModel = SkinCustomization.contains(flags, SkinCustomization.hat);
if (modelPlayer.bipedLeftLegwear.showModel)
modelPlayer.bipedLeftLegwear.showModel = SkinCustomization.contains(flags, SkinCustomization.left_pants_leg);
if (modelPlayer.bipedRightLegwear.showModel)
modelPlayer.bipedRightLegwear.showModel = SkinCustomization.contains(flags, SkinCustomization.right_pants_leg);
if (modelPlayer.bipedLeftArmwear.showModel)
modelPlayer.bipedLeftArmwear.showModel = SkinCustomization.contains(flags, SkinCustomization.left_sleeve);
if (modelPlayer.bipedRightArmwear.showModel)
modelPlayer.bipedRightArmwear.showModel = SkinCustomization.contains(flags, SkinCustomization.right_sleeve);
if (modelPlayer.bipedBodyWear.showModel)
modelPlayer.bipedBodyWear.showModel = SkinCustomization.contains(flags, SkinCustomization.jacket);
if (modelPlayer.bipedCloak.showModel)
modelPlayer.bipedCloak.showModel = SkinCustomization.contains(flags, SkinCustomization.cape);

super.doRender(p_76986_1_, p_76986_2_, p_76986_4_, p_76986_6_, p_76986_8_, p_76986_9_);

modelPlayer.bipedHeadwear.showModel = smHeadwear;
modelPlayer.bipedLeftLegwear.showModel = smLeftLegwear;
modelPlayer.bipedRightLegwear.showModel = smRightLegwear;
modelPlayer.bipedLeftArmwear.showModel = smLeftArmwear;
modelPlayer.bipedRightArmwear.showModel = smRightArmwear;
modelPlayer.bipedBodyWear.showModel = smBodyWear;
modelPlayer.bipedCloak.showModel = smCloak;
}

@Override
protected ResourceLocation getEntityTexture(AbstractClientPlayer player)
{
ISkin skin = SkinProviderAPI.getSkin(player);
if (!skin.isSkinReady())
skin = SkinProviderAPI.getDefaultSkin(player);
return skin.getSkinLocation();
}

@Override
protected void renderEquippedItems(AbstractClientPlayer p_77029_1_, float p_77029_2_)
{
boolean smHeadwear = modelPlayer.bipedHeadwear.showModel;
boolean smLeftLegwear = modelPlayer.bipedLeftLegwear.showModel;
boolean smRightLegwear = modelPlayer.bipedRightLegwear.showModel;
boolean smLeftArmwear = modelPlayer.bipedLeftArmwear.showModel;
boolean smRightArmwear = modelPlayer.bipedRightArmwear.showModel;
boolean smBodyWear = modelPlayer.bipedBodyWear.showModel;
boolean smCloak = modelPlayer.bipedCloak.showModel;

int flags = SkinPort.clientCache.getUnchecked(p_77029_1_.getUniqueID());
if (modelPlayer.bipedHeadwear.showModel)
modelPlayer.bipedHeadwear.showModel = SkinCustomization.contains(flags, SkinCustomization.hat);
if (modelPlayer.bipedLeftLegwear.showModel)
modelPlayer.bipedLeftLegwear.showModel = SkinCustomization.contains(flags, SkinCustomization.left_pants_leg);
if (modelPlayer.bipedRightLegwear.showModel)
modelPlayer.bipedRightLegwear.showModel = SkinCustomization.contains(flags, SkinCustomization.right_pants_leg);
if (modelPlayer.bipedLeftArmwear.showModel)
modelPlayer.bipedLeftArmwear.showModel = SkinCustomization.contains(flags, SkinCustomization.left_sleeve);
if (modelPlayer.bipedRightArmwear.showModel)
modelPlayer.bipedRightArmwear.showModel = SkinCustomization.contains(flags, SkinCustomization.right_sleeve);
if (modelPlayer.bipedBodyWear.showModel)
modelPlayer.bipedBodyWear.showModel = SkinCustomization.contains(flags, SkinCustomization.jacket);
if (modelPlayer.bipedCloak.showModel)
modelPlayer.bipedCloak.showModel = SkinCustomization.contains(flags, SkinCustomization.cape);

super.renderEquippedItems(p_77029_1_, p_77029_2_);

modelPlayer.bipedHeadwear.showModel = smHeadwear;
modelPlayer.bipedLeftLegwear.showModel = smLeftLegwear;
modelPlayer.bipedRightLegwear.showModel = smRightLegwear;
modelPlayer.bipedLeftArmwear.showModel = smLeftArmwear;
modelPlayer.bipedRightArmwear.showModel = smRightArmwear;
modelPlayer.bipedBodyWear.showModel = smBodyWear;
modelPlayer.bipedCloak.showModel = smCloak;
}

@Override
public void renderFirstPersonArm(EntityPlayer player)
{
boolean smHeadwear = modelPlayer.bipedHeadwear.showModel;
boolean smLeftLegwear = modelPlayer.bipedLeftLegwear.showModel;
boolean smRightLegwear = modelPlayer.bipedRightLegwear.showModel;
boolean smLeftArmwear = modelPlayer.bipedLeftArmwear.showModel;
boolean smRightArmwear = modelPlayer.bipedRightArmwear.showModel;
boolean smBodyWear = modelPlayer.bipedBodyWear.showModel;
boolean smCloak = modelPlayer.bipedCloak.showModel;

int flags = SkinPort.clientCache.getUnchecked(player.getUniqueID());
if (modelPlayer.bipedHeadwear.showModel)
modelPlayer.bipedHeadwear.showModel = SkinCustomization.contains(flags, SkinCustomization.hat);
if (modelPlayer.bipedLeftLegwear.showModel)
modelPlayer.bipedLeftLegwear.showModel = SkinCustomization.contains(flags, SkinCustomization.left_pants_leg);
if (modelPlayer.bipedRightLegwear.showModel)
modelPlayer.bipedRightLegwear.showModel = SkinCustomization.contains(flags, SkinCustomization.right_pants_leg);
if (modelPlayer.bipedLeftArmwear.showModel)
modelPlayer.bipedLeftArmwear.showModel = SkinCustomization.contains(flags, SkinCustomization.left_sleeve);
if (modelPlayer.bipedRightArmwear.showModel)
modelPlayer.bipedRightArmwear.showModel = SkinCustomization.contains(flags, SkinCustomization.right_sleeve);
if (modelPlayer.bipedBodyWear.showModel)
modelPlayer.bipedBodyWear.showModel = SkinCustomization.contains(flags, SkinCustomization.jacket);
if (modelPlayer.bipedCloak.showModel)
modelPlayer.bipedCloak.showModel = SkinCustomization.contains(flags, SkinCustomization.cape);

// #blameMojang
Minecraft.getMinecraft().getTextureManager().bindTexture(getEntityTexture(player));

modelPlayer.isRiding = modelPlayer.isSneak = false;
super.renderFirstPersonArm(player);

modelPlayer.bipedHeadwear.showModel = smHeadwear;
modelPlayer.bipedLeftLegwear.showModel = smLeftLegwear;
modelPlayer.bipedRightLegwear.showModel = smRightLegwear;
modelPlayer.bipedLeftArmwear.showModel = smLeftArmwear;
modelPlayer.bipedRightArmwear.showModel = smRightArmwear;
modelPlayer.bipedBodyWear.showModel = smBodyWear;
modelPlayer.bipedCloak.showModel = smCloak;
}

}

0 comments on commit dca4128

Please sign in to comment.