BlockBehaviour .java

net.minecraft.world.level.block.state.BlockBehaviour (class, 1330 lines): members: showAsInteractableInSpectatorMode, StateArgumentPredicate, dynamicShape.

net.minecraft.world.level.block.stateclass1,330 linescommon49.3 KB

Implements

API Surface (197)

BlockBehaviour.Properties properties()
void updateIndirectNeighbourShapes(final BlockState state, final LevelAccessor level, final BlockPos pos, final @Block.UpdateFlags int updateFlags, final int updateLimit)
boolean isPathfindable(final BlockState state, final PathComputationType type)
BlockState updateShape(final BlockState state, final LevelReader level, final ScheduledTickAccess ticks, final BlockPos pos, final Direction directionToNeighbour, final BlockPos neighbourPos, final BlockState neighbourState, final RandomSource random)
boolean skipRendering(final BlockState state, final BlockState neighborState, final Direction direction)
void neighborChanged(final BlockState state, final Level level, final BlockPos pos, final Block block, final @Nullable Orientation orientation, final boolean movedByPiston)
void onPlace(final BlockState state, final Level level, final BlockPos pos, final BlockState oldState, final boolean movedByPiston)
void affectNeighborsAfterRemoval(final BlockState state, final ServerLevel level, final BlockPos pos, final boolean movedByPiston)
void onExplosionHit(final BlockState state, final ServerLevel level, final BlockPos pos, final Explosion explosion, final BiConsumer<ItemStack, BlockPos> onHit)
InteractionResult useWithoutItem(final BlockState state, final Level level, final BlockPos pos, final Player player, final BlockHitResult hitResult)
InteractionResult useItemOn(final ItemStack itemStack, final BlockState state, final Level level, final BlockPos pos, final Player player, final InteractionHand hand, final BlockHitResult hitResult)
boolean showAsInteractableInSpectatorMode(final BlockState state, final Level level, final BlockPos pos, final BlockHitResult hitResult)
boolean triggerEvent(final BlockState state, final Level level, final BlockPos pos, final int b0, final int b1)
RenderShape getRenderShape(final BlockState state)
boolean useShapeForLightOcclusion(final BlockState state)
FluidState getFluidState(final BlockState state)
boolean hasAnalogOutputSignal(final BlockState state)
float getMaxHorizontalOffset()
float getMaxVerticalOffset()
FeatureFlagSet requiredFeatures()
boolean shouldChangedStateKeepBlockEntity(final BlockState oldState)
BlockState rotate(final BlockState state, final Rotation rotation)
BlockState mirror(final BlockState state, final Mirror mirror)
boolean canBeReplaced(final BlockState state, final BlockPlaceContext context)
boolean canBeReplaced(final BlockState state, final Fluid fluid)
List<ItemStack> getDrops(final BlockState state, final LootParams.Builder params)
long getSeed(final BlockState state, final BlockPos pos)
VoxelShape getOcclusionShape(final BlockState state)
VoxelShape getBlockSupportShape(final BlockState state, final BlockGetter level, final BlockPos pos)
VoxelShape getInteractionShape(final BlockState state, final BlockGetter level, final BlockPos pos)
int getLightDampening(final BlockState state)
boolean canSurvive(final BlockState state, final LevelReader level, final BlockPos pos)
float getShadeBrightness(final BlockState state, final BlockGetter level, final BlockPos pos)
int getAnalogOutputSignal(final BlockState state, final Level level, final BlockPos pos, final Direction direction)
VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context)
VoxelShape getCollisionShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context)
VoxelShape getEntityInsideCollisionShape(final BlockState state, final BlockGetter level, final BlockPos pos, final Entity entity)
boolean isCollisionShapeFullBlock(final BlockState state, final BlockGetter level, final BlockPos pos)
VoxelShape getVisualShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context)
void randomTick(final BlockState state, final ServerLevel level, final BlockPos pos, final RandomSource random)
void tick(final BlockState state, final ServerLevel level, final BlockPos pos, final RandomSource random)
float getDestroyProgress(final BlockState state, final Player player, final BlockGetter level, final BlockPos pos)
void spawnAfterBreak(final BlockState state, final ServerLevel level, final BlockPos pos, final ItemStack tool, final boolean dropExperience)
void attack(final BlockState state, final Level level, final BlockPos pos, final Player player)
boolean isSignalSource(final BlockState state)
boolean shouldRedstoneWireConnectTo(final BlockState state, final BlockGetter level, final BlockPos pos, final @Nullable Direction direction)
int getSignal(final BlockState state, final BlockGetter level, final BlockPos pos, final Direction direction)
int ownSignal(final BlockState state, final BlockGetter level, final BlockPos pos)
void entityInside(final BlockState state, final Level level, final BlockPos pos, final Entity entity, final InsideBlockEffectApplier effectApplier, final boolean isPrecise)
int getDirectSignal(final BlockState state, final BlockGetter level, final BlockPos pos, final Direction direction)
Optional<ResourceKey<LootTable>> getLootTable()
String getDescriptionId()
void onProjectileHit(final Level level, final BlockState state, final BlockHitResult blockHit, final Projectile projectile)
boolean propagatesSkylightDown(final BlockState state)
boolean isRandomlyTicking(final BlockState state)
SoundType getSoundType(final BlockState state)
ItemStack getCloneItemStack(final LevelReader level, final BlockPos pos, final BlockState state, final boolean includeData)
MapColor defaultMapColor()
float defaultDestroyTime()
void initCache()
Block getBlock()
Holder<Block> typeHolder()
boolean isSolid()
boolean isValidSpawn(final BlockGetter level, final BlockPos pos, final EntityType<?> type)
boolean propagatesSkylightDown()
int getLightDampening()
VoxelShape getFaceOcclusionShape(final Direction direction)
VoxelShape getOcclusionShape()
boolean hasLargeCollisionShape()
boolean useShapeForLightOcclusion()
int getLightEmission()
boolean isAir()
boolean ignitedByLava()
boolean liquid()
MapColor getMapColor(final BlockGetter level, final BlockPos pos)
BlockState rotate(final Rotation rotation)
BlockState mirror(final Mirror mirror)
RenderShape getRenderShape()
boolean emissiveRendering()
float getShadeBrightness(final BlockGetter level, final BlockPos pos)
boolean isRedstoneConductor(final BlockGetter level, final BlockPos pos)
boolean isSignalSource()
boolean shouldRedstoneWireConnectTo(final BlockGetter level, final BlockPos pos, final @Nullable Direction direction)
int getOwnSignal(final BlockGetter level, final BlockPos pos)
int getSignal(final BlockGetter level, final BlockPos pos, final Direction direction)
boolean hasAnalogOutputSignal()
int getAnalogOutputSignal(final Level level, final BlockPos pos, final Direction direction)
float getDestroySpeed(final BlockGetter level, final BlockPos pos)
float getDestroyProgress(final Player player, final BlockGetter level, final BlockPos pos)
int getDirectSignal(final BlockGetter level, final BlockPos pos, final Direction direction)
PushReaction getPistonPushReaction()
boolean isSolidRender()
boolean canOcclude()
boolean skipRendering(final BlockState neighborState, final Direction direction)
VoxelShape getShape(final BlockGetter level, final BlockPos pos)
VoxelShape getShape(final BlockGetter level, final BlockPos pos, final CollisionContext context)
VoxelShape getCollisionShape(final BlockGetter level, final BlockPos pos)
VoxelShape getCollisionShape(final BlockGetter level, final BlockPos pos, final CollisionContext context)
VoxelShape getEntityInsideCollisionShape(final BlockGetter level, final BlockPos pos, final Entity entity)
VoxelShape getBlockSupportShape(final BlockGetter level, final BlockPos pos)
VoxelShape getVisualShape(final BlockGetter level, final BlockPos pos, final CollisionContext context)
VoxelShape getInteractionShape(final BlockGetter level, final BlockPos pos)
boolean entityCanStandOn(final BlockGetter level, final BlockPos pos, final Entity entity)
boolean entityCanStandOnFace(final BlockGetter level, final BlockPos pos, final Entity entity, final Direction faceDirection)
Vec3 getOffset(final BlockPos pos)
boolean hasOffsetFunction()
boolean triggerEvent(final Level level, final BlockPos pos, final int b0, final int b1)
void handleNeighborChanged(final Level level, final BlockPos pos, final Block block, final @Nullable Orientation orientation, final boolean movedByPiston)
void updateNeighbourShapes(final LevelAccessor level, final BlockPos pos, final @Block.UpdateFlags int updateFlags)
void updateNeighbourShapes(final LevelAccessor level, final BlockPos pos, final @Block.UpdateFlags int updateFlags, final int updateLimit)
void updateIndirectNeighbourShapes(final LevelAccessor level, final BlockPos pos, final @Block.UpdateFlags int updateFlags)
void updateIndirectNeighbourShapes(final LevelAccessor level, final BlockPos pos, final @Block.UpdateFlags int updateFlags, final int updateLimit)
void onPlace(final Level level, final BlockPos pos, final BlockState oldState, final boolean movedByPiston)
void affectNeighborsAfterRemoval(final ServerLevel level, final BlockPos pos, final boolean movedByPiston)
void onExplosionHit(final ServerLevel level, final BlockPos pos, final Explosion explosion, final BiConsumer<ItemStack, BlockPos> onHit)
void tick(final ServerLevel level, final BlockPos pos, final RandomSource random)
void randomTick(final ServerLevel level, final BlockPos pos, final RandomSource random)
void entityInside(final Level level, final BlockPos pos, final Entity entity, final InsideBlockEffectApplier effectApplier, final boolean isPrecise)
void spawnAfterBreak(final ServerLevel level, final BlockPos pos, final ItemStack tool, final boolean dropExperience)
List<ItemStack> getDrops(final LootParams.Builder params)

