"Leaf" Decay for Custom Blocks

Upvotes: 7
Issue description

As the title suggests, adding an option for decay in blocks.

Basically trying to emulate what vanilla leaves do when a player cuts down a tree; many MCreator modders I've seen have been looking for a way to do this, to avoid floating trees. I feel this could be implemented in the block creation element editor with a check box and (if checked) setting which block acts as the "wood" for the given "leaf". I hope that makes sense.

Also I'm not sure if I'm blind but if adding above isn't possible then perhaps adding a a component that checks in a radius around a block is? That component by itself would make emulating leaf decay a possibility with MCreator, as one could just make it so a block checks a given radius around it for another block, and then staying spawned in or decaying from there. The [get block] component kind of does this, but only checks at the given xyz location rather than over an area to what I've experienced using it ^^;

Attachment Size
LeafDecayProcedure1.16 KB 1.16 KB
Check for block in 6x6x6 box1.03 KB 1.03 KB
Check for Block -- fixed without entity requirement1.08 KB 1.08 KB

Issue comments

"For checking blocks in "area", you can use do n times block and nest three of them to check in x, y and z axis"

What's this?

  1. Create 3 local variables: offx, offy and offz, set them to -3
  2. Use repeat n times, say 6 times procedure block (check in range +/- 3 blocks square)
  3. Using math blocks, increase offx here by 1
  4. Place another one in it
  5. Using math blocks, increase offy here by 1
  6. And another one inside previous one
  7. Using math blocks, increase offz here by 1
  8. Check for the block at x + offx, y + offy and z + offz

Soo... something like this maybe? Tried following your steps as best as I could Klemen, albeit I'm still a lil confused hehe ^^; I'm pretty new to the whole procedure thing I've only made simple ones that can spawn saplings and stuff when blocks are broken, and followed the video guides for anything more complicated, so I really don't know if this is correct.

hhhhhh

Edit --- Actually I will say that I did attempt to load up a client test environment and it failed compiling because of this procedure despite there not being any errors given, so I'm outta ideas for now. Any pointers would be appreciated <3 I plan on releasing the procedure as a importable template for others to use in the future as well so there can be no more floating trees!

 

and yea I know there's that one empty slot near the bottom I honestly didn't know what to put there, as I want it to do nothing if the given wood block is within the radius of the leaf ;;;;;;;; but no errors showed up so I assumed it was fine like that? I dunno q.q I'm really hopeless when it comes to coding won't lie-

 

 

How do you mean no errors given? So it works?

Regarding the procedure, you need to put the if block in the actual loop. Add another logic variable, say woodFound and set it to false by default. Then inside the most inner loop, use the if to check if the block is wood. If it is, set the woodFound to true.

Outside the loop, check if the woodFound is false, and if it is, remove the leaf block.

What this does, it iterates all the blocks in 6x6x6 area and if any of them is your custom block, it sets the woodFound to true. If this is not the case, the variable remains false and in this case the leaf is removed.

Not really the radius, but the size of the box it will check. It will check in a box of 6x6x6 size for a custom block and if it is not there, the leaf block is removed.

No errors given as when I was creating the procedure it never said anything was wrong/missing, yet when I attempted to load up the test client recompile failed due to it~

And thank you for the corrections, I will let you know if I need anymore help!!

 

Do you have all the variables you use on the list of local variables?

I do, the only variables I have are OffX, OffY, OffZ, and WoodFound. The offsets are number variables and WoodFound is a logic variable as you had suggested.

I went ahead and exported + attached both the procedure by itself, as well as my entire mod's workspace. I hope me exporting it with my mod's elements doesn't mess anything up when you import it into your MCreator workspace (Hence why I've also provided my entire workspace in case it does happen, the procedure you're looking for is the last thing in the workspace btw!)

I also found the problem, was an error on my part that I didn't happen to see! There was a x+1 component missing, so I went ahead and plugged it in and the variable error disappeared, but the problem still remains and the leaf block will not remain even when placed right up against the wood. I hope you work your magic and find the solution with no problems!

There were some logical/procedural errors (issues) with your procedure, I have attached a fixed procedure (leaf decay fixed 1), but I did not have the time to test it out yet, but it should work.

Please report back if it works and it if does I will consider adding this procedure to templates.

Ok i will try it out in a few minutes, If it work, Add it in Template Library, it would be useful

Wait, I check it now and you didn't attach it? I don't see LeafDecayFixed1

