Jump to content

Recommended Posts

Posted

Alright so, I have decided to use Gson to add a float value (weight) to every item in the game. Now I was thinking, would it be possible to fill the json with the information by running through the block/item registry, and gathering the unlocalized name of said block or item, along with checking if it implements my IWeightedItem interface. If it does, get the weight value from that and add it to the json; if not, return 0.0F. I feel this would make it easy to gather blocks and items from any mod loaded, and add them to the json. Plus, any mod implementing my interface on their item from my api, would have they values already set. Is this possible? Is there a better way?

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

Use

GameData.getBlockRegistry

and

GameData.getItemRegistry

to get the block and item registries. Use

FMLControlledNamespacedRegistry#typeSafeIterable

to get an

Iterable

that can be used in a for-each loop (a.k.a enhanced for loop).

 

Use

RegistryNamespaced#getNameForObject

(inherited by

FMLControlledNamespacedRegistry

) to get the registry name of an object. This may be a

ResourceLocation

or a

String

.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

Considering I've never worked with this, could I get a slight example of how to utilize the information you gave me?

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted
FMLControlledNamespacedRegistry<Block> blockRegistry = GameData.getBlockRegistry();
for (Block block : blockRegistry.typeSafeIterable()){
String name = blockRegistry.getNameForObject(block).toString();
}

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

My only worry is writing this to the file. If I am writing Items and Blocks at the same time, won't they conflict?

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

Yes, a

Block

and its

ItemBlock

have the same registry name. Since you're only dealing with items in inventories, you can just ignore the block registry completely and only deal with the item registry.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

In fact, the item registry will be better for two reasons:

 

Some blocks don't have item forms and can never be in the inventory (except via cheats) such as water and lava.  Some items correspond to more than one block, such as the sign (which in addition to not having an item block form of either Block 63 or Block 68, the item can place down either, depending on context).

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

Perfect, thank you guy's so much! Also Dracos - I don't seem to understand why people think you're a jerk? You've been nothing but helpful, and not even blunt about it. So thank you for your time, and thank you Choonster for yours!

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted
I don't seem to understand why people think you're a jerk? You've been nothing but helpful, and not even blunt about it. So thank you for your time, and thank you Choonster for yours!

 

The people who say that are people who are trying to learn Java by modding.  Or more accurately, learning how to program by modding.  There's a few other instances too, where I'll be more blunt or abrasive than I need to be and people take it as a personal insult.

 

As an extreme example, I was once in an argument with a global moderator of a forum where he intentionally misquoted what I was saying in order to make his position stronger (something to the effect of taking my post about "I've never heard about [events] until after they happen" and some other bit and recombining them to say, "WHAT? You've never heard of the Steam Workshop!?").  According to the forum TOS, intentional mis-quoting was an instant ban offense.  I screen-shoted it and went "WTF, dude."  My post got deleted and I got a warning due to language (I had "WTF" as letters, not words, in the image), he got off scott free.

 

Well, not exactly scott free, but he retained his position as global moderator.  I contacted the community manager (not exactly a mod or admin, but someone who had the authority to slap mods upside the head for being idiots) and explained what happened.  The warning was removed from my account and the mod team got a stern talking to.

 

That forum was pretty damn toxic at the time though.  Everyone would find any excuse possible to call in the mods in order to win an argument.  I once got an unofficial warning (moderator posting in the thread "no personal attacks please") for saying, "That's a straw man argument, please try again."

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

Now see, I actually got into programming by modding; but I learned to research basic java before hand. :P Honestly though, I don't like people that think they are being insulted when someone tells them "You forgot to make it public, please learn Java". There is something right under this forum saying "Help with modding goes in here, however, please keep in mind that this is not a Java school. You are expected to have basic knowledge of Java before posting here." I'd say 80% to 90% of my smites came from people that I asked to learn Java. Anyway, I just want to thank you for your help with my issues time and time again, even if they seem a bit idiotic. Without you, and some others on this forum, I would be more frustrated then I should be. xD

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

No worries, there is no such thing as a stupid question.  There's only questions that clearly indicate that the user isn't trying to learn.

(I've muted a couple of these folks after a thread basically goes "I have a problem," "ok, do X," "it didn't work," "show your new code," "ok, here it is," "you didn't do X like I told you to." Back and forth six times).

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.

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.