Jump to content

LayerRendering for Custom PlayerRenderer (With RenderPlayerAPI)


ItsAMysteriousYT

Recommended Posts

Hey there - i wanna add my own playerRenderer which works great using the renderPlayerAPI. Now - my problem is, that my custom layer does not render. No matter if i call renderLayers() or not. See my code here:

 

 

@Override

public void doRender(AbstractClientPlayer entity, double d1, double d2, double d3, float f1, float f2) {

GL11.glPushMatrix();

GL11.glDisable(GL11.GL_CULL_FACE);

GL11.glTranslated(0, 1.5f, 0);

GL11.glRotated(-f1, 0, 1, 0);

if (getEntityTexture(entity) != null) {

Minecraft.getMinecraft().renderEngine.bindTexture((getEntityTexture(entity)));

}

model.render(entity, (float) d1, (float) d2, (float) d3, f1, f2, -0.065f);

        renderLayers(entity, (float) d1, (float) d2, (float) d3, f1, f2, 1f, 0.0625F);

GL11.glPopMatrix();

}

 

 

 

The Layer class:

 

 

package itsamysterious.mods.reallifemod.core.rendering.Entities;

 

import itsamysterious.mods.reallifemod.init.Reference;

import net.minecraft.client.Minecraft;

import net.minecraft.client.renderer.entity.layers.LayerRenderer;

import net.minecraft.entity.EntityLivingBase;

import net.minecraft.util.ResourceLocation;

import net.minecraftforge.fml.relauncher.Side;

import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)

public class RenderClothes implements LayerRenderer {

 

private final CustomPlayerRenderer renderer;

private AdvancedPlayerModel model;

 

public RenderClothes(CustomPlayerRenderer renderer) {

this.renderer = renderer;

this.model = new AdvancedPlayerModel(1.5f);

}

 

@Override

public void doRenderLayer(EntityLivingBase entity, float f, float f1, float f2,

float f3, float f4, float f5, float f6) {

System.out.println("rendering");

this.model.setModelAttributes(renderer.getMainModel());

Minecraft.getMinecraft().renderEngine.bindTexture((new ResourceLocation(Reference.ID+"textures/gui/tabs")));

this.model.render(entity, f, f1, f2, f3, f4, f5);

}

 

@Override

public boolean shouldCombineTextures() {

return true;

}

 

}

 

 

 

 

I probably miss something essential - problem is i can't find it :/

Link to comment
Share on other sites

Show renderLayers()

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Show where you instantiate, register, or otherwise perform an operation with

RenderClothes

.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

This is where i register the renderer to the API:

 

 

@EventHandler

public void preInit(FMLPreInitializationEvent event) {

NetworkRegistry.INSTANCE.registerGuiHandler(RealLifeMod.instance, new GuiHandler());

 

FMLCommonHandler.instance().bus().register(instance);

FMLCommonHandler.instance().bus().register(new ClientProxy());

FMLCommonHandler.instance().bus().register(new CommonHandler());

 

MinecraftForge.EVENT_BUS.register(proxy);

MinecraftForge.EVENT_BUS.register(new ClientHandler());

 

config = new Configuration(event.getSuggestedConfigurationFile());

RealLifeModConfig.syncConfig();

 

//////////////////////////////

// Starting to load the Mod //

//////////////////////////////

 

RealLifeMod_Blocks.defineBlocks();

RealLifeMod_Items.defineItems();

 

registerEntities();

proxy.registerRenderThings();

 

RenderPlayerAPI.register(Reference.ID, CustomPlayerRenderer.class);

Physics.init();

 

this.vehiclefile = new File(MinecraftServer.getServer().getDataDirectory() + "/RLM/vehicles/");

this.signfile = new File(MinecraftServer.getServer().getDataDirectory() + "/RLM/signs/");

 

loadAddonPacks();

Vehicles.setupVehicles();

Signs.setupSigns();

setupApps();

 

network = NetworkRegistry.INSTANCE.newSimpleChannel(Reference.ID);

network.registerMessage(SetPropertiesHandler.class, SetPropertiesPackage.class, 0, Side.SERVER);

network.registerMessage(PacketHandlerPropsSet.class, PropertiesSetPackage.class, 1, Side.CLIENT);

network.registerMessage(MountHandler.class, MountVehicleMessage.class, 2, Side.SERVER);

network.registerMessage(SetPositionHandler.class, UpdateVehiclePacket.class, 3, Side.SERVER);

network.registerMessage(CustomCollisionHandler.class, CustomCollisionPacket.class, 4, Side.SERVER);

network.registerMessage(UpdateControlHandler.class, UpdateControlPackage.class, 5, Side.SERVER);

network.registerMessage(ControllableInputHandler.class, ControlableInputPacket.class, 6, Side.SERVER);

network.registerMessage(KeyHeldHandler.class, PacketDriveableKeyHeld.class, 7, Side.SERVER);

network.registerMessage(PlaySoundHandler.class, PacketPlaySound.class, 8, Side.CLIENT);

network.registerMessage(DefecationHandler.class, DefecatePacket.class, 9, Side.SERVER);

network.registerMessage(UpdateToiletHandler.class, UpdateToiletPacket.class, 10, Side.SERVER);

 

setupTileEntities();

GameRegistry.registerWorldGenerator(new WorldGenCopper(), 8);

if (event.getSide().isClient()) {

B3DLoader.instance.addDomain(Reference.ID);

OBJLoader.instance.addDomain(Reference.ID);

}

}

 

 