…and 77 more (see full source).

Fields & Constants (29)

UPDATE_SHAPE_ORDER
hasCollision
explosionResistance
isRandomlyTicking
soundType
friction
speedFactor
jumpFactor
bounceRestitution
fallDistanceReduction
dynamicShape
requiredFeatures
properties
drops
descriptionId
updateFlags
state
level
ticks
pos
directionToNeighbour
neighbourPos
neighbourState
orientation
explosion

…and 4 more (see full source).

String literals (3)

"blocks/"
"block"
"Block id not set"

Code Graph: Dependencies (73)

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

Full Source

BlockBehaviour.java1330 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.block.state;
2
3
import java.util.Arrays;
4
import java.util.Collections;
5
import java.util.List;
6
import java.util.Locale;
7
import java.util.Objects;
8
import java.util.Optional;
9
import java.util.function.BiConsumer;
10
import java.util.function.Function;
11
import java.util.function.Predicate;
12
import java.util.function.ToIntFunction;
13
import net.fabricmc.fabric.api.block.v1.FabricBlock.FabricProperties;
14
import net.minecraft.core.BlockPos;
15
import net.minecraft.core.Direction;
16
import net.minecraft.core.Holder;
17
import net.minecraft.core.TypedInstance;
18
import net.minecraft.core.registries.BuiltInRegistries;
19
import net.minecraft.core.registries.Registries;
20
import net.minecraft.resources.DependantName;
21
import net.minecraft.resources.ResourceKey;
22
import net.minecraft.server.level.ServerLevel;
23
import net.minecraft.tags.BlockTags;
24
import net.minecraft.tags.FluidTags;
25
import net.minecraft.tags.TagKey;
26
import net.minecraft.util.Mth;
27
import net.minecraft.util.RandomSource;
28
import net.minecraft.util.Util;
29
import net.minecraft.world.InteractionHand;
30
import net.minecraft.world.InteractionResult;
31
import net.minecraft.world.MenuProvider;
32
import net.minecraft.world.entity.Entity;
33
import net.minecraft.world.entity.EntityType;
34
import net.minecraft.world.entity.InsideBlockEffectApplier;
35
import net.minecraft.world.entity.player.Player;
36
import net.minecraft.world.entity.projectile.Projectile;
37
import net.minecraft.world.flag.FeatureElement;
38
import net.minecraft.world.flag.FeatureFlag;
39
import net.minecraft.world.flag.FeatureFlagSet;
40
import net.minecraft.world.flag.FeatureFlags;
41
import net.minecraft.world.item.DyeColor;
42
import net.minecraft.world.item.Item;
43
import net.minecraft.world.item.ItemStack;
44
import net.minecraft.world.item.context.BlockPlaceContext;
45
import net.minecraft.world.level.BlockGetter;
46
import net.minecraft.world.level.EmptyBlockGetter;
47
import net.minecraft.world.level.Explosion;
48
import net.minecraft.world.level.Level;
49
import net.minecraft.world.level.LevelAccessor;
50
import net.minecraft.world.level.LevelReader;
51
import net.minecraft.world.level.ScheduledTickAccess;
52
import net.minecraft.world.level.block.Block;
53
import net.minecraft.world.level.block.Blocks;
54
import net.minecraft.world.level.block.EntityBlock;
55
import net.minecraft.world.level.block.Mirror;
56
import net.minecraft.world.level.block.Portal;
57
import net.minecraft.world.level.block.RenderShape;
58
import net.minecraft.world.level.block.Rotation;
59
import net.minecraft.world.level.block.SoundType;
60
import net.minecraft.world.level.block.SupportType;
61
import net.minecraft.world.level.block.entity.BlockEntity;
62
import net.minecraft.world.level.block.entity.BlockEntityTicker;
63
import net.minecraft.world.level.block.entity.BlockEntityType;
64
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument;
65
import net.minecraft.world.level.block.state.properties.Property;
66
import net.minecraft.world.level.material.Fluid;
67
import net.minecraft.world.level.material.FluidState;
68
import net.minecraft.world.level.material.Fluids;
69
import net.minecraft.world.level.material.MapColor;
70
import net.minecraft.world.level.material.PushReaction;
71
import net.minecraft.world.level.pathfinder.PathComputationType;
72
import net.minecraft.world.level.redstone.Orientation;
73
import net.minecraft.world.level.storage.loot.LootParams;
74
import net.minecraft.world.level.storage.loot.LootTable;
75
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
76
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
77
import net.minecraft.world.phys.AABB;
78
import net.minecraft.world.phys.BlockHitResult;
79
import net.minecraft.world.phys.Vec3;
80
import net.minecraft.world.phys.shapes.CollisionContext;
81
import net.minecraft.world.phys.shapes.Shapes;
82
import net.minecraft.world.phys.shapes.VoxelShape;
83
import org.jspecify.annotations.Nullable;
84
85
public abstract class BlockBehaviour implements FeatureElement {
86
	protected static final Direction[] UPDATE_SHAPE_ORDER = new Direction[]{
87
		Direction.WEST, Direction.EAST, Direction.NORTH, Direction.SOUTH, Direction.DOWN, Direction.UP
88
	};
89
	protected final boolean hasCollision;
90
	protected final float explosionResistance;
91
	protected final boolean isRandomlyTicking;
92
	protected final SoundType soundType;
93
	protected final float friction;
94
	protected final float speedFactor;
95
	protected final float jumpFactor;
96
	protected final float bounceRestitution;
97
	protected final float fallDistanceReduction;
98
	protected final boolean dynamicShape;
99
	protected final FeatureFlagSet requiredFeatures;
100
	protected final BlockBehaviour.Properties properties;
101
	protected final Optional<ResourceKey<LootTable>> drops;
102
	protected final String descriptionId;
103
104
	public BlockBehaviour(final BlockBehaviour.Properties properties) {
105
		this.hasCollision = properties.hasCollision;
106
		this.drops = properties.effectiveDrops();
107
		this.descriptionId = properties.effectiveDescriptionId();
108
		this.explosionResistance = properties.explosionResistance;
109
		this.isRandomlyTicking = properties.isRandomlyTicking;
110
		this.soundType = properties.soundType;
111
		this.friction = properties.friction;
112
		this.speedFactor = properties.speedFactor;
113
		this.jumpFactor = properties.jumpFactor;
114
		this.bounceRestitution = properties.bounceRestitution;
115
		this.fallDistanceReduction = properties.fallDistanceReduction;
116
		this.dynamicShape = properties.dynamicShape;
117
		this.requiredFeatures = properties.requiredFeatures;
118
		this.properties = properties;
119
	}
120
121
	public BlockBehaviour.Properties properties() {
122
		return this.properties;
123
	}
124
125
	protected void updateIndirectNeighbourShapes(
126
		final BlockState state, final LevelAccessor level, final BlockPos pos, final @Block.UpdateFlags int updateFlags, final int updateLimit
127
	) {
128
	}
129
130
	protected boolean isPathfindable(final BlockState state, final PathComputationType type) {
131
		return switch (type) {
132
			case LAND -> !state.isCollisionShapeFullBlock(EmptyBlockGetter.INSTANCE, BlockPos.ZERO);
133
			case WATER -> state.getFluidState().is(FluidTags.WATER);
134
			case AIR -> !state.isCollisionShapeFullBlock(EmptyBlockGetter.INSTANCE, BlockPos.ZERO);
135
			default -> false;
136
		};
137
	}
138
139
	protected BlockState updateShape(
140
		final BlockState state,
141
		final LevelReader level,
142
		final ScheduledTickAccess ticks,
143
		final BlockPos pos,
144
		final Direction directionToNeighbour,
145
		final BlockPos neighbourPos,
146
		final BlockState neighbourState,
147
		final RandomSource random
148
	) {
149
		return state;
150
	}
151
152
	protected boolean skipRendering(final BlockState state, final BlockState neighborState, final Direction direction) {
153
		return false;
154
	}
155
156
	protected void neighborChanged(
157
		final BlockState state, final Level level, final BlockPos pos, final Block block, final @Nullable Orientation orientation, final boolean movedByPiston
158
	) {
159
	}
160
161
	protected void onPlace(final BlockState state, final Level level, final BlockPos pos, final BlockState oldState, final boolean movedByPiston) {
162
	}
163
164
	protected void affectNeighborsAfterRemoval(final BlockState state, final ServerLevel level, final BlockPos pos, final boolean movedByPiston) {
165
	}
166
167
	protected void onExplosionHit(
168
		final BlockState state, final ServerLevel level, final BlockPos pos, final Explosion explosion, final BiConsumer<ItemStack, BlockPos> onHit
169
	) {
170
		if (!state.isAir() && explosion.getBlockInteraction() != Explosion.BlockInteraction.TRIGGER_BLOCK) {
171
			Block block = state.getBlock();
172
			boolean doDropExperienceHack = explosion.getIndirectSourceEntity() instanceof Player;
173
			if (block.dropFromExplosion(explosion)) {
174
				BlockEntity blockEntity = state.hasBlockEntity() ? level.getBlockEntity(pos) : null;
175
				LootParams.Builder params = new LootParams.Builder(level)
176
					.withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(pos))
177
					.withParameter(LootContextParams.TOOL, ItemStack.EMPTY)
178
					.withOptionalParameter(LootContextParams.BLOCK_ENTITY, blockEntity)
179
					.withOptionalParameter(LootContextParams.THIS_ENTITY, explosion.getDirectSourceEntity());
180
				if (explosion.getBlockInteraction() == Explosion.BlockInteraction.DESTROY_WITH_DECAY) {
181
					params.withParameter(LootContextParams.EXPLOSION_RADIUS, explosion.radius());
182
				}
183
184
				state.spawnAfterBreak(level, pos, ItemStack.EMPTY, doDropExperienceHack);
185
				state.getDrops(params).forEach(stack -> onHit.accept(stack, pos));
186
			}
187
188
			level.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
189
			block.wasExploded(level, pos, explosion);
190
		}
191
	}
