make shrooms spread like vanilla shrooms

Started by fenixgalax on

Topic category: Help with modding (Java Edition)

Last seen on 20:36, 28. Nov 2023
Joined Sep 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
make shrooms spread like vanilla shrooms

hello 

i have made a mod that adds more shrooms to the game however i need to make them spread to be farmable.

how can i make it in most simple way ?

 

also i have item separated from blocks and when i right click while holding the item i place block... however i cant get sound for placing the block play....

please help

 

thank you in advance

Last seen on 20:36, 28. Nov 2023
Joined Sep 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
bump! I figured how to do…
Wed, 11/01/2023 - 16:35

bump!

I figured how to do the spreading part and it works perfectly however ..... code for spreading keeps running even after shrooms are broken which creates infinite spawning of shrooms which eventualy eats ram.

 

if anyone can help me please.

 

this is the code im using for one of the shrooms.

 

package net.mcreator.farmersextended.procedures;

/* imports omitted */

public class KingspreadProcedure {
public static void execute(LevelAccessor world, double x, double y, double z) {
while ((world.getBlockState(new BlockPos(x, y, z))).getBlock() == FarmersextendedModBlocks.KING_BOLETE.get()) {
new Object() {
private int ticks = 0;
private float waitTicks;
private LevelAccessor world;

public void start(LevelAccessor world, int waitTicks) {
this.waitTicks = waitTicks;
MinecraftForge.EVENT_BUS.register(this);
this.world = world;
}

@SubscribeEvent
public void tick(TickEvent.ServerTickEvent event) {
if (event.phase == TickEvent.Phase.END) {
this.ticks += 1;
if (this.ticks >= this.waitTicks)
run();
}
}

private void run() {
if (world.getLevelData().isRaining()) {
if ((world.getBlockState(new BlockPos(x + 1, y - 1, z))).getBlock() == Blocks.GRASS_BLOCK) {
if (Math.random() < 1) {
world.setBlock(new BlockPos(x + 1, y + 0, z + 0), FarmersextendedModBlocks.KING_BOLETE.get().defaultBlockState(), 3);
}
} else if ((world.getBlockState(new BlockPos(x + 1, y - 1, z))).getBlock() == Blocks.MYCELIUM) {
if (Math.random() < 1) {
world.setBlock(new BlockPos(x + 1, y + 0, z + 0), FarmersextendedModBlocks.KING_BOLETE.get().defaultBlockState(), 3);
}
} else if ((world.getBlockState(new BlockPos(x + 1, y - 1, z))).getBlock() == Blocks.DIRT) {
if (Math.random() < 1) {
world.setBlock(new BlockPos(x + 1, y + 0, z + 0), FarmersextendedModBlocks.KING_BOLETE.get().defaultBlockState(), 3);
}
} else if ((world.getBlockState(new BlockPos(x + 1, y - 1, z))).getBlock() == Blocks.COARSE_DIRT) {
if (Math.random() < 1) {
world.setBlock(new BlockPos(x + 1, y + 0, z + 0), FarmersextendedModBlocks.KING_BOLETE.get().defaultBlockState(), 3);
}
} else if ((world.getBlockState(new BlockPos(x + 1, y - 1, z))).getBlock() == Blocks.PODZOL) {
if (Math.random() < 1) {
world.setBlock(new BlockPos(x + 1, y + 0, z + 0), FarmersextendedModBlocks.KING_BOLETE.get().defaultBlockState(), 3);
}
} else if ((world.getBlockState(new BlockPos(x + 1, y - 1, z))).getBlock() == Blocks.ROOTED_DIRT) {
if (Math.random() < 1) {
world.setBlock(new BlockPos(x + 1, y + 0, z + 0), FarmersextendedModBlocks.KING_BOLETE.get().defaultBlockState(), 3);
}
} else if ((world.getBlockState(new BlockPos(x + 1, y - 1, z))).getBlock() == Blocks.MOSS_BLOCK) {
if (Math.random() < 1) {
world.setBlock(new BlockPos(x + 1, y + 0, z + 0), FarmersextendedModBlocks.KING_BOLETE.get().defaultBlockState(), 3);
}
}
}
KingspreadProcedure.execute(world, x, y, z);
MinecraftForge.EVENT_BUS.unregister(this);
}
}.start(world, 100);
}
}
}