public static Side getSecondaryPlacementDirection(Vector3f direction, Vector3f normal) { Side surfaceDir = Side.inDirection(normal); Vector3f attachDir = surfaceDir.reverse().getVector3i().toVector3f(); Vector3f rawDirection = new Vector3f(direction); float dot = rawDirection.dot(attachDir); rawDirection.sub(new Vector3f(dot * attachDir.x, dot * attachDir.y, dot * attachDir.z)); return Side.inDirection(rawDirection.x, rawDirection.y, rawDirection.z).reverse(); }
@Test public void testSideInDirection() { for (Side side : Side.getAllSides()) { assertEquals(side, Side.inDirection(side.getVector3i().x, side.getVector3i().y, side.getVector3i().z)); } }
private Side determineAttachSide(Side facingDir, Side offsetDir, Vector3i bottomBlockPos, Vector3i topBlockPos) { Side attachSide = null; if (offsetDir.isHorizontal()) { if (canAttachTo(topBlockPos, offsetDir.reverse()) && canAttachTo(bottomBlockPos, offsetDir.reverse())) { attachSide = offsetDir.reverse(); } } if (attachSide == null) { Side clockwise = facingDir.yawClockwise(1); if (canAttachTo(topBlockPos, clockwise) && canAttachTo(bottomBlockPos, clockwise)) { attachSide = clockwise; } } if (attachSide == null) { Side anticlockwise = facingDir.yawClockwise(-1); if (canAttachTo(topBlockPos, anticlockwise) && canAttachTo(bottomBlockPos, anticlockwise)) { attachSide = anticlockwise; } } return attachSide; }
public Side getRelativeSide(Direction direction) { if (direction == Direction.UP) { return pitchClockwise(1); } else if (direction == Direction.DOWN) { return pitchClockwise(-1); } else if (direction == Direction.LEFT) { return yawClockwise(1); } else if (direction == Direction.RIGHT) { return yawClockwise(-1); } else if (direction == Direction.BACKWARD) { return reverse(); } else { return this; } }
private List<Chunk> listAdjacentChunks(Chunk chunk) { final Vector3i centerChunkPosition = chunk.getPosition(); List<Chunk> adjacentChunks = new ArrayList<>(6); for (Side side : Side.getAllSides()) { final Vector3i adjacentChunkPosition = side.getAdjacentPos(centerChunkPosition); final Chunk adjacentChunk = chunkCache.get(adjacentChunkPosition); if (adjacentChunk != null) { adjacentChunks.add(adjacentChunk); } } return adjacentChunks; }
Side facingDir = Side.inDirection(horizDir); if (!facingDir.isHorizontal()) { event.consume(); return; Side offsetDir = Side.inDirection(offset); primePos.add(offsetDir.getVector3i()); Block primeBlock = worldProvider.getBlock(primePos); if (!primeBlock.isReplacementAllowed()) { Side closedSide = facingDir.reverse(); if (closedSide == attachSide || closedSide.reverse() == attachSide) { closedSide = attachSide.yawClockwise(1); DoorComponent newDoorComp = newDoor.getComponent(DoorComponent.class); newDoorComp.closedSide = closedSide; newDoorComp.openSide = attachSide.reverse(); newDoorComp.isOpen = false; newDoor.saveComponent(newDoorComp);
/** * Propagates a value from a position out into all adjacent blocks. * <p> * If the value spreading into a block is larger than the current value there, set it and queue it for propagating again * If the value is smaller than the current value, do nothing * * @param pos The initial position * @param value The value to propagate */ private void push(Vector3i pos, byte value) { Block block = world.getBlockAt(pos); for (Side side : Side.getAllSides()) { byte propagatedValue = rules.propagateValue(value, side, block); if (rules.canSpreadOutOf(block, side)) { Vector3i adjPos = side.getAdjacentPos(pos); byte adjValue = world.getValueAt(adjPos); if (adjValue < propagatedValue && adjValue != PropagatorWorldView.UNAVAILABLE) { Block adjBlock = world.getBlockAt(adjPos); if (rules.canSpreadInto(adjBlock, side.reverse())) { increase(adjPos, propagatedValue); } } } } }
for (Side side : Side.getAllSides()) { Vector3i offset = side.getVector3i(); Block blockToCheck = view.getBlock(x + offset.x, y + offset.y, z + offset.z); adjacentBlocks.put(side, blockToCheck); for (Side side : Side.getAllSides()) { if (isSideVisibleForBlockTypes(adjacentBlocks.get(side), selfBlock, side)) { drawParts[side.ordinal()] = blockAppearance.getPart(BlockPart.fromSide(side)); for (Side side : Side.horizontalSides()) { Vector3i offset = side.getVector3i(); Block adjacentAbove = view.getBlock(x + offset.x, y + 1, z + offset.z); Block adjacent = adjacentBlocks.get(side); drawParts[side.ordinal()] = selfBlock.getTopLiquidMesh(side); for (Side side : Side.getAllSides()) { if (drawParts[side.ordinal()] != null) { drawParts[side.ordinal()] = selfBlock.getLowLiquidMesh(side); for (Side dir : Side.getAllSides()) { if (drawParts[dir.ordinal()] != null) { Vector4f colorOffset = selfBlock.calcColorOffsetFor(BlockPart.fromSide(dir), selfBiome); sideVertexFlag = ChunkVertexFlag.COLOR_MASK; drawParts[dir.ordinal()].appendTo(chunkMesh, x, y, z, colorOffset, renderType, sideVertexFlag);
public StandardBatchPropagator(PropagationRules rules, PropagatorWorldView world) { this.world = world; this.rules = rules; for (Side side : Side.getAllSides()) { Vector3i delta = new Vector3i(side.getVector3i()); if (delta.x < 0) { delta.x += ChunkConstants.SIZE_X; } else if (delta.x > 0) { delta.x -= ChunkConstants.SIZE_X; } if (delta.y < 0) { delta.y += ChunkConstants.SIZE_Y; } else if (delta.y > 0) { delta.y -= ChunkConstants.SIZE_Y; } if (delta.z < 0) { delta.z += ChunkConstants.SIZE_Z; } else if (delta.z > 0) { delta.z -= ChunkConstants.SIZE_Z; } chunkEdgeDeltas.put(side, delta); } increaseQueues = new Set[rules.getMaxValue()]; reduceQueues = new Set[rules.getMaxValue()]; for (int i = 0; i < rules.getMaxValue(); ++i) { increaseQueues[i] = Sets.newLinkedHashSet(); reduceQueues[i] = Sets.newLinkedHashSet(); } }
public ImmutableBlockLocation move(Side side) { final Vector3i directionVector = side.getVector3i(); return new ImmutableBlockLocation(x + directionVector.x, y + directionVector.y, z + directionVector.z); }
Side surfaceSide = Side.inDirection(event.getHitNormal()); Side secondaryDirection = ChunkMath.getSecondaryPlacementDirection(event.getDirection(), event.getHitNormal()); placementPos.add(surfaceSide.getVector3i());
private boolean hasSupportFromBlockOnSide(Vector3i blockPosition, Side side, Map<Vector3i, Block> blockOverrides) { final Vector3i sideBlockPosition = side.getAdjacentPos(blockPosition); if (!getWorldProvider().isBlockRelevant(sideBlockPosition)) { return true; } return getBlockWithOverrides(sideBlockPosition, blockOverrides).canAttachTo(side.reverse()); }
while (expectedValue > adjValue && adjValue != PropagatorWorldView.UNAVAILABLE && rules.canSpreadOutOf(lastBlock, side)) { lastBlock = adjChunk.getBlock(adjPos); if (rules.canSpreadInto(lastBlock, side.reverse())) { rules.setValue(adjChunk, adjPos, expectedValue); adjPos.add(side.getVector3i()); depth++; expectedValue--;
public Side rotate(Side side) { Side result = side; result = result.rollClockwise(roll.getIncrements()); result = result.pitchClockwise(pitch.getIncrements()); result = result.yawClockwise(yaw.getIncrements()); return result; }
@Override public boolean isSufficientlySupported(Vector3i location, Map<Vector3i, Block> blockOverrides) { final AttachSupportRequiredComponent component = getComponent(location, blockOverrides); if (component != null) { final Block block = getBlockWithOverrides(location, blockOverrides); for (Side side : Side.getAllSides()) { if (hasRequiredSupportOnSideForBlock(location, side, block)) { return true; } } return false; } return true; }
Block block = blockBuilder.constructSimpleBlock(definition, "top", new BlockUri(definition.getUrn(), new Name(Side.TOP.name())), this); block.setRotation(Rotation.rotate(Pitch.CLOCKWISE_270)); blockMap.put(Side.TOP, block); for (Rotation rot : Rotation.horizontalRotations()) { Side side = rot.rotate(Side.FRONT); blockMap.put(side, blockBuilder.constructTransformedBlock(definition, side.toString().toLowerCase(Locale.ENGLISH), rot, new BlockUri(definition.getUrn(), new Name(side.name())), this)); Block block = blockBuilder.constructSimpleBlock(definition, "bottom", new BlockUri(definition.getUrn(), new Name(Side.BOTTOM.name())), this); block.setRotation(Rotation.rotate(Pitch.CLOCKWISE_90)); blockMap.put(Side.BOTTOM, block); for (Side side : Side.getAllSides()) { Block block = blockMap.get(side); if (block != null) {
public Side getSide() { return Side.inDirection(impactNormal); } }
@Override public Block getBlockForPlacement(Vector3i location, Side attachmentSide, Side direction) { if (attachmentSide.isHorizontal()) { return blocks.get(attachmentSide); } if (direction != null) { return blocks.get(direction); } else { return blocks.get(Side.FRONT); } }
/** * Returns true if the side should be rendered adjacent to the second side provided. * * @param blockToCheck The block to check * @param currentBlock The current block * @return True if the side is visible for the given block types */ private boolean isSideVisibleForBlockTypes(Block blockToCheck, Block currentBlock, Side side) { // Liquids can be transparent but there should be no visible adjacent faces if (currentBlock.isLiquid() && blockToCheck.isLiquid()) { return false; } return currentBlock.isWaving() != blockToCheck.isWaving() || blockToCheck.getMeshGenerator() == null || !blockToCheck.isFullSide(side.reverse()) || (!currentBlock.isTranslucent() && blockToCheck.isTranslucent()); }
@Override public boolean isSufficientlySupported(Vector3i location, Map<Vector3i, Block> blockOverrides) { final Block block = getBlockWithOverrides(location, blockOverrides); if (block.isSupportRequired()) { final Vector3i bottomLocation = Side.BOTTOM.getAdjacentPos(location); return !getWorldProvider().isBlockRelevant(bottomLocation) || getBlockWithOverrides(bottomLocation, blockOverrides).isFullSide(Side.TOP); } return true; }