The Bug:
Composters always increase in level when first composting items.
Steps to Reproduce:
Obtain some wheat seeds. (These items have a 30% chance of adding a level of compost upon being placed inside of composters).
Summon a large area of composters by using the command provided below.
/fill ~1 ~ ~1 ~10 ~ ~10 minecraft:composter
Place multiple wheat seeds into multiple composters and as you do this, watch closely.
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
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 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
Hi there!
I can confirm in 1.16.1 and 1.16.2 Prerelease 1.