Space Select Module >=26.1
The package dev.anvilcraft.lib.v2.space_select provides a visual space selection system. Items implementing the SpaceSelectItem interface allow players to define cubic regions in the world, with support for expand/contract/move/scroll-scale operations. Selection state is stored server-side and rendered as wireframes on the client.
Architecture Overview
- Data Layer —
Districtrecords the start and end positions of a selection - Server Management —
DistrictManagermaintains selections keyed byDistrictKey(slot, offhand, item) - Client Management —
ClientDistrictManager(AnvilLibSpaceSelectClient.MANAGER) tracks selection process and render data - Item Layer —
SpaceSelectIteminterface implements selection logic (select/cancel/onCreateDistrict) - Network Layer —
SpaceSelectPayload(IServerboundPacket) client→server submits selections - Rendering Layer —
DistrictRendererdraws selection wireframes,SpaceSelectScrollHandlerhandles scroll zoom - Event Layer —
PlayerCreateDistrictEventtriggers on server when a district is created
Data Flow
Player right-clicks selection tool
→ SpaceSelectItem.select(player, pos)
→ ClientDistrictManager.startSelect / endSelect
→ SpaceSelectPayload (C→S, IServerboundPacket)
→ PlayerCreateDistrictEvent
→ Business logic processes the selectionCore API
District
Selection record defined by start/end MutableBlockPos.
District district = District.create(pos1, pos2);
boolean inside = district.contains(x, y, z);| Method | Description |
|---|---|
create(BlockPos, BlockPos) | Create district with auto min/max normalization |
expand(Direction, int) | Expand in the given direction |
contraction(Direction, int) | Contract from the given direction |
move(Direction, int) | Move the entire district |
scaleOnAxis(Axis, scrollAmount, playerPos, boundingBox, lookAngle) | Scale based on player position and view |
getPrimaryAxis(Vec3 lookAngle) | Determine primary axis from view angle |
contains(double, double, double) | Point containment check |
shape() | Returns the district VoxelShape |
color() | Random semi-transparent color based on hashCode |
DistrictManager
Server-side selection storage, indexed by DistrictKey.
DistrictManager.DistrictKey key = new DistrictManager.DistrictKey(
slot, // inventory slot (-1 for offhand)
offhand, // whether in offhand
item // the item used
);
manager.select(key, district);
manager.clear(key);SpaceSelectItem
Interface for items. Default logic: right-click tracks selection through AnvilLibSpaceSelectClient.MANAGER ( startSelect→endSelect), sending SpaceSelectPayload on completion.
public class MySelectTool extends Item implements SpaceSelectItem {
@Override
public void onCreateDistrict(Player player, ItemStack stack,
BlockPos start, BlockPos end) { }
}Network Packet
SpaceSelectPayload is IServerboundPacket (client→server), carrying offhand, start, end. Server posts PlayerCreateDistrictEvent on receipt.
Dependency
dependencies {
implementation "dev.anvilcraft.lib:anvillib-space-select-neoforge-26.1:2.0.0"
}Notes
SpaceSelectPayloadis serverbound (IServerboundPacket), sent from client to server- Districts are keyed by
(slot, offhand, item)triple — different slots/items have independent selections District.start/endareMutableBlockPosfor in-place modification- District color is a random semi-transparent color derived from
District.hashCode() - Depends on
module.registrumandmodule.network - Client rendering via
DistrictRendereratRenderLevelStageEvent.AfterTranslucentParticles