public Vector3i getAdjacentPos(Vector3i position) { Vector3i result = new Vector3i(position); result.add(vector3iDir); return result; }
/** * @param offset * @return A copy of the region offset by the given value */ public Region3i move(BaseVector3i offset) { Vector3i newMin = min(); newMin.add(offset); return Region3i.createFromMinAndSize(newMin, size); }
/** * @return The largest vector in the region */ public Vector3i max() { Vector3i max = new Vector3i(min); max.add(size); max.sub(1, 1, 1); return max; }
public static Region3i getChunkRegionAroundWorldPos(Vector3i pos, int extent) { Vector3i minPos = new Vector3i(-extent, -extent, -extent); minPos.add(pos); Vector3i maxPos = new Vector3i(extent, extent, extent); maxPos.add(pos); Vector3i minChunk = calcChunkPos(minPos); Vector3i maxChunk = calcChunkPos(maxPos); return Region3i.createFromMinMax(minChunk, maxChunk); }
public Region3i expand(BaseVector3i amount) { Vector3i expandedMin = min(); expandedMin.sub(amount); Vector3i expandedMax = max(); expandedMax.add(amount); return createFromMinMax(expandedMin, expandedMax); }
private boolean canAttachTo(Vector3i doorPos, Side side) { Vector3i adjacentBlockPos = new Vector3i(doorPos); adjacentBlockPos.add(side.getVector3i()); Block adjacentBlock = worldProvider.getBlock(adjacentBlockPos); return adjacentBlock.isAttachmentAllowed(); }
/** * Creates a new region that is the same as this region but expanded in all directions by the given amount * * @param amount * @return A new region */ public Region3i expand(int amount) { Vector3i expandedMin = min(); expandedMin.sub(amount, amount, amount); Vector3i expandedMax = max(); expandedMax.add(amount, amount, amount); return createFromMinMax(expandedMin, expandedMax); }
@Test public void testAdd() { Vector3i v = new Vector3i(v1); v.add(v2); assertEquals(v3, v); }
@Test public void testAddTriple() { Vector3i v = new Vector3i(v1); v.add(v2.x, v2.y, v2.z); assertEquals(v3, v); }
private void checkBlockEntry(EntityRef entity, Vector3i oldPosition, Vector3i newPosition, float characterHeight) { // TODO: This will only work for tall mobs/players and single block mobs // is this a different position than previously if (!oldPosition.equals(newPosition)) { Biome oldBiome = worldProvider.getBiome(oldPosition); Biome newBiome = worldProvider.getBiome(newPosition); if (oldBiome != newBiome) { entity.send(new OnEnterBiomeEvent(oldPosition, newPosition, oldBiome, newBiome)); } // get the old position's blocks Block[] oldBlocks = new Block[(int) Math.ceil(characterHeight)]; Vector3i currentPosition = new Vector3i(oldPosition); for (int currentHeight = 0; currentHeight < oldBlocks.length; currentHeight++) { oldBlocks[currentHeight] = worldProvider.getBlock(currentPosition); currentPosition.add(0, 1, 0); } // get the new position's blocks Block[] newBlocks = new Block[(int) Math.ceil(characterHeight)]; currentPosition = new Vector3i(newPosition); for (int currentHeight = 0; currentHeight < characterHeight; currentHeight++) { newBlocks[currentHeight] = worldProvider.getBlock(currentPosition); currentPosition.add(0, 1, 0); } for (int i = 0; i < characterHeight; i++) { // send a block enter/leave event for this character entity.send(new OnEnterBlockEvent(oldBlocks[i], newBlocks[i], new Vector3i(0, i, 0))); } } }
/** * find a spot above the surface that is big enough for this character * @param spawnPos the position to check * @param height the height of the entity to spawn * @return the topmost solid block <code>null</code> if none was found */ private Vector3i findOpenVerticalPosition(Vector3i spawnPos, float height) { int consecutiveAirBlocks = 0; Vector3i newSpawnPos = new Vector3i(spawnPos); // TODO: also start looking downwards if initial spawn pos is in the air for (int i = 1; i < 20; i++) { if (worldProvider.isBlockRelevant(newSpawnPos)) { if (worldProvider.getBlock(newSpawnPos).isPenetrable()) { consecutiveAirBlocks++; } else { consecutiveAirBlocks = 0; } if (consecutiveAirBlocks >= height) { newSpawnPos.subY(consecutiveAirBlocks); return newSpawnPos; } newSpawnPos.add(0, 1, 0); } } return null; } }
@Override public void setDirtyAround(Region3i region) { Vector3i minPos = new Vector3i(region.min()); minPos.sub(1, 1, 1); Vector3i maxPos = new Vector3i(region.max()); maxPos.add(1, 1, 1); Vector3i minChunk = ChunkMath.calcChunkPos(minPos, chunkPower); Vector3i maxChunk = ChunkMath.calcChunkPos(maxPos, chunkPower); for (Vector3i pos : Region3i.createFromMinMax(minChunk, maxChunk)) { chunks[pos.x + offset.x + chunkRegion.size().x * (pos.z + offset.z)].setDirty(true); } }
private void processUpdateForBlockLocation(Vector3i blockLocation) { for (Side side : Side.getAllSides()) { Vector3i neighborLocation = new Vector3i(blockLocation); neighborLocation.add(side.getVector3i()); if (worldProvider.isBlockRelevant(neighborLocation)) { Block neighborBlock = worldProvider.getBlock(neighborLocation); final BlockFamily blockFamily = neighborBlock.getBlockFamily(); if (blockFamily instanceof UpdatesWithNeighboursFamily) { UpdatesWithNeighboursFamily neighboursFamily = (UpdatesWithNeighboursFamily) blockFamily; Block neighborBlockAfterUpdate = neighboursFamily.getBlockForNeighborUpdate(neighborLocation, neighborBlock); if (neighborBlock != neighborBlockAfterUpdate) { worldProvider.setBlock(neighborLocation, neighborBlockAfterUpdate); } } } } }
private void renderOverlayForOneBlockSelection(BlockSelectionComponent blockSelectionComponent, BlockSelectionRenderer selectionRenderer) { selectionRenderer.beginRenderOverlay(); if (blockSelectionComponent.currentSelection == null) { if (blockSelectionComponent.startPosition != null) { selectionRenderer.renderMark(blockSelectionComponent.startPosition); } } else { Vector3i size = blockSelectionComponent.currentSelection.size(); Vector3i block = new Vector3i(); for (int z = 0; z < size.z; z++) { for (int y = 0; y < size.y; y++) { for (int x = 0; x < size.x; x++) { block.set(x, y, z); block.add(blockSelectionComponent.currentSelection.min()); selectionRenderer.renderMark(block); } } } } selectionRenderer.endRenderOverlay(); }
primePos.add(offsetDir.getVector3i()); Block primeBlock = worldProvider.getBlock(primePos); if (!primeBlock.isReplacementAllowed()) {
placementPos.add(surfaceSide.getVector3i());