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

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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