Jump to content

Recommended Posts

Posted

So if I have a weapon, like a sword... How can I visually scale it up in game so it looks bigger when you hold it? (hitbox doesn't need to change)

 

edit: Scaling is working, but it's at the wrong angle. Is there a way to rotate or flip it?

Posted

Ok I would use a custom item renderer. Make a new class and make it implement the IItemRenderer.

 

Example:


package godis_apan.thedecorationpack.medieval.client.render.item;

import godis_apan.thedecorationpack.medieval.client.model.ModelOrnateTable;
import godis_apan.thedecorationpack.medieval.client.model.ModelTable;
import godis_apan.thedecorationpack.medieval.lib.Reference;
import godis_apan.thedecorationpack.medieval.lib.Textures;
import godis_apan.thedecorationpack.medieval.tileentity.TileEntityTable;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.IItemRenderer;

import org.lwjgl.opengl.GL11;

import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class RenderItem implements IItemRenderer
{

    public RenderItemTable()
    {
    }

    @Override
    public boolean handleRenderType(ItemStack stack, ItemRenderType renderType)
    {
        return true;
    }

    @Override
    public boolean shouldUseRenderHelper(ItemRenderType renderType, ItemStack stack, ItemRendererHelper renderHelper)
    {
        return true;
    }

    @Override
    public void renderItem(ItemRenderType renderType, ItemStack stack, Object... data)
    {
    }
}

 

Thats the basic class. Now in the renderItem() method you want to check the item render type. If it's in the inventory, first/third person or rendered as an entity item on the ground.

 

if (renderType == renderType.EQUIPPED)

{

    GL11.glPushMatrix();

    GL11.glScalef(1.5F, 1.5F, 1,5F);

    GL11.glPopMatrix();

}

 

The you scale it up using the glScalef(). If you scale it alot you will have to translate the item in a correct position (GL11.glTranlatef(x, y, z)).

 

Lastly you want to register the item renderer using:

 

MinecraftForgeClient.registerItemRenderer(myItem, new myRenderer());

 

I'm suggesting you do that in the client proxy.

 

 

Posted

Ok I would use a custom item renderer. Make a new class and make it implement the IItemRenderer.

 

Example:


package godis_apan.thedecorationpack.medieval.client.render.item;

import godis_apan.thedecorationpack.medieval.client.model.ModelOrnateTable;
import godis_apan.thedecorationpack.medieval.client.model.ModelTable;
import godis_apan.thedecorationpack.medieval.lib.Reference;
import godis_apan.thedecorationpack.medieval.lib.Textures;
import godis_apan.thedecorationpack.medieval.tileentity.TileEntityTable;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.IItemRenderer;

import org.lwjgl.opengl.GL11;

import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class RenderItem implements IItemRenderer
{

    public RenderItemTable()
    {
    }

    @Override
    public boolean handleRenderType(ItemStack stack, ItemRenderType renderType)
    {
        return true;
    }

    @Override
    public boolean shouldUseRenderHelper(ItemRenderType renderType, ItemStack stack, ItemRendererHelper renderHelper)
    {
        return true;
    }

    @Override
    public void renderItem(ItemRenderType renderType, ItemStack stack, Object... data)
    {
    }
}

 

Thats the basic class. Now in the renderItem() method you want to check the item render type. If it's in the inventory, first/third person or rendered as an entity item on the ground.

 

if (renderType == renderType.EQUIPPED)

{

    GL11.glPushMatrix();

    GL11.glScalef(1.5F, 1.5F, 1,5F);

    GL11.glPopMatrix();

}

 

The you scale it up using the glScalef(). If you scale it alot you will have to translate the item in a correct position (GL11.glTranlatef(x, y, z)).

 

Lastly you want to register the item renderer using:

 

MinecraftForgeClient.registerItemRenderer(myItem, new myRenderer());

 

I'm suggesting you do that in the client proxy.

When I put in the line:

MinecraftForgeClient.registerItemRenderer(HawkshotRifle.class, new RenderRifle());

 

I am told that registerItemRenderer isn't applicable for the arguments and it gives an error.

 

Very helpful! But having same problem as above.

 

Posted

That's because it takes an Item, not a Class. Just look at the method arguments and you will see that.

Ah yes, so no errors and the game loads, but now my weapon appears invisible.

 

My render file:

 

 

 

package com.darkMod.item;

 

import net.minecraft.client.renderer.Tessellator;

import net.minecraft.item.ItemStack;

import net.minecraft.util.ResourceLocation;

import net.minecraftforge.client.IItemRenderer;

 

import org.lwjgl.opengl.GL11;

 

import cpw.mods.fml.client.FMLClientHandler;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

@SideOnly(Side.CLIENT)

public class RifleRender implements IItemRenderer

{

 

    public void RenderItemTable()

    {

    }

 

    @Override

    public boolean handleRenderType(ItemStack stack, ItemRenderType renderType)

    {

        return true;

    }

 

    @Override

    public boolean shouldUseRenderHelper(ItemRenderType renderType, ItemStack stack, ItemRendererHelper renderHelper)

    {

        return true;

    }

 

    @Override

    public void renderItem(ItemRenderType renderType, ItemStack stack, Object... data)

    {

    if (renderType == renderType.EQUIPPED)

    {

        GL11.glPushMatrix();

        GL11.glScalef(1.5F, 1.5F, 1.5F);

        GL11.glPopMatrix();

    }

    }

}

 

 

 

My main file related stuff:

 

 

public static Item HawkshotRifle = new HawkshotRifle(StartingItemID+6, Gun).setUnlocalizedName("hawkshotRifle").setTextureName("eternisles:hawkShot");

 

private final static RifleRender rifleRender = new RifleRender();

 

@EventHandler

  public void load(FMLInitializationEvent event) {

    addItemsToRegistries();

  }

 

private void addItemsToRegistries() {

MinecraftForgeClient.registerItemRenderer(HawkshotRifle, new GunRender());

}

 

 

 

Posted

Render type EQUIPPED is for 3rd person, and EQUIPPED_FIRST_PERSON is for 1st person (which I'm guessing is where you noticed it's invisible). You need to account for both cases in your render class.

 

If you need a further example, take a look at my RenderBigItem class that I used for my hammers and big swords.

That makes it appear, however it is at the wrong angle. Is there a way to rotate/flip it?

Posted

GL11.glRotatef();

 

The params it takes are:

 

GL11.glRotatef(float angle, float x, float y, float z);

 

So if you want to rotate it on the y axis 90 degress the code should be:

 

 

GL11.glRotatef(90F, 0F, 1.0F, 0F);

 

The most simple way is to play around with it 'til it works!

Posted

Ohh and a important thing is the order the GL11 codes comes in, so here is the order:

 

GL11.glPushMatrix();

GL11.glTranslatef();

GL11.glScalef();

GL11.glRotatef();

 

Here your model goes!!!

 

GL11.glPopMatrix();

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.

Announcements



×
×
  • Create New...

Important Information

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