Link to comment
Share on other sites

RenderClothes

is not referenced here, this is useless or you haven't registered it properly.  Show the entirety of

CustomPlayerRenderer

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

There you go - The CustomPlayerRenderer class:

 

 

package itsamysterious.mods.reallifemod.core.rendering.Entities;

 

import java.awt.image.BufferedImage;

import java.awt.image.DataBufferByte;

import java.awt.image.Raster;

import java.io.File;

import java.io.IOException;

import java.util.ArrayList;

import java.util.List;

 

import javax.imageio.ImageIO;

 

import org.lwjgl.opengl.GL11;

 

import api.player.model.ModelPlayerAPI;

import api.player.render.RenderPlayerAPI;

import api.player.render.RenderPlayerBase;

import itsamysterious.mods.reallifemod.RealLifeMod;

import net.minecraft.client.Minecraft;

import net.minecraft.client.entity.AbstractClientPlayer;

import net.minecraft.client.model.ModelBase;

import net.minecraft.client.renderer.entity.layers.LayerHeldItem;

import net.minecraft.client.renderer.entity.layers.LayerRenderer;

import net.minecraft.client.resources.DefaultPlayerSkin;

import net.minecraft.entity.Entity;

import net.minecraft.entity.EntityLivingBase;

import net.minecraft.util.ResourceLocation;

 

