Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,35 @@

public class SparseMultiblock extends AbstractMultiblock {
private final Map<BlockPos, IStateMatcher> data;
private final Map<BlockPos, IStateMatcher> bookData;
private final Vec3i size;

public SparseMultiblock(Map<BlockPos, IStateMatcher> data) {
Preconditions.checkArgument(!data.isEmpty(), "No data given to sparse multiblock!");
this.data = ImmutableMap.copyOf(data);
this.size = calculateSize();
}

@Override
public Vec3i getSize() {
return size;
}

private Vec3i calculateSize() {
int minX = data.keySet().stream().mapToInt(BlockPos::getX).min().getAsInt();
int maxX = data.keySet().stream().mapToInt(BlockPos::getX).max().getAsInt();
int minY = data.keySet().stream().mapToInt(BlockPos::getY).min().getAsInt();
int maxY = data.keySet().stream().mapToInt(BlockPos::getY).max().getAsInt();
int minZ = data.keySet().stream().mapToInt(BlockPos::getZ).min().getAsInt();
int maxZ = data.keySet().stream().mapToInt(BlockPos::getZ).max().getAsInt();
return new Vec3i(maxX - minX + 1, maxY - minY + 1, maxZ - minZ + 1);
this.size = new Vec3i(maxX - minX + 1, maxY - minY + 1, maxZ - minZ + 1);

ImmutableMap.Builder<BlockPos, IStateMatcher> builder = ImmutableMap.builder();
data.forEach((pos, matcher) -> builder.put(pos.offset(-minX, -minY, -minZ), matcher));
bookData = builder.build();
}

@Override
public Vec3i getSize() {
return size;
}

@Override
public BlockState getBlockState(BlockPos pos) {
long ticks = world != null ? world.getGameTime() : 0L;
return data.getOrDefault(pos, StateMatcher.AIR).getDisplayedState(ticks);
return bookData.getOrDefault(pos, StateMatcher.AIR).getDisplayedState(ticks);
}

@Override
Expand Down