Executing gradle command: build
Build info: MCreator 1.8.3, 64-bit, 8061 MB, Windows 10 - cmd, JVM 1.8.0_202, JAVA_HOME: C:\Pylo\MCreator183\jdk
C:\Pylo\MCreator183\forge>gradlew -Dorg.gradle.java.home="C:/Pylo/MCreator183/jdk" -Dorg.gradle.parallel=false -Dorg.gradle.jvmargs="-Xms625m -Xmx2048m" build 
This mapping 'snapshot_20171003' was designed for MC 1.12! Use at your own peril.
:deobfCompileDummyTask
:deobfProvidedDummyTask
:sourceApiJava UP-TO-DATE
:compileApiJava NO-SOURCE
:processApiResources NO-SOURCE
:apiClasses UP-TO-DATE
:sourceMainJava
C:\Pylo\MCreator183\forge\build\sources\main\java\mod\mcreator\mcreator_furiumLeavesDecay.java:42: error: incompatible types: double cannot be converted to boolean
      OffX = (double) -3;
             ^
C:\Pylo\MCreator183\forge\build\sources\main\java\mod\mcreator\mcreator_furiumLeavesDecay.java:43: error: incompatible types: double cannot be converted to boolean
      OffY = (double) -3;
             ^
C:\Pylo\MCreator183\forge\build\sources\main\java\mod\mcreator\mcreator_furiumLeavesDecay.java:44: error: incompatible types: double cannot be converted to boolean
      OffZ = (double) -3;
             ^
