Jump to content

Recommended Posts

Posted

What do you mean? It’s certainly easier & allows vanilla to better handle your item, and allows you to override vanilla’s items but no it’s not exactly necessary - you are able to replicate the vanilla behaviour without replicating it, but for example the tooltips that vanilla puts on swords won’t appear and you’ll have to implement them yourself. For code maintainability you should probably extend vanilla because

a) if vanilla changes something you will know about and can change it

b) knowing something _is_ (extends) something else is better than knowing something _should be_ (replicates the functionality of) something else 

About Me

  Reveal hidden contents

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)

Posted
  On 9/27/2018 at 6:18 AM, Niinnnnnn said:

This was made for ease, right? it is not mandatory to use

Expand  

It was made for compatibility, if mod one wants all swords to be used in there machine, then it will check if an Item is an instance of ItemSword.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

Minecraft code is pretty inconsistent, and sometimes uses direct instance checking and sometimes uses instanceof. However it DOES use instanceof sometimes and you'll probably want to take advantage of it. For example, the getAttackDamage() method only gets called from EntityLiving if the item is an instanceof ItemSword.

 

As an example of inconsistency (or not the best programming practice). the Item#isShield() method is implemented as:

    public boolean isShield(ItemStack stack, @Nullable EntityLivingBase entity)
    {
        return stack.getItem() == Items.SHIELD;
    }

That is frankly a "dumb" way to do it. Better programming (from type hierarchy point of view) would be simply return false and let ItemShield return true. Alternatively, it should check for instanceof ItemShield. However, this implementation means that for your custom shield you need to override this method directly. It would be better programming practice to be able to extend ItemShield and automatically it would know that isShield() is true...

 

So you'll need to do a mix of extending the class, overriding things that shouldn't be necessary, and working around places where the instance is hard-coded in vanilla.

 

There are times when you don't want to extend though -- if you don't want your item to be always treated as a sword. I have a tutorial about deciding whether to extend or copy a vanilla class: https://jabelarminecraft.blogspot.com/p/minecraft-forge-172-know-when-to-copy.html?showComment=1538061795434

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted
  On 9/27/2018 at 3:25 PM, jabelar said:

As an example of inconsistency (or not the best programming practice). the Item#isShield() method is implemented as:

Expand  

The reason it's implemented like is is because it's a forge patch. Vanilla simply did item == Items.SHIELD when checking for a shield in various places. Forge removed those direct checks and instead did this patch to the item class. It's functionally the same, preserves vanilla's functionality and allows anyone to override this when they want to make a custom shield themselves.

Or at least I assume it's a forge patch because it's together with the rest of them and has a javadoc.

Posted
  On 9/27/2018 at 3:45 PM, V0idWa1k3r said:

The reason it's implemented like is is because it's a forge patch. Vanilla simply did item == Items.SHIELD when checking for a shield in various places. Forge removed those direct checks and instead did this patch to the item class. It's functionally the same, preserves vanilla's functionality and allows anyone to override this when they want to make a custom shield themselves.

Or at least I assume it's a forge patch because it's together with the rest of them and has a javadoc.

Expand  

 

Good point -- so it is bad Forge practice! Still doesn't change the criticism. They should have done like they did and replace all the checks with the isShield() call but the default implementation of isShield() in the Item class should have just returned false and should have been overridden to return true in ItemShield.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted
  On 9/27/2018 at 3:49 PM, jabelar said:

Good point -- so it is bad Forge practice! 

Expand  

I think it is done this way to make as little patches as possible and have the patches be as small as possible. 1 patch to the Item class < 1 patch to the Item class and 1 patch to the ItemShield class.

Posted
  On 9/27/2018 at 3:52 PM, V0idWa1k3r said:

I think it is done this way to make as little patches as possible and have the patches be as small as possible. 1 patch to the Item class < 1 patch to the Item class and 1 patch to the ItemShield class.

Expand  

Yes, I understand that goal but the point of Forge intervening is to make it amenable to modders.  And in any case I offered a way to do it without patch to ItemShield -- they could test instanceof ItemShield instead of = Items.SHIELD. 

 

The way it is currently, a person might extend ItemShield and then wonder why it isn't working. The onus is on the modder to understand there is a hard-coded method in the parent class that needs to be overwritten. It would be nice to simply extend ItemShield and have it immediately work as a shield.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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

    • Ignore shrimple, it doesn't work with Oculus. Also, enableShaders was alr true when it said that towards the end of the log. If you could also figure out why my tags are messed up that'd be cool too, but that's a later issue. https://drive.google.com/drive/folders/1ovEKDZECUCl7zZxGfpyQcS4s5PZPQyfa?usp=drive_link
    • accidental duplicate mesage cuz lag
    • https://gnomebot.dev/paste/231527759279685634/1372324909073563730/1372324908629102716 https://gnomebot.dev/paste/231527759279685634/1372320454861262908/1372320454299090996 seems like theres a registry sync error, not sure what that means though, however in an old pack i played on, i actually had a registry sync error happen whenever the world tried too save and it would suddenly stop loading chunks, is there a mod fix for this or some way too bypass registry syncing? is this a server problem? i have no issues with the pack on pc, only on my server.
    • i think the problem is the player animator library but i need it for one of my main mods is there any way i can fix this? The game crashed: rendering overlay Error: java.lang.IllegalArgumentException: Failed to create player model for default heres the crash report: https://pastebin.com/U5Wp8ysb
    • I have been an enthusiastic investor in crypt0currencies for several years, and my digital assets have been integral to my financial strategy. A few months ago, I encountered a distressing predicament when I lost access to my primary cryptocurrency walleet after clicking on an airdrop link that inadvertently connected to my walleet. The dread of potentially losing all my hard-earned funds was overwhelming, leaving me uncertain about where to seek assistance. In my pursuit of solutions, I stumbled upon ChainDigger Retrievers. From our initial consultation to the triumphant recovery of my assets, the team exhibited exceptional expertise. They provided comprehensive explanations of the recovery process, ensuring I was informed at every stage and offering reassurance during this tumultuous time. Their approach was not only meticulous but also compassionate, which significantly alleviated my anxiety. ChainDigger Retrievers unwavering commitment to resolving my issue was evident throughout the process. Leveraging their profound understanding of crypt0currency technology and digital forensics, they initiated an exhaustive investigation to trace the transactions linked to my compromised wallet. Their meticulous analysis and relentless determination were apparent as they left no stone unturned in their quest to recover my funds. After several days of diligent investigation, the team successfully recovered everything I had lost. They uncovered that the link I had clicked contained malware, which scammeers had used to infiltrate my walleet. This revelation was both alarming and enlightening, underscoring the inherent risks associated with crypt0currency transactions when proper precautions are not taken.Thanks to ChainDigger Retrievers, I not only regained everything but also acquired invaluable knowledge about safeguarding my investments. Their expertise and steadfast support transformed a daunting situation into a manageable one, and I am profoundly grateful for their assistance. I can now continue my investment journey with renewed confidence, knowing that I have a trustworthy ally in ChainDigger Retrievers. Their client satisfaction is truly commendable, and I wholeheartedly recommend their services to anyone facing similar challenges in the crypt0currency realm. With their help, I was able to turn a distressing time into a positive outcome, and I will forever be grateful for their support.  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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