Jump to content

Recommended Posts

Posted

Hi

Is it possible to bind a texture in code to a .JSON cuboid (I highly think this is not possible due to the vast limitations of the new model system...but that's why I am asking here to find out). Thanks in advance.

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Posted

I don't know about a .json cuboid specifically, but you can most certainly still bind textures - just look at any vanilla Entity render class.

That sounds useful for some of my later ideas. Do you know if this is possible - let's say I have an item and I want two .JSON's to render AKA two item models rendered together. Is this at all possible? I would really like to know!

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Posted

I've rendered multiple models several times. 

 

One example is I wanted some effects to show up on players skins.  I render the normal player and then render a every so slightly larger model with the effect in just certain places.  looks seamless. 

Long time Bukkit & Forge Programmer

Happy to try and help

Posted

Wow, that's just what I needed. Maybe the new system is flexible after all. So that means (based on earlier posts) I can draw a .JSON model, UV that model, bind the player's skin to it, render it, then render my other model all for just one item. Sounds great.

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Posted

Be sure as you go out a layer to grow the model by .01% or something or there will be rippling.  Use GLSCALE.

Long time Bukkit & Forge Programmer

Happy to try and help

Posted

Thanks @delpi. I have a minor problem - I am returning models in getModel based on whether the player is in first person / third person. This works until you look in your inventory in survival mode when you are able to see your player holding the item. The player here is holding the first person item when he should be holding the third person item (I don't know why it does that when your looking at the player in the inventory third perspective). Any ideas on how to fix this? Thanks.

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Posted

If you put the item on a mob, you are going to have that same issue with the render oddity.

 

Its happening because of just what you said.  You are basing it on whether the player is in 1st person or 3rd. 

 

I can't think of a way off the top of my head to fix.  I'll poke around tonight with some of my stuff.

 

I'm assuming in the render you are grabbing something like "minecraft.theplayer.view".  I know that is the wrong code, but you are getting the perspective from the client is the part I'm interested in.

Long time Bukkit & Forge Programmer

Happy to try and help

Posted

Thanks for the reply, @delpi. I see what you mean by the mob rendering the item for the player with first person view code. You were interested in the client side perspective getting? Here's the code (keep in mind I'm not at my usual workspace so some code may be off in terms of names):

@Override
@SideOnly(Side.CLIENT)
public ModelResourceLocation getModel(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, int par3Integer)
{
    boolean isFirstPerson = Minecraft.getMinecraft.gameSettings.isThirdPersonView;
    if(isFirstPerson)
    {
        //return first person model here
    }
    else
    {
        //return third person model here
    }
}

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Posted

Look at this for example.  Its far more than you probably need, but this works right so you should be able to compare and figure out what is messing up in yours.

 

This is from 1.7.2.  In the process of moving to 1.8 now, but taking some time.

 

 

 

package clandoolittle.dimension_multiplyer.Client.Render.Items;

 

import java.util.logging.Level;

 

import org.lwjgl.opengl.GL11;

 

import clandoolittle.dimension_multiplyer.Dimension_Multiplyer;

import clandoolittle.dimension_multiplyer.Client.Render.Model.ModelWarHammer;

import net.minecraft.client.Minecraft;

import net.minecraft.client.renderer.OpenGlHelper;

import net.minecraft.client.renderer.entity.RenderItem;

import net.minecraft.entity.Entity;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.util.IIcon;

import net.minecraft.util.ResourceLocation;

import net.minecraftforge.client.IItemRenderer;

 

public class RenderWarHammer implements IItemRenderer {

 

    // Setup References

public Dimension_Multiplyer instance = Dimension_Multiplyer.instance;

 

    // Setup Variables

    private ModelWarHammer hammer;

    private ResourceLocation texture = new ResourceLocation(instance.modid, instance.textures().textures("WARHAMMER.PNG"));

    private ResourceLocation texture_armor = new ResourceLocation(instance.modid, instance.textures().textures("WARHAMMERLIGHT.PNG"));

    private int rendercounter = 0;

    private int rendercounter_limit = 5;

    private int lightningChance = 10;

    private boolean raptor;

    private boolean charged;

 

    public RenderWarHammer(Boolean raptor, Boolean charged) {

   

        // Setup Variables

    this.raptor = raptor;

    this.charged = charged;

        hammer = new ModelWarHammer(raptor);

       

    }

   

    private int rendercounter() {

   

    // incriment

    rendercounter++;

   

    // Check for limit

    if (rendercounter > rendercounter_limit) rendercounter = 0;

   

    // Return

    return rendercounter;

   

    }

 

    @Override

    public boolean handleRenderType(ItemStack item, ItemRenderType type) {

   

        switch (type) {

       

            case EQUIPPED:

                return true;

 

            case EQUIPPED_FIRST_PERSON:

                return true;

 

            case INVENTORY:

                return true;

 

            default:

                return false;

               

        }

       

    }

 

    @Override

    public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {

   

        // TODO Auto-generated method stub

        return false;

       

    }

 

    @Override

    public void renderItem(ItemRenderType type, ItemStack item, Object... data) {

   

        switch (type) {

       

            case EQUIPPED: {

           

            // Reset Rendering

                GL11.glPushMatrix();

 

                // Bind Texture

                Minecraft.getMinecraft().renderEngine.bindTexture(texture);

               

                // Rescale Texture

                float scale = 0.5F;               

                GL11.glScalef(scale, scale, scale);

               

                // Rotate Y

                GL11.glRotatef(15, 0.0F, 1.0F, 0.0F);

 

                // Rotate X

                GL11.glRotatef(180 + 15, 1.0F, 0.0F, 0.0F);

               

                // Rotate z

                GL11.glRotatef(-15, 0.0F, 0.0F, 1.0F);

 

                // Move to correct position

                GL11.glTranslatef(0.85F, 0.0F, 0.05F); // Left-Right Forward-Backwards Up-Down

 

                // Render Model

                hammer.render((Entity) data[1], 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);

               

                // Check for WarHammer Raptor

                if (charged && instance.functions_common().random().nextInt(lightningChance) == 0) raptor_flash((Entity) data[1]);

                               

                // Finish Rendering

                GL11.glPopMatrix();

               

               

               

                break;

            }

         

            case EQUIPPED_FIRST_PERSON: {

           

            // Reset Rendering

                GL11.glPushMatrix();

 

                // Bind Texture

                Minecraft.getMinecraft().renderEngine.bindTexture(texture);

               

                // Rescale Texture

                float scale = 0.5F;               

                GL11.glScalef(scale, scale, scale);

               

                // Rotate Y

                GL11.glRotatef(90 + 15, 0.0F, 1.0F, 0.0F);

 

                // Rotate X

                GL11.glRotatef(180 + 15, 1.0F, 0.0F, 0.0F);

               

                // Rotate z

                GL11.glRotatef(-15, 0.0F, 0.0F, 1.0F);

 

                // Move to correct position

                //GL11.glTranslatef(0.85F, 0.0F, 0.05F); // Left-Right Forward-Backwards Up-Down

 

                // Render Model

                hammer.render((Entity) data[1], 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);

               

                // Check for WarHammer Raptor

                if (charged && instance.functions_common().random().nextInt(lightningChance) == 0) raptor_flash((Entity) data[1]);

               

                // Finish Rendering

                GL11.glPopMatrix();

           

                break;

            }

 

            case INVENTORY: {

           

            // Reset Rendering

                GL11.glPushMatrix();

               

                // Setup OpenGL

    GL11.glEnable(GL11.GL_ALPHA_TEST);

           

            // Setup Render

                RenderItem renderItem = new RenderItem();

               

                // set Texture

                IIcon icon = item.getIconIndex();

               

                // Enable Blending

                //GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE);

               

                // Render

                renderItem.renderIcon(0, 0, icon, 16, 16);

               

                // Undo;

                //GL11.glDisable(GL11.GL_BLEND);

               

                // Finish Rendering

                GL11.glPopMatrix();

               

                break;

               

            }

 

            default:

           

                break;

               

        }

       

    }

   

    private void raptor_flash(Entity entity) {

   

    // Rescale Texture

        float scale = 1.05F;               

        //GL11.glScalef(scale, scale, scale);

       

        // Shift down to right spot

        //GL11.glTranslatef(0.05F, 0.15F, 0F);

   

    // Setup Variables

    float f1 = rendercounter();

        float f2 = f1 * 0.01F * (instance.functions_common().random().nextFloat() - 1.0F) * 2.0F;

        float f3 = f1 * 0.01F * (instance.functions_common().random().nextFloat() - 1.0F) * 2.0F;

        float f4 = f1 * 0.01F * (instance.functions_common().random().nextFloat() - 1.0F) * 2.0F;

       

        // Shift the image around

        GL11.glTranslatef(f2, f3, f4);

       

        // Enable Blending

        GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE);

                                           

        // Bind Armor Texture

        Minecraft.getMinecraft().renderEngine.bindTexture(texture_armor);

       

        // Render With Armor

        hammer.render(entity, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);

       

        // Undo;

        GL11.glDisable(GL11.GL_BLEND);

   

    }

   

    protected float degToRad(float degrees) {

   

        return degrees * (float)Math.PI / 180 ;

       

    }

   

}

 

 

