Jump to content

Item variant without knowing the ID


Zeurkous

Recommended Posts

Hey guys,

 

Is there a simple way to give a player an item variant (sort of wood, color of wool, etc...) without the player knowing it's specific ID.

In other words:

Is there like a method that would accept the standard name (for example Birch Wood Plank) and output that item (or it's ID so I can work with that)?

Link to comment
Share on other sites

No. Because

1. They are just english names, think about consistency with other languages.

2. Reverse-translation using Locale is also impossible because they could be parametrized.

 

So.. it's even impossible to retrieve unlocalized name from localized name.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

Following what diesieben07 told me I came to this

 

 

	@SubscribeEvent
public void onRightClickBlock(RightClickBlock e) {
	World world = e.getWorld();
	if (!world.isRemote) {
		String name = world.getBlockState(e.getPos()).getBlock().getLocalizedName();
		if (name.equals("Sign")) {
			TileEntitySign sign = (TileEntitySign) world.getTileEntity(e.getPos());
			String itemString = sign.signText[0].getUnformattedComponentText().toLowerCase();
			String variant = sign.signText[1].getUnformattedComponentText().toLowerCase();

//Important stuff
			Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation("minecraft:" + itemString));
			for(IProperty<?> prop : block.getDefaultState().getPropertyNames()){
				String propname = prop.getName();
				if(propname.equals("variant")){
					for(Comparable<?> values : prop.getAllowedValues()){
						if(values.equals(variant)){
// So what now
							ItemStack stack = new ItemStack();
						}

					}
				}


			}
		}
	}

}

 

Basicly what I do here is right click a sign wich says "planks" on the first row and "acacia" on the second. This totally works (thanks for that) but how do I get an item out of this now?

Link to comment
Share on other sites

1. Cause the sign is not in my hand, It's a sign that is placed somewhere that the player then can rightclick. So is there a better way?

 

2. Alright thanks i'll remove that.

 

3. Well purely for testing I hardcoded variant. I'm aware that other blocks have other property's (atleast I just found out) :)

 

4.

if(values instanceof BlockPlanks.EnumType){
						}

So then how would I compare this to the variant input?

Okay so I guess that i'll need a switch to makes sure that the EnumType matches the item?

 

5. Well but how do I set the block to be the block of that variant (in this case)

 

I'm sorry if I'm being a noob here :) Don't have alot modding experience

Link to comment
Share on other sites

Okay you said "at hand", I read "in hand". My bad. Fixed that.

 

On the other 2 problems however you lost me sorry.

I'm iterating over the possible values

for(Comparable<?> value : prop.getAllowedValues()){}

but then value doesn't have a #getName

 

And if I try

for(IProperty value : prop.getAllowedValues()){}

It tells me to change the type of value to Comparable<T> (Eclipse does that)

 

 

Link to comment
Share on other sites

Right.

I'm getting really confused when I'm working with DataTypes I don't understand.

So

for(Comparable<?> value : prop.getAllowedValues()){
prop.getName(value);
}

gives me this error on #getName(value): "The method getName(capture#3-of ?) in the type IProperty<capture#3-of ?> is not applicable for the arguments (Comparable<capture#4-of ?>)"

 

 

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.

Announcements



×
×
  • Create New...

Important Information

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