Jump to content

Recommended Posts

Posted

slot.putStack(new ItemStack(???);

 

I'm trying to create an ItemStack using itemRegistryNames. I want to use a list of itemRegistryNames to fill 12 inventory slots. I know how to set a slot to empty "slot.putStack(ItemStack.EMPTY);", but not how to actually create an itemStack to put in the slots. Please help.

Posted

Get the Item from the Registry by name.

Make a new stack from the Item.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
  On 11/6/2019 at 11:29 PM, Draco18s said:

Get the Item from the Registry by name.

Expand  

how? I tried "ForgeRegistries.ITEMS", but I can't find a way to get an item by it's registry name. It's possible to get an item by it's resource location, but I would much rather get it by registry name as I have a lot of code already written using the registry names.

Posted

ForgeRegistries.ITEMS.getValue(key)

 

I'm not sure how you couldn't find that.

 

You can construct a resource location from a string. String -> RL -> Item -> Stack

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
  On 11/7/2019 at 9:36 PM, andGarrett said:

but I can't find a way to get an item by it's registry name. It's possible to get an item by it's resource location

Expand  

The registry name is a resource location. You probably have it in String form in which case just pass it into the ResourceLocation constructor.

  • Thanks 1

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
  On 11/7/2019 at 10:23 PM, Draco18s said:

ForgeRegistries.ITEMS.getValue(key)

 

I'm not sure how you couldn't find that.

Expand  

 

lol, the "key" in "ForgeRegistries.ITEMS.getValue(key)" is the ResourceLocation I mentioned here:

 

  On 11/7/2019 at 9:36 PM, andGarrett said:

It's possible to get an item by it's resource location

Expand  

 

unfortunately for me, I didn't write my code in such a way as to work well with converting the registry names into resource locations. I would have to create new ResourceLocations too often to be considered efficient. I may need to rethink some of my code.

Posted

ResourceLocation is literally just two strings with utility methods attached, I don't think there's much performance hit creating new ones

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.

  Reveal hidden contents

 

Posted

By "A LOT" you don't mean every tick, do you?

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.

  Reveal hidden contents

 

Posted (edited)
  On 11/8/2019 at 8:04 AM, diesieben07 said:

Short-lived objects (aka "create resource location, look up in map, drop resource location") are heaven for modern Java GCs. Don't worry about it.

Expand  

so, hypothetically, something like ForgeRegistries.ITEMS.getValue(new ResourceLocation("minecraft:polished_diorite")); done a hundred times isn't a problem?

 

  On 11/8/2019 at 5:05 AM, DaemonUmbra said:

By "A LOT" you don't mean every tick, do you?

Expand  

actually, now that I've gone through the code again, it isn't all that much.

Edited by andGarrett
Posted
  On 11/8/2019 at 5:49 PM, andGarrett said:

done a hundred times isn't a problem?

Expand  

It takes 100,000 to even calculate preformance.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • 4 years later...

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.