192
193
	protected InteractionResult useWithoutItem(final BlockState state, final Level level, final BlockPos pos, final Player player, final BlockHitResult hitResult) {
194
		return InteractionResult.PASS;
195
	}
196
197
	protected InteractionResult useItemOn(
198
		final ItemStack itemStack,
199
		final BlockState state,
200
		final Level level,
201
		final BlockPos pos,
202
		final Player player,
203
		final InteractionHand hand,
204
		final BlockHitResult hitResult
205
	) {
206
		return InteractionResult.TRY_WITH_EMPTY_HAND;
207
	}
208
209
	protected boolean showAsInteractableInSpectatorMode(final BlockState state, final Level level, final BlockPos pos, final BlockHitResult hitResult) {
210
		return state.getMenuProvider(level, pos) != null || state.getBlock() instanceof Portal;
211
	}
212
213
	protected boolean triggerEvent(final BlockState state, final Level level, final BlockPos pos, final int b0, final int b1) {
214
		return false;
215
	}
216
217
	protected RenderShape getRenderShape(final BlockState state) {
218
		return RenderShape.MODEL;
219
	}
220
221
	protected boolean useShapeForLightOcclusion(final BlockState state) {
222
		return false;
223
	}
224
225
	protected FluidState getFluidState(final BlockState state) {
226
		return Fluids.EMPTY.defaultFluidState();
227
	}
228
229
	protected boolean hasAnalogOutputSignal(final BlockState state) {
230
		return false;
231
	}
232
233
	protected float getMaxHorizontalOffset() {
234
		return 0.25F;
235
	}
236
237
	protected float getMaxVerticalOffset() {
238
		return 0.2F;
239
	}
240
241
	@Override
242
	public FeatureFlagSet requiredFeatures() {
243
		return this.requiredFeatures;
244
	}
245
246
	protected boolean shouldChangedStateKeepBlockEntity(final BlockState oldState) {
247
		return false;
248
	}
249
250
	protected BlockState rotate(final BlockState state, final Rotation rotation) {
251
		return state;
252
	}
253
254
	protected BlockState mirror(final BlockState state, final Mirror mirror) {
255
		return state;
256
	}
257
258
	protected boolean canBeReplaced(final BlockState state, final BlockPlaceContext context) {
259
		return state.canBeReplaced() && (context.getItemInHand().isEmpty() || !context.getItemInHand().is(this.asItem()));
260
	}
261
262
	protected boolean canBeReplaced(final BlockState state, final Fluid fluid) {
263
		return state.canBeReplaced() || !state.isSolid();
264
	}
265
266
	protected List<ItemStack> getDrops(final BlockState state, final LootParams.Builder params) {
267
		if (this.drops.isEmpty()) {
268
			return Collections.emptyList();
269
		}
270
271
		LootParams lootParams = params.withParameter(LootContextParams.BLOCK_STATE, state).create(LootContextParamSets.BLOCK);
272
		ServerLevel level = lootParams.getLevel();
273
		LootTable table = level.getServer().reloadableRegistries().getLootTable(this.drops.get());
274
		return table.getRandomItems(lootParams);
275
	}
276
277
	protected long getSeed(final BlockState state, final BlockPos pos) {
278
		return Mth.getSeed(pos);
279
	}
280
281
	protected VoxelShape getOcclusionShape(final BlockState state) {
282
		return state.getShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO);
283
	}
284
285
	protected VoxelShape getBlockSupportShape(final BlockState state, final BlockGetter level, final BlockPos pos) {
286
		return this.getCollisionShape(state, level, pos, CollisionContext.empty());
287
	}
288
289
	protected VoxelShape getInteractionShape(final BlockState state, final BlockGetter level, final BlockPos pos) {
290
		return Shapes.empty();
291
	}
292
293
	protected int getLightDampening(final BlockState state) {
294
		if (state.isSolidRender()) {
295
			return 15;
296
		} else {
297
			return state.propagatesSkylightDown() ? 0 : 1;
298
		}
299
	}
300
301
	protected @Nullable MenuProvider getMenuProvider(final BlockState state, final Level level, final BlockPos pos) {
302
		return null;
303
	}
304
305
	protected boolean canSurvive(final BlockState state, final LevelReader level, final BlockPos pos) {
306
		return true;
307
	}
308
309
	protected float getShadeBrightness(final BlockState state, final BlockGetter level, final BlockPos pos) {
310
		return state.isCollisionShapeFullBlock(level, pos) ? 0.2F : 1.0F;
311
	}
312
313
	protected int getAnalogOutputSignal(final BlockState state, final Level level, final BlockPos pos, final Direction direction) {
314
		return 0;
315
	}
316
317
	protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
318
		return Shapes.block();
319
	}
320
321
	protected VoxelShape getCollisionShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
322
		return this.hasCollision ? state.getShape(level, pos) : Shapes.empty();
323
	}
324
325
	protected VoxelShape getEntityInsideCollisionShape(final BlockState state, final BlockGetter level, final BlockPos pos, final Entity entity) {
326
		return Shapes.block();
327
	}
328
329
	protected boolean isCollisionShapeFullBlock(final BlockState state, final BlockGetter level, final BlockPos pos) {
330
		return Block.isShapeFullBlock(state.getCollisionShape(level, pos));
331
	}
332
333
	protected VoxelShape getVisualShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
334
		return this.getCollisionShape(state, level, pos, context);
335
	}
336
337
	protected void randomTick(final BlockState state, final ServerLevel level, final BlockPos pos, final RandomSource random) {
338
	}
339
340
	protected void tick(final BlockState state, final ServerLevel level, final BlockPos pos, final RandomSource random) {
341
	}
342
343
	protected float getDestroyProgress(final BlockState state, final Player player, final BlockGetter level, final BlockPos pos) {
344
		float destroySpeed = state.getDestroySpeed(level, pos);
345
		if (destroySpeed == -1.0F) {
346
			return 0.0F;
347
		}
348
349
		int modifier = player.hasCorrectToolForDrops(state) ? 30 : 100;
350
		return player.getDestroySpeed(state) / destroySpeed / modifier;
351
	}
352
353
	protected void spawnAfterBreak(final BlockState state, final ServerLevel level, final BlockPos pos, final ItemStack tool, final boolean dropExperience) {
354
	}
355
356
	protected void attack(final BlockState state, final Level level, final BlockPos pos, final Player player) {
357
	}
358
359
	protected boolean isSignalSource(final BlockState state) {
360
		return false;
361
	}
362
363
	protected boolean shouldRedstoneWireConnectTo(final BlockState state, final BlockGetter level, final BlockPos pos, final @Nullable Direction direction) {
364
		return state.isSignalSource() && direction != null;
365
	}
