NetherrackBlock .java

net.minecraft.world.level.block.NetherrackBlock (class): members: isValidBonemealTarget, isBonemealSuccess, performBonemeal, getType. imports: BlockTags.

net.minecraft.world.level.blockclass60 linescommonextends Block2.4 KB

Implements

API Surface (4)

boolean isValidBonemealTarget(final LevelReader level, final BlockPos pos, final BlockState state, final BonemealSource source)
boolean isBonemealSuccess(final Level level, final RandomSource random, final BlockPos pos, final BlockState state, final BonemealSource source)
void performBonemeal(final ServerLevel level, final RandomSource random, final BlockPos pos, final BlockState state, final BonemealSource source)
BonemealableBlock.Type getType()

Full Source

NetherrackBlock.java60 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.block;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.server.level.ServerLevel;
5
import net.minecraft.tags.BlockTags;
6
import net.minecraft.util.Continuation;
7
import net.minecraft.util.RandomSource;
8
import net.minecraft.world.level.Level;
9
import net.minecraft.world.level.LevelReader;
10
import net.minecraft.world.level.block.state.BlockBehaviour;
11
import net.minecraft.world.level.block.state.BlockState;
12
import org.apache.commons.lang3.mutable.MutableBoolean;
13
14
public class NetherrackBlock extends Block implements BonemealableBlock {
15
	public NetherrackBlock(final BlockBehaviour.Properties properties) {
16
		super(properties);
17
	}
18
19
	@Override
20
	public boolean isValidBonemealTarget(final LevelReader level, final BlockPos pos, final BlockState state, final BonemealSource source) {
21
		return !level.getBlockState(pos.above()).propagatesSkylightDown()
22
			? false
23
			: level.findBlocksIn(pos.offset(-1, -1, -1), pos.offset(1, 1, 1)).filterState(blockState -> blockState.is(BlockTags.NYLIUM)).anyMatched();
24
	}
25
26
	@Override
27
	public boolean isBonemealSuccess(final Level level, final RandomSource random, final BlockPos pos, final BlockState state, final BonemealSource source) {
28
		return true;
29
	}
30
31
	@Override
32
	public void performBonemeal(final ServerLevel level, final RandomSource random, final BlockPos pos, final BlockState state, final BonemealSource source) {
33
		MutableBoolean foundRed = new MutableBoolean();
34
		MutableBoolean foundBlue = new MutableBoolean();
35
		level.findBlocksIn(pos.offset(-1, -1, -1), pos.offset(1, 1, 1))
36
			.filterState(blockState -> blockState.is(BlockTags.NYLIUM))
37
			.forEachUntil((var2, blockState) -> {
38
				if (blockState.is(Blocks.WARPED_NYLIUM)) {
39
					foundBlue.setTrue();
40
				} else if (blockState.is(Blocks.CRIMSON_NYLIUM)) {
41
					foundRed.setTrue();
42
				}
43
44
				return Continuation.abortIf(foundBlue.isTrue() && foundRed.isTrue());
45
			});
46
		if (foundBlue.isTrue() && foundRed.isTrue()) {
47
			level.setBlockAndUpdate(pos, random.nextBoolean() ? Blocks.WARPED_NYLIUM.defaultBlockState() : Blocks.CRIMSON_NYLIUM.defaultBlockState());
48
		} else if (foundBlue.isTrue()) {
49
			level.setBlockAndUpdate(pos, Blocks.WARPED_NYLIUM.defaultBlockState());
50
		} else if (foundRed.isTrue()) {
51
			level.setBlockAndUpdate(pos, Blocks.CRIMSON_NYLIUM.defaultBlockState());
52
		}
53
	}
54
55
	@Override
56
	public BonemealableBlock.Type getType() {
57
		return BonemealableBlock.Type.NEIGHBOR_SPREADER;
58
	}
59
}
60

Decompiled Minecraft 26.3 source of NetherrackBlock (net/minecraft/world/level/block/NetherrackBlock.java) with Mojang official mappings, stored verbatim on the site.