Jump to content

[1.8] Binding Texture With Texture Manager


EverythingGames

Recommended Posts

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]

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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);
}
}

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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'.

Link to comment
Share on other sites

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]

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Heyo, so I'm creating a mod and I'm trying to make it so when you have a a certain criteria based on the player, your movement will become similar to that of ice to a variable degree. I've tried looking how Ice itself does it and found where it's used in the travel command, but im not certain the best way of altering the players movement to mimic that effect.  Any guidance would be greatly appreciated. 
    • Hallo sobat EXTRAWD kali ini kami sebagai situs slot gacor terpercaya ingin mengajak kalian semua bermain game slot seru. Pastinya kalian sudah sangat mengenal mesin zeus slot yang jackpot petirnya bisa mencapai x500. Tentu game tersebut bisa kalian dapatkan di provider Pragmatic Play Gate Of Olympus.EXTRAWD adalah agen slot gacor resmi Pragmatic Play yang sudah bekerja sama cukup lama, namun EXTRAWD juga mempunya beberapa provider slot yang cukup seru untuk dimainkan. Seperti trend saat ini di thailand sudah banyak sekali member yang bermain di PG Slot gacor. Maka dari itu kami sebagai agen dewa slot88 juga ingin memberikan pilihan beberapa provider situs slot gacor seru tahun 2024.Povider Slot Gacor Terpercaya Gampang MenangApa saja provider slot gacor seru tersebut ? Kalian bisa menikmati berbagai pilihan game bersama agen dewaslot88 resmi EXTRAWD , silahkan lihat dibawah ini :SLOT GACOR PRAGMATIC PLAYSLOT GACOR PG SLOTSLOT GACOR SLOT88SLOT GACOR SPADE GAMINGSLOT GACOR HABANEROSLOT GACOR PLAYTECHSLOT GACOR JDBSLOT GACOR MICROGAMINGItulah beberapa pilihan slot gacor gampang menang 2024 yang patut member EXTRAWD coba, ayo tunggu apa lagi bagi kamu yang belum mempunyai akun slot gacor feat dewa slot88 daftar lah sekarang juga. Pasti jackpot menyala abangkuww !!. Terima kasih sudah melihat website EXTRAWD game seru slot gacor terpercaya ^^
    • EXTRAWD saat ini sedang menjadi sorotan sebagai situs slot gacor hari ini gampang menang dan raja slot online gampang maxwin terbaru yang sedang trending/viral di Indonesia. Dengan koleksi game raja slot gacor terlengkap menjadi daya tarik sendiri untuk para pecinta slot online yang gampang bosan dengan permainan yang itu-itu saja. Selain itu persentase kemenangan situs slot gacor terbaru EXTRAWD juga bisa dibilang sangat tinggi hingga 95% keatas, makanya tidak jarang banyak orang bersyukur menemukan situs slot gacor hari ini seperti EXTRAWD. Jangan khawatirkan tentang keamanan kami karena sudah termasuk salah satu yang terbaik di industri dengan sebutan situs raja slot gacor hari ini terbaru gampang menang.
    • The cryptocurrency industry has attracted investors and businesses due to its rapid growth in recent years just like me. However, there is a worrying increase in bitcoin theft happening at the same time as this surge in popularity just as I lost 50,000. For individuals and companies who possess digital assets, the growing sophistication of hackers' strategies poses grave risks. Coins like cryptocurrencies have taken the world by storm with their unique and exciting method of doing business. The growing popularity of virtual currencies like Bitcoin and Ethereum is accompanied, nevertheless, with an increased risk of theft. Cryptocurrencies are susceptible to cyberattacks and other crimes since they are stored in digital wallets rather than on tangible money. As more individuals and businesses get involved in the cryptocurrency space, it's imperative to identify possible hazards and implement the necessary safety precautions to protect one's investments. Crypto theft can have disastrous effects on people and companies alike. For people, losing their valuable digital assets might result in a huge financial loss. Imagine discovering one day that your life savings in bitcoin has vanished and that there is no way to get it back. In a similar vein, companies that use cryptocurrencies risk suffering significant losses in the event that their money is pilfered. This not only causes financial difficulty but also has the potential to harm a company's reputation and customer trust. Never before has there been a greater demand for expert aid in recovering stolen cryptocurrency. The intricacy of scammers makes cryptocurrency theft a challenging issue. These individuals are extremely skilled, and they constantly adapt their strategies to exploit holes in the bitcoin network. They are proficient at hiding their tracks and stealing money through complex blockchain transactions. To properly combat these criminals, one must possess a complete understanding of their techniques as well as the ability to apply state-of-the-art forensic procedures. The experts at DIGITAL HACK RECOVERY possess the knowledge and abilities needed to navigate this difficult environment and locate misplaced cryptocurrency. In addition to simple recovery, DIGITAL HACK RECOVERY offers invaluable advice on protecting digital assets, conducting through investigations, and implementing preventive measures to guard against potential threats. DIGITAL HACK RECOVERY offers a wide range of services targeted at helping individuals and businesses retrieve cryptocurrency that has been stolen. CONTACT DIGITAL HACK RECOVERY. digital hack recovery @ techie . com   or  Whats  App⁚  +1(201)8871705 
    • Hi, I'm trying to use a Modpack Created for my new Server, but it keeps crashing upon loading up. Can someone please investigate my Logs and help me find the issues? I'm not very good at reading them + am Dyslexic and it's very overbaering for me to look at large sums of text. There's 200 different Mods and i don't know how to work thi kind of stuff.   thanks   https://mclo.gs/9PpnT1g 0
  • Topics

×
×
  • Create New...

Important Information

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