BlockBox .java

net.minecraft.core.BlockBox (record, 90 lines): members: min, max, isBlock, include, extend, sizeZ, aabb, sizeX, sizeY, iterator, move, contains, offset.

net.minecraft.corerecord90 linescommon2.6 KB

Implements

API Surface (15)

BlockBox decode(final ByteBuf input)
void encode(final ByteBuf output, final BlockBox value)
BlockBox of(final BlockPos pos)
BlockBox of(final BlockPos a, final BlockPos b)
BlockBox include(final BlockPos pos)
boolean isBlock()
boolean contains(final BlockPos pos)
AABB aabb()
Iterator<BlockPos> iterator()
int sizeX()
int sizeY()
int sizeZ()
BlockBox extend(final Direction direction, final int amount)
BlockBox move(final Direction direction, final int amount)
BlockBox offset(final Vec3i offset)

Fields & Constants (1)

STREAM_CODEC

Code Graph: Dependencies (6)

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

Full Source

BlockBox.java90 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.core;
2
3
import io.netty.buffer.ByteBuf;
4
import java.util.Iterator;
5
import net.minecraft.network.FriendlyByteBuf;
6
import net.minecraft.network.codec.StreamCodec;
7
import net.minecraft.world.phys.AABB;
8
9
public record BlockBox(BlockPos min, BlockPos max) implements Iterable<BlockPos> {
10
	public static final StreamCodec<ByteBuf, BlockBox> STREAM_CODEC = new StreamCodec<ByteBuf, BlockBox>() {
11
		public BlockBox decode(final ByteBuf input) {
12
			return new BlockBox(FriendlyByteBuf.readBlockPos(input), FriendlyByteBuf.readBlockPos(input));
13
		}
14
15
		public void encode(final ByteBuf output, final BlockBox value) {
16
			FriendlyByteBuf.writeBlockPos(output, value.min());
17
			FriendlyByteBuf.writeBlockPos(output, value.max());
18
		}
19
	};
20
21
	public BlockBox(final BlockPos min, final BlockPos max) {
22
		this.min = BlockPos.min(min, max);
23
		this.max = BlockPos.max(min, max);
24
	}
25
26
	public static BlockBox of(final BlockPos pos) {
27
		return new BlockBox(pos, pos);
28
	}
29
30
	public static BlockBox of(final BlockPos a, final BlockPos b) {
31
		return new BlockBox(a, b);
32
	}
33
34
	public BlockBox include(final BlockPos pos) {
35
		return new BlockBox(BlockPos.min(this.min, pos), BlockPos.max(this.max, pos));
36
	}
37
38
	public boolean isBlock() {
39
		return this.min.equals(this.max);
40
	}
41
42
	public boolean contains(final BlockPos pos) {
43
		return pos.getX() >= this.min.getX()
44
			&& pos.getY() >= this.min.getY()
45
			&& pos.getZ() >= this.min.getZ()
46
			&& pos.getX() <= this.max.getX()
47
			&& pos.getY() <= this.max.getY()
48
			&& pos.getZ() <= this.max.getZ();
49
	}
50
51
	public AABB aabb() {
52
		return AABB.encapsulatingFullBlocks(this.min, this.max);
53
	}
54
55
	@Override
56
	public Iterator<BlockPos> iterator() {
57
		return BlockPos.betweenClosed(this.min, this.max).iterator();
58
	}
59
60
	public int sizeX() {
61
		return this.max.getX() - this.min.getX() + 1;
62
	}
63
64
	public int sizeY() {
65
		return this.max.getY() - this.min.getY() + 1;
66
	}
67
68
	public int sizeZ() {
69
		return this.max.getZ() - this.min.getZ() + 1;
70
	}
71
72
	public BlockBox extend(final Direction direction, final int amount) {
73
		if (amount == 0) {
74
			return this;
75
		} else {
76
			return direction.getAxisDirection() == Direction.AxisDirection.POSITIVE
77
				? of(this.min, BlockPos.max(this.min, this.max.relative(direction, amount)))
78
				: of(BlockPos.min(this.min.relative(direction, amount), this.max), this.max);
79
		}
80
	}
81
82
	public BlockBox move(final Direction direction, final int amount) {
83
		return amount == 0 ? this : new BlockBox(this.min.relative(direction, amount), this.max.relative(direction, amount));
84
	}
85
86
	public BlockBox offset(final Vec3i offset) {
87
		return new BlockBox(this.min.offset(offset), this.max.offset(offset));
88
	}
89
}
90

Decompiled Minecraft 26.3 source of BlockBox (net/minecraft/core/BlockBox.java) with Mojang official mappings, stored verbatim on the site.