int k;
// Go member by member, starting at the tail, ending at the head
for (int i = 0; i < owner.size() - 1; i++) {
MinecartMember<?> member = owner.get(i);
MinecartMember<?> toMember = owner.get(i + 1);
IntVector3 from = member.getBlockPos();
IntVector3 to = toMember.getBlockPos();
IntVector3 diff = to.subtract(from);
// Map the member to blocks in between, except 'to'
blockSpace.put(from, member);
if (!member.isOnSlope()) {
if (diff.x == 0 && diff.z == 0) {
// Along y-axis
for (k = 1; k < diff.y; k++) {
blockSpace.put(from.add(0, k, 0), member);
}
for (k = -1; k > diff.y; k--) {
blockSpace.put(from.add(0, k, 0), member);
}
continue;
} else if (diff.y == 0 && diff.x == 0) {
// Along z-axis
for (k = 1; k < diff.z; k++) {
blockSpace.put(from.add(0, 0, k), member);
}
for (k = -1; k > diff.z; k--) {
blockSpace.put(from.add(0, 0, k), member);
}
continue;
} else if (diff.y == 0 && diff.z == 0) {
// Along x-axis
for (k = 1; k < diff.x; k++) {
blockSpace.put(from.add(k, 0, 0), member);
}
for (k = -1; k > diff.x; k--) {
blockSpace.put(from.add(k, 0, 0), member);
}
continue;
}
}
// Curve or other logic - use a Block Iterator for this
TrackIterator iter = toMember.getRailTracker().getTrackIterator();
if (iter.hasNext()) {
// Skip the first block
iter.next();
// Go and find the other blocks
final int maxLength = Math.abs(diff.x) + Math.abs(diff.y) + Math.abs(diff.z);
for (k = 0; k < maxLength && iter.hasNext(); k++) {
final Block block = iter.next();
if (from.x == block.getX() && from.y == block.getY() && from.z == block.getZ()) {
// Found the end block
break;
}
// Put the member
blockSpace.put(new IntVector3(block), member);
}
}
}
blockSpace.put(owner.tail().getBlockPos(), owner.tail());
}
// First clear the live active sign buffer of all members
for (MinecartMember<?> member : owner) {
member.getBlockTracker().liveActiveSigns.clear();
}
// Add all active signs to the block tracker of all members
World world = owner.getWorld();
for (Entry<IntVector3, MinecartMember<?>> entry : blockSpace.entrySet()) {
IntVector3 pos = entry.getKey();
for (RailType type : RailType.values()) {
if (type.isRail(world, pos.x, pos.y, pos.z)) {
Block block = pos.toBlock(world);
List<Block> signs = entry.getValue().getBlockTracker().liveActiveSigns;
Util.addSignsFromRails(signs, block, type.getSignColumnDirection(block));
}
}
}