366
367
	protected int getSignal(final BlockState state, final BlockGetter level, final BlockPos pos, final Direction direction) {
368
		return this.ownSignal(state, level, pos);
369
	}
370
371
	protected int ownSignal(final BlockState state, final BlockGetter level, final BlockPos pos) {
372
		return 0;
373
	}
374
375
	protected void entityInside(
376
		final BlockState state, final Level level, final BlockPos pos, final Entity entity, final InsideBlockEffectApplier effectApplier, final boolean isPrecise
377
	) {
378
	}
379
380
	protected int getDirectSignal(final BlockState state, final BlockGetter level, final BlockPos pos, final Direction direction) {
381
		return 0;
382
	}
383
384
	public final Optional<ResourceKey<LootTable>> getLootTable() {
385
		return this.drops;
386
	}
387
388
	public final String getDescriptionId() {
389
		return this.descriptionId;
390
	}
391
392
	protected void onProjectileHit(final Level level, final BlockState state, final BlockHitResult blockHit, final Projectile projectile) {
393
	}
394
395
	protected boolean propagatesSkylightDown(final BlockState state) {
396
		return !Block.isShapeFullBlock(state.getShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO)) && state.getFluidState().isEmpty();
397
	}
398
399
	protected boolean isRandomlyTicking(final BlockState state) {
400
		return this.isRandomlyTicking;
401
	}
402
403
	protected SoundType getSoundType(final BlockState state) {
404
		return this.soundType;
405
	}
406
407
	protected ItemStack getCloneItemStack(final LevelReader level, final BlockPos pos, final BlockState state, final boolean includeData) {
408
		return new ItemStack(this.asItem());
409
	}
410
411
	public abstract Item asItem();
412
413
	protected abstract Block asBlock();
414
415
	public MapColor defaultMapColor() {
416
		return this.properties.mapColor.apply(this.asBlock().defaultBlockState());
417
	}
418
419
	public float defaultDestroyTime() {
420
		return this.properties.destroyTime;
421
	}