public class CustomPlayerRenderer extends RenderPlayerBase {

 

public static AdvancedPlayerModel model = new AdvancedPlayerModel();

public boolean createdTextureThisSession = false;

 

private List<LayerRenderer> layerRenderer = new ArrayList<LayerRenderer>();

 

public CustomPlayerRenderer(RenderPlayerAPI renderPlayerAPI) {

super(renderPlayerAPI);

this.createdTextureThisSession = false;

layerRenderer.add(new RenderClothes(this));

}

 

@Override

public void renderModel(AbstractClientPlayer entity, float f, float f1, float f2, float f3, float f4, float f5) {

GL11.glPushMatrix();

GL11.glRotated(-entity.rotationYaw, 0, 1, 0);

GL11.glScaled(1, -1, 1);

if (getEntityTexture((AbstractClientPlayer) entity) != null) {

Minecraft.getMinecraft().renderEngine.bindTexture((getEntityTexture((AbstractClientPlayer) entity)));

}

model.render(entity, (float) f, (float) f1, (float) f2, f3, f4, -0.065f);

this.renderLayers(entity, (float) f, (float) f1, (float) f2, f3, f4, f5, 0.0625F);

GL11.glPopMatrix();

}

 

@Override

public void renderLayers(AbstractClientPlayer entity, float f1, float f2, float f3, float f4, float f5, float f6,

float f7) {

for (LayerRenderer renderer : layerRenderer) {

renderer.doRenderLayer((EntityLivingBase) entity, f1, f2, f3, f4, f5, f6, f7);

}

}

 

public ResourceLocation getTemporaryTexturefile(AbstractClientPlayer player, ResourceLocation playerskin) {

File texturefile = new File(Minecraft.getMinecraft().mcDataDir,

"RLM/assets/reallifemod/textures/playerskin.png");

if (!texturefile.exists()) {

try {

BufferedImage texture = ImageIO

.read(Minecraft.getMinecraft().getResourceManager().getResource(playerskin).getInputStream());

boolean hasAlphaChannel = texture.getAlphaRaster() != null;

boolean hasAlexSkin = player.getSkinType() != DefaultPlayerSkin.getDefaultSkinLegacy().toString();

int pixellength = hasAlphaChannel ? 4 : 3;

int width = texture.getWidth();

int height = texture.getHeight();

 

if (texture != null) {

byte[] pixels = ((DataBufferByte) texture.getRaster().getDataBuffer()).getData();

// copying the armtexture (sides)

ArrayList<Byte> armtexture_bottom = new ArrayList<Byte>();

ArrayList<Byte> armtexture_side = new ArrayList<Byte>();

 

// Copying the single textureparts

 

/* 1: Top&Bottom */

for (int pixelY = 0; pixelY < 4; pixelY++) {

if (hasAlexSkin) {

for (int pixelX = 0; pixelX < 3; pixelX++) {

for (int bytenumber = 0; bytenumber < pixellength; bytenumber++) {

int posPixel = ((16 * pixellength * width) + (pixelY * pixellength * width))

+ ((47 * pixellength) + (pixelX + bytenumber));

armtexture_bottom.add(pixels[posPixel]);

}

}

} else

for (int pixelX = 0; pixelX < 4; pixelX++) {

for (int bytenumber = 0; bytenumber < pixellength; bytenumber++) {

int posPixel = ((16 * pixellength * width) + (pixelY * pixellength * width))

+ (((48 * pixellength) + pixelX) + bytenumber);

armtexture_bottom.add(pixels[posPixel]);

}

}

 

}

/* 2: Sides */

 

for (int pixelY = 0; pixelY < 8; pixelY++) {

// Checking wether the player has alex skinmodel or not

if (hasAlexSkin) {

for (int pixelX = 0; pixelX < 14; pixelX++) {

for (int bytenumber = 0; bytenumber < pixellength; bytenumber++) {

int thepixel = ((24 * pixellength * width) + (pixelY * pixellength * width)

+ ((39 * pixellength) + (pixelX * pixellength))) + bytenumber;

armtexture_side.add(pixels[thepixel]);

}

}

} else {

for (int pixelX = 0; pixelX < 16; pixelX++) {

for (int bytenumber = 0; bytenumber < pixellength; bytenumber++) {

int thepixel = ((24 * pixellength * width) + (pixelY * pixellength * width)

+ ((39 * pixellength) + (pixelX * pixellength))) + bytenumber;

armtexture_side.add(pixels[thepixel]);

}

}

}

 

}

 

// ------------[End of Copy-Section]--------------//

 

///////////////////////////////////////////////////

 

// ------------[start of Pasting-Section]--------------//

 

int counterY = 0;

int counterX = 0;

 

for (int pixelY = 0; pixelY < 64; pixelY++) {

counterY++;

for (int pixelX = 0; pixelX < 64; pixelX++) {

counterX++;

/* top & bottom */

if (hasAlexSkin) {

if (pixelX >= 44 && pixelX < 50 && pixelY > 31 && pixelY < 36) {

for (int bytenumber = 0; bytenumber < pixellength; bytenumber++) {

int rowYInByteArray = counterY - 31;

pixels[((pixelY * pixellength * width) + (pixelX * pixellength))

+ bytenumber] = armtexture_bottom

.get(((pixelY % 4) * pixellength) * 3

+ ((pixelX % 3) * pixellength) + bytenumber);

}

}

 

/* sides */

if (pixelX >= 40 && pixelX < 54 && pixelY > 35 && pixelY < 48) {

int rowYInByteArray = counterY - 35;

for (int bytenumber = 0; bytenumber < pixellength; bytenumber++) {

pixels[((pixelY * pixellength * width) + (pixelX * pixellength)

+ bytenumber)] = armtexture_side

.get(((pixelY % 8) * pixellength * 14)

+ ((pixelX % 14) * pixellength) + bytenumber);

}

}

} else {

/* top & bottom */

if (pixelX >= 44 && pixelX < 52 && pixelY > 31 && pixelY < 36) {

for (int bytenumber = 0; bytenumber < pixellength; bytenumber++) {

int rowYInByteArray = counterY - 31;

pixels[((pixelY * pixellength * width) + (pixelX * pixellength))

+ bytenumber] = armtexture_bottom

.get(((pixelY % 4) * pixellength * 4)

+ ((pixelX % 4) * pixellength) + bytenumber);

}

}

 

/* sides */

if (pixelX > 39 && pixelX < 56 && pixelY > 35 && pixelY < 48) {

int rowYInByteArray = counterY - 35;

for (int bytenumber = 0; bytenumber < pixellength; bytenumber++) {

pixels[((pixelY * pixellength * width) + (pixelX * pixellength))

+ bytenumber] = armtexture_side

.get(((pixelY % 8) * pixellength * 16)

+ ((pixelX % 16) * pixellength) + bytenumber);

}

}

}

}

}

 

BufferedImage newTexture = new BufferedImage(64, 64,

hasAlphaChannel ? BufferedImage.TYPE_4BYTE_ABGR : BufferedImage.TYPE_3BYTE_BGR);

newTexture.setData(Raster.createRaster(newTexture.getSampleModel(),

new DataBufferByte(pixels, pixels.length), new java.awt.Point()));

 

if (!texturefile.exists() && createdTextureThisSession == false) {

texturefile.mkdirs();

ImageIO.write(newTexture, "png", texturefile);

RealLifeMod.log("Refreshing Minecraft Resources");

createdTextureThisSession = true;

Minecraft.getMinecraft().scheduleResourcesRefresh();

}

 

return new ResourceLocation("reallifemod:textures/playerskin.png");

}

} catch (

 

IOException e)

 

{

e.printStackTrace();

}

 

return null;

 

} else if (texturefile.exists()) {

return new ResourceLocation("reallifemod:textures/playerskin.png");

} else

return null;

}

 

@Override

public ModelBase getMainModel() {

return this.model;

}

 

@Override

public ResourceLocation getEntityTexture(AbstractClientPlayer player) {

if (getTemporaryTexturefile(player, player.getLocationSkin()) != null) {

return getTemporaryTexturefile(player, player.getLocationSkin());

} else

return null;

}

 

}

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.