iAmRinzler Posted January 13, 2017 Posted January 13, 2017 Hello! How do I get the value of the property? I have been experimenting with blockstates recently but I can't seem to pass the appropriate argument to the .getValue(IProperty<T> property) function. if (args.length == 1 && args[0].equals("blockstate")) { World world = sender.getEntityWorld(); cDroid.setPos2(cDroid.getBlockPosUnderMouse()); sender.addChatMessage(new TextComponentString("Setting Block: " + cDroid.getPos2() + "\n")); System.out.println(world.getBlockState(cDroid.getPos2())); System.out.println(world.getBlockState(cDroid.getPos2()).getMaterial() + " THE MATERIAL"); System.out.println(world.getBlockState(cDroid.getPos2()).getProperties() + " THE PROPERTIES"); System.out.println(world.getBlockState(cDroid.getPos2()).getPropertyNames() + " THE PROPERTY NAMES."); System.out.println(world.getBlockState(cDroid.getPos2()).getBlock() + " THE BLOCK."); } This is a bit that I have written to dive into what I can do with blockstates. All the above calls provide the expected output. My issue is with getting individual values of the properties so i can run comparisons against similar blocks. I can't seem to pass the IProperty<T> property argument to the .getValue function properly. 1) I have a Wool block that has the property color=lime. 2) How do I pull the value 'lime' out of the property? The forge (https://mcforge.readthedocs.io/en/latest/blockstates/states/)documentation about blockstates tells me that I should pass .getValue(<PROPERTY>) to get the values of the properties. This clearly doesn't work and the compiler complains anyway I try and pass this argument. I have tried every way I can think of to pass the EnumDyeColor property to this function: .getValue(<EnumDyeColor>) //doesn't work .getValue(EnumDyeColor.LIME) //doesn't work .getValue(IProperty<EnumDyeColor> EnumDyeColor.LIME) //doesn't work For the sake of redundancy I won't post all my various attempts but none of them provide a property value (I have also tried passing PropertyEnum, the class used for the wool block colors as returned by blockstate.getProperties()). Sorry if I am missing something simple here... The only thing I'm trying to do right now is (in the case of wool blocks): If property color = X //do stuff If property color = Y //do different stuff Quote
iAmRinzler Posted January 13, 2017 Author Posted January 13, 2017 I understand the bits of code that aren't valid java. I only posted them to illustrate that I have been attempting everything and Java is a fairly new language for me. I also understand that the forge documentation is pseudocode, that doesn't mean it is clear or 'good' pseudocode. This is where IProperty<?> comes in. Each Block has a set of zero or more of these objects, that describe, unsurprisingly, properties that the block have. Examples of this include color (IProperty<EnumDyeColor>), facing (IProperty<EnumFacing>), integer and boolean values, etc. Each property can have a value of the type parametrized by IProperty. For example, for the respective example properties, we can have values EnumDyeColor.WHITE, EnumFacing.EAST, 1, or false. From the Forge documentation. This confused me. If I can't use IProperty<EnumDyeColor> then how do I get the appropriate IProperty instance I want the value of? Thanks. Quote
iAmRinzler Posted January 13, 2017 Author Posted January 13, 2017 IProperty<EnumDyeColor> is a type, it's not an instance. A simple example: String is a type, "hello" is an instance of that type. In the same way IProperty<EnumDyeColor> is the type of dye-color properties. The color property for blocks using BlockColored (like wool, etc.) is stored in a static field in BlockColored , you should be able to find it easily. Usually you will find the properties for a block as static fields in it's implementation class or one of it's parent classes. Thanks for clearing that up. I'll look into the instance. I only thought the function needed the property type, not the specific property instance. 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.