public StructureInfo(int length, int height, int width, BlockData[] blockData) { this.structureWidth = width; this.structureHeight = height; this.structureLength = length; IBlockState[][][] states = new IBlockState[height][length][width]; for(int y = 0; y < height; y++) { for(int x = 0; x < length; x++) { for(int z = 0; z < width; z++) { for(BlockData data : blockData) { if(inside(x, y, z, data.pos, data.endPos)) { states[y][x][z] = convert(data); break; } } } } } data = states; maxBlockIndex = blockIndex = structureHeight * structureLength * structureWidth; }
public boolean canStep() { int index = blockIndex; do { if(++index >= maxBlockIndex) { return false; } } while(isEmpty(index)); return true; }
if(structureData.canStep() || ++fullStructureSteps >= 5) { structureData.step(); fullStructureSteps = 0; structureData.reset(); structureData.setShowLayer(9);
if(z >= 0 && z < structure[y][x].length) { int index = y * (data.structureLength * data.structureWidth) + x * data.structureWidth + z; if(index <= data.getLimiter()) { return structure[y][x][z] != null ? structure[y][x][z] : Blocks.AIR.getDefaultState();
private IBlockState convert(BlockData data) { Block block = Block.getBlockFromName(data.block); if(block == null) { return Blocks.AIR.getDefaultState(); } IBlockState state; if(data.state == null || data.state.isEmpty()) { state = block.getStateFromMeta(data.meta); } else { state = block.getDefaultState(); for(Map.Entry<String, String> entry : data.state.entrySet()) { Optional<IProperty<?>> property = state.getPropertyKeys().stream().filter(iProperty -> entry.getKey().equals(iProperty.getName())).findFirst(); if(property.isPresent()) { state = setProperty(state, property.get(), entry.getValue()); } } } return state; }
public void init(int[] size, BlockData[] data) { int yOff = 0; structureData = new StructureInfo(size[0], size[1], size[2], data); blockAccess = new StructureBlockAccess(structureData);
public void step() { int start = blockIndex; do { if(++blockIndex >= maxBlockIndex) { blockIndex = 0; } } while(isEmpty(blockIndex) && blockIndex != start); }