C:\Pylo\MCreator183\forge\build\sources\main\java\mod\mcreator\mcreator_furiumLeavesDecay.java:49: error: bad operand types for binary operator '+'
               if (((world.getBlockState(new BlockPos((int) (x + (OffX)), (int) (y + (OffY)), (int) (z + (OffZ))))).getBlock() == mcreator_firiumStem.block
                                                               ^
  first type:  int
  second type: boolean
C:\Pylo\MCreator183\forge\build\sources\main\java\mod\mcreator\mcreator_furiumLeavesDecay.java:49: error: bad operand types for binary operator '+'
               if (((world.getBlockState(new BlockPos((int) (x + (OffX)), (int) (y + (OffY)), (int) (z + (OffZ))))).getBlock() == mcreator_firiumStem.block
                                                                                   ^
  first type:  int
  second type: boolean
C:\Pylo\MCreator183\forge\build\sources\main\java\mod\mcreator\mcreator_furiumLeavesDecay.java:49: error: bad operand types for binary operator '+'
               if (((world.getBlockState(new BlockPos((int) (x + (OffX)), (int) (y + (OffY)), (int) (z + (OffZ))))).getBlock() == mcreator_firiumStem.block
                                                                                                       ^
  first type:  int
  second type: boolean
C:\Pylo\MCreator183\forge\build\sources\main\java\mod\mcreator\mcreator_furiumLeavesDecay.java:53: error: bad operand types for binary operator '+'
               OffZ = (double) ((OffZ) + 1);
                                       ^
  first type:  boolean
  second type: int
C:\Pylo\MCreator183\forge\build\sources\main\java\mod\mcreator\mcreator_furiumLeavesDecay.java:53: error: incompatible types: double cannot be converted to boolean
               OffZ = (double) ((OffZ) + 1);
                      ^
C:\Pylo\MCreator183\forge\build\sources\main\java\mod\mcreator\mcreator_furiumLeavesDecay.java:55: error: bad operand types for binary operator '+'
            OffY = (double) ((OffY) + 1);
                                    ^
  first type:  boolean
  second type: int
C:\Pylo\MCreator183\forge\build\sources\main\java\mod\mcreator\mcreator_furiumLeavesDecay.java:55: error: incompatible types: double cannot be converted to boolean
            OffY = (double) ((OffY) + 1);
                   ^
C:\Pylo\MCreator183\forge\build\sources\main\java\mod\mcreator\mcreator_furiumLeavesDecay.java:57: error: bad operand types for binary operator '+'
         OffX = (double) ((OffX) + 1);
                                 ^
  first type:  boolean
  second type: int
C:\Pylo\MCreator183\forge\build\sources\main\java\mod\mcreator\mcreator_furiumLeavesDecay.java:57: error: incompatible types: double cannot be converted to boolean
         OffX = (double) ((OffX) + 1);
                ^
12 errors
:compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 52s
5 actionable tasks: 4 executed, 1 up-to-date
C:\Pylo\MCreator183\forge>
Task completed with return code 0 in 53888 milliseconds

You set OffX to be logic, not number based on this message:

double cannot be converted to boolean
      OffX = (double) -3;

Make sure OffX, y, and z are numbers

Oups I forgot that Thanks, I tested the procedure aaaaaaand… it don't work :/

The leaves disappear instantly on Tick Update, I tried with Neighbor block change but it's not the best idea :)

I wanna say it's not working, as I've tried to compile multiple times/restarting MCreator/etc to see if that'd change anything.

The Type of error is as follows:

Executing gradle command: build
Build info: MCreator 1.8.3, 64-bit, 3554 MB, Windows 8.1 - cmd, JVM 1.8.0_202, JAVA_HOME: C:\Pylo\MCreator183\jdk
C:\Pylo\MCreator183\forge>gradlew -Dorg.gradle.java.home="C:/Pylo/MCreator183/jdk" -Dorg.gradle.parallel=false -Dorg.gradle.jvmargs="-Xms625m -Xmx2048m" build 
This mapping 'snapshot_20171003' was designed for MC 1.12! Use at your own peril.
:deobfCompileDummyTask
:deobfProvidedDummyTask
:sourceApiJava UP-TO-DATE
:compileApiJava NO-SOURCE
:processApiResources NO-SOURCE
:apiClasses UP-TO-DATE
:sourceMainJava UP-TO-DATE
C:\Pylo\MCreator183\forge\build\sources\main\java\mod\mcreator\mcreator_procedureCrystalliLeafDecay.java:41: error: incompatible types: double cannot be converted to boolean
      OffX = (double) -3;
             ^
C:\Pylo\MCreator183\forge\build\sources\main\java\mod\mcreator\mcreator_procedureCrystalliLeafDecay.java:42: error: incompatible types: double cannot be converted to boolean
      OffY = (double) -3;
             ^
C:\Pylo\MCreator183\forge\build\sources\main\java\mod\mcreator\mcreator_procedureCrystalliLeafDecay.java:43: error: incompatible types: double cannot be converted to boolean
      OffZ = (double) -3;
             ^
C:\Pylo\MCreator183\forge\build\sources\main\java\mod\mcreator\mcreator_procedureCrystalliLeafDecay.java:48: error: bad operand types for binary operator '+'
               if (((world.getBlockState(new BlockPos((int) (x + (OffX)), (int) (y + (OffY)), (int) (z + (OffZ))))).getBlock() == mcreator_logCrystalli.block
                                                               ^
  first type:  int
  second type: boolean
C:\Pylo\MCreator183\forge\build\sources\main\java\mod\mcreator\mcreator_procedureCrystalliLeafDecay.java:48: error: bad operand types for binary operator '+'
               if (((world.getBlockState(new BlockPos((int) (x + (OffX)), (int) (y + (OffY)), (int) (z + (OffZ))))).getBlock() == mcreator_logCrystalli.block
                                                                                   ^
  first type:  int
  second type: boolean
C:\Pylo\MCreator183\forge\build\sources\main\java\mod\mcreator\mcreator_procedureCrystalliLeafDecay.java:48: error: bad operand types for binary operator '+'
               if (((world.getBlockState(new BlockPos((int) (x + (OffX)), (int) (y + (OffY)), (int) (z + (OffZ))))).getBlock() == mcreator_logCrystalli.block
                                                                                                       ^
  first type:  int
  second type: boolean
C:\Pylo\MCreator183\forge\build\sources\main\java\mod\mcreator\mcreator_procedureCrystalliLeafDecay.java:52: error: bad operand types for binary operator '+'
               OffZ = (double) ((OffZ) + 1);
                                       ^
  first type:  boolean
  second type: int
C:\Pylo\MCreator183\forge\build\sources\main\java\mod\mcreator\mcreator_procedureCrystalliLeafDecay.java:52: error: incompatible types: double cannot be converted to boolean
               OffZ = (double) ((OffZ) + 1);
                      ^
C:\Pylo\MCreator183\forge\build\sources\main\java\mod\mcreator\mcreator_procedureCrystalliLeafDecay.java:54: error: bad operand types for binary operator '+'
            OffY = (double) ((OffY) + 1);
                                    ^
  first type:  boolean
  second type: int
C:\Pylo\MCreator183\forge\build\sources\main\java\mod\mcreator\mcreator_procedureCrystalliLeafDecay.java:54: error: incompatible types: double cannot be converted to boolean
            OffY = (double) ((OffY) + 1);
                   ^
C:\Pylo\MCreator183\forge\build\sources\main\java\mod\mcreator\mcreator_procedureCrystalliLeafDecay.java:56: error: bad operand types for binary operator '+'
         OffX = (double) ((OffX) + 1);
                                 ^
  first type:  boolean
  second type: int
C:\Pylo\MCreator183\forge\build\sources\main\java\mod\mcreator\mcreator_procedureCrystalliLeafDecay.java:56: error: incompatible types: double cannot be converted to boolean
         OffX = (double) ((OffX) + 1);
                ^
12 errors
:compileJava FAILED

!!!

To fix this I had to manually go in and replace all the set local:[numbervariable] and get local:[numvariable] because when importing it imported incorrectly, I believe. It only happened with the custom number variables, so it may be a small bug?

When I loaded it up in the test client it still did the same as last time (disappeared even when placed right next to a log), not too sure how to fix it.



Donate to MCreator

By donating to developers you can speed up development, as with more resources, we can dedicate more time to MCreator. It is a free project made by developers working on it in their free time.