Long time Bukkit & Forge Programmer

Happy to try and help

Posted

That's pretty useful and I appreciate your help greatly @delpi. I don't think this will work, though, because IItemRenderer is deprecated and no longer works in 1.8. I really wish Lex didn't scrap that interface. I see how you can switch the enum types based on "EQUIPPED" and "EQUIPPED_FIRST_PERSON" to fix my problem, but like I said, sadly I can't use IItemRenderer in 1.8.

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Posted

As I said, I'm in the process of converting.  I'll probably get to one of my mods that has custom item renders this weekend.  If I figure something out, i'll post it.

Long time Bukkit & Forge Programmer

Happy to try and help

Posted

Part of the problem, at least in the code you posted, is your logic is wrong. If thirdPersonView resolves to 'true', the view is 3rd person, not first.

 

However, as you've found, that will not work for inside the inventory as thirdPersonView can be false but in the inventory view it should be using 3rd person no matter what, and you are breaking that by returning models from there.

 

The solution is to use IPerspectiveAwareModel, so that your model class itself can handle it - #handlePerspective returns a pair of the model to use and the transformations required.

 

You can store references to multiple models easily in the class:

private final IBakedModel baseModel;
private final IBakedModel emptyModel;
public ModelItemBomb(IBakedModel baseModel) {
bombModel = new ModelBomb();
this.baseModel = baseModel;
ModelResourceLocation resource = new ModelResourceLocation(ModInfo.ID + ":empty", "inventory");
this.emptyModel = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getModelManager().getModel(resource);
if (emptyModel == null) {
	ZSSMain.logger.warn("Failed to retrieve model for resource location: " + resource);
}
}

