Zeurkous Posted June 30, 2016 Posted June 30, 2016 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)? Quote
Abastro Posted June 30, 2016 Posted June 30, 2016 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. Quote I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.
Zeurkous Posted June 30, 2016 Author Posted June 30, 2016 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? Quote
Zeurkous Posted June 30, 2016 Author Posted June 30, 2016 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 Quote
Zeurkous Posted June 30, 2016 Author Posted June 30, 2016 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) Quote
Zeurkous Posted June 30, 2016 Author Posted June 30, 2016 Yes, but this gives me an error for(IProperty value : prop.getAllowedValues()){} Am I missing something? I feel like I'm doing something very wrong here. Quote
Zeurkous Posted June 30, 2016 Author Posted June 30, 2016 But that gives me thing like 'variant' , 'color', etc.. That part is done. for(IProperty<?> prop : block.getDefaultState().getPropertyNames()){ String propname = prop.getName(); if(propname.equals("variant")){ No? Quote
Zeurkous Posted June 30, 2016 Author Posted June 30, 2016 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 ?>)" Quote
Zeurkous Posted June 30, 2016 Author Posted June 30, 2016 This is where my Java knowledge lets me down. I'll try to find a solution to that. In the mean time, I thank you for the help so far. Quote
Zeurkous Posted June 30, 2016 Author Posted June 30, 2016 I'm sorry man, I'm lost over here. Care to help me out? Quote
Zeurkous Posted June 30, 2016 Author Posted June 30, 2016 This totally works, thanks alot. You're a lifesaver. Generics is something I've been struggling with. Thanks again Quote
Recommended Posts
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.