Jump to content

Trying to draw a hand when holding an item.


FireIsH0t

Recommended Posts

package net.arsenalnetwork.arsenalmod.client.render.item;

import net.arsenalnetwork.arsenalmod.item.tools.ItemMelee;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderPlayer;
import net.minecraft.client.renderer.tileentity.TileEntityItemStackRenderer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import org.lwjgl.opengl.GL12;

public class RenderItem extends TileEntityItemStackRenderer
{

    @Override
    public void renderByItem(ItemStack itemStackIn) {
        Minecraft mc = Minecraft.getMinecraft();

        final EntityPlayer player = Minecraft.getMinecraft().player;

        if (itemStackIn != null)
        {
            GlStateManager.pushMatrix();

            if (itemStackIn.getItem() instanceof ItemMelee)
            {
                if (!player.isSwingInProgress)
                {
                    /**
                     * For the right hand
                     */
                    GlStateManager.pushMatrix();
                    GlStateManager.glEnableClientState(GL12.GL_RESCALE_NORMAL);
                    mc.getTextureManager().bindTexture(((EntityPlayerSP) player).getLocationSkin());
                    GlStateManager.translate(1F, 1F, 0F);
                    GlStateManager.rotate(125.0F, 0.0F, 0.0F, 1.0F);
                    GlStateManager.rotate(180.0F, 1.0F, 0.0F, 0.0F);
                    GlStateManager.scale(1.0F, 1.8F, 1.0F);
                    GlStateManager.translate(0.19F, -1.14F, 0.3F);
                    Render render = Minecraft.getMinecraft().getRenderManager().getEntityRenderObject(mc.player);
                    mc.getRenderManager().getEntityRenderObject(mc.player);
                    RenderPlayer renderPlayer = (RenderPlayer)render;
                    float f11 = 1.0F;
                    GlStateManager.scale(f11, f11, f11);
                    renderPlayer.renderRightArm(mc.player);
                    GlStateManager.popMatrix();
                }

                this.renderItemThirdPerson((EntityPlayer) player, itemStackIn);

                GlStateManager.popMatrix();

                return;
            }
        }
    }

    public void renderItemThirdPerson(EntityPlayer player, ItemStack itemStack)
    {
        GlStateManager.translate(0.0F, 0.0F, -0.05F);

        GlStateManager.rotate(180, 1.0F, 0.0F, 0.0F);
        GlStateManager.rotate(-15, 0.0F, 0.0F, 1.0F);
        GlStateManager.rotate(78, 0.0F, 1.0F, 0.0F);

        GlStateManager.translate(0.0F, 0.7F, 0.25F);

        GlStateManager.rotate(15, 0.0F, 0.0F, 1.0F);

        double scale = 1.2D;
        GlStateManager.scale(scale, scale, scale);
    }
}
Link to comment
Share on other sites

Just now, V0idWa1k3r said:

Apart from messing with GL matrix this

does nothing in your implementation.

So yeah 

if (itemStackIn.getItem() instanceof ItemMelee)

trying to get all the melee items that are created and render that hand. Why doesn't it work like what am i doing wrong?

Link to comment
Share on other sites

5 minutes ago, FireIsH0t said:

Why doesn't it work like what am i doing wrong?

 

7 minutes ago, V0idWa1k3r said:

this

Quote

public void renderItemThirdPerson(EntityPlayer player, ItemStack itemStack)

does nothing in your implementation.

 

Also show where you assign the TEISR to your item.

 

4 minutes ago, FireIsH0t said:

1.12.2

ItemStack can't be null in 1.12.2. It can only be empty. But you already know that not to be the case if the render method is even executed. This check is pointless

Link to comment
Share on other sites

1 minute ago, V0idWa1k3r said:

 

 

Also show where you assign the TEISR to your item.

 

ItemStack can't be null in 1.12.2. It can only be empty. But you already know that not to be the case if the render method is even executed. This check is pointless

@Override
public void renderByItem(ItemStack itemStackIn) {
    Minecraft mc = Minecraft.getMinecraft();

    final EntityPlayer player = Minecraft.getMinecraft().player;
    
        GlStateManager.pushMatrix();
        
        if (itemStackIn.getItem() instanceof ItemMelee)
        {
            if (!player.isSwingInProgress)
            {
                /**
                 * For the right hand
                 */
                GlStateManager.pushMatrix();
                GlStateManager.glEnableClientState(GL12.GL_RESCALE_NORMAL);
                mc.getTextureManager().bindTexture(((EntityPlayerSP) player).getLocationSkin());
                GlStateManager.translate(1F, 1F, 0F);
                GlStateManager.rotate(125.0F, 0.0F, 0.0F, 1.0F);
                GlStateManager.rotate(180.0F, 1.0F, 0.0F, 0.0F);
                GlStateManager.scale(1.0F, 1.8F, 1.0F);
                GlStateManager.translate(0.19F, -1.14F, 0.3F);
                Render render = Minecraft.getMinecraft().getRenderManager().getEntityRenderObject(mc.player);
                mc.getRenderManager().getEntityRenderObject(mc.player);
                RenderPlayer renderPlayer = (RenderPlayer)render;
                float f11 = 1.0F;
                GlStateManager.scale(f11, f11, f11);
                renderPlayer.renderRightArm(mc.player);
                GlStateManager.popMatrix();
            }

            this.renderItemThirdPerson((EntityPlayer) player, itemStackIn);

            GlStateManager.popMatrix();

            return;
    }
}

 