Posted

Thanks, @coolAlias. The code I posted works until you look in your inventory (that may not be correct code, I am not at my usual workspace, I just thought of a rough idea of what my code was, sorry about that).  I thought I had to use IPerspectiveAwareModel, TGG told me that about a million times...it's just that it's new and I'm not used to any of the new rendering. I'll try it later on.

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Posted

I was sleepy when I wrote that code - I meant to put:

boolean isFirstPerson = Minecraft.getMinecraft().gameSettings.isThirdPersonView == 0;

The "isThirdPerson" is an integer, not a boolean (though my code returns a boolean value based on what isThirdPersonView is / returns), but anyway, I'll try IPerspectiveAwareModel.

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Posted

Thank you @delpi. I've read through this tutorial and wondered why this was for version 1.8, considering the class seen in the tutorial implements IItemRenderer (a deprecated interface that was considered "unusable" because of the new modeling / rendering system). No problem, I can probably use that, but I would really like to have this done the right way with the new system. I really don't know how to use these:

(don't quote me on some wrong interface / class names)

* IBakedModel

* IFlexibleModel

* IPerspectiveAwareModel

I wish there was some 1.8 tutorials on this so I don't have to guess my way throughout my code. Nevertheless, I'm still going to try. Things for myself to accomplish:

1.) Render player arms as a separate model through .JSON and bind the player skin to it

