use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.
the class ItemVaultCTBehaviour method getUpDirection.
@Override
protected Direction getUpDirection(BlockAndTintGetter reader, BlockPos pos, BlockState state, Direction face) {
Axis vaultBlockAxis = ItemVaultBlock.getVaultBlockAxis(state);
boolean alongX = vaultBlockAxis == Axis.X;
if (face.getAxis().isVertical() && alongX)
return super.getUpDirection(reader, pos, state, face).getClockWise();
if (face.getAxis() == vaultBlockAxis || face.getAxis().isVertical())
return super.getUpDirection(reader, pos, state, face);
return Direction.fromAxisAndDirection(vaultBlockAxis, alongX ? AxisDirection.POSITIVE : AxisDirection.NEGATIVE);
}
use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.
the class ItemVaultConnectivityHandler method formVaults.
private static void formVaults(BlockEntityType<?> type, BlockGetter world, VaultSearchCache cache, List<ItemVaultTileEntity> frontier) {
PriorityQueue<Pair<Integer, ItemVaultTileEntity>> creationQueue = makeCreationQueue();
Set<BlockPos> visited = new HashSet<>();
int minY = Integer.MAX_VALUE;
for (ItemVaultTileEntity fluidTankTileEntity : frontier) {
BlockPos pos = fluidTankTileEntity.getBlockPos();
minY = Math.min(pos.getY(), minY);
}
minY -= 3;
while (!frontier.isEmpty()) {
ItemVaultTileEntity tank = frontier.remove(0);
BlockPos tankPos = tank.getBlockPos();
if (visited.contains(tankPos))
continue;
visited.add(tankPos);
int amount = tryToFormNewVault(tank, cache, true);
if (amount > 1)
creationQueue.add(Pair.of(amount, tank));
for (Axis axis : Iterate.axes) {
Direction d = Direction.fromAxisAndDirection(axis, AxisDirection.NEGATIVE);
BlockPos next = tankPos.relative(d);
if (next.getY() <= minY)
continue;
if (visited.contains(next))
continue;
ItemVaultTileEntity nextTank = vaultAt(type, world, next);
if (nextTank == null)
continue;
if (nextTank.isRemoved())
continue;
frontier.add(nextTank);
}
}
visited.clear();
while (!creationQueue.isEmpty()) {
Pair<Integer, ItemVaultTileEntity> next = creationQueue.poll();
ItemVaultTileEntity toCreate = next.getValue();
if (visited.contains(toCreate.getBlockPos()))
continue;
visited.add(toCreate.getBlockPos());
tryToFormNewVault(toCreate, cache, false);
}
}
use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.
the class ItemVaultItem method tryMultiPlace.
private void tryMultiPlace(BlockPlaceContext ctx) {
Player player = ctx.getPlayer();
if (player == null)
return;
if (player.isSteppingCarefully())
return;
Direction face = ctx.getClickedFace();
ItemStack stack = ctx.getItemInHand();
Level world = ctx.getLevel();
BlockPos pos = ctx.getClickedPos();
BlockPos placedOnPos = pos.relative(face.getOpposite());
BlockState placedOnState = world.getBlockState(placedOnPos);
if (!ItemVaultBlock.isVault(placedOnState))
return;
ItemVaultTileEntity tankAt = ItemVaultConnectivityHandler.vaultAt(AllTileEntities.ITEM_VAULT.get(), world, placedOnPos);
if (tankAt == null)
return;
ItemVaultTileEntity controllerTE = tankAt.getControllerTE();
if (controllerTE == null)
return;
int width = controllerTE.radius;
if (width == 1)
return;
int tanksToPlace = 0;
Axis vaultBlockAxis = ItemVaultBlock.getVaultBlockAxis(placedOnState);
if (vaultBlockAxis == null)
return;
if (face.getAxis() != vaultBlockAxis)
return;
Direction vaultFacing = Direction.fromAxisAndDirection(vaultBlockAxis, AxisDirection.POSITIVE);
BlockPos startPos = face == vaultFacing.getOpposite() ? controllerTE.getBlockPos().relative(vaultFacing.getOpposite()) : controllerTE.getBlockPos().relative(vaultFacing, controllerTE.length);
if (VecHelper.getCoordinate(startPos, vaultBlockAxis) != VecHelper.getCoordinate(pos, vaultBlockAxis))
return;
for (int xOffset = 0; xOffset < width; xOffset++) {
for (int zOffset = 0; zOffset < width; zOffset++) {
BlockPos offsetPos = vaultBlockAxis == Axis.X ? startPos.offset(0, xOffset, zOffset) : startPos.offset(xOffset, zOffset, 0);
BlockState blockState = world.getBlockState(offsetPos);
if (ItemVaultBlock.isVault(blockState))
continue;
if (!blockState.getMaterial().isReplaceable())
return;
tanksToPlace++;
}
}
if (!player.isCreative() && stack.getCount() < tanksToPlace)
return;
for (int xOffset = 0; xOffset < width; xOffset++) {
for (int zOffset = 0; zOffset < width; zOffset++) {
BlockPos offsetPos = vaultBlockAxis == Axis.X ? startPos.offset(0, xOffset, zOffset) : startPos.offset(xOffset, zOffset, 0);
BlockState blockState = world.getBlockState(offsetPos);
if (ItemVaultBlock.isVault(blockState))
continue;
BlockPlaceContext context = BlockPlaceContext.at(ctx, offsetPos, face);
player.getPersistentData().putBoolean("SilenceVaultSound", true);
super.place(context);
player.getPersistentData().remove("SilenceVaultSound");
}
}
}
use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.
the class ConnectedPillarBlock method updateColumn.
private BlockState updateColumn(Level level, BlockPos pos, BlockState state, boolean present) {
MutableBlockPos currentPos = new MutableBlockPos();
Axis axis = state.getValue(AXIS);
for (Direction connection : Iterate.directions) {
if (connection.getAxis() == axis)
continue;
boolean connect = true;
Move: for (Direction movement : Iterate.directionsInAxis(axis)) {
currentPos.set(pos);
for (int i = 0; i < 1000; i++) {
if (!level.isAreaLoaded(currentPos, 1))
break;
BlockState other1 = currentPos.equals(pos) ? state : level.getBlockState(currentPos);
BlockState other2 = level.getBlockState(currentPos.relative(connection));
boolean col1 = canConnect(state, other1);
boolean col2 = canConnect(state, other2);
currentPos.move(movement);
if (!col1 && !col2)
break;
if (col1 && col2)
continue;
connect = false;
break Move;
}
}
state = setConnection(state, connection, connect);
}
return state;
}
use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.
the class AABBOutline method renderFace.
protected void renderFace(PoseStack ms, SuperRenderTypeBuffer buffer, Direction direction, Vec3 p1, Vec3 p2, Vec3 p3, Vec3 p4, boolean noCull) {
if (!params.faceTexture.isPresent())
return;
ResourceLocation faceTexture = params.faceTexture.get().getLocation();
float alphaBefore = params.alpha;
params.alpha = (direction == params.getHighlightedFace() && params.hightlightedFaceTexture.isPresent()) ? 1 : 0.5f;
RenderType translucentType = RenderTypes.getOutlineTranslucent(faceTexture, !noCull);
VertexConsumer builder = buffer.getLateBuffer(translucentType);
Axis axis = direction.getAxis();
Vec3 uDiff = p2.subtract(p1);
Vec3 vDiff = p4.subtract(p1);
float maxU = (float) Math.abs(axis == Axis.X ? uDiff.z : uDiff.x);
float maxV = (float) Math.abs(axis == Axis.Y ? vDiff.z : vDiff.y);
putQuadUV(ms, builder, p1, p2, p3, p4, 0, 0, maxU, maxV, Direction.UP);
params.alpha = alphaBefore;
}
Aggregations