RingBell .java

net.minecraft.world.entity.ai.behavior.RingBell (class, 34 lines): members: RING_BELL_FROM_DISTANCE, BELL_RING_CHANCE, create. imports: BellBlock, Blocks.

net.minecraft.world.entity.ai.behaviorclass34 linescommon1.1 KB

API Surface (1)

BehaviorControl<LivingEntity> create()

Fields & Constants (2)

BELL_RING_CHANCE
RING_BELL_FROM_DISTANCE

Code Graph: Dependencies (8)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

RingBell.java34 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.ai.behavior;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.world.entity.LivingEntity;
5
import net.minecraft.world.entity.ai.behavior.declarative.BehaviorBuilder;
6
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
7
import net.minecraft.world.level.block.BellBlock;
8
import net.minecraft.world.level.block.Blocks;
9
import net.minecraft.world.level.block.state.BlockState;
10
11
public class RingBell {
12
	private static final float BELL_RING_CHANCE = 0.95F;
13
	public static final int RING_BELL_FROM_DISTANCE = 3;
14
15
	public static BehaviorControl<LivingEntity> create() {
16
		return BehaviorBuilder.create(i -> i.group(i.present(MemoryModuleType.MEETING_POINT)).apply(i, meetingPoint -> (level, body, timestamp) -> {
17
			if (level.getRandom().nextFloat() <= 0.95F) {
18
				return false;
19
			}
20
21
			BlockPos pos = i.get(meetingPoint).pos();
22
			if (pos.closerThan(body.blockPosition(), 3.0)) {
23
				BlockState state = level.getBlockState(pos);
24
				if (state.is(Blocks.BELL)) {
25
					BellBlock bellBlock = (BellBlock)state.getBlock();
26
					bellBlock.attemptToRing(body, level, pos, null);
27
				}
28
			}
29
30
			return true;
31
		}));
32
	}
33
}
34

Decompiled Minecraft 26.3 source of RingBell (net/minecraft/world/entity/ai/behavior/RingBell.java) with Mojang official mappings, stored verbatim on the site.