2.) Render the separate arms with my custom model

3.) Learn how properly control when and how an item is rendered with the new system (1.8 rendering / modeling methods)

That's all I need to do, then rendering can be a thing of the pass. I appreciate all previous and future posts, I'm going to go see if TGG has any tutorials. Thanks!

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Posted

I'm going to go see if TGG has any tutorials. Thanks!

He does ;)

 

It is quite intimidating at first, but once you get used to it and start learning your way around, it's not so bad. One thing that is super obvious but that I didn't realize for longer than I care to admit is that you can return 'this' from any of the model methods, which helps enormously. I don't know why, but I thought I had to return a previously baked model or something, and that was causing me all sorts of grief.

Posted

I was reading his code on the smart item model for the chessboard. It was going great, but then it got quite confusing. I don't know how exactly I'm supposed to manipulate my .JSON with my item and this interface with my item... I'm terribly confused, I'm sorry I'm not understanding this, rendering has not been my cup of tea.

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Posted

Thanks. So basically I need to create an IModel to hold two models and return that in the getModel method as a ModelResourceLocation? I like your hack in one of your other posts, seems a lot easier. I didn't know that you could call GL rotation / translation functions in getModel!

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Posted

You're not really supposed to... but that was the only way I could get that particular one to work. Ideally, it should all be done within the Model class.

 

You don't even have to create an IModel to hold the references - you can do it directly in the Item class much like storing IIcon in 1.7.10:

@SideOnly(Side.CLIENT)
private List<ModelResourceLocation> models;

// I have a method called automatically for every Item, much like the previous registerIcons method:
@Override
@SideOnly(Side.CLIENT)
public void registerRenderers(ItemModelMesher mesher) {
String name = getUnlocalizedName(); // don't yell at me Lex - it's the 2nd R of RRR 
name = ModInfo.ID + ":" + name.substring(name.lastIndexOf(".") + 1);
models = new ArrayList<ModelResourceLocation>();
for (int i = 0; i < 4; ++i) {
	models.add(new ModelResourceLocation(name + "_" + i, "inventory"));
}
// Register the first model as the base resource
mesher.register(this, 0, models.get(0));
}

@Override
@SideOnly(Side.CLIENT)
public ModelResourceLocation getModel(ItemStack stack, EntityPlayer player, int ticksRemaining) {
if (!player.isUsingItem()) {
	return models.get(0);
}
int ticks = stack.getMaxItemUseDuration() - ticksRemaining;
int i = (ticks > 17 ? 3 : ticks > 13 ? 2 : ticks > 0 ? 1 : 0);
return models.get(i);
}
[code]
As long as you only access (including initialization) the models List (or array, whatever you want) on the client side, you can use it quite easily to return a valid model that is defined in JSON. The example above is taken from my Hero's Bow, and the models are the different states of 'pulling'.

Posted

Actually, what interfaces would I need to implement from my model class to be able to:

1.) Make changes to a specific quad (bind skin texture to .JSON cuboid)

2.) Return different models based on perspective (first person, third person, etc.)

 

I am guessing I should use IPerspectiveAwareModel and IFlexibleBakedModel? If you can tell me I would really like to know so I can start out. Also, with defining quads, are you just defining the cuboids within a .JSON model (that kind of scares me because my .JSON's have like 100 some odd cuboids...)? I know what some methods mean, but most kind of confuse me, especially when looking at TGG's code in MinecraftByExample. If you could clear up some stuff on what interfaces I need to implement and what those key methods in the interface do, I should be good to go on my own and be able to solve some minor problems that should arise. Thanks for all the help so far!

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

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.