Jump to content

[1.12.2] How do i make it so my sword renders in my mobs hand?.


Recommended Posts

Posted

So i put 
protected void onInitialSpawn(DifficultyInstance difficulty)
        {
            this.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(ModItems.BARBARIAN_SWORD));
        }
  in my entity class and i did try the one from the wither class and even tried Override with it but for some reason the sword just won't load in on the mobs hand and i don't know what method to use where to declare the mobs arm but if there's a way so my sword can load on my mob let me know!.

Posted

Okay, But my main problem is why won't my sword spawn on my mob because i did just change it to the vanilla code and it still doesn't work.

 

Posted

I believe you have to override postRenderArm in your entity's model class for the item to be rendered. You can adjust the rotation points in there to get it to the position you want it.

Posted

 

 

6 hours ago, diesieben07 said:

Show updated code.

    protected void setEquipmentBasedOnDifficult(DifficultyInstance difficulty)
    {
        this.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(ModItems.BARBARIAN_SWORD));
    }

Posted
3 hours ago, Cerandior said:

I believe you have to override postRenderArm in your entity's model class for the item to be rendered. You can adjust the rotation points in there to get it to the position you want it.

I'm still kinda new to coding mobs so if you could show me an example on how to do it that would be amazing!.

Posted (edited)
5 minutes ago, diesieben07 said:

Still not using @Override.

Still only posting snippets of code, which mean nothing without context.

It's because i was showing you where i only setup the sword for the mob and that method doesn't want override.

Entity barbarian

 

public class EntityBarbarian extends EntityMob
{

    public EntityBarbarian(World worldIn) 
    {
        super(worldIn);
        this.setSize(0.6F, 1.95F);
        this.setHealth(50); 
    }
    
    @Override
    protected void initEntityAI()
    {
    
        super.initEntityAI();
        this.tasks.addTask(0, new EntityAISwimming(this));
        this.tasks.addTask(4, new EntityAIAttackMelee(this, 1.0D, false));
        this.tasks.addTask(8, new EntityAIWander(this, 0.6D));
        this.tasks.addTask(9, new EntityAIWatchClosest(this, EntityPlayer.class, 3.0F, 1.0F));
        this.tasks.addTask(10, new EntityAIWatchClosest(this, EntityLiving.class, 8.0F));
        this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true, new Class[] {EntityVindicator.class}));
        this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, true));
        this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityVillager.class, true));
        this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityIronGolem.class, true));
    }    

    
    @Override
    protected void applyEntityAttributes()
    {
        super.applyEntityAttributes();    
        this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(6.0D);
          this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.23000000417232513D);
        this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).setBaseValue(48.0D);
    }
    
    @Override
    public float getEyeHeight()
    {
        return 1.6F;
    }
    

    protected void setEquipmentBasedOnDifficult(DifficultyInstance difficulty)
    {
        this.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(ModItems.BARBARIAN_SWORD));
    }


 
}

Edited by J0WAY
Posted

I see @Override on every method except the one that would benefit from it, and I have the sinking feeling that it used to be there but was removed because it was complaining.

This is my Forum Signature, I am currently attempting to transform it into a small guide for fixing easier issues using spoiler blocks to keep things tidy.

 

As the most common issue I feel I should put this outside the main bulk:

The only official source for Forge is https://files.minecraftforge.net, and the only site I trust for getting mods is CurseForge.

If you use any site other than these, please take a look at the StopModReposts project and install their browser extension, I would also advise running a virus scan.

 

For players asking for assistance with Forge please expand the spoiler below and read the appropriate section(s) in its/their entirety.

Spoiler

Logs (Most issues require logs to diagnose):

Spoiler

Please post logs using one of the following sites (Thank you Lumber Wizard for the list):

https://gist.github.com/100MB Requires member (Free)

https://pastebin.com/: 512KB as guest, 10MB as Pro ($$$)

https://hastebin.com/: 400KB

Do NOT use sites like Mediafire, Dropbox, OneDrive, Google Drive, or a site that has a countdown before offering downloads.

 

What to provide:

...for Crashes and Runtime issues:

Minecraft 1.14.4 and newer:

Post debug.log

Older versions:

Please update...

 

...for Installer Issues:

Post your installer log, found in the same place you ran the installer

This log will be called either installer.log or named the same as the installer but with .log on the end

Note for Windows users:

Windows hides file extensions by default so the installer may appear without the .jar extension then when the .log is added the log will appear with the .jar extension

 

Where to get it:

Mojang Launcher: When using the Mojang launcher debug.log is found in .minecraft\logs.

 

Curse/Overwolf: If you are using the Curse Launcher, their configurations break Forge's log settings, fortunately there is an easier workaround than I originally thought, this works even with Curse's installation of the Minecraft launcher as long as it is not launched THROUGH Twitch:

Spoiler
  1. Make sure you have the correct version of Forge installed (some packs are heavily dependent on one specific build of Forge)
  2. Make a launcher profile targeting this version of Forge.
  3. Set the launcher profile's GameDir property to the pack's instance folder (not the instances folder, the folder that has the pack's name on it).
  4. Now launch the pack through that profile and follow the "Mojang Launcher" instructions above.

Video:

Spoiler

 

 

 

or alternately, 

 

Fallback ("No logs are generated"):

If you don't see logs generated in the usual place, provide the launcher_log.txt from .minecraft

 

Server Not Starting:

Spoiler

If your server does not start or a command window appears and immediately goes away, run the jar manually and provide the output.

 

Reporting Illegal/Inappropriate Adfocus Ads:

Spoiler

Get a screenshot of the URL bar or copy/paste the whole URL into a thread on the General Discussion board with a description of the Ad.

Lex will need the Ad ID contained in that URL to report it to Adfocus' support team.

 

Posting your mod as a GitHub Repo:

Spoiler

When you have an issue with your mod the most helpful thing you can do when asking for help is to provide your code to those helping you. The most convenient way to do this is via GitHub or another source control hub.

When setting up a GitHub Repo it might seem easy to just upload everything, however this method has the potential for mistakes that could lead to trouble later on, it is recommended to use a Git client or to get comfortable with the Git command line. The following instructions will use the Git Command Line and as such they assume you already have it installed and that you have created a repository.

 

  1. Open a command prompt (CMD, Powershell, Terminal, etc).
  2. Navigate to the folder you extracted Forge’s MDK to (the one that had all the licenses in).
  3. Run the following commands:
    1. git init
    2. git remote add origin [Your Repository's URL]
      • In the case of GitHub it should look like: https://GitHub.com/[Your Username]/[Repo Name].git
    3. git fetch
    4. git checkout --track origin/master
    5. git stage *
    6. git commit -m "[Your commit message]"
    7. git push
  4. Navigate to GitHub and you should now see most of the files.
    • note that it is intentional that some are not synced with GitHub and this is done with the (hidden) .gitignore file that Forge’s MDK has provided (hence the strictness on which folder git init is run from)
  5. Now you can share your GitHub link with those who you are asking for help.

[Workaround line, please ignore]

 

Posted
2 minutes ago, diesieben07 said:

Please, please, please learn the god damn basics.

Understand what overriding does. Understand what @Override does.

Understand that this method now STILL DOES NOT DO ANYTHING, because NOBODY WILL CALL IT.

 

Please learn basic Java and OOP concepts before making a mod. They are a necessary requirement. Not optional.

I was just saying that because you said still not using override, And my whole point of making this post is i need help with the mob and i'm asking why won't it spawn with a sword, To be honest i don't know any of the code to make the mob spawn with the sword so if you could tell me what to do so my mob can spawn with a sword that would be amazing!, Also yeah i do agree i should of learned more basic java before i jumped into this.

Posted (edited)

Hint: You are not overriding a method.

Nevermind me

Edited by DaemonUmbra

This is my Forum Signature, I am currently attempting to transform it into a small guide for fixing easier issues using spoiler blocks to keep things tidy.

 

As the most common issue I feel I should put this outside the main bulk:

The only official source for Forge is https://files.minecraftforge.net, and the only site I trust for getting mods is CurseForge.

If you use any site other than these, please take a look at the StopModReposts project and install their browser extension, I would also advise running a virus scan.

 

For players asking for assistance with Forge please expand the spoiler below and read the appropriate section(s) in its/their entirety.

Spoiler

Logs (Most issues require logs to diagnose):

Spoiler

Please post logs using one of the following sites (Thank you Lumber Wizard for the list):

https://gist.github.com/100MB Requires member (Free)

https://pastebin.com/: 512KB as guest, 10MB as Pro ($$$)

https://hastebin.com/: 400KB

Do NOT use sites like Mediafire, Dropbox, OneDrive, Google Drive, or a site that has a countdown before offering downloads.

 

What to provide:

...for Crashes and Runtime issues:

Minecraft 1.14.4 and newer:

Post debug.log

Older versions:

Please update...

 

...for Installer Issues:

Post your installer log, found in the same place you ran the installer

This log will be called either installer.log or named the same as the installer but with .log on the end

Note for Windows users:

Windows hides file extensions by default so the installer may appear without the .jar extension then when the .log is added the log will appear with the .jar extension

 

Where to get it:

Mojang Launcher: When using the Mojang launcher debug.log is found in .minecraft\logs.

 

Curse/Overwolf: If you are using the Curse Launcher, their configurations break Forge's log settings, fortunately there is an easier workaround than I originally thought, this works even with Curse's installation of the Minecraft launcher as long as it is not launched THROUGH Twitch:

Spoiler
  1. Make sure you have the correct version of Forge installed (some packs are heavily dependent on one specific build of Forge)
  2. Make a launcher profile targeting this version of Forge.
  3. Set the launcher profile's GameDir property to the pack's instance folder (not the instances folder, the folder that has the pack's name on it).
  4. Now launch the pack through that profile and follow the "Mojang Launcher" instructions above.

Video:

Spoiler

 

 

 

or alternately, 

 

Fallback ("No logs are generated"):

If you don't see logs generated in the usual place, provide the launcher_log.txt from .minecraft

 

Server Not Starting:

Spoiler

If your server does not start or a command window appears and immediately goes away, run the jar manually and provide the output.

 

Reporting Illegal/Inappropriate Adfocus Ads:

Spoiler

Get a screenshot of the URL bar or copy/paste the whole URL into a thread on the General Discussion board with a description of the Ad.

Lex will need the Ad ID contained in that URL to report it to Adfocus' support team.

 

Posting your mod as a GitHub Repo:

Spoiler

When you have an issue with your mod the most helpful thing you can do when asking for help is to provide your code to those helping you. The most convenient way to do this is via GitHub or another source control hub.

When setting up a GitHub Repo it might seem easy to just upload everything, however this method has the potential for mistakes that could lead to trouble later on, it is recommended to use a Git client or to get comfortable with the Git command line. The following instructions will use the Git Command Line and as such they assume you already have it installed and that you have created a repository.

 

  1. Open a command prompt (CMD, Powershell, Terminal, etc).
  2. Navigate to the folder you extracted Forge’s MDK to (the one that had all the licenses in).
  3. Run the following commands:
    1. git init
    2. git remote add origin [Your Repository's URL]
      • In the case of GitHub it should look like: https://GitHub.com/[Your Username]/[Repo Name].git
    3. git fetch
    4. git checkout --track origin/master
    5. git stage *
    6. git commit -m "[Your commit message]"
    7. git push
  4. Navigate to GitHub and you should now see most of the files.
    • note that it is intentional that some are not synced with GitHub and this is done with the (hidden) .gitignore file that Forge’s MDK has provided (hence the strictness on which folder git init is run from)
  5. Now you can share your GitHub link with those who you are asking for help.

[Workaround line, please ignore]

 

Posted
6 hours ago, diesieben07 said:

You call Entity#setItemStackToSlot in EntityLiving#onInitialSpawn.

This will probably sound really stupid but i get the first part called setItemStackToSlot in my EntityBarbarian but what do you mean by in EntityLiving#onInitialSpawn.
It's probably really simple and i'm just confused or somethin.

Posted

Which if you mean call
    @Override
    public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata) 
    {
        // TODO Auto-generated method stub
        return super.onInitialSpawn(difficulty, livingdata);
    }
What would i replace difficulty and livingdata with?.

Posted

I wouldn't say that you need to know java specifically in order to get into modding, but you need to have a good idea on Object Oriented Programming. In terms of concept, it is different from procedural programming. Which I am assuming is what you have started learning first. The way of thinking in terms of objects and how they interact with each-other is what you must work on at the moment. When you get the concepts right, learning the language becomes easier because you understand what is going on. There are plenty of courses online related to OOP and they will be worth your time not just for modding.

Posted (edited)
6 hours ago, diesieben07 said:

Why would you replace them?! This is a simple method override and you are calling super. There is no need to replace anything.


Again: Please learn Java basics before making a mod.

Well to be honest at this point i really don't know what i'm doing and it's not working still when i call those methods so if you could show me an example of what to do that would be amazing, Also are mobs suppose to have inventories because if they are then my doesn't have one and i think the main problem in this is it can't find which hand to set the sword to so that's why it isn't spawning with the mob and it just keeps denying it, Again i don't know how to fix because like i said before i'm only good at blocks and items and i just got into making mobs like 3 days ago.

Edited by J0WAY
Posted (edited)
On 12/7/2019 at 2:53 PM, diesieben07 said:

Post updated code, your entire mob class.

public class EntityBarbarian extends EntityMob
{

    public EntityBarbarian(World worldIn) 
    {
        super(worldIn);
        this.setSize(0.6F, 1.95F);
        this.setHealth(50); 
    }
    
    @Override
    protected void initEntityAI()
    {
    
        super.initEntityAI();
        this.tasks.addTask(0, new EntityAISwimming(this));
        this.tasks.addTask(4, new EntityAIAttackMelee(this, 1.0D, false));
        this.tasks.addTask(8, new EntityAIWander(this, 0.6D));
        this.tasks.addTask(9, new EntityAIWatchClosest(this, EntityPlayer.class, 3.0F, 1.0F));
        this.tasks.addTask(10, new EntityAIWatchClosest(this, EntityLiving.class, 8.0F));
        this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true, new Class[] {EntityVindicator.class}));
        this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, true));
        this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityVillager.class, true));
        this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityIronGolem.class, true));
    }    

    
    @Override
    protected void applyEntityAttributes()
    {
        super.applyEntityAttributes();    
        this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(6.0D);
          this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.23000000417232513D);
        this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).setBaseValue(48.0D);
    }
    
    @Override
    public float getEyeHeight()
    {
        return 1.6F;
    }


    @Override
    public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata) 
    {

        return super.onInitialSpawn(difficulty, livingdata);
    }


    @Override
    public void setItemStackToSlot(EntityEquipmentSlot slotIn, ItemStack stack) 
    {

        super.setItemStackToSlot(slotIn.MAINHAND, new ItemStack (ModItems.BARBARIAN_SWORD));
    }

}