422
423
	public abstract static class BlockStateBase extends StateHolder<Block, BlockState> implements TypedInstance<Block> {
424
		private static final Direction[] DIRECTIONS = Direction.values();
425
		private static final VoxelShape[] EMPTY_OCCLUSION_SHAPES = Util.make(new VoxelShape[DIRECTIONS.length], s -> Arrays.fill(s, Shapes.empty()));
426
		private static final VoxelShape[] FULL_BLOCK_OCCLUSION_SHAPES = Util.make(new VoxelShape[DIRECTIONS.length], s -> Arrays.fill(s, Shapes.block()));
427
		private final int lightEmission;
428
		private final boolean useShapeForLightOcclusion;
429
		private final boolean isAir;
430
		private final boolean ignitedByLava;
431
		@Deprecated
432
		private final boolean liquid;
433
		@Deprecated
434
		private boolean legacySolid;
435
		private final PushReaction pushReaction;
436
		private final MapColor mapColor;
437
		private final float destroySpeed;
438
		private final boolean requiresCorrectToolForDrops;
439
		private final boolean canOcclude;
440
		private final BlockBehaviour.StatePredicate isRedstoneConductor;
441
		private final BlockBehaviour.StatePredicate isSuffocating;
442
		private final BlockBehaviour.StateArgumentPredicate<AABB> isViewBlocking;
443
		private final BlockBehaviour.PostProcess postProcess;
444
		private final Predicate<BlockState> emissiveRendering;
445
		private final BlockBehaviour.@Nullable OffsetFunction offsetFunction;
446
		private final boolean spawnTerrainParticles;
447
		private final NoteBlockInstrument instrument;
448
		private final boolean replaceable;
449
		private BlockBehaviour.BlockStateBase.@Nullable Cache cache;
450
		private FluidState fluidState = Fluids.EMPTY.defaultFluidState();
451
		private boolean isRandomlyTicking;
452
		private boolean solidRender;
453
		private VoxelShape occlusionShape;
454
		private VoxelShape[] occlusionShapesByFace;
455
		private boolean propagatesSkylightDown;
456
		private int lightDampening;
457
458
		protected BlockStateBase(final Block owner, final Property<?>[] propertyKeys, final Comparable<?>[] propertyValues) {
459
			super(owner, propertyKeys, propertyValues);
460
			BlockBehaviour.Properties properties = owner.properties;
461
			this.lightEmission = properties.lightEmission.applyAsInt(this.asState());
462
			this.useShapeForLightOcclusion = owner.useShapeForLightOcclusion(this.asState());
463
			this.isAir = properties.isAir;
464
			this.ignitedByLava = properties.ignitedByLava;
465
			this.liquid = properties.liquid;
466
			this.pushReaction = properties.pushReaction;
467
			this.mapColor = properties.mapColor.apply(this.asState());
468
			this.destroySpeed = properties.destroyTime;
469
			this.requiresCorrectToolForDrops = properties.requiresCorrectToolForDrops;
470
			this.canOcclude = properties.canOcclude;
471
			this.isRedstoneConductor = properties.isRedstoneConductor;
472
			this.isSuffocating = properties.isSuffocating;
473
			this.isViewBlocking = properties.isViewBlocking;
474
			this.postProcess = properties.postProcess;
475
			this.emissiveRendering = properties.emissiveRendering;
476
			this.offsetFunction = properties.offsetFunction;
477
			this.spawnTerrainParticles = properties.spawnTerrainParticles;
478
			this.instrument = properties.instrument;
479
			this.replaceable = properties.replaceable;
480
		}
481
482
		private boolean calculateSolid() {
483
			if (this.owner.properties.forceSolidOn) {
484
				return SolidDebugger.logAndGet(this.typeHolder(), SolidDebugger.Reason.FORCE_SOLID_ON);
485
			} else if (this.owner.properties.forceSolidOff) {
486
				return SolidDebugger.logAndGet(this.typeHolder(), SolidDebugger.Reason.FORCE_SOLID_OFF);
487
			} else if (this.cache == null) {
488
				return SolidDebugger.logAndGet(this.typeHolder(), SolidDebugger.Reason.NULL_CACHE);
489
			} else {
490
				VoxelShape shape = this.cache.collisionShape;
491
				if (shape.isEmpty()) {
492
					return SolidDebugger.logAndGet(this.typeHolder(), SolidDebugger.Reason.EMPTY_COLLISION_SHAPE);
493
				} else {
494
					AABB bounds = shape.bounds();
495
					if (bounds.getSize() >= 0.7291666666666666) {
496
						return SolidDebugger.logAndGet(this.typeHolder(), SolidDebugger.Reason.LARGE_ENOUGH_COLLISION_SHAPE);
497
					} else {
498
						return bounds.getYsize() >= 1.0
499
							? SolidDebugger.logAndGet(this.typeHolder(), SolidDebugger.Reason.HIGH_ENOUGH_COLLISION_SHAPE)
500
							: SolidDebugger.logAndGet(this.typeHolder(), SolidDebugger.Reason.FALLTHROUGH);
501
					}
502
				}
503
			}
504
		}
505
506
		public void initCache() {
507
			this.fluidState = this.owner.getFluidState(this.asState());
508
			this.isRandomlyTicking = this.owner.isRandomlyTicking(this.asState());
509
			if (!this.getBlock().hasDynamicShape()) {
510
				this.cache = new BlockBehaviour.BlockStateBase.Cache(this.asState());
511
			}
512
513
			this.legacySolid = this.calculateSolid();
514
			this.occlusionShape = this.canOcclude ? this.owner.getOcclusionShape(this.asState()) : Shapes.empty();
515
			this.solidRender = Block.isShapeFullBlock(this.occlusionShape);
516
			if (this.occlusionShape.isEmpty()) {
517
				this.occlusionShapesByFace = EMPTY_OCCLUSION_SHAPES;
518
			} else if (this.solidRender) {
519
				this.occlusionShapesByFace = FULL_BLOCK_OCCLUSION_SHAPES;
520
			} else {
521
				this.occlusionShapesByFace = new VoxelShape[DIRECTIONS.length];
522
523
				for (Direction direction : DIRECTIONS) {
524
					this.occlusionShapesByFace[direction.ordinal()] = this.occlusionShape.getFaceShape(direction);
525
				}
526
			}
527
528
			this.propagatesSkylightDown = this.owner.propagatesSkylightDown(this.asState());
529
			this.lightDampening = this.owner.getLightDampening(this.asState());
530
		}
531
532
		public Block getBlock() {
533
			return this.owner;
534
		}
535
536
		@Override
537
		public Holder<Block> typeHolder() {
538
			return this.getBlock().builtInRegistryHolder();
539
		}
540
541
		@Deprecated
542
		public boolean isSolid() {
543
			return this.legacySolid;
544
		}
545
546
		public boolean isValidSpawn(final BlockGetter level, final BlockPos pos, final EntityType<?> type) {
547
			return this.getBlock().properties.isValidSpawn.test(this.asState(), level, pos, type);
548
		}
549
550
		public boolean propagatesSkylightDown() {
551
			return this.propagatesSkylightDown;
552
		}
553
554
		public int getLightDampening() {
555
			return this.lightDampening;
556
		}
557
558
		public VoxelShape getFaceOcclusionShape(final Direction direction) {
559
			return this.occlusionShapesByFace[direction.ordinal()];
560
		}
561
562
		public VoxelShape getOcclusionShape() {
563
			return this.occlusionShape;
564
		}
565
566
		public boolean hasLargeCollisionShape() {
567
			return this.cache == null || this.cache.largeCollisionShape;
568
		}
569
570
		public boolean useShapeForLightOcclusion() {
571
			return this.useShapeForLightOcclusion;
572
		}
573
574
		public int getLightEmission() {
575
			return this.lightEmission;
576
		}
577
578
		public boolean isAir() {
579
			return this.isAir;
580
		}
581
582
		public boolean ignitedByLava() {
583
			return this.ignitedByLava;
584
		}
585
586
		@Deprecated
587
		public boolean liquid() {
588
			return this.liquid;
589
		}
590
591
		public MapColor getMapColor(final BlockGetter level, final BlockPos pos) {
592
			return this.mapColor;
593
		}
594
595
		public BlockState rotate(final Rotation rotation) {
596
			return this.getBlock().rotate(this.asState(), rotation);
597
		}
598
599
		public BlockState mirror(final Mirror mirror) {
600
			return this.getBlock().mirror(this.asState(), mirror);
601
		}
602
603
		public RenderShape getRenderShape() {
604
			return this.getBlock().getRenderShape(this.asState());
605
		}
606
607
		public boolean emissiveRendering() {
608
			return this.emissiveRendering.test(this.asState());
609
		}
610
611
		public float getShadeBrightness(final BlockGetter level, final BlockPos pos) {
612
			return this.getBlock().getShadeBrightness(this.asState(), level, pos);
613
		}
614
615
		public boolean isRedstoneConductor(final BlockGetter level, final BlockPos pos) {
616
			return this.isRedstoneConductor.test(this.asState(), level, pos);
617
		}
618
619
		public boolean isSignalSource() {
620
			return this.getBlock().isSignalSource(this.asState());
621
		}
622
623
		public boolean shouldRedstoneWireConnectTo(final BlockGetter level, final BlockPos pos, final @Nullable Direction direction) {
624
			return this.getBlock().shouldRedstoneWireConnectTo(this.asState(), level, pos, direction);
625
		}
626
627
		public int getOwnSignal(final BlockGetter level, final BlockPos pos) {
628
			return this.getBlock().ownSignal(this.asState(), level, pos);
629
		}
630
631
		public int getSignal(final BlockGetter level, final BlockPos pos, final Direction direction) {
632
			return this.getBlock().getSignal(this.asState(), level, pos, direction);
633
		}
634
635
		public boolean hasAnalogOutputSignal() {
636
			return this.getBlock().hasAnalogOutputSignal(this.asState());
637
		}
638
639
		public int getAnalogOutputSignal(final Level level, final BlockPos pos, final Direction direction) {
640
			return this.getBlock().getAnalogOutputSignal(this.asState(), level, pos, direction);
641
		}
642
643
		public float getDestroySpeed(final BlockGetter level, final BlockPos pos) {
644
			return this.destroySpeed;
645
		}
646
647
		public float getDestroyProgress(final Player player, final BlockGetter level, final BlockPos pos) {
648
			return this.getBlock().getDestroyProgress(this.asState(), player, level, pos);
649
		}
650
651
		public int getDirectSignal(final BlockGetter level, final BlockPos pos, final Direction direction) {
652
			return this.getBlock().getDirectSignal(this.asState(), level, pos, direction);
653
		}
654
655
		public PushReaction getPistonPushReaction() {
656
			return this.pushReaction;
657
		}
658
659
		public boolean isSolidRender() {
660
			return this.solidRender;
661
		}
662
663
		public boolean canOcclude() {
664
			return this.canOcclude;
665
		}
666
667
		public boolean skipRendering(final BlockState neighborState, final Direction direction) {
668
			return this.getBlock().skipRendering(this.asState(), neighborState, direction);
669
		}
670
671
		public VoxelShape getShape(final BlockGetter level, final BlockPos pos) {
672
			return this.getShape(level, pos, CollisionContext.empty());
673
		}
674
675
		public VoxelShape getShape(final BlockGetter level, final BlockPos pos, final CollisionContext context) {
676
			return this.getBlock().getShape(this.asState(), level, pos, context);
677
		}
678
679
		public VoxelShape getCollisionShape(final BlockGetter level, final BlockPos pos) {
680
			return this.cache != null ? this.cache.collisionShape : this.getCollisionShape(level, pos, CollisionContext.empty());
681
		}
682
683
		public VoxelShape getCollisionShape(final BlockGetter level, final BlockPos pos, final CollisionContext context) {
684
			return this.getBlock().getCollisionShape(this.asState(), level, pos, context);
685
		}
686
687
		public VoxelShape getEntityInsideCollisionShape(final BlockGetter level, final BlockPos pos, final Entity entity) {
688
			return this.getBlock().getEntityInsideCollisionShape(this.asState(), level, pos, entity);
689
		}
690
691
		public VoxelShape getBlockSupportShape(final BlockGetter level, final BlockPos pos) {
692
			return this.getBlock().getBlockSupportShape(this.asState(), level, pos);
693
		}
694
695
		public VoxelShape getVisualShape(final BlockGetter level, final BlockPos pos, final CollisionContext context) {
696
			return this.getBlock().getVisualShape(this.asState(), level, pos, context);
697
		}
698
699
		public VoxelShape getInteractionShape(final BlockGetter level, final BlockPos pos) {
700
			return this.getBlock().getInteractionShape(this.asState(), level, pos);
701
		}
702
703
		public final boolean entityCanStandOn(final BlockGetter level, final BlockPos pos, final Entity entity) {
704
			return this.entityCanStandOnFace(level, pos, entity, Direction.UP);
705
		}
706
707
		public final boolean entityCanStandOnFace(final BlockGetter level, final BlockPos pos, final Entity entity, final Direction faceDirection) {
708
			return Block.isFaceFull(this.getCollisionShape(level, pos, CollisionContext.of(entity)), faceDirection);
709
		}
710
711
		public Vec3 getOffset(final BlockPos pos) {
712
			BlockBehaviour.OffsetFunction function = this.offsetFunction;
713
			return function != null ? function.evaluate(this.asState(), pos) : Vec3.ZERO;
714
		}
715
716
		public boolean hasOffsetFunction() {
717
			return this.offsetFunction != null;
718
		}
719
720
		public boolean triggerEvent(final Level level, final BlockPos pos, final int b0, final int b1) {
721
			return this.getBlock().triggerEvent(this.asState(), level, pos, b0, b1);
722
		}
723
724
		public void handleNeighborChanged(
725
			final Level level, final BlockPos pos, final Block block, final @Nullable Orientation orientation, final boolean movedByPiston
726
		) {
727
			this.getBlock().neighborChanged(this.asState(), level, pos, block, orientation, movedByPiston);
728
		}
729
730
		public final void updateNeighbourShapes(final LevelAccessor level, final BlockPos pos, final @Block.UpdateFlags int updateFlags) {
731
			this.updateNeighbourShapes(level, pos, updateFlags, 512);
732
		}
733
734
		public final void updateNeighbourShapes(final LevelAccessor level, final BlockPos pos, final @Block.UpdateFlags int updateFlags, final int updateLimit) {
735
			BlockPos.MutableBlockPos blockPos = new BlockPos.MutableBlockPos();
736
737
			for (Direction direction : BlockBehaviour.UPDATE_SHAPE_ORDER) {
738
				blockPos.setWithOffset(pos, direction);
739
				level.neighborShapeChanged(direction.getOpposite(), blockPos, pos, this.asState(), updateFlags, updateLimit);
740
			}
741
		}
742
743
		public final void updateIndirectNeighbourShapes(final LevelAccessor level, final BlockPos pos, final @Block.UpdateFlags int updateFlags) {
744
			this.updateIndirectNeighbourShapes(level, pos, updateFlags, 512);
745
		}
746
747
		public void updateIndirectNeighbourShapes(final LevelAccessor level, final BlockPos pos, final @Block.UpdateFlags int updateFlags, final int updateLimit) {
748
			this.getBlock().updateIndirectNeighbourShapes(this.asState(), level, pos, updateFlags, updateLimit);
749
		}
750
751
		public void onPlace(final Level level, final BlockPos pos, final BlockState oldState, final boolean movedByPiston) {
752
			this.getBlock().onPlace(this.asState(), level, pos, oldState, movedByPiston);
753
		}
754
755
		public void affectNeighborsAfterRemoval(final ServerLevel level, final BlockPos pos, final boolean movedByPiston) {
756
			this.getBlock().affectNeighborsAfterRemoval(this.asState(), level, pos, movedByPiston);
757
		}
758
759
		public void onExplosionHit(final ServerLevel level, final BlockPos pos, final Explosion explosion, final BiConsumer<ItemStack, BlockPos> onHit) {
760
			this.getBlock().onExplosionHit(this.asState(), level, pos, explosion, onHit);
761
		}
762
763
		public void tick(final ServerLevel level, final BlockPos pos, final RandomSource random) {
764
			this.getBlock().tick(this.asState(), level, pos, random);
765
		}
766
767
		public void randomTick(final ServerLevel level, final BlockPos pos, final RandomSource random) {
768
			this.getBlock().randomTick(this.asState(), level, pos, random);
769
		}
770
771
		public void entityInside(final Level level, final BlockPos pos, final Entity entity, final InsideBlockEffectApplier effectApplier, final boolean isPrecise) {
772
			this.getBlock().entityInside(this.asState(), level, pos, entity, effectApplier, isPrecise);
773
		}
774
775
		public void spawnAfterBreak(final ServerLevel level, final BlockPos pos, final ItemStack tool, final boolean dropExperience) {
776
			this.getBlock().spawnAfterBreak(this.asState(), level, pos, tool, dropExperience);
777
		}
778
779
		public List<ItemStack> getDrops(final LootParams.Builder params) {
780
			return this.getBlock().getDrops(this.asState(), params);
781
		}
782
783
		public InteractionResult useItemOn(
784
			final ItemStack itemStack, final Level level, final Player player, final InteractionHand hand, final BlockHitResult hitResult
785
		) {
786
			return this.getBlock().useItemOn(itemStack, this.asState(), level, hitResult.getBlockPos(), player, hand, hitResult);
787
		}
788
789
		public InteractionResult useWithoutItem(final Level level, final Player player, final BlockHitResult hitResult) {
790
			return this.getBlock().useWithoutItem(this.asState(), level, hitResult.getBlockPos(), player, hitResult);
791
		}
792
793
		public boolean showAsInteractableInSpectatorMode(final Level level, final BlockPos pos, final BlockHitResult hitResult) {
794
			return this.getBlock().showAsInteractableInSpectatorMode(this.asState(), level, pos, hitResult);
795
		}
796
797
		public void attack(final Level level, final BlockPos pos, final Player player) {
798
			this.getBlock().attack(this.asState(), level, pos, player);
799
		}
800
801
		public boolean isSuffocating(final BlockGetter level, final BlockPos pos) {
802
			return this.isSuffocating.test(this.asState(), level, pos);
803
		}
804
805
		public boolean isLightPermeable() {
806
			return !this.solidRender || this.getLightDampening() == 0;
807
		}
808
809
		public boolean isViewBlocking(final BlockGetter level, final BlockPos blockPos, final AABB nearPlaneBox) {
810
			return this.isViewBlocking.test(this.asState(), level, blockPos, nearPlaneBox);
811
		}
812
813
		public BlockState updateShape(
814
			final LevelReader level,
815
			final ScheduledTickAccess ticks,
816
			final BlockPos pos,
817
			final Direction directionToNeighbour,
818
			final BlockPos neighbourPos,
819
			final BlockState neighbourState,
820
			final RandomSource random
821
		) {
822
			return this.getBlock().updateShape(this.asState(), level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random);
823
		}
824
825
		public boolean isPathfindable(final PathComputationType type) {
826
			return this.getBlock().isPathfindable(this.asState(), type);
827
		}
828
829
		public boolean canBeReplaced(final BlockPlaceContext context) {
830
			return this.getBlock().canBeReplaced(this.asState(), context);
831
		}
832
833
		public boolean canBeReplaced(final Fluid fluid) {
834
			return this.getBlock().canBeReplaced(this.asState(), fluid);
835
		}
836
837
		public boolean canBeReplaced() {
838
			return this.replaceable;
839
		}
840
841
		public boolean canSurvive(final LevelReader level, final BlockPos pos) {
842
			return this.getBlock().canSurvive(this.asState(), level, pos);
843
		}
844
845
		public @Nullable BlockPos getPostProcessPos(final BlockGetter level, final BlockPos pos) {
846
			return this.postProcess.getPostProcessPos(this.asState(), level, pos);
847
		}
848
849
		public @Nullable MenuProvider getMenuProvider(final Level level, final BlockPos pos) {
850
			return this.getBlock().getMenuProvider(this.asState(), level, pos);
851
		}
852
853
		public boolean is(final TagKey<Block> tag, final Predicate<BlockBehaviour.BlockStateBase> predicate) {
854
			return this.is(tag) && predicate.test(this);
855
		}
856
857
		public boolean hasBlockEntity() {
858
			return this.getBlock() instanceof EntityBlock;
859
		}
860
861
		public boolean shouldChangedStateKeepBlockEntity(final BlockState oldState) {
862
			return this.getBlock().shouldChangedStateKeepBlockEntity(oldState);
863
		}
864
865
		public <T extends BlockEntity> @Nullable BlockEntityTicker<T> getTicker(final Level level, final BlockEntityType<T> type) {
866
			return this.getBlock() instanceof EntityBlock ? ((EntityBlock)this.getBlock()).getTicker(level, this.asState(), type) : null;
867
		}
868
869
		public FluidState getFluidState() {
870
			return this.fluidState;
871
		}
872
873
		public boolean isRandomlyTicking() {
874
			return this.isRandomlyTicking;
875
		}
876
877
		public long getSeed(final BlockPos pos) {
878
			return this.getBlock().getSeed(this.asState(), pos);
879
		}
880
881
		public SoundType getSoundType() {
882
			return this.getBlock().getSoundType(this.asState());
883
		}
884
885
		public void onProjectileHit(final Level level, final BlockState state, final BlockHitResult blockHit, final Projectile entity) {
886
			this.getBlock().onProjectileHit(level, state, blockHit, entity);
887
		}
888
889
		public boolean isFaceSturdy(final BlockGetter level, final BlockPos pos, final Direction direction) {
890
			return this.isFaceSturdy(level, pos, direction, SupportType.FULL);
891
		}
892
893
		public boolean isFaceSturdy(final BlockGetter level, final BlockPos pos, final Direction direction, final SupportType supportType) {
894
			return this.cache != null ? this.cache.isFaceSturdy(direction, supportType) : supportType.isSupporting(this.asState(), level, pos, direction);
895
		}
896
897
		public boolean isCollisionShapeFullBlock(final BlockGetter level, final BlockPos pos) {
898
			return this.cache != null ? this.cache.isCollisionShapeFullBlock : this.getBlock().isCollisionShapeFullBlock(this.asState(), level, pos);
899
		}
900
901
		public ItemStack getCloneItemStack(final LevelReader level, final BlockPos pos, final boolean includeData) {
902
			return this.getBlock().getCloneItemStack(level, pos, this.asState(), includeData);
903
		}
904
905
		protected abstract BlockState asState();
906
907
		public boolean requiresCorrectToolForDrops() {
908
			return this.requiresCorrectToolForDrops;
909
		}
910
911
		public boolean shouldSpawnTerrainParticles() {
912
			return this.spawnTerrainParticles;
913
		}
914
915
		public BlockState withPropertiesOf(final BlockState source) {
916
			BlockState result = this.asState();
917
918
			for (Property<?> property : source.getBlock().getStateDefinition().getProperties()) {
919
				result = copyProperty(source, result, property);
920
			}
921
922
			return result;
923
		}
924
925
		public static <T extends Comparable<T>> BlockState copyProperty(final BlockState from, final BlockState to, final Property<T> property) {
926
			return to.trySetValue(property, from.getValue(property));
927
		}
928
929
		public NoteBlockInstrument instrument() {
930
			return this.instrument;
931
		}
932
933
		private static final class Cache {
934
			private static final Direction[] DIRECTIONS = Direction.values();
935
			private static final int SUPPORT_TYPE_COUNT = SupportType.values().length;
936
			public final VoxelShape collisionShape;
937
			public final boolean largeCollisionShape;
938
			private final boolean[] faceSturdy;
939
			public final boolean isCollisionShapeFullBlock;
940
941
			private Cache(final BlockState state) {
942
				Block block = state.getBlock();
943
				this.collisionShape = block.getCollisionShape(state, EmptyBlockGetter.INSTANCE, BlockPos.ZERO, CollisionContext.empty());
944
				if (!this.collisionShape.isEmpty() && state.hasOffsetFunction()) {
945
					throw new IllegalStateException(
946
						String.format(
947
							Locale.ROOT, "%s has a collision shape and an offset type, but is not marked as dynamicShape in its properties.", BuiltInRegistries.BLOCK.getKey(block)
948
						)
949
					);
950
				}
951
952
				this.largeCollisionShape = Arrays.stream(Direction.Axis.values())
953
					.anyMatch(axis -> this.collisionShape.min(axis) < 0.0 || this.collisionShape.max(axis) > 1.0);
954
				this.faceSturdy = new boolean[DIRECTIONS.length * SUPPORT_TYPE_COUNT];
955
956
				for (Direction direction : DIRECTIONS) {
957
					for (SupportType type : SupportType.values()) {
958
						this.faceSturdy[getFaceSupportIndex(direction, type)] = type.isSupporting(state, EmptyBlockGetter.INSTANCE, BlockPos.ZERO, direction);
959
					}
960
				}
961
962
				this.isCollisionShapeFullBlock = Block.isShapeFullBlock(state.getCollisionShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO));
963
			}
964
965
			public boolean isFaceSturdy(final Direction direction, final SupportType supportType) {
966
				return this.faceSturdy[getFaceSupportIndex(direction, supportType)];
967
			}
968
969
			private static int getFaceSupportIndex(final Direction direction, final SupportType supportType) {
970
				return direction.ordinal() * SUPPORT_TYPE_COUNT + supportType.ordinal();
971
			}
972
		}
