axialeaa / DoormatCarpetExtension

Welcome to the entrance of my ideas! Wipe your feet please...
GNU Lesser General Public License v3.0
6 stars 1 forks source link

/randomtick command set to a high count value creates multiple overlapping tree features when targeting a sapling #1

Closed axialeaa closed 3 months ago

axialeaa commented 11 months ago

An obnoxious sapling

This is perhaps to do with the for loop in the execute() method failing to break when the blockState has already been grown.

public class DoormatCommands {
    [...]
    public static class RandomTickCommand {
        public static int execute(ServerCommandSource source, BlockPos pos, int count) throws CommandSyntaxException {
            ServerWorld world = source.getWorld();
            BlockState state = world.getBlockState(pos);
            Random random = world.getRandom();
            if (state.hasRandomTicks()) {
                for (int i = 0; i < count; i++)
                    state.randomTick(world, pos, random);
                source.sendFeedback(() -> Text.translatable("carpet.command.randomTick.success", count, pos.getX(), pos.getY(), pos.getZ()), true);
                return 1;
            }
            else throw new SimpleCommandExceptionType(Text.translatable("carpet.command.randomTick.failed")).create();
        }
    }

}

Noted behaviour:

Expected behavior:

To reproduce:

  1. Enable /randomtick via /carpet commandRandomTick true
  2. Place down a sapling
  3. Point your crosshair at it, and begin typing /randomtick , autocompleting the block coordinates
  4. Type 4096 as the parameter, enter, and use the ^ key to retype this command again
  5. On this attempt, the sapling should be obnoxious-ified
axialeaa commented 3 months ago

this issue is fixable by putting the pos and count values to a list/map, and iterating through them in the server tick method. commands seem to run on a different thread or something, leading to a weird disparity