Making other blocks spread like fire and mushrooms

I was wondering if anyone knew what controls block spreading in craftbukkit? There is a block spread event, meaning somewhere there is code that handled block spreading that creates and triggers this event.

I ask because I want to make glowstone spread under certain conditions, just like fire and mushrooms using reflections. I think that if I can just find the code that controls this that I may have a chance of figuring out how to make additional materials spread.

Haha, very nice; funny enough I found it too but in a difference class; in BlockGrass.java. So I made this class for now to experiment, but the question is still, "Using reflections how do I get craftbukkit to use my GlowStoneBlock class just as it does the GrassBlock class"?

Haha, very nice; funny enough I found it too but in a difference class; in BlockGrass.java. So I made this class for now to experiment, but the question is still, "Using reflections how do I get craftbukkit to use my GlowStoneBlock class just as it does the GrassBlock class"?

Okay, so I've made a little bit more progress... I found that in Block.java there are a bunch of static final block variables where block are originally declared, inside that class is the following variable:

Now my question is does anyone know what the obfuscated function "a" handles in this class? I ask because in an almost identical class (BlockGrass.java) that has the behavior I want (block spreading) the "a" method is what controls block spreading, as can be seen below:

Now even though the "a" method exist in both classes, I don't believe they are the same method because they accept different arguments:

BlockGrass.java

Code:

public void a(World world, int i, int j, int k, Random random) {

BlockLightStone.java

Code:

public int a(Random random) {

If the "a" method of BlockLightStone is utilized for block spreading then I can simply alter it's functionality using reflections, but sadly if they aren't the same method then I am boned because you can't insert a new method into a class using reflections.

Any input on this subject would be appreciated, thank you for your time and attention to this matter.

Father Of Time To me that a() method seems like it controls how many glowstone dust are dropped. If you numerically analyze the method, it returns a value between 2 and 4, which coincides with the Minecraft Wiki on how many glowstone dust are dropped. The method getDropCount() calls that method too so I'm pretty sure it has nothing to do with a() from BlockGrass.java. Just looks like a case of obfuscation gone wild If you want to implement your own block spreading consider the a() method in BlockGrass.java.

I don't understand the question. The BlockSpreadEvent is called right before the actual block spreading occurs. The event just allows players to gather some information about the event before it happens and then cancel it if they see the need to do so.

xTrollxDudex This is just a guess here as I have no idea what explicitly calls that method which initiates the spread (something obfuscated in NMS), but it's probably some ChunkUpdater class that calls a() every couple of ticks.

I am pretty sure you would just need to override this method in your BlockLightStone class (that you reflect into the static NMS fields) like the other spreading blocks do. You can add all the checks you want there and you also already have examples for this. If you don't know how to reflect it into NMS take a look at this (also you probably shouldn't be messing with that stuff, if you don't know how to).

mollekake
using a scheduler is inefficient for what the OP is trying to do, and can be a hassle when there are hundreds of 'clumps'. Using a scheduler would also mean managing enabling/disabling the scheduler accordingly.

TheGreenGamerHD 1/26 seemed a bit odd. Looked it up; just a reminder the integer passed to nextInt() is exclusive so it would return 0-24

Father Of Time I remember reading someone's post a while back about using reflection for CraftBukkit/NMS. From what I got out of that thread, I don't think that's allowed because the Bukkit team wants you to update your code every MC update. If that method name changed (which it commonly does when re-obfuscated to a new version) but the signature didn't, something catastrophic could happen to someone's world. Not entirely sure if that's on point but just letting you know.

xTrollxDudex From what I get from that BlockMushroom class, BlockSpreadEvent is called after a BlockState object is referenced. Once the logic of probability and entity checks are completed, it fires the event, and as long as the event isn't cancelled, the block is updated to that state. It depends on what OP wants to do. If he truly just wants to just

then using BlockSpreadEvent is best in this case because you can check light level and other stuff I guess. If he wants to really change the mechanics of block spreading (which could be dangerous if not coded carefully) they he might want to re-code that method.

xTrollxDudex From what I get from that BlockMushroom class, BlockSpreadEvent is called after a BlockState object is referenced. Once the logic of probability and entity checks are completed, it fires the event, and as long as the event isn't cancelled, the block is updated to that state. It depends on what OP wants to do. If he truly just wants to just then using BlockSpreadEvent is best in this case because you can check light level and other stuff I guess. If he wants to really change the mechanics of block spreading (which could be dangerous if not coded carefully) they he might want to re-code that method.

Kazzababe Listening for any event will not cause it to happen, but you can modify it. In the case of glowstone spreading because it naturally doesn't you are right in saying that the event won't help. But for other spreading blocks like grass it would. To the OP, I say extend Block and polymorph that method and copy BlockGrass's implementation.