I'm trying to set my custom leaves of a certain type to have DECAYABLE set to 'false'.
I'm very new to modding, so I'm not sure the proper format to do this. Ideally I would like to extend the range at which my leaves will be sustained by a log with.canSustainLeaves
For now though, I will gladly settle for turning the decay off entirely so that I can work on the overall design of my tree. This is what I have so far, don't worry, I already know it's not right.
When instantiating WorldGenWillowTree, create the IBlockState you want your Leaves to have (e.g. leaves.getDefaultState().withProperty(VARIANT, CustomPlanks.EnumType.WILLOW).withProperty(DECAYABLE, false)) and then use Block#getMetaFromState to get the metadata of this. Pass this to the WorldGenWillowTree constructor as the metaLeaves argument.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
byte b0 = 0;
int i = b0 | ((CustomPlanks.EnumType)state.getValue(CustomLeaves.VARIANT)).getMetadata();
if (!((Boolean)state.getValue(BlockLeaves.DECAYABLE)).booleanValue()) {
i |= 4;
}
if (((Boolean)state.getValue(BlockLeaves.CHECK_DECAY)).booleanValue()) {
i |= 8;
}
return i;
}
Though, I'm not quite sure how to properly pass the metadata to the WorldGenWillowTree constructor as the metaLeaves argument.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
When instantiating your worldgen class, use the following code:
IBlockState leavesState = MythAdventure.Myth_Leaves.getDefaultState().withProperty(CustomLeaves.VARIANT, CustomPlanks.EnumType.WILLOW).withProperty(BlockLeaves.DECAYABLE, false);
int leavesMeta = MythAdventure.Myth_Leaves.getMetaFromState(leavesState);
WorldGenWillowTree treeGen = new WorldGenWillowTree(MythAdventure.Myth_Log, MythAdventure.MythLeaves, CustomPlanks.EnumType.WILLOW.getMetadata(), leavesMeta);
This is suitable for initial world gen, but for your sapling you'll want to use the other WorldGenWillowTree constructor to set doBlockNotify to true.
I hate to be a pest, but I've tried inserting that code you so kindly provided in areas of the CommonProxy, Main (MythAdventure.class) and even WorldGenWillowTree.class. I had no problem setting doBlockNotify to true in my CustomSapling class, and I get trees to generate just fine. The problem is that I really don't understand where to put that bit of code. I'm not sure if you mean for me to use it after I create a class that I don't have yet dealing with world gen, or if I'm stupidly overlooking how to use it in the classes I already have.
I had planned to get around to getting the trees to generate in the world eventually. I had just thought I could get them to generate looking the exact way I wanted to before that step.
This code should go wherever you need to grow a willow tree, e.g. where you register your willow trees to generate in the world or in your sapling class where you grow your willow tree.
All its doing is instantiating your WorldGenWillowTree class with a leaves metadata value that translates to having the DECAYABLE property set to false.
You could even provide another constructor in WorldGenWillowTrees that takes an IBlockState each for the log and leaves blocks, sets the DECAYABLE property on the leaves state and then gets the Block and metadata from each state using Block#getMetaFromState or change your class to use IBlockState directly instead of the Block and metadata.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
This code should go wherever you need to grow a willow tree, e.g. where you register your willow trees to generate in the world or in your sapling class where you grow your willow tree.
I've placed it in the CustomSapling class, where I grow my willow tree.
the problem I have is that wherever I've tried to place the code it does one of two things. It either prevents my sapling from growing into a tree at all, or it doesn't change the decaying of the leaves. When placed here where I have it in the screenshot, it stops the sapling from becoming a tree. But that is the exact place in my sapling class where I grow the tree. Gist
You're never using the treeGen variable, so leaves still decay. In this case, assign the new WorldGenWillowTrees instance (the one that uses the leavesMeta variable) to the object variable instead of creating a new variable for it and get rid of the first WorldGenWillowTrees instantiation (the one that uses the Willow metadata for the leaves directly).
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Wow, it seems so obvious now. I can only imagine how much easier this kind of thing will be after I've learned Java better. Thanks for walking me through this, Choonster.
I'm trying to set my custom leaves of a certain type to have DECAYABLE set to 'false'.
I'm very new to modding, so I'm not sure the proper format to do this. Ideally I would like to extend the range at which my leaves will be sustained by a log with.canSustainLeaves
For now though, I will gladly settle for turning the decay off entirely so that I can work on the overall design of my tree. This is what I have so far, don't worry, I already know it's not right.
public boolean willowDecay(IBlockAccess worldIn, BlockPos pos, IBlockState stateIn) {
IBlockState iblockstate = worldIn.getBlockState(pos);
if (iblockstate.getBlock() == this) {
CustomPlanks.EnumType enumtype = (CustomPlanks.EnumType)iblockstate.getValue(VARIANT);
if (enumtype == CustomPlanks.EnumType.WILLOW) {
return ((World) worldIn).setBlockState(pos, stateIn.withProperty(DECAYABLE, enumtype));
}
}
return false;
}
Any help is appreciated.
When instantiating WorldGenWillowTree, create the IBlockState you want your Leaves to have (e.g. leaves.getDefaultState().withProperty(VARIANT, CustomPlanks.EnumType.WILLOW).withProperty(DECAYABLE, false)) and then use Block#getMetaFromState to get the metadata of this. Pass this to the WorldGenWillowTree constructor as the metaLeaves argument.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
I think I've got the first two elements of that post done correctly.
protected void createBlockState() {
((Block) MythAdventure.Myth_Leaves).getDefaultState().withProperty(CustomLeaves.VARIANT, CustomPlanks.EnumType.WILLOW).withProperty(BlockLeaves.DECAYABLE, false);
}
public int getMetaFromState(IBlockState state){
byte b0 = 0;
int i = b0 | ((CustomPlanks.EnumType)state.getValue(CustomLeaves.VARIANT)).getMetadata();
if (!((Boolean)state.getValue(BlockLeaves.DECAYABLE)).booleanValue()) {
i |= 4;
}
if (((Boolean)state.getValue(BlockLeaves.CHECK_DECAY)).booleanValue()) {
i |= 8;
}
return i;
}
Though, I'm not quite sure how to properly pass the metadata to the WorldGenWillowTree constructor as the metaLeaves argument.
My Gist
Don't put those methods in your worldgen class.
When instantiating your worldgen class, use the following code:
This is suitable for initial world gen, but for your sapling you'll want to use the other WorldGenWillowTree constructor to set doBlockNotify to true.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
I hate to be a pest, but I've tried inserting that code you so kindly provided in areas of the CommonProxy, Main (MythAdventure.class) and even WorldGenWillowTree.class. I had no problem setting doBlockNotify to true in my CustomSapling class, and I get trees to generate just fine. The problem is that I really don't understand where to put that bit of code. I'm not sure if you mean for me to use it after I create a class that I don't have yet dealing with world gen, or if I'm stupidly overlooking how to use it in the classes I already have.
I had planned to get around to getting the trees to generate in the world eventually. I had just thought I could get them to generate looking the exact way I wanted to before that step.
This code should go wherever you need to grow a willow tree, e.g. where you register your willow trees to generate in the world or in your sapling class where you grow your willow tree.
All its doing is instantiating your WorldGenWillowTree class with a leaves metadata value that translates to having the DECAYABLE property set to false.
You could even provide another constructor in WorldGenWillowTrees that takes an IBlockState each for the log and leaves blocks, sets the DECAYABLE property on the leaves state and then gets the Block and metadata from each state using Block#getMetaFromState or change your class to use IBlockState directly instead of the Block and metadata.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
I've placed it in the CustomSapling class, where I grow my willow tree.
the problem I have is that wherever I've tried to place the code it does one of two things. It either prevents my sapling from growing into a tree at all, or it doesn't change the decaying of the leaves. When placed here where I have it in the screenshot, it stops the sapling from becoming a tree. But that is the exact place in my sapling class where I grow the tree. Gist
You're never using the treeGen variable, so leaves still decay. In this case, assign the new WorldGenWillowTrees instance (the one that uses the leavesMeta variable) to the object variable instead of creating a new variable for it and get rid of the first WorldGenWillowTrees instantiation (the one that uses the Willow metadata for the leaves directly).
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Wow, it seems so obvious now. I can only imagine how much easier this kind of thing will be after I've learned Java better. Thanks for walking me through this, Choonster.