mojira.dev
MC-196452

Composters always increase in level when first composting items

The Bug:

Composters always increase in level when first composting items.

Steps to Reproduce:

  1. Obtain some wheat seeds. (These items have a 30% chance of adding a level of compost upon being placed inside of composters).

  2. Summon a large area of composters by using the command provided below.

    /fill ~1 ~ ~1 ~10 ~ ~10 minecraft:composter
  3. Place multiple wheat seeds into multiple composters and as you do this, watch closely.

  4. Take note as to whether or not composters always increase in level when first composting items.

Observed Behavior:

Composters always increase in level when first composting items.

Expected Behavior:

Composters would not always increase in level when first composting items.

Code analysis

Code analysis by @unknown can be found in this comment.

Attachments

Comments 9

Hi there!

I can confirm in 1.16.1 and 1.16.2 Prerelease 1.

Probably Intended, not sure

It looks like intended because if you compost something it doesn't make sense that composter is empty after that (because composter level 0 is empty).

Can confirm in 1.16.5 and 1.17 Release Candidate 1.

Can confirm in 1.17.

Can confirm in 1.17.1.

Can confirm in 21w40a. The expected behavior would be that empty composters don't always increase in level upon first composting an item.

Code Analysis - (Yarn 22w17a)

net.minecraft.block.ComposterBlock.java

static BlockState addToComposter(BlockState state, WorldAccess world, BlockPos pos, ItemStack item) {
	int level = state.get(LEVEL);
	float f = ITEM_TO_LEVEL_INCREASE_CHANCE.getFloat(item.getItem());
	if ((level != 0 || !(f > 0.0F)) && !(world.getRandom().nextDouble() < (double)f)) {
		return state;
	} else {
		int newLevel = level + 1;
		BlockState blockState = state.with(LEVEL, newLevel);
		world.setBlockState(pos, blockState, Block.NOTIFY_ALL);
		if (newLevel == 7) {
			world.createAndScheduleBlockTick(pos, state.getBlock(), 20);
		}
		return blockState;
	}
}

Let me invert the first part so its easier to read

int level = state.get(LEVEL);
float chance = ITEM_TO_LEVEL_INCREASE_CHANCE.getFloat(item.getItem());
double randD = world.getRandom().nextDouble();
// !(f > 0.0F) just makes sure the chances are not negative
if (level != 0 && d >= f) { // Make it so that if the level is 0, it always pass
	return state; // Fails, does not add a new level
} else {
	// ... - Add a new level
}

So as you can see, if the level is 0 it won't care about the random.

Seems intentional

Can confirm for 1.20.6

bugsbugsbugs

Avoma

(Unassigned)

Confirmed

Gameplay

Normal

Block states, Items

composter

1.16.1, 1.16.2 Pre-release 1, 1.16.2 Pre-release 2, 1.16.2 Pre-release 3, 1.16.2 Release Candidate 1, ..., 1.21, 1.21.3, 1.21.4, 25w08a, 1.21.7

Retrieved