973
	}
974
975
	@FunctionalInterface
976
	public interface OffsetFunction {
977
		Vec3 evaluate(BlockState state, BlockPos pos);
978
	}
979
980
	public enum OffsetType {
981
		NONE,
982
		XZ,
983
		XYZ;
984
	}
985
986
	@FunctionalInterface
987
	public interface PostProcess {
988
		@Nullable BlockPos getPostProcessPos(BlockState state, BlockGetter level, BlockPos pos);
989
	}
990
991
	public static class Properties implements FabricProperties {
992
		private Function<BlockState, MapColor> mapColor = state -> MapColor.NONE;
993
		private boolean hasCollision = true;
994
		private SoundType soundType = SoundType.STONE;
995
		private ToIntFunction<BlockState> lightEmission = state -> 0;
996
		private float explosionResistance;
997
		private float destroyTime;
998
		private boolean requiresCorrectToolForDrops;
999
		private boolean isRandomlyTicking;
1000
		private float friction = 0.6F;
1001
		private float speedFactor = 1.0F;
1002
		private float jumpFactor = 1.0F;
1003
		private float bounceRestitution;
1004
		private @Nullable ResourceKey<Block> id;
1005
		private DependantName<Block, Optional<ResourceKey<LootTable>>> drops = id -> Optional.of(
1006
			ResourceKey.create(Registries.LOOT_TABLE, id.identifier().withPrefix("blocks/"))
1007
		);
1008
		private DependantName<Block, String> descriptionId = id -> Util.makeDescriptionId("block", id.identifier());
1009
		private boolean canOcclude = true;
1010
		private boolean isAir;
1011
		private boolean ignitedByLava;
1012
		@Deprecated
1013
		private boolean liquid;
1014
		@Deprecated
1015
		private boolean forceSolidOff;
1016
		private boolean forceSolidOn;
1017
		private PushReaction pushReaction = PushReaction.PUSH_PULL;
1018
		private boolean spawnTerrainParticles = true;
1019
		private NoteBlockInstrument instrument = NoteBlockInstrument.HARP;
1020
		private boolean replaceable;
1021
		private BlockBehaviour.StateArgumentPredicate<EntityType<?>> isValidSpawn = (state, level, pos, entityType) -> state.isFaceSturdy(level, pos, Direction.UP)
1022
			&& state.getLightEmission() < 14;
1023
		private BlockBehaviour.StatePredicate isRedstoneConductor = BlockBehaviour.BlockStateBase::isCollisionShapeFullBlock;
1024
		private BlockBehaviour.StatePredicate isSuffocating = (state, level, pos) -> state.is(BlockTags.CAUSES_SUFFOCATION)
1025
			&& state.isCollisionShapeFullBlock(level, pos);
1026
		private BlockBehaviour.StateArgumentPredicate<AABB> isViewBlocking = (state, level, pos, var4) -> this.isSuffocating.test(state, level, pos);
1027
		private BlockBehaviour.PostProcess postProcess = (state, level, pos) -> null;
1028
		private Predicate<BlockState> emissiveRendering = var0 -> false;
1029
		private boolean dynamicShape;
1030
		private FeatureFlagSet requiredFeatures = FeatureFlags.VANILLA_SET;
1031
		private BlockBehaviour.@Nullable OffsetFunction offsetFunction;
1032
		private float fallDistanceReduction;
1033
1034
		private Properties() {
1035
		}
1036
1037
		public static BlockBehaviour.Properties of() {
1038
			return new BlockBehaviour.Properties();
1039
		}
1040
1041
		public static BlockBehaviour.Properties ofFullCopy(final BlockBehaviour block) {
1042
			BlockBehaviour.Properties copyTo = ofLegacyCopy(block);
1043
			BlockBehaviour.Properties copyFrom = block.properties;
1044
			copyTo.jumpFactor = copyFrom.jumpFactor;
1045
			copyTo.isRedstoneConductor = copyFrom.isRedstoneConductor;
1046
			copyTo.isValidSpawn = copyFrom.isValidSpawn;
1047
			copyTo.postProcess = copyFrom.postProcess;
1048
			copyTo.isSuffocating = copyFrom.isSuffocating;
1049
			copyTo.isViewBlocking = copyFrom.isViewBlocking;
1050
			copyTo.drops = copyFrom.drops;
1051
			copyTo.descriptionId = copyFrom.descriptionId;
1052
			return copyTo;
1053
		}
1054
1055
		@Deprecated
1056
		public static BlockBehaviour.Properties ofLegacyCopy(final BlockBehaviour block) {
1057
			BlockBehaviour.Properties copyTo = new BlockBehaviour.Properties();
1058
			BlockBehaviour.Properties copyFrom = block.properties;
1059
			copyTo.destroyTime = copyFrom.destroyTime;
1060
			copyTo.explosionResistance = copyFrom.explosionResistance;
1061
			copyTo.hasCollision = copyFrom.hasCollision;
1062
			copyTo.isRandomlyTicking = copyFrom.isRandomlyTicking;
1063
			copyTo.lightEmission = copyFrom.lightEmission;
1064
			copyTo.mapColor = copyFrom.mapColor;
1065
			copyTo.soundType = copyFrom.soundType;
1066
			copyTo.friction = copyFrom.friction;
1067
			copyTo.speedFactor = copyFrom.speedFactor;
1068
			copyTo.bounceRestitution = copyFrom.bounceRestitution;
1069
			copyTo.dynamicShape = copyFrom.dynamicShape;
1070
			copyTo.canOcclude = copyFrom.canOcclude;
1071
			copyTo.isAir = copyFrom.isAir;
1072
			copyTo.ignitedByLava = copyFrom.ignitedByLava;
1073
			copyTo.liquid = copyFrom.liquid;
1074
			copyTo.forceSolidOff = copyFrom.forceSolidOff;
1075
			copyTo.forceSolidOn = copyFrom.forceSolidOn;
1076
			copyTo.pushReaction = copyFrom.pushReaction;
1077
			copyTo.requiresCorrectToolForDrops = copyFrom.requiresCorrectToolForDrops;
1078
			copyTo.offsetFunction = copyFrom.offsetFunction;
1079
			copyTo.spawnTerrainParticles = copyFrom.spawnTerrainParticles;
1080
			copyTo.requiredFeatures = copyFrom.requiredFeatures;
1081
			copyTo.emissiveRendering = copyFrom.emissiveRendering;
1082
			copyTo.instrument = copyFrom.instrument;
1083
			copyTo.replaceable = copyFrom.replaceable;
1084
			return copyTo;
1085
		}
1086
1087
		public BlockBehaviour.Properties mapColor(final DyeColor dyeColor) {
1088
			this.mapColor = state -> dyeColor.getMapColor();
1089
			return this;
1090
		}
1091
1092
		public BlockBehaviour.Properties mapColor(final MapColor mapColor) {
1093
			this.mapColor = state -> mapColor;
1094
			return this;
1095
		}
1096
1097
		public BlockBehaviour.Properties mapColor(final Function<BlockState, MapColor> mapColor) {
1098
			this.mapColor = mapColor;
1099
			return this;
1100
		}
1101
1102
		public BlockBehaviour.Properties noCollision() {
1103
			this.hasCollision = false;
1104
			this.canOcclude = false;
1105
			return this;
1106
		}
1107
1108
		public BlockBehaviour.Properties noOcclusion() {
1109
			this.canOcclude = false;
1110
			return this;
1111
		}
1112
1113
		public BlockBehaviour.Properties friction(final float friction) {
1114
			this.friction = friction;
1115
			return this;
1116
		}
1117
1118
		public BlockBehaviour.Properties speedFactor(final float speedFactor) {
1119
			this.speedFactor = speedFactor;
1120
			return this;
1121
		}
1122
1123
		public BlockBehaviour.Properties jumpFactor(final float jumpFactor) {
1124
			this.jumpFactor = jumpFactor;
1125
			return this;
1126
		}
1127
1128
		public BlockBehaviour.Properties bounceRestitution(final float bounceRestitution) {
1129
			this.bounceRestitution = bounceRestitution;
1130
			return this;
1131
		}
1132
1133
		public BlockBehaviour.Properties fallDistanceReduction(final float fallDistanceReduction) {
1134
			this.fallDistanceReduction = fallDistanceReduction;
1135
			return this;
1136
		}
1137
1138
		public BlockBehaviour.Properties sound(final SoundType soundType) {
1139
			this.soundType = soundType;
1140
			return this;
1141
		}
1142
1143
		public BlockBehaviour.Properties lightLevel(final ToIntFunction<BlockState> lightEmission) {
1144
			this.lightEmission = lightEmission;
1145
			return this;
1146
		}
1147
1148
		public BlockBehaviour.Properties strength(final float destroyTime, final float explosionResistance) {
1149
			return this.destroyTime(destroyTime).explosionResistance(explosionResistance);
1150
		}
1151
1152
		public BlockBehaviour.Properties instabreak() {
1153
			return this.strength(0.0F);
1154
		}
1155
1156
		public BlockBehaviour.Properties strength(final float destroyTime) {
1157
			this.strength(destroyTime, destroyTime);
1158
			return this;
1159
		}
1160
1161
		public BlockBehaviour.Properties randomTicks() {
1162
			this.isRandomlyTicking = true;
1163
			return this;
1164
		}
1165
1166
		public BlockBehaviour.Properties dynamicShape() {
1167
			this.dynamicShape = true;
1168
			return this;
1169
		}
1170
1171
		public BlockBehaviour.Properties noLootTable() {
1172
			this.drops = DependantName.fixed(Optional.empty());
1173
			return this;
1174
		}
1175
1176
		public BlockBehaviour.Properties overrideLootTable(final Optional<ResourceKey<LootTable>> table) {
1177
			this.drops = DependantName.fixed(table);
1178
			return this;
1179
		}
1180
1181
		protected Optional<ResourceKey<LootTable>> effectiveDrops() {
1182
			return this.drops.get(Objects.requireNonNull(this.id, "Block id not set"));
1183
		}
1184
1185
		public BlockBehaviour.Properties ignitedByLava() {
1186
			this.ignitedByLava = true;
1187
			return this;
1188
		}
1189
1190
		public BlockBehaviour.Properties liquid() {
1191
			this.liquid = true;
1192
			return this;
1193
		}
1194
1195
		public BlockBehaviour.Properties forceSolidOn() {
1196
			this.forceSolidOn = true;
1197
			return this;
1198
		}
1199
1200
		@Deprecated
1201
		public BlockBehaviour.Properties forceSolidOff() {
1202
			this.forceSolidOff = true;
1203
			return this;
1204
		}
1205
1206
		public BlockBehaviour.Properties pushReaction(final PushReaction pushReaction) {
1207
			this.pushReaction = pushReaction;
1208
			return this;
1209
		}
1210
1211
		public BlockBehaviour.Properties air() {
1212
			this.isAir = true;
1213
			return this;
1214
		}
1215
1216
		public BlockBehaviour.Properties isValidSpawn(final BlockBehaviour.StateArgumentPredicate<EntityType<?>> isValidSpawn) {
1217
			this.isValidSpawn = isValidSpawn;
1218
			return this;
1219
		}
1220
1221
		public BlockBehaviour.Properties isRedstoneConductor(final BlockBehaviour.StatePredicate isRedstoneConductor) {
1222
			this.isRedstoneConductor = isRedstoneConductor;
1223
			return this;
1224
		}
1225
1226
		public BlockBehaviour.Properties isSuffocating(final BlockBehaviour.StatePredicate isSuffocating) {
1227
			this.isSuffocating = isSuffocating;
1228
			return this;
1229
		}
1230
1231
		public BlockBehaviour.Properties isViewBlocking(final BlockBehaviour.StateArgumentPredicate<AABB> isViewBlocking) {
1232
			this.isViewBlocking = isViewBlocking;
1233
			return this;
1234
		}
1235
1236
		public BlockBehaviour.Properties postProcess(final BlockBehaviour.PostProcess postProcess) {
1237
			this.postProcess = postProcess;
1238
			return this;
1239
		}
1240
1241
		public BlockBehaviour.Properties emissiveRendering(final Predicate<BlockState> emissiveRendering) {
1242
			this.emissiveRendering = emissiveRendering;
1243
			return this;
1244
		}
1245
1246
		public BlockBehaviour.Properties requiresCorrectToolForDrops() {
1247
			this.requiresCorrectToolForDrops = true;
1248
			return this;
1249
		}
1250
1251
		public BlockBehaviour.Properties destroyTime(final float destroyTime) {
1252
			this.destroyTime = destroyTime;
1253
			return this;
1254
		}
1255
1256
		public BlockBehaviour.Properties explosionResistance(final float explosionResistance) {
1257
			this.explosionResistance = Math.max(0.0F, explosionResistance);
1258
			return this;
1259
		}
1260
1261
		public BlockBehaviour.Properties offsetType(final BlockBehaviour.OffsetType offsetType) {
1262
			this.offsetFunction = switch (offsetType) {
1263
				case NONE -> null;
1264
				case XZ -> (state, pos) -> {
1265
					Block block = state.getBlock();
1266
					long seed = Mth.getSeed(pos.getX(), 0, pos.getZ());
1267
					float maxHorizontalOffset = block.getMaxHorizontalOffset();
1268
					double x = Mth.clamp(((float)(seed & 15L) / 15.0F - 0.5) * 0.5, -maxHorizontalOffset, maxHorizontalOffset);
1269
					double z = Mth.clamp(((float)(seed >> 8 & 15L) / 15.0F - 0.5) * 0.5, -maxHorizontalOffset, maxHorizontalOffset);
1270
					return new Vec3(x, 0.0, z);
1271
				};
1272
				case XYZ -> (state, pos) -> {
1273
					Block block = state.getBlock();
1274
					long seed = Mth.getSeed(pos.getX(), 0, pos.getZ());
1275
					double y = ((float)(seed >> 4 & 15L) / 15.0F - 1.0) * block.getMaxVerticalOffset();
1276
					float maxHorizontalOffset = block.getMaxHorizontalOffset();
1277
					double x = Mth.clamp(((float)(seed & 15L) / 15.0F - 0.5) * 0.5, -maxHorizontalOffset, maxHorizontalOffset);
1278
					double z = Mth.clamp(((float)(seed >> 8 & 15L) / 15.0F - 0.5) * 0.5, -maxHorizontalOffset, maxHorizontalOffset);
1279
					return new Vec3(x, y, z);
1280
				};
1281
			};
1282
			return this;
1283
		}
1284
1285
		public BlockBehaviour.Properties noTerrainParticles() {
1286
			this.spawnTerrainParticles = false;
1287
			return this;
1288
		}
1289
1290
		public BlockBehaviour.Properties requiredFeatures(final FeatureFlag... flags) {
1291
			this.requiredFeatures = FeatureFlags.REGISTRY.subset(flags);
1292
			return this;
1293
		}
1294
1295
		public BlockBehaviour.Properties instrument(final NoteBlockInstrument instrument) {
1296
			this.instrument = instrument;
1297
			return this;
1298
		}
1299
1300
		public BlockBehaviour.Properties replaceable() {
1301
			this.replaceable = true;
1302
			return this;
1303
		}
1304
1305
		public BlockBehaviour.Properties setId(final ResourceKey<Block> id) {
1306
			this.id = id;
1307
			return this;
1308
		}
1309
1310
		public BlockBehaviour.Properties overrideDescription(final String descriptionId) {
1311
			this.descriptionId = DependantName.fixed(descriptionId);
1312
			return this;
1313
		}
1314
1315
		protected String effectiveDescriptionId() {
1316
			return this.descriptionId.get(Objects.requireNonNull(this.id, "Block id not set"));
1317
		}
1318
	}
1319
1320
	@FunctionalInterface
1321
	public interface StateArgumentPredicate<A> {
1322
		boolean test(BlockState state, BlockGetter level, BlockPos pos, A a);
1323
	}
1324
1325
	@FunctionalInterface
1326
	public interface StatePredicate {
1327
		boolean test(BlockState state, BlockGetter level, BlockPos pos);
1328
	}
1329
}
1330

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