mirror of
https://github.com/FabricMC/fabric.git
synced 2024-11-25 00:58:17 -05:00
This commit is contained in:
parent
6cebf059ec
commit
da9bb83539
2 changed files with 31 additions and 2 deletions
|
@ -105,11 +105,12 @@ public class ComposterWrapper extends SnapshotParticipant<Float> {
|
||||||
// Play the sound
|
// Play the sound
|
||||||
location.world.playSound(null, location.pos, SoundEvents.BLOCK_COMPOSTER_EMPTY, SoundCategory.BLOCKS, 1.0F, 1.0F);
|
location.world.playSound(null, location.pos, SoundEvents.BLOCK_COMPOSTER_EMPTY, SoundCategory.BLOCKS, 1.0F, 1.0F);
|
||||||
} else if (increaseProbability > 0) {
|
} else if (increaseProbability > 0) {
|
||||||
boolean increaseSuccessful = location.world.getRandom().nextDouble() < increaseProbability;
|
BlockState state = location.getBlockState();
|
||||||
|
// Always increment on first insert (like vanilla).
|
||||||
|
boolean increaseSuccessful = state.get(ComposterBlock.LEVEL) == 0 || location.world.getRandom().nextDouble() < increaseProbability;
|
||||||
|
|
||||||
if (increaseSuccessful) {
|
if (increaseSuccessful) {
|
||||||
// Mimic ComposterBlock#addToComposter logic.
|
// Mimic ComposterBlock#addToComposter logic.
|
||||||
BlockState state = location.getBlockState();
|
|
||||||
int newLevel = state.get(ComposterBlock.LEVEL) + 1;
|
int newLevel = state.get(ComposterBlock.LEVEL) + 1;
|
||||||
BlockState newState = state.with(ComposterBlock.LEVEL, newLevel);
|
BlockState newState = state.with(ComposterBlock.LEVEL, newLevel);
|
||||||
location.setBlockState(newState);
|
location.setBlockState(newState);
|
||||||
|
|
|
@ -22,6 +22,7 @@ import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.block.ComparatorBlock;
|
import net.minecraft.block.ComparatorBlock;
|
||||||
|
import net.minecraft.block.ComposterBlock;
|
||||||
import net.minecraft.block.entity.BrewingStandBlockEntity;
|
import net.minecraft.block.entity.BrewingStandBlockEntity;
|
||||||
import net.minecraft.block.entity.ChiseledBookshelfBlockEntity;
|
import net.minecraft.block.entity.ChiseledBookshelfBlockEntity;
|
||||||
import net.minecraft.block.entity.FurnaceBlockEntity;
|
import net.minecraft.block.entity.FurnaceBlockEntity;
|
||||||
|
@ -327,4 +328,31 @@ public class VanillaStorageTests {
|
||||||
|
|
||||||
context.complete();
|
context.complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regression test for <a href="https://github.com/FabricMC/fabric/issues/3017">composters not always incrementing their level on the first insert</a>.
|
||||||
|
*/
|
||||||
|
@GameTest(templateName = FabricGameTest.EMPTY_STRUCTURE)
|
||||||
|
public void testComposterFirstInsert(TestContext context) {
|
||||||
|
BlockPos pos = new BlockPos(0, 1, 0);
|
||||||
|
|
||||||
|
ItemVariant carrot = ItemVariant.of(Items.CARROT);
|
||||||
|
|
||||||
|
for (int i = 0; i < 200; ++i) { // Run many times as this can be random.
|
||||||
|
context.setBlockState(pos, Blocks.COMPOSTER.getDefaultState());
|
||||||
|
Storage<ItemVariant> storage = ItemStorage.SIDED.find(context.getWorld(), context.getAbsolutePos(pos), Direction.UP);
|
||||||
|
|
||||||
|
try (Transaction tx = Transaction.openOuter()) {
|
||||||
|
if (storage.insert(carrot, 1, tx) != 1) {
|
||||||
|
context.throwPositionedException("Carrot should have been inserted", pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
tx.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
context.checkBlockState(pos, state -> state.get(ComposterBlock.LEVEL) == 1, () -> "Composter should have level 1");
|
||||||
|
}
|
||||||
|
|
||||||
|
context.complete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue