Jump to content

[1.11] is it possible to crate an item array?


Frost2779

Recommended Posts

So far i have been declaring my items like so

 

public static Item reinforcedStick;
public static Item reinforcedLeatherSquare;
public static Item reinforcedLeatherWing;
public static Item leatherHarness;
public static Item woodenElytra;

 

And i was wondering if it was possible to compress all of that down into an array like this or something similar.

 

item[] itemArray = {reinforcedStick, reinforcedLeatherSquare, ect.};

 

I messed around with it to try and get it to work but was unsuccessful.

Link to comment
Share on other sites

So far i have been declaring my items like so

 

public static Item reinforcedStick;
public static Item reinforcedLeatherSquare;
public static Item reinforcedLeatherWing;
public static Item leatherHarness;
public static Item woodenElytra;

 

And i was wondering if it was possible to compress all of that down into an array like this or something similar.

 

item[] itemArray = {reinforcedStick, reinforcedLeatherSquare, ect.};

 

I messed around with it to try and get it to work but was unsuccessful.

What I like to do is add them to a List in a base classes constructor. Then loop through it for registry and model binding. Check out episode 1 or 2 of my tutorials for an example.

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.

Link to comment
Share on other sites

And i was wondering if it was possible to compress all of that down into an array like this or something similar.

 

For being able to reference your stuff later, using an array isn't a good idea.  The only time you'd want it is if you were doing something with the whole collection.  Which a number of folks have done for their item registration, but you'd still have the public static properties.

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.

Link to comment
Share on other sites

And i was wondering if it was possible to compress all of that down into an array like this or something similar.

 

For being able to reference your stuff later, using an array isn't a good idea.  The only time you'd want it is if you were doing something with the whole collection.  Which a number of folks have done for their item registration, but you'd still have the public static properties.

Yes, agreed you could also use a Reflection way to register IE loop through all of your fields and all instances of Block you register as a Block and all instances of Item you register as an Item.

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.

Link to comment
Share on other sites

Which I don't like (or the array for that matter) because it assumes that all of my blocks and all of my items are going to be registered in the same way.  Which they aren't.

 

Which is why I have a whole slew of helper methods for registration (six main methods: Block, Block + ItemBlock, Block + Custom ItemBlock, Block + Custom ItemBlock + Custom StateMapper, Item, Item w/ Variants).

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.

Link to comment
Share on other sites

Which I don't like (or the array for that matter) because it assumes that all of my blocks and all of my items are going to be registered in the same way.  Which they aren't.

 

Which is why I have a whole slew of helper methods for registration (six main methods: Block, Block + ItemBlock, Block + Custom ItemBlock, Block + Custom ItemBlock + Custom StateMapper, Item, Item w/ Variants).

I can definately agree with what you are saying, but having an Interface such as I"Modid"Block that has custom methods such as createCustomStateMapper.

 

Or even just include them in the base block class.

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.

Link to comment
Share on other sites

Yes, I had to use an interface for the statemapper business. Couldn't find another clean way of handling it.

But no, still no loops other than looping over valid blockstates for registering item renderers.

 

		millstone = new BlockMillstone(); //create
	EasyRegistry.registerBlockWithItem(millstone, "millstone"); //register
	axel = new BlockAxel(); //create
	EasyRegistry.registerBlockWithItem(axel, "axel"); //register
//etc

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.

Link to comment
Share on other sites

Yes, I had to use an interface for the statemapper business. Couldn't find another clean way of handling it.

But no, still no loops other than looping over valid blockstates for registering item renderers.

 

		millstone = new BlockMillstone(); //create
	EasyRegistry.registerBlockWithItem(millstone, "millstone"); //register
	axel = new BlockAxel(); //create
	EasyRegistry.registerBlockWithItem(axel, "axel"); //register
//etc

Yes, but that gets quite long and gets harder to find certain blocks. And then you have to specifically register them one by one instead of in mass, by I digress. We are "arguing" opinions not much of a reason to do that.

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.

Link to comment
Share on other sites

I'm not sure a giant collection of "instanceof X? do Y" code blocks is going to be any less chaotic.  If anything it splits one logical operation ("Create this block and register it") out across several methods ("create this block" "register it with the game" "register an item block for it too" "register the block's renderer" "register the ItemBlock's renderer").

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.

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.



×
×
  • Create New...

Important Information

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