Edited by J0WAY
Posted
10 minutes ago, J0WAY said:

    @Override
    public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata) 
    {

        return super.onInitialSpawn(difficulty, livingdata);
    }


    @Override
    public void setItemStackToSlot(EntityEquipmentSlot slotIn, ItemStack stack) 
    {

        super.setItemStackToSlot(slotIn.MAINHAND, new ItemStack (ModItems.BARBARIAN_SWORD));
    }

}

 

Listen man.

super refers to the parent class. In your case, your entity class (EntityBarbarian) extends EntityMob, therefore your entity is a "child" of EntityMob (the parent). Every method of your parent class is accessible to you, but if you want a specific implementation of those methods, you override them (the @Override annotation). In your case, you don't really need a specific implementation of "setItemStackToSlot" so you don't have to override that method. You simply have to call it with the specified parameters.

You have overriden "setItemStackToSlot" to always call the super class's method with the MAINHAND slot and your BARBARIAN_SWORD as the itemstack. Now that's bad because your entity now will always call that method with your specified parameters. That's perhaps something you don't care about. You just want it to work, and the bloody thing doesn't work.


The reason why It doesn't work, is because you are never calling the "setItemStackToSlot" method anywhere. How do you expect it to do anything if it is never being called. The perfect place to call this method would be at the "onInitialSpawn" method, which currently does absolutely nothing in your class. That method is called when your entity is initially spawned on the world, as the name of the method suggests. However you just return the super class's implementation of that method and do nothing else. Which actually means you are doing nothing, because your super class's "onInitialSpawn" method would have been called anyway even if you didn't override it.

Before you return the super class's implementation of "onInitialSpawn", you call the "setItemStackToSlot" with the parameters that you want (Mainhand slot and a new itemstack instance of barbarian sword). So now your class has its own implementation of "onInitialSpawn" and overriding the method makes sense.

Posted
1 hour ago, Cerandior said:

 

Listen man.

super refers to the parent class. In your case, your entity class (EntityBarbarian) extends EntityMob, therefore your entity is a "child" of EntityMob (the parent). Every method of your parent class is accessible to you, but if you want a specific implementation of those methods, you override them (the @Override annotation). In your case, you don't really need a specific implementation of "setItemStackToSlot" so you don't have to override that method. You simply have to call it with the specified parameters.

You have overriden "setItemStackToSlot" to always call the super class's method with the MAINHAND slot and your BARBARIAN_SWORD as the itemstack. Now that's bad because your entity now will always call that method with your specified parameters. That's perhaps something you don't care about. You just want it to work, and the bloody thing doesn't work.


The reason why It doesn't work, is because you are never calling the "setItemStackToSlot" method anywhere. How do you expect it to do anything if it is never being called. The perfect place to call this method would be at the "onInitialSpawn" method, which currently does absolutely nothing in your class. That method is called when your entity is initially spawned on the world, as the name of the method suggests. However you just return the super class's implementation of that method and do nothing else. Which actually means you are doing nothing, because your super class's "onInitialSpawn" method would have been called anyway even if you didn't override it.

Before you return the super class's implementation of "onInitialSpawn", you call the "setItemStackToSlot" with the parameters that you want (Mainhand slot and a new itemstack instance of barbarian sword). So now your class has its own implementation of "onInitialSpawn" and overriding the method makes sense.

Yeah i do get it now and i really should of learned basic java before coding my mob which ill do and ill come back to this once i learn some more about basic java.

Posted (edited)

Also i fixed the problem, It was nothing to do with setItemStackToSlot it was because i needed to add in renderbarbarian 

{
    this.addLayer(new LayerBipedArmor(this));
     this.addLayer(new LayerHeldItem(this));
    }

 

so turns out it wasn't anything to do with itemstack just like when i made the most and said if there's any render method but yeah, thanks for the help anyways.

Also your ModelClass for your mob needs to extend ModelBiped if you want it to work!.

Edited by J0WAY
  • Like 1

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.