Removed that null thing "Also show where you assign the TEISR to your item." ?

Link to comment
Share on other sites

4 minutes ago, FireIsH0t said:

"Also show where you assign the TEISR to your item." ?

Exactly as it sounds. a TEISR needs to be assigned to the item using Item#setTileEntityItemStackRenderer(one of the options anyway). Code isn't magic, it's not going to just work because you've made some classes.

Link to comment
Share on other sites

@SideOnly(Side.CLIENT)
@Nullable
private net.minecraft.client.renderer.tileentity.TileEntityItemStackRenderer teisr;

@SideOnly(Side.CLIENT)
public void setTileEntityItemStackRenderer(@Nullable net.minecraft.client.renderer.tileentity.TileEntityItemStackRenderer teisr)
{
    this.teisr = teisr;
}

this right?

Link to comment
Share on other sites

package net.arsenalnetwork.arsenalmod.client.render.item;

import net.arsenalnetwork.arsenalmod.item.tools.ItemMelee;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderPlayer;
import net.minecraft.client.renderer.tileentity.TileEntityItemStackRenderer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.opengl.GL12;

import javax.annotation.Nullable;

public class RenderItem extends TileEntityItemStackRenderer
{

    @Override
    public void renderByItem(ItemStack itemStackIn) {
        Minecraft mc = Minecraft.getMinecraft();

        final EntityPlayer player = Minecraft.getMinecraft().player;

            GlStateManager.pushMatrix();

            if (itemStackIn.getItem() instanceof ItemMelee)
            {
                if (!player.isSwingInProgress)
                {
                    /**
                     * For the right hand
                     */
                    GlStateManager.pushMatrix();
                    GlStateManager.glEnableClientState(GL12.GL_RESCALE_NORMAL);
                    mc.getTextureManager().bindTexture(((EntityPlayerSP) player).getLocationSkin());
                    GlStateManager.translate(1F, 1F, 0F);
                    GlStateManager.rotate(125.0F, 0.0F, 0.0F, 1.0F);
                    GlStateManager.rotate(180.0F, 1.0F, 0.0F, 0.0F);
                    GlStateManager.scale(1.0F, 1.8F, 1.0F);
                    GlStateManager.translate(0.19F, -1.14F, 0.3F);
                    Render render = Minecraft.getMinecraft().getRenderManager().getEntityRenderObject(mc.player);
                    mc.getRenderManager().getEntityRenderObject(mc.player);
                    RenderPlayer renderPlayer = (RenderPlayer)render;
                    float f11 = 1.0F;
                    GlStateManager.scale(f11, f11, f11);
                    renderPlayer.renderRightArm(mc.player);
                    GlStateManager.popMatrix();
                }

                this.renderItemThirdPerson((EntityPlayer) player, itemStackIn);

                GlStateManager.popMatrix();

                return;
        }
    }

    public void renderItemThirdPerson(EntityPlayer player, ItemStack itemStack)
    {
        GlStateManager.translate(0.0F, 0.0F, -0.05F);

        GlStateManager.rotate(180, 1.0F, 0.0F, 0.0F);
        GlStateManager.rotate(-15, 0.0F, 0.0F, 1.0F);
        GlStateManager.rotate(78, 0.0F, 1.0F, 0.0F);

        GlStateManager.translate(0.0F, 0.7F, 0.25F);

        GlStateManager.rotate(15, 0.0F, 0.0F, 1.0F);

        double scale = 1.2D;
        GlStateManager.scale(scale, scale, scale);
    }

    @SideOnly(Side.CLIENT)
    @Nullable
    private net.minecraft.client.renderer.tileentity.TileEntityItemStackRenderer teisr;

    @SideOnly(Side.CLIENT)
    public void setTileEntityItemStackRenderer(@Nullable net.minecraft.client.renderer.tileentity.TileEntityItemStackRenderer teisr)
    {
        this.teisr = teisr;
    }
}

 

ok boom.

Link to comment
Share on other sites

I didn't tell you "Oh, see these methods in the Item class? Yeah, copy them into your TEISR class, it will magically find your class by these methods and just work". I told you

11 minutes ago, V0idWa1k3r said:

a TEISR needs to be assigned to the item using Item#setTileEntityItemStackRenderer(one of the options anyway). Code isn't magic, it's not going to just work because you've made some classes.

This means "invoke Item#setTileEntityItemStackRenderer to bind your TEISR to the item". No, don't invoke it in your TEISR. Do it somewhere that makes sense, somewhere where you know it will be executed by the game. Like in your client proxy.

Link to comment
Share on other sites

What’s wrong with just using a JSON model?

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

5 minutes ago, Cadiboo said:

What’s wrong with just using a JSON model?

I don't think you can draw a player's hand with a json model since, well, the game renders the quads you provide with the default texture atlas. The player's hand on the other hand uses the player's skin as it's texture, which is a separate texture object.

I mean, I can kinda see how you might be able to do it with a custom IBakedModel but it would be breaking multiple things and borderline a dirty hack. I think that a TEISR is a solution here, but feel free to disagree.

Link to comment
Share on other sites

5 minutes ago, V0idWa1k3r said:

I don't think you can draw a player's hand with a json model since, well, the game renders the quads you provide with the default texture atlas. The player's hand on the other hand uses the player's skin as it's texture, which is a separate texture object.

I mean, I can kinda see how you might be able to do it with a custom IBakedModel but it would be breaking multiple things and borderline a dirty hack. I think that a TEISR is a solution here, but feel free to disagree.

I am a bit confused now lol

Link to comment
Share on other sites

Alright Update:

 

New RenderBaseBall Class: https://hastebin.com/yatirebome.java

 

And have this in my ClientEventSubscriber:

@SubscribeEvent
public static void onRegisterModelsEvent(final ModelRegistryEvent event) {

    ModItems.BASEBALL_BAT.setTileEntityItemStackRenderer(new RenderBaseBallBat());

 

but the hand still doesnt render onto the baseball bat item

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

    • Add crash-reports with sites like https://paste.ee/ Maybe an issue with blur, essentials or cumulus_menus
    • Add the crash-report or latest.log (logs-folder) with sites like https://paste.ee/ and paste the link to it here  
    • I have a problem, I am trying to put two different effects to two different armors but when I run it only the emerald armor effect works. This is the code public class ModArmorItem extends ArmorItem{ private static final Map<ArmorMaterial, MobEffectInstance> MATERIAL_TO_EFFECT_MAP = (new ImmutableMap.Builder<ArmorMaterial, MobEffectInstance>()) .put(ModArmorMaterials.EMERALD, new MobEffectInstance(MobEffects.HERO_OF_THE_VILLAGE,200, 1,false,false, true)) .put(ModArmorMaterials.OBSIDIAN, new MobEffectInstance(MobEffects.FIRE_RESISTANCE,200, 1,false,false, true)).build(); public ModArmorItem(ArmorMaterial pMaterial, Type pType, Properties pProperties) { super(pMaterial, pType, pProperties); } @Override public void onArmorTick(ItemStack stack, Level world, Player player){ if (!world.isClientSide()) { if (hasFullSuitOfArmorOn(player)) { evaluateArmorEffects(player); } } } private void evaluateArmorEffects(Player player) { for (Map.Entry<ArmorMaterial,MobEffectInstance> entry : MATERIAL_TO_EFFECT_MAP.entrySet()){ ArmorMaterial mapArmorMaterial = entry.getKey(); MobEffectInstance mapStatusEffect = entry.getValue(); if (hasCorrectArmorOn(mapArmorMaterial, player)) { addStatusEffectForMaterial(player, mapArmorMaterial, mapStatusEffect); } } } private void addStatusEffectForMaterial(Player player, ArmorMaterial mapArmorMaterial, MobEffectInstance mapStatusEffect) { boolean hasPlayerEffect = player.hasEffect(mapStatusEffect.getEffect()); if (hasCorrectArmorOn(mapArmorMaterial, player) && !hasPlayerEffect) { player.addEffect(new MobEffectInstance(mapStatusEffect)); } } private boolean hasCorrectArmorOn(ArmorMaterial material, Player player) { for (ItemStack armorStack : player.getInventory().armor){ if (!(armorStack.getItem() instanceof ArmorItem)) { return false; } } ArmorItem helmet = ((ArmorItem)player.getInventory().getArmor(3).getItem()); ArmorItem breastplace = ((ArmorItem)player.getInventory().getArmor(2).getItem()); ArmorItem leggins = ((ArmorItem)player.getInventory().getArmor(1).getItem()); ArmorItem boots = ((ArmorItem)player.getInventory().getArmor(0).getItem()); return helmet.getMaterial() == material && breastplace.getMaterial() == material && leggins.getMaterial() == material && boots.getMaterial() == material; } private boolean hasFullSuitOfArmorOn(Player player){ ItemStack helmet = player.getInventory().getArmor(3); ItemStack breastplace = player.getInventory().getArmor(2); ItemStack leggins = player.getInventory().getArmor(1); ItemStack boots = player.getInventory().getArmor(0); return !helmet.isEmpty() && !breastplace.isEmpty() && !leggins.isEmpty() && !boots.isEmpty(); } } Also when I place two effects on the same armor, the game crashes. Here is the crash file. The code is the same, only this part is different   private static final Map<ArmorMaterial, MobEffectInstance> MATERIAL_TO_EFFECT_MAP = (new ImmutableMap.Builder<ArmorMaterial, MobEffectInstance>()) .put(ModArmorMaterials.EMERALD, new MobEffectInstance(MobEffects.HERO_OF_THE_VILLAGE,200, 1,false,false, true)) .put(ModArmorMaterials.EMERALD, new MobEffectInstance(MobEffects.FIRE_RESISTANCE,200, 1,false,false, true)).build(); I hope you guys can